summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorShaun Guth <sguth@practicefusion.com>2016-01-24 23:30:28 +0000
committerWilliam Langford <wlangfor@gmail.com>2017-02-12 16:03:59 -0500
commite0b784ac6d7885669846337faad446be4ed0ded8 (patch)
treee9437d2c7f2d71e6d9fe6fd47e69932193156ac0 /tests
parentdc679081fa770c260ca9a569a8a4fdbb10bcdc20 (diff)
Add @base64d for decoding base64 #47
Diffstat (limited to 'tests')
-rw-r--r--tests/base64.test35
-rwxr-xr-xtests/base64test5
-rw-r--r--tests/jq.test7
3 files changed, 46 insertions, 1 deletions
diff --git a/tests/base64.test b/tests/base64.test
new file mode 100644
index 00000000..0f82b0b7
--- /dev/null
+++ b/tests/base64.test
@@ -0,0 +1,35 @@
+# Tests are groups of three lines: program, input, expected output
+# Blank lines and lines starting with # are ignored
+
+@base64
+"<>&'\"\t"
+"PD4mJyIJ"
+
+# decoding encoded output results in same text
+(@base64|@base64d)
+"<>&'\"\t"
+"<>&'\"\t"
+
+# regression test for #436
+@base64
+"foóbar\n"
+"Zm/Ds2Jhcgo="
+
+@base64d
+"Zm/Ds2Jhcgo="
+"foóbar\n"
+
+# optional trailing equals padding (With padding, this is cWl4YmF6Cg==)
+@base64d
+"cWl4YmF6Cg"
+"qixbaz\n"
+
+# invalid base64 characters (whitespace)
+. | try @base64d catch .
+"Not base64 data"
+"string (\"Not base64...) is not valid base64 data"
+
+# invalid base64 (too many bytes, QUJD = "ABCD"
+. | try @base64d catch .
+"QUJDa"
+"string (\"QUJDa\") trailing base64 byte found"
diff --git a/tests/base64test b/tests/base64test
new file mode 100755
index 00000000..85fe64b7
--- /dev/null
+++ b/tests/base64test
@@ -0,0 +1,5 @@
+#!/bin/sh
+
+. "${0%/*}/setup" "$@"
+
+$VALGRIND $Q $JQ -L "$mods" --run-tests $JQTESTDIR/base64.test
diff --git a/tests/jq.test b/tests/jq.test
index fa02b6d7..f510a917 100644
--- a/tests/jq.test
+++ b/tests/jq.test
@@ -61,7 +61,7 @@ null
null
"interpolation"
-@text,@json,([1,.] | (@csv, @tsv)),@html,@uri,@sh,@base64
+@text,@json,([1,.] | (@csv, @tsv)),@html,@uri,@sh,@base64,(@base64 | @base64d)
"<>&'\"\t"
"<>&'\"\t"
"\"<>&'\\\"\\t\""
@@ -71,12 +71,17 @@ null
"%3C%3E%26'%22%09"
"'<>&'\\''\"\t'"
"PD4mJyIJ"
+"<>&'\"\t"
# regression test for #436
@base64
"foóbar\n"
"Zm/Ds2Jhcgo="
+@base64d
+"Zm/Ds2Jhcgo="
+"foóbar\n"
+
@uri
"\u03bc"
"%CE%BC"