aboutsummaryrefslogtreecommitdiffstats
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/meson.build18
-rwxr-xr-xtest/test_filter.py94
-rwxr-xr-xtest/test_grep.py94
3 files changed, 206 insertions, 0 deletions
diff --git a/test/meson.build b/test/meson.build
index e8392559..67907c25 100644
--- a/test/meson.build
+++ b/test/meson.build
@@ -77,6 +77,14 @@ if get_option('utils')
bad_args = [
['/no/such/file'],
['ftp://unsupported.org'],
+ ['-F', '', '-G', ''],
+ ['-F'],
+ ['-F', '?s ?p ?o . ?q ?r ?s .', '-s', ''],
+ ['-F', '?s ?p ?o .\n?q ?r ?s .\n', '-s', ''],
+ ['-F', 'bad_pattern', '-s', ''],
+ ['-G'],
+ ['-G', '?s ?p ?o . ?q ?r ?s .', '-s', ''],
+ ['-G', 'bad_pattern', '-s', ''],
['-I'],
['-c'],
['-i', 'unknown'],
@@ -135,6 +143,16 @@ if get_option('utils')
env: test_env,
suite: ['serdi', 'options'])
+ test('filter', files('test_filter.py'),
+ args: script_args,
+ env: test_env,
+ suite: ['serdi', 'options'])
+
+ test('grep', files('test_grep.py'),
+ args: script_args,
+ env: test_env,
+ suite: ['serdi', 'options'])
+
# Inputs
test('stdin', files('test_stdin.py'),
diff --git a/test/test_filter.py b/test/test_filter.py
new file mode 100755
index 00000000..d44677f5
--- /dev/null
+++ b/test/test_filter.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python3
+
+"""Test filtering statements inclusively."""
+
+import argparse
+import sys
+import shlex
+import subprocess
+import tempfile
+
+DOCUMENTS = {
+ "ntriples": """
+ <urn:example:s> <urn:example:p> <urn:example:o> .
+ <urn:example:s> <urn:example:q> <urn:example:r> .
+""",
+ "nquads": """
+ <urn:example:s> <urn:example:p> <urn:example:o> <urn:example:g> .
+ <urn:example:s> <urn:example:q> <urn:example:r> <urn:example:g> .
+""",
+}
+
+parser = argparse.ArgumentParser(description=__doc__)
+
+parser.add_argument("--serdi", default="./serdi", help="path to serdi")
+parser.add_argument("--wrapper", default="", help="executable wrapper")
+
+args = parser.parse_args(sys.argv[1:])
+
+
+def check_pattern(syntax, pattern, result):
+ command = shlex.split(args.wrapper) + [
+ args.serdi,
+ "-i",
+ syntax,
+ "-F",
+ pattern,
+ "-s",
+ DOCUMENTS[syntax],
+ ]
+
+ with tempfile.TemporaryFile() as out:
+ proc = subprocess.run(
+ command,
+ check=False,
+ encoding="utf-8",
+ capture_output=True,
+ )
+
+ assert proc.returncode == 0
+ assert args.wrapper or len(proc.stderr) == 0
+ assert proc.stdout == result
+
+
+check_pattern(
+ "ntriples",
+ "?s <urn:example:p> <urn:example:o> .",
+ "<urn:example:s> <urn:example:q> <urn:example:r> .\n",
+)
+
+check_pattern(
+ "ntriples",
+ "<urn:example:s> ?p <urn:example:o> .",
+ "<urn:example:s> <urn:example:q> <urn:example:r> .\n",
+)
+
+check_pattern(
+ "ntriples",
+ "<urn:example:s> <urn:example:p> ?o .",
+ "<urn:example:s> <urn:example:q> <urn:example:r> .\n",
+)
+
+check_pattern(
+ "nquads",
+ "?s <urn:example:p> <urn:example:o> <urn:example:g> .",
+ "<urn:example:s> <urn:example:q> <urn:example:r> <urn:example:g> .\n",
+)
+
+check_pattern(
+ "nquads",
+ "<urn:example:s> ?p <urn:example:o> <urn:example:g> .",
+ "<urn:example:s> <urn:example:q> <urn:example:r> <urn:example:g> .\n",
+)
+
+check_pattern(
+ "nquads",
+ "<urn:example:s> <urn:example:p> ?o <urn:example:g> .",
+ "<urn:example:s> <urn:example:q> <urn:example:r> <urn:example:g> .\n",
+)
+
+check_pattern(
+ "nquads",
+ "<urn:example:s> <urn:example:p> <urn:example:o> ?g .",
+ "<urn:example:s> <urn:example:q> <urn:example:r> <urn:example:g> .\n",
+)
diff --git a/test/test_grep.py b/test/test_grep.py
new file mode 100755
index 00000000..0c8c5228
--- /dev/null
+++ b/test/test_grep.py
@@ -0,0 +1,94 @@
+#!/usr/bin/env python3
+
+"""Test filtering statements exclusively."""
+
+import argparse
+import sys
+import shlex
+import subprocess
+import tempfile
+
+DOCUMENTS = {
+ "ntriples": """
+ <urn:example:s> <urn:example:p> <urn:example:o> .
+ <urn:example:s> <urn:example:q> <urn:example:r> .
+""",
+ "nquads": """
+ <urn:example:s> <urn:example:p> <urn:example:o> <urn:example:g> .
+ <urn:example:s> <urn:example:q> <urn:example:r> <urn:example:g> .
+""",
+}
+
+parser = argparse.ArgumentParser(description=__doc__)
+
+parser.add_argument("--serdi", default="./serdi", help="path to serdi")
+parser.add_argument("--wrapper", default="", help="executable wrapper")
+
+args = parser.parse_args(sys.argv[1:])
+
+
+def check_pattern(syntax, pattern, result):
+ command = shlex.split(args.wrapper) + [
+ args.serdi,
+ "-i",
+ syntax,
+ "-G",
+ pattern,
+ "-s",
+ DOCUMENTS[syntax],
+ ]
+
+ with tempfile.TemporaryFile() as out:
+ proc = subprocess.run(
+ command,
+ check=False,
+ encoding="utf-8",
+ capture_output=True,
+ )
+
+ assert proc.returncode == 0
+ assert args.wrapper or len(proc.stderr) == 0
+ assert proc.stdout == result
+
+
+check_pattern(
+ "ntriples",
+ "?s <urn:example:p> <urn:example:o> .",
+ "<urn:example:s> <urn:example:p> <urn:example:o> .\n",
+)
+
+check_pattern(
+ "ntriples",
+ "<urn:example:s> ?p <urn:example:o> .",
+ "<urn:example:s> <urn:example:p> <urn:example:o> .\n",
+)
+
+check_pattern(
+ "ntriples",
+ "<urn:example:s> <urn:example:p> ?o .",
+ "<urn:example:s> <urn:example:p> <urn:example:o> .\n",
+)
+
+check_pattern(
+ "nquads",
+ "?s <urn:example:p> <urn:example:o> <urn:example:g> .",
+ "<urn:example:s> <urn:example:p> <urn:example:o> <urn:example:g> .\n",
+)
+
+check_pattern(
+ "nquads",
+ "<urn:example:s> ?p <urn:example:o> <urn:example:g> .",
+ "<urn:example:s> <urn:example:p> <urn:example:o> <urn:example:g> .\n",
+)
+
+check_pattern(
+ "nquads",
+ "<urn:example:s> <urn:example:p> ?o <urn:example:g> .",
+ "<urn:example:s> <urn:example:p> <urn:example:o> <urn:example:g> .\n",
+)
+
+check_pattern(
+ "nquads",
+ "<urn:example:s> <urn:example:p> <urn:example:o> ?g .",
+ "<urn:example:s> <urn:example:p> <urn:example:o> <urn:example:g> .\n",
+)