summaryrefslogtreecommitdiffstats
path: root/tests/004
diff options
context:
space:
mode:
authorKaz Kylheku <kaz@kylheku.com>2009-10-30 14:23:43 -0800
committerKaz Kylheku <kaz@kylheku.com>2009-10-30 14:23:43 -0800
commita4054e21a03f6c388aa7c8ff79eefc8f36bd3f76 (patch)
tree78480e7e9042070ea95a545efdded2f59fa2abe7 /tests/004
parent0bf28ecd2bf99a65d6284b6bc00dc15ca01b93b2 (diff)
downloadtxr-a4054e21a03f6c388aa7c8ff79eefc8f36bd3f76.tar.gz
txr-a4054e21a03f6c388aa7c8ff79eefc8f36bd3f76.tar.bz2
txr-a4054e21a03f6c388aa7c8ff79eefc8f36bd3f76.zip
Starting txr git.graftedtxr-018
Diffstat (limited to 'tests/004')
-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)