summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2017-07-31 17:43:17 -0700
committerKaz Kylheku <kaz@kylheku.com>2017-07-31 17:43:17 -0700
commitbfb3317cdedb2725e945a659ccb6d34fd11ace61 (patch)
tree78480e7e9042070ea95a545efdded2f59fa2abe7 /tests
parent0bf28ecd2bf99a65d6284b6bc00dc15ca01b93b2 (diff)
downloadtxr-old.tar.gz
txr-old.tar.bz2
txr-old.zip
txr-018 2009-10-17txr-old
Diffstat (limited to 'tests')
-rw-r--r--tests/004/query-1.expected3
-rw-r--r--tests/004/query-1.txr67
2 files changed, 70 insertions, 0 deletions
diff --git a/tests/004/query-1.expected b/tests/004/query-1.expected
new file mode 100644
index 00000000..c07de878
--- /dev/null
+++ b/tests/004/query-1.expected
@@ -0,0 +1,3 @@
+option a was supplied, with argument 123
+option b was supplied
+option c was supplied
diff --git a/tests/004/query-1.txr b/tests/004/query-1.txr
new file mode 100644
index 00000000..c8a9e226
--- /dev/null
+++ b/tests/004/query-1.txr
@@ -0,0 +1,67 @@
+#!./txr
+@(next args)
+@#
+@# Define option_error exception, subtyped from error
+@#
+@(defex option_error error)
+@#
+@# Function for matching option that takes no argument
+@#
+@(define match_option (text opt_sym))
+@ (cases)
+@ (skip)
+@ text
+@ (bind opt_sym "y")
+@ (or)
+@ (bind opt_sym "n")
+@ (end)
+@(end)
+@#
+@# Function for matching option that takes an argument
+@#
+@(define match_option_arg (text opt_sym arg_sym))
+@ (cases)
+@ (skip)
+@ text
+@ arg_sym
+@ (bind opt_sym "y")
+@ (or)
+@ (skip)
+@ text
+@ (throw option_error `@text requires arg`)
+@ (or)
+@ (bind opt_sym "n")
+@ (end)
+@(end)
+@#
+@# Main query
+@#
+@(try)
+@ (maybe)
+@ (match_option_arg "-a" opt_a opt_arg_a)
+@ (or)
+@ (match_option "-b" opt_b)
+@ (or)
+@ (match_option "-c" opt_c)
+@ (end)
+@ (maybe)
+@ (bind opt_a "y")
+@ (output)
+option a was supplied, with argument @opt_arg_a
+@ (end)
+@ (or)
+@ (bind opt_b "y")
+@ (output)
+option b was supplied
+@ (end)
+@ (or)
+@ (bind opt_c "y")
+@ (output)
+option c was supplied
+@ (end)
+@ (end)
+@(catch option_error (arg))
+@(output)
+error: @arg
+@(end)
+@(end)