aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2021-02-25 11:16:13 -0500
committerDavid Robillard <d@drobilla.net>2022-01-14 19:37:51 -0500
commit4436f80225c441a878c4baf856d21dee0394c8dc (patch)
tree707757fd8544595a8c6fa423c72e7a5fe5c2d6be /test
parent17003e707a3368a029dd8c0e7bdf98979f691daf (diff)
downloadserd-4436f80225c441a878c4baf856d21dee0394c8dc.tar.gz
serd-4436f80225c441a878c4baf856d21dee0394c8dc.tar.bz2
serd-4436f80225c441a878c4baf856d21dee0394c8dc.zip
Leave statement caret at the start of literals
This allows a precise location to be reported for errors within literals, by adding the offset of the error in the literal to the caret. This will be used to report nice errors for things like regular expressions and supported XSD datatypes.
Diffstat (limited to 'test')
-rw-r--r--test/test_reader.c50
1 files changed, 50 insertions, 0 deletions
diff --git a/test/test_reader.c b/test/test_reader.c
index 3651e014..32b475f9 100644
--- a/test/test_reader.c
+++ b/test/test_reader.c
@@ -368,6 +368,55 @@ test_read_empty(void)
serd_world_free(world);
}
+static SerdStatus
+check_cursor(void* handle, const SerdEvent* event)
+{
+ bool* const called = (bool*)handle;
+
+ if (event->type == SERD_STATEMENT) {
+ const SerdCaret* const caret =
+ serd_statement_caret(event->statement.statement);
+ assert(caret);
+
+ assert(!strcmp(serd_node_string(serd_caret_name(caret)), "string"));
+ assert(serd_caret_line(caret) == 1);
+ assert(serd_caret_column(caret) == 47);
+ }
+
+ *called = true;
+ return SERD_SUCCESS;
+}
+
+static void
+test_error_cursor(void)
+{
+ SerdWorld* world = serd_world_new();
+ bool called = false;
+ SerdSink* sink = serd_sink_new(&called, check_cursor, NULL);
+ SerdEnv* const env = serd_env_new(SERD_EMPTY_STRING());
+ SerdReader* const reader =
+ serd_reader_new(world, SERD_TURTLE, 0, env, sink, 4096);
+
+ assert(sink);
+ assert(reader);
+
+ SerdByteSource* byte_source =
+ serd_byte_source_new_string("<http://example.org/s> <http://example.org/p> "
+ "<http://example.org/o> .",
+ NULL);
+
+ SerdStatus st = serd_reader_start(reader, byte_source);
+ assert(!st);
+ assert(serd_reader_read_document(reader) == SERD_SUCCESS);
+ assert(called);
+
+ serd_byte_source_free(byte_source);
+ serd_reader_free(reader);
+ serd_env_free(env);
+ serd_sink_free(sink);
+ serd_world_free(world);
+}
+
int
main(void)
{
@@ -377,5 +426,6 @@ main(void)
test_read_eof_by_byte();
test_read_chunks();
test_read_empty();
+ test_error_cursor();
return 0;
}