aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDavid Robillard <d@drobilla.net>2013-03-03 04:53:59 +0000
committerDavid Robillard <d@drobilla.net>2013-03-03 04:53:59 +0000
commit1d32c6e37bb4409719d6170c4b0e45cd3557df9a (patch)
tree19e607e681f18715d5c6b9c55dab48ee4e4aecf8
parent2f993d40296ef007fa313756a721e48890f3df89 (diff)
downloadserd-1d32c6e37bb4409719d6170c4b0e45cd3557df9a.tar.gz
serd-1d32c6e37bb4409719d6170c4b0e45cd3557df9a.tar.bz2
serd-1d32c6e37bb4409719d6170c4b0e45cd3557df9a.zip
Don't write xsd:decimal literals to Turtle bare if they would not be read back
with the same type. Run thru tests on manifest-based test suites. git-svn-id: http://svn.drobilla.net/serd/trunk@428 490d8e77-9747-427b-9fa3-0b8f29cee8a0
-rw-r--r--NEWS4
-rw-r--r--src/writer.c10
-rw-r--r--wscript26
3 files changed, 28 insertions, 12 deletions
diff --git a/NEWS b/NEWS
index 6f9ab57b..49052d17 100644
--- a/NEWS
+++ b/NEWS
@@ -1,6 +1,8 @@
serd (0.18.3) unstable;
- * Support most of the latest Turtle Editor's Draft
+ * Support most of the latest Turtle Draft
+ * Don't write xsd:decimal literals to Turtle bare if they would not be read
+ back with the same type
* Fix possible crash in serd_writer_end_anon() when writing invalid lists
* Generate blank names like _:b1 and _:B2 not _:genid1 _:docid2
* Correctly handle posix_memalign failure
diff --git a/src/writer.c b/src/writer.c
index 3c94d087..380a561d 100644
--- a/src/writer.c
+++ b/src/writer.c
@@ -442,10 +442,18 @@ write_node(SerdWriter* writer,
const char* type_uri = (const char*)datatype->buf;
if (!strncmp(type_uri, NS_XSD, sizeof(NS_XSD) - 1) && (
!strcmp(type_uri + sizeof(NS_XSD) - 1, "boolean") ||
- !strcmp(type_uri + sizeof(NS_XSD) - 1, "decimal") ||
!strcmp(type_uri + sizeof(NS_XSD) - 1, "integer"))) {
sink(node->buf, node->n_bytes, writer);
break;
+ } else if (!strcmp(type_uri + sizeof(NS_XSD) - 1, "decimal") &&
+ strchr((const char*)node->buf, '.') &&
+ node->buf[node->n_bytes - 1] != '.') {
+ /* xsd:decimal literals without trailing digits, e.g. "5.", can
+ not be written bare in Turtle. We could add a 0 which is
+ prettier, but changes the text and breaks round tripping.
+ */
+ sink(node->buf, node->n_bytes, writer);
+ break;
}
}
if (writer->syntax != SERD_NTRIPLES
diff --git a/wscript b/wscript
index 16588640..51dacc4f 100644
--- a/wscript
+++ b/wscript
@@ -282,19 +282,18 @@ def earl_assertion(test, passed, asserter):
"earl:passed" if passed else "earl:failed",
datetime.datetime.now().replace(microsecond=0).isoformat())
-def test_thru(ctx, base, path, flags):
- in_filename = os.path.join(ctx.path.abspath(), path)
- out_filename = path + '.thru'
- check_filename = in_filename.replace('.ttl', '.nt')
+def test_thru(ctx, base, in_filename, check_filename, flags):
+ out_filename = in_filename + '.thru'
- command = ('%s %s -i ntriples -o turtle -p foo "%s" "%s"'
- '| %s -i turtle -o ntriples -c foo - "%s" > %s') % (
+ command = ('%s %s -i ntriples -o turtle -p foo "%s" "%s" | '
+ '%s -i turtle -o ntriples -c foo - "%s" > %s') % (
'serdi_static', flags.ljust(5),
in_filename, base,
'serdi_static', base, out_filename)
passed = autowaf.run_test(ctx, APPNAME, command, 0, name=out_filename)
if not passed:
+ Logs.pprint('RED', '** Failed command: %s' % command)
return False
if not os.access(out_filename, os.F_OK):
@@ -302,7 +301,7 @@ def test_thru(ctx, base, path, flags):
elif not file_equals(check_filename, out_filename, '_:docid', '_:genid'):
Logs.pprint('RED', 'FAIL: %s != %s' % (out_filename, check_filename))
else:
- Logs.pprint('GREEN', '** Pass %s == %s' % (out_filename, check_filename))
+ #Logs.pprint('GREEN', '** Pass %s == %s' % (out_filename, check_filename))
return True
return False
@@ -358,17 +357,21 @@ def test_manifest(ctx, srcdir, testdir, report, test_base, parse_base):
passed = run_test(action_node, 0)
if passed:
+ action = os.path.join(srcdir, 'tests', testdir, action_node)
output = os.path.join('tests', testdir, action_node + '.out')
result = os.path.join(srcdir, 'tests', testdir, result_node)
+ rel = os.path.relpath(action, os.path.join(srcdir, 'tests', testdir))
if not os.access(output, os.F_OK):
passed = False
Logs.pprint('RED', 'FAIL: %s output %s is missing' % (name, output))
elif not file_equals(result, output):
passed = False
- Logs.pprint('RED', 'FAIL: %s\n != %s' % (os.path.abspath(output), result))
+ Logs.pprint('RED', 'FAIL: %s != %s' % (os.path.abspath(output), result))
else:
Logs.pprint('GREEN', '** Pass %s' % output)
+ test_thru(ctx, parse_base + rel, action, result, "")
+
report.write(earl_assertion(test, passed, asserter))
def test(ctx):
@@ -492,8 +495,11 @@ def test(ctx):
if (num % 7 == 0):
flags += ' -e'
- path = os.path.join('tests', tdir, test)
- test_thru(ctx, test_base(test), path, flags)
+ path = os.path.join('tests', tdir, test)
+ in_filename = os.path.join(ctx.path.abspath(), path)
+ check_filename = in_filename.replace('.ttl', '.nt')
+
+ test_thru(ctx, test_base(test), in_filename, check_filename, flags)
try:
report = open('earl.ttl', 'w')