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