mod common; assert_matches! { wildcard("23", "_"); literal_int("23", "23"); literal_str("`foobar`", "`foobar`"); literal_bool("True", "True"); literal_list("[1, 2]", "[1, 2]"); literal_dict("@dict::new(x=1, y=2).", "(x=1, y=2)"); unit_dot_dot(".", "."); unit_dot_braces(".", "{}"); unit_braces_dot("{}", "."); unit_braces_braces("{}", "{}"); typed_unit_dot(".", "_: none"); typed_unit_braces("{}", "_: none"); typed_int("23", "_: int"); typed_str("`foobar`", "_: str"); typed_bool("True", "_: bool"); typed_list("[1, 2]", "_: int list"); typed_dict("@dict::new(x=1, y=2).", "_: int dict"); typed_function("@fn $x -> $x", "_: function"); spread_list("[1, 2, 3]", "[1, *[2, 3]]"); spread_dict("@dict::new(x=1, y=2, z=3).", "(x=1, **(y=2, z=3))"); equals_dict("@dict::new(x=1, y=2, z=3).", "=@dict::new(z=3, y=2, x=1)."); spread_list_wildcard("[1, 2, 3]", "[1, ...]"); spread_dict_wildcard("@dict::new(x=1, y=2, z=3).", "(x=1, ...)"); spread_tag_wildcard("foo", " _ "); tag_simple("Foo", " _ "); tag_empty("", ""); tag_attr("Foo", " _ "); tag_wildcard_name("Foo", "<_> _ "); tag_seq("{}", "{}"); tag_spread("{}", "{ *_ }"); tag_one_in_seq("", "{}"); html_text_seq("{Foo}", "{_}"); html_text_seq_spread("{Foo}", "{*_}"); equals_captured_var("[23, 23]", "[$x, =$x]"); var_and_literal("[23, 23]", "[23 & $x, 23 & =$x]"); var_and_template("[`foo bar`, [`foo bar`, `foo`, `bar`]]", "[$x & '$a $b', =[$x, $a, $b]]"); or_left("1", "1 | 2"); or_right("2", "1 | 2"); and_or_precedence("1", "1 | 2 & 3"); } assert_ok! { equals_value( "@let(x=23, y=17) @match 17 {=$x -> {Failed (equals x)}, =$y -> OK, _ -> Failed}", "

OK

" ); list_part( "@match [1, 2, 3] {[$x, *_] -> $x}", "

1

", ); dict_part( "@match @dict::new(x=1, y=2, z=3). {(x=$x, **_) -> $x}", "

1

", ); template_part( r#"@match `hello world` {"hello $x" -> $x}"#, "

world

", ); tag_part( "@match {
Foo} {{$x} -> $x}", "

Foo

" ); tag_spread_part( "@match {
FooBar} {{*$x} -> $x}", "

FooBar

" ); type_of( "@match `foobar` {_: $t -> $t}", "

str

", ); or_left_bind( "@match 123 {$x | $y -> [$x, $y]}", "
  • 123
", ); or_right_bind( "@match 123 {$x: bool | $y -> [$x, $y]}", "
  • 123
", ); } assert_err! { literal_in_html("@match 5 {{5} -> OK}", SyntaxError::PatternCannotMatchHTML); no_matching_branch("@match 5 {6 -> Fail}", RuntimeError::NoMatchingBranch); }