summaryrefslogtreecommitdiff
path: root/test/matchargstr.myr
blob: 50d539bc0b8dcd9a69831dcdc44e55cccc3c6467 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
use std
/* checks pattern matching on unions with arguments.
exits with 42. */
type u = union
	`Int int
	`Str byte[:]
	`Nil
;;

const main = {
	var v

	v = `Str "asdf"
	match v
	| `Int 127:	std.fatal(1, "wrong match `Int 127\n")
	| `Str "foo":	std.fatal(1, "Wrong match `Str \"foo\"\n")
	| `Str "fsda":	std.fatal(1, "Wrong match `Str \"fsda\"\n")
	| `Str "asdf":	std.put("Correct `Str \"asdf\"!\n")
	| `Nil:		std.fatal(1, "Wrong match `Str \"fsda\"\n")
	| _:		std.fatal(1, "Impossible failed match\n")
	;;
}