Hash :
f990b98e
Author :
Thomas de Grivel
Date :
2022-12-06T13:37:43
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93
/* c3
* Copyright 2022 kmx.io <contact@kmx.io>
*
* Permission is hereby granted to use this software excepted
* on Apple computers granted the above copyright notice and
* this permission paragraph are included in all copies and
* substantial portions of this software.
*
* THIS SOFTWARE IS PROVIDED "AS-IS" WITHOUT ANY GUARANTEE OF
* PURPOSE AND PERFORMANCE. IN NO EVENT WHATSOEVER SHALL THE
* AUTHOR BE CONSIDERED LIABLE FOR THE USE AND PERFORMANCE OF
* THIS SOFTWARE.
*/
#include <string.h>
#include "../libc3/fact.h"
#include "../libc3/str.h"
#include "fact_test.h"
#include "test.h"
#define FACT_TEST_INSPECT(test, expected) \
do { \
s_str str; \
TEST_EQ(fact_inspect(test, &str), &str); \
TEST_EQ(str.size, strlen(expected)); \
if (g_test_last_ok) \
TEST_STRNCMP(str.ptr.p, (expected), str.size); \
str_clean(&str); \
} while (0)
void fact_test ();
void fact_test_init ();
void fact_test_inspect ();
void fact_test ()
{
fact_test_init();
fact_test_inspect();
}
void fact_test_clean_1 (s_fact *fact)
{
assert(fact);
tag_delete((s_tag *) fact->subject);
}
void fact_test_clean_3 (s_fact *fact)
{
assert(fact);
tag_delete((s_tag *) fact->subject);
tag_delete((s_tag *) fact->predicate);
tag_delete((s_tag *) fact->object);
}
void fact_test_init ()
{
s_tag sym[3];
s_fact fact;
tag_init_sym_1(sym, "A");
tag_init_sym_1(sym + 1, "B");
tag_init_sym_1(sym + 2, "C");
TEST_EQ(fact_init(&fact, sym, sym + 1, sym + 2), &fact);
TEST_EQ(fact.subject, sym);
TEST_EQ(fact.predicate, sym + 1);
TEST_EQ(fact.object, sym + 2);
}
s_fact * fact_test_init_1 (s_fact *fact, const s8 *tag)
{
assert(fact);
fact->subject = fact->predicate = fact->object = tag_new_1(tag);
return fact;
}
s_fact * fact_test_init_3 (s_fact *fact, const s8 *subject,
const s8 *predicate, const s8 *object)
{
assert(fact);
fact->subject = tag_new_1(subject);
fact->predicate = tag_new_1(predicate);
fact->object = tag_new_1(object);
return fact;
}
void fact_test_inspect ()
{
s_tag tag[3];
s_fact fact;
tag_init_1(tag, "A");
tag_init_1(tag + 1, "B");
tag_init_1(tag + 2, "C");
fact_init(&fact, tag, tag + 1, tag + 2);
FACT_TEST_INSPECT(&fact, "{A, B, C}");
}