@@ -2342,17 +2342,28 @@ def test_parse_record_with_trailing_comma_raises_parse_error(self) -> None:
23422342 def test_parse_symbol_returns_symbol (self ) -> None :
23432343 self .assertEqual (parse ([SymbolToken ("abc" )]), Symbol ("abc" ))
23442344
2345- # def test_parse_guard(self) -> None:
2346- # self.assertEqual(
2347- # parse(tokenize("| x guard y -> x")),
2348- # MatchFunction([MatchCase(Guard(Var("x"), Var("y")), Var("x"))]),
2349- # )
2350-
2351- # def test_parse_guard_exp(self) -> None:
2352- # self.assertEqual(
2353- # parse(tokenize("| x guard x==1 -> x")),
2354- # MatchFunction([MatchCase(Guard(Var("x"), Binop(BinopKind.EQUAL, Var("x"), Int(1))), Var("x"))]),
2355- # )
2345+ def test_parse_guard (self ) -> None :
2346+ self .assertEqual (
2347+ parse (tokenize ("| x guard y -> x" )),
2348+ MatchFunction ([MatchCase (Var ("x" ), Var ("y" ), Var ("x" ))]),
2349+ )
2350+
2351+ def test_parse_guard_exp (self ) -> None :
2352+ self .assertEqual (
2353+ parse (tokenize ("| x guard x==1 -> x" )),
2354+ MatchFunction ([MatchCase (Var ("x" ), Binop (BinopKind .EQUAL , Var ("x" ), Int (1 )), Var ("x" ))]),
2355+ )
2356+
2357+ def test_parse_multiple_guards (self ) -> None :
2358+ self .assertEqual (
2359+ parse (tokenize ("| x guard y -> x | a guard b -> 1" )),
2360+ MatchFunction (
2361+ [
2362+ MatchCase (Var ("x" ), Var ("y" ), Var ("x" )),
2363+ MatchCase (Var ("a" ), Var ("b" ), Int (1 )),
2364+ ]
2365+ ),
2366+ )
23562367
23572368
23582369class MatchTests (unittest .TestCase ):
0 commit comments