summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorWilliam Langford <wlangfor@gmail.com>2014-06-18 19:49:38 -0400
committerNicolas Williams <nico@cryptonector.com>2014-06-18 21:02:47 -0500
commit8ff935c01a6e9a16e0d84b29c548dc621bc8ff98 (patch)
treed6fa5ce55d7fdee31080f92148c9b9f0613f3f84 /tests
parent5d9d1b1020b5d7f5fe11d81eb641197bb98819d9 (diff)
Added regex support as per issue #164.
jq now depends on oniguruma for regex support. Modified configure.ac accordingly. Added valgrind suppression file for oniguruma to prevent one-time and bounded leaks from causing tests to fail. Signed-off-by: Nicolas Williams <nico@cryptonector.com>
Diffstat (limited to 'tests')
-rw-r--r--tests/all.test46
-rw-r--r--tests/onig.supp21
-rwxr-xr-xtests/run2
3 files changed, 67 insertions, 2 deletions
diff --git a/tests/all.test b/tests/all.test
index 1e220cd0..0b5b9479 100644
--- a/tests/all.test
+++ b/tests/all.test
@@ -649,6 +649,50 @@ def inc(x): x |= .+1; inc(.[].a)
["fo", "foo", "barfoo", "foobar", "barfoob"]
[false, true, true, false, false]
+# match builtin
+[match("( )*"; "g")]
+"abc"
+[{"offset":0, "length":0, "string":"", "captures":[]},{"offset":1, "length":0, "string":"", "captures":[]},{"offset":2, "length":0, "string":"", "captures":[]}]
+
+[match("( )*"; "gn")]
+"abc"
+[]
+
+[match("a"; "gi")]
+"āáàä"
+[]
+
+[match(["(bar)"])]
+"foo bar"
+[{"offset": 4, "length": 3, "string": "bar", "captures":[{"offset": 4, "length": 3, "string": "bar", "name": null}]}]
+
+# offsets account for combining codepoints and multi-byte UTF-8
+[match("bar")]
+"ā bar with a combining codepoint U+0304"
+[{"offset": 3, "length": 3, "string": "bar", "captures":[]}]
+
+# matches with combining codepoints still count them in their length
+[match("bār")]
+"a bār"
+[{"offset": 2, "length": 4, "string": "bār", "captures":[]}]
+
+[match(".+?\\b")]
+"ā two-codepoint grapheme"
+[{"offset": 0, "length": 2, "string": "ā", "captures":[]}]
+
+[match(["foo (?<bar123>bar)? foo", "ig"])]
+"foo bar foo foo foo"
+[{"offset": 0, "length": 11, "string": "foo bar foo", "captures":[{"offset": 4, "length": 3, "string": "bar", "name": "bar123"}]},{"offset":12, "length": 8, "string": "foo foo", "captures":[{"offset": -1, "length": 0, "string": null, "name": "bar123"}]}]
+
+#test builtin
+[test("( )*"; "gn")]
+"abc"
+[false]
+
+[test("ā")]
+"ā"
+[true]
+
[.[]|ltrimstr("foo")]
["fo", "foo", "barfoo", "foobar", "afoo"]
["fo","","barfoo","bar","afoo"]
@@ -857,4 +901,4 @@ flatten(2)
flatten(2)
[0, [1, [2]], [1, [[3], 2]]]
-[0, 1, 2, 1, [3], 2] \ No newline at end of file
+[0, 1, 2, 1, [3], 2]
diff --git a/tests/onig.supp b/tests/onig.supp
new file mode 100644
index 00000000..37c847ee
--- /dev/null
+++ b/tests/onig.supp
@@ -0,0 +1,21 @@
+{
+ onig node recycling
+ Memcheck:Leak
+ ...
+ fun:onig_parse_make_tree
+ ...
+}
+{
+ onig unicode case insensitivity 1
+ Memcheck:Leak
+ ...
+ fun:setup_tree
+ ...
+}
+{
+ onig unicode case insensitivity 2
+ Memcheck:Leak
+ ...
+ fun:onig*unicode*
+ ...
+}
diff --git a/tests/run b/tests/run
index ff09246c..5268e2ea 100755
--- a/tests/run
+++ b/tests/run
@@ -1,7 +1,7 @@
#!/bin/sh
if which valgrind > /dev/null; then
- VALGRIND='valgrind --error-exitcode=1 -q --leak-check=full'
+ VALGRIND='valgrind --error-exitcode=1 -q --leak-check=full --suppressions=tests/onig.supp'
else
VALGRIND=
fi