summaryrefslogtreecommitdiff
path: root/tests
diff options
context:
space:
mode:
authorMichael Williamson <mike@zwobble.org>2020-05-02 11:12:18 +0100
committerMichael Williamson <mike@zwobble.org>2020-05-02 11:12:18 +0100
commite7471d1a36ab71abdab4d1f3cd8f246108b42eb6 (patch)
tree65f1d59bb8a3761c0c4fd3eec75ee4980e1eb60c /tests
parentfa7399eb01fce0a81e617af03d752527093e7d72 (diff)
Add convenience functions
Diffstat (limited to 'tests')
-rw-r--r--tests/jq_tests.py57
1 files changed, 57 insertions, 0 deletions
diff --git a/tests/jq_tests.py b/tests/jq_tests.py
index 17dfc0c..27734e6 100644
--- a/tests/jq_tests.py
+++ b/tests/jq_tests.py
@@ -195,3 +195,60 @@ def repr_of_compile_result_is_compilation_string():
def program_string_can_be_retrieved_from_program():
program = jq.compile(".")
assert_equal(".", program.program_string)
+
+
+@istest
+class ConvenienceFunctions(object):
+ @istest
+ def first_function_with_json_value_input_returns_first_output_element(self):
+ output = jq.first(".[] + 1", [1, 2, 3])
+
+ assert_equal(2, output)
+
+ @istest
+ def first_function_with_json_text_input_returns_first_output_element(self):
+ output = jq.first(".[] + 1", text="[1, 2, 3]")
+
+ assert_equal(2, output)
+
+ @istest
+ def text_function_with_json_value_input_returns_all_output_elements_as_string(self):
+ output = jq.text(".[] + 1", [1, 2, 3])
+
+ assert_equal("2\n3\n4", output)
+
+ @istest
+ def text_function_with_json_text_input_returns_all_output_elements_as_string(self):
+ output = jq.text(".[] + 1", text="[1, 2, 3]")
+
+ assert_equal("2\n3\n4", output)
+
+ @istest
+ def all_function_with_json_value_input_returns_all_output_elements_in_list(self):
+ output = jq.all(".[] + 1", [1, 2, 3])
+
+ assert_equal([2, 3, 4], output)
+
+ @istest
+ def all_function_with_json_text_input_returns_all_output_element_in_list(self):
+ output = jq.all(".[] + 1", text="[1, 2, 3]")
+
+ assert_equal([2, 3, 4], output)
+
+ @istest
+ def iter_function_with_json_value_input_returns_all_output_elements_in_iterator(self):
+ iterator = jq.iter(".[] + 1", [1, 2, 3])
+
+ assert_equal(2, next(iterator))
+ assert_equal(3, next(iterator))
+ assert_equal(4, next(iterator))
+ assert_equal("end", next(iterator, "end"))
+
+ @istest
+ def iter_function_with_json_text_input_returns_all_output_element_in_iterator(self):
+ iterator = jq.iter(".[] + 1", text="[1, 2, 3]")
+
+ assert_equal(2, next(iterator))
+ assert_equal(3, next(iterator))
+ assert_equal(4, next(iterator))
+ assert_equal("end", next(iterator, "end"))