ref: 74d91a0021de012908cfdb35fb61a1473a376130
dir: /test/matchor.myr/
use std const main = { type foo = union `Black `Blue `Green `Red `Yellow `White ;; match `Green | `Black || `White: std.exit(1) | `Blue || `Green || `Red: std.put("color\n") | _: std.exit(1) ;; match `std.Some 100 | `std.Some (100 || 200 || 300): std.put("hundreds\n") | `std.Some _: std.exit(1) | _: std.exit(1) ;; match `std.Some (`std.Some 333, 123, 789) | `std.Some (`std.Some (101||451||789||333), _, _): std.put("good #1\n") | `std.Some (`std.Some (100||200), 222, 333): std.exit(1) | `std.Some _: std.exit(1) | `std.None: std.exit(1) ;; match 4 | 1||2||4: std.put("good $2\n") | _: std.exit(1) ;; const a = 4 match 4 | 1||2||a: std.put("good $3\n") | _: std.exit(1) ;; type bar = union `A int `B int `C int `D (byte[:], int) `E (byte[:], int) `F (int, std.option(int)) `G (int, std.option(int)) `H (int, int) `I (int, int) `J (int, (int, (int, int))) ;; match `A 123 | `A x || `B x: std.put("good #4 {}\n", x) | _: std.exit(1) ;; match `G (223, `std.Some 556) | `F (x, `std.Some y) || `G (x, `std.Some y): std.put("good #5 x={} y={}\n", x, y) | _: std.exit(1) ;; match `H (100, 200) | `H (x, _) || `I (_, x): std.put("#6 x={}\n", x) if x != 100 std.exit(1) ;; | _: std.exit(1) ;; match `J (100, (200, (300, 400))) | `H (x, _) || `J (_, (_, (_, x))): std.put("#7 x={}\n", x) if x != 400 std.exit(1) ;; | _: std.exit(1) ;; std.put("all good\n") }