فهرست منبع

WIP fixing W3C TTL tests.

scossu 1 هفته پیش
والد
کامیت
9df20a2594
5فایلهای تغییر یافته به همراه63 افزوده شده و 6 حذف شده
  1. 2 1
      include/volksdata/codec/parser_common.h
  2. 3 3
      src/codec/lexer_nt.re
  3. 2 0
      src/codec/lexer_ttl.re
  4. 54 0
      test/test_codec_nt.c
  5. 2 2
      test/test_codec_ttl.c

+ 2 - 1
include/volksdata/codec/parser_common.h

@@ -90,6 +90,7 @@ static void parse_init (ParseIterator *it, FILE *fh, const char *sh)
         it->buf = malloc(it->buf_size);
         if (!it->buf) log_error ("Error allocating lexer buffer.");
         it->cur = it->mar = it->tok = it->lim = it->buf + it->buf_size - 1;
+        it->bol = it->buf;
         it->eof = 0;
     } else {
         // String handling. Uses the provided string as the buffer.
@@ -102,10 +103,10 @@ static void parse_init (ParseIterator *it, FILE *fh, const char *sh)
         it->buf = NULL;
         it->cur = it->tok = (YYCTYPE*)it->sh;
         it->lim = it->mar = it->cur + it->buf_size - 1;
+        it->bol = it->cur;
         it->eof = 1;
     }
     it->line = 1;
-    it->bol = it->buf;
     it->ct = 0;
     /*!stags:re2c format = "it->@@ = NULL; "; */
 

+ 3 - 3
src/codec/lexer_nt.re

@@ -195,7 +195,7 @@ loop:
         *term = VOLK_iriref_new ((char*)data);
         free (data);
 
-        if (!UNLIKELY (term)) return -1;
+        if (UNLIKELY (!term)) return -1;
         return T_IRIREF;
     }
 
@@ -236,7 +236,7 @@ loop:
         free (data);
         free (metadata);
 
-        if (!UNLIKELY (term)) return -1;
+        if (UNLIKELY (!term)) return -1;
         return T_LITERAL;
     }
 
@@ -248,7 +248,7 @@ loop:
         *term = VOLK_term_new (VOLK_TERM_BNODE, (char*)data, NULL);
         free (data);
 
-        if (!UNLIKELY (term)) return -1;
+        if (UNLIKELY (!term)) return -1;
         return T_BNODE;
     }
 

+ 2 - 0
src/codec/lexer_ttl.re

@@ -231,6 +231,8 @@ loop: // Start new token.
         return T_IRIREF;
     }
 
+    '[' WS? ']' { return T_EMPTY_BNODE; }
+
     '@prefix' WS @pfx (PSTART_CHAR NAME_CHAR*)? ":" {
         *token_p = uint8_ndup (pfx, YYCURSOR - pfx - 1);
         LOG_TRACE("Prefix declaration: '%s'", *token_p);

+ 54 - 0
test/test_codec_nt.c

@@ -1,3 +1,5 @@
+#include <unistd.h>
+
 #include "volksdata/codec/codec_nt.h"
 #include "test.h"
 
@@ -247,6 +249,56 @@ test_decode_nt_graph()
 }
 
 
+int
+test_decode_nt_file()
+{
+    VOLK_Graph *gr;
+    size_t ct;
+    char *err;
+    FILE *fh = fopen ("test/assets/test2.nt", "r");
+
+    EXPECT_PASS (codec.decode_graph (fh, NULL, &gr, &ct, &err));
+
+    EXPECT_INT_EQ (VOLK_graph_size (gr), 7);
+    EXPECT_INT_EQ (ct, 8);
+
+    VOLK_graph_free (gr);
+    fclose(fh);
+
+    return 0;
+}
+
+
+#define LARGE_LIT_SIZE CHUNK_SIZE * 2 + 1  // More than 2  buffer pages.
+int
+test_decode_large_lit_file()
+{
+    VOLK_Graph *gr;
+    size_t ct;
+    char *err;
+    const char *fpath = "/tmp/test_large_lit.nt";
+    FILE *fh = fopen (fpath, "w");
+
+    fprintf (fh, "<urn:s:1> <urn:p:1> \"");
+    for (unsigned i = 0; i < LARGE_LIT_SIZE; i++)
+        fputc (rand() % 25 + 65, fh);  // A-Z
+    fprintf(fh, "\" .\n");
+    fclose(fh);
+
+    fh = fopen (fpath, "r");
+    EXPECT_PASS (codec.decode_graph (fh, NULL, &gr, &ct, &err));
+
+    EXPECT_INT_EQ (VOLK_graph_size (gr), 1);
+    EXPECT_INT_EQ (ct, 1);
+
+    VOLK_graph_free (gr);
+    fclose(fh);
+    unlink (fpath);
+
+    return 0;
+}
+
+
 int
 test_decode_nt_bad_graph()
 {
@@ -281,6 +333,8 @@ int codec_nt_tests()
     RUN (test_encode_nt_graph);
     RUN (test_decode_nt_term);
     RUN (test_decode_nt_graph);
+    RUN (test_decode_nt_file);
+    //RUN (test_decode_large_lit_file);  // FIXME large literals still not working.
     RUN (test_decode_nt_bad_graph);
 
     free_terms (terms);

+ 2 - 2
test/test_codec_ttl.c

@@ -126,8 +126,8 @@ int codec_ttl_tests()
     RUN (test_decode_nt_bad_graph);
     // TODO temporarily disabled; full W3C test suite at
     // https://w3c.github.io/rdf-tests/rdf/ shall replace these.
-    //RUN (test_w3c_pos);
-    //RUN (test_w3c_neg);
+    RUN (test_w3c_pos);
+    RUN (test_w3c_neg);
 
     free_terms(terms);
     for (int i = 0; i < TRP_CT; i++)