Commit 960ab2e8dd9731a07483803d907bc2eb3df9e8a3

Thomas de Grivel 2022-11-10T20:34:30

facts_with_test

diff --git a/libc3/tag.c b/libc3/tag.c
index bdddfc0..37e6dd3 100644
--- a/libc3/tag.c
+++ b/libc3/tag.c
@@ -256,7 +256,10 @@ t_hash_context * tag_hash_update (t_hash_context *context,
   case TAG_U16: u16_hash_update(context, tag->data.u16);          break;
   case TAG_U32: u32_hash_update(context, tag->data.u32);          break;
   case TAG_U64: u64_hash_update(context, tag->data.u64);          break;
-  case TAG_VAR: errx(1, "var hash update");                 return NULL;
+  case TAG_VAR:
+    assert(! "var hash update");
+    errx(1, "var hash update");
+    return NULL;
   }
   return context;
 }
@@ -628,7 +631,8 @@ e_bool tag_is_number (const s_tag *tag)
 e_bool tag_is_var (const s_tag *tag)
 {
   return (tag &&
-          tag->type.type == TAG_VAR);
+          tag->type.type == TAG_VAR &&
+          tag->data.var == NULL);
 }
 
 s_tag * tag_list (s_tag *tag, s_list *x)
diff --git a/test/facts_with_test.c b/test/facts_with_test.c
index 398bd23..1dbbf21 100644
--- a/test/facts_with_test.c
+++ b/test/facts_with_test.c
@@ -66,8 +66,8 @@ void facts_with_test_ ()
   FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
   fact_init(&fact, tag + 6, tag + 7, tag + 2);
   FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
   facts_with_cursor_clean(&cursor);
   facts_with(&facts, &cursor, (s_tag *[]) { tag,
                                             tag_init_var(&predicate),
@@ -79,8 +79,8 @@ void facts_with_test_ ()
   FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
   fact_init(&fact, tag, tag + 4, tag + 3);
   FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
   facts_with_cursor_clean(&cursor);
   facts_with(&facts, &cursor, (s_tag *[]) { tag,
                                             tag + 1,
@@ -90,15 +90,15 @@ void facts_with_test_ ()
   FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
   fact_init(&fact, tag, tag + 1, tag + 3);
   FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
   facts_with_cursor_clean(&cursor);
   facts_with(&facts, &cursor, (s_tag *[]) { tag, tag + 1, tag + 2,
                                             NULL, NULL });
   fact_init(&fact, tag, tag + 1, tag + 2);
   FACT_TEST_EQ(&fact, facts_with_cursor_next(&cursor));
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
   facts_with_cursor_clean(&cursor);
   facts_with(&facts, &cursor, (s_tag *[]) { tag_init_var(&subject),
                                             tag_init_var(&predicate),
@@ -113,27 +113,23 @@ void facts_with_test_ ()
   TAG_TEST_EQ(predicate.data.var, tag + 1);
   TAG_TEST_EQ(object.data.var, tag + 2);
   TEST_ASSERT(facts_with_cursor_next(&cursor));
-  TAG_TEST_EQ(subject.data.var, tag + 5);
-  TAG_TEST_EQ(predicate.data.var, tag + 1);
-  TAG_TEST_EQ(object.data.var, tag + 2);
-  TEST_ASSERT(facts_with_cursor_next(&cursor));
   TAG_TEST_EQ(subject.data.var, tag);
   TAG_TEST_EQ(predicate.data.var, tag + 1);
   TAG_TEST_EQ(object.data.var, tag + 3);
   TEST_ASSERT(facts_with_cursor_next(&cursor));
-  TAG_TEST_EQ(subject.data.var, tag);
-  TAG_TEST_EQ(predicate.data.var, tag + 4);
-  TAG_TEST_EQ(object.data.var, tag + 3);
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
+  TAG_TEST_EQ(subject.data.var, tag + 5);
+  TAG_TEST_EQ(predicate.data.var, tag + 1);
+  TAG_TEST_EQ(object.data.var, tag + 2);
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
   facts_with_cursor_clean(&cursor);
   facts_with(&facts, &cursor, (s_tag *[]) { tag + 3, tag, tag + 1,
                                                      tag, tag + 2,
                                                      NULL,
                                             tag + 4, tag + 1, tag + 2,
                                             NULL, NULL });
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
   facts_with_cursor_clean(&cursor);
   facts_with(&facts, &cursor, (s_tag *[]) { tag_init_var(&subject),
                                             tag_init_var(&predicate),
@@ -144,8 +140,8 @@ void facts_with_test_ ()
                                                      NULL,
                                             tag + 4, tag + 1, tag + 2,
                                             NULL, NULL });
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
   facts_with_cursor_clean(&cursor);
   facts_with(&facts, &cursor, (s_tag *[]) { tag_init_var(&subject),
                                             tag_init_var(&predicate),
@@ -156,8 +152,8 @@ void facts_with_test_ ()
                                                  NULL,
                                             tag + 4, tag + 1, tag + 2,
                                             NULL, NULL });
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
-  TEST_EQ(facts_with_cursor_next(&cursor), NULL);
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
+  TEST_ASSERT(! facts_with_cursor_next(&cursor));
   facts_with_cursor_clean(&cursor);
   facts_clean(&facts);
 }