diff --git a/src/term/builtins.rs b/src/term/builtins.rs index 30d52cbf4..112187ecb 100644 --- a/src/term/builtins.rs +++ b/src/term/builtins.rs @@ -104,11 +104,11 @@ impl Pattern { } fn encode_str(str: &str) -> Pattern { - let lnil = Pattern::Ctr(Name::from(LNIL), vec![]); + let lnil = Pattern::Ctr(Name::from(SNIL), vec![]); str.chars().rfold(lnil, |tail, head| { let head = Pattern::Num(NumCtr::Num(head as u64)); - Pattern::Ctr(Name::from(LCONS), vec![head, tail]) + Pattern::Ctr(Name::from(SCONS), vec![head, tail]) }) } } diff --git a/tests/golden_tests/run_file/match_str.hvm b/tests/golden_tests/run_file/match_str.hvm new file mode 100644 index 000000000..ff1255163 --- /dev/null +++ b/tests/golden_tests/run_file/match_str.hvm @@ -0,0 +1,9 @@ +(is_as "As") = 2 +(is_as "as") = 2 +(is_as "") = 1 +(is_as *) = 0 + +map f (List.cons x xs) = (List.cons (f x) (map f xs)) +map f [] = [] + +main = (map is_as ["As" "as" "" "Asd" "qwerty" "AAs"]) \ No newline at end of file diff --git a/tests/snapshots/run_file__match_str.hvm.snap b/tests/snapshots/run_file__match_str.hvm.snap new file mode 100644 index 000000000..984f5b323 --- /dev/null +++ b/tests/snapshots/run_file__match_str.hvm.snap @@ -0,0 +1,5 @@ +--- +source: tests/golden_tests.rs +input_file: tests/golden_tests/run_file/match_str.hvm +--- +[2, 2, 1, 0, 0, 0] diff --git a/tests/snapshots/simplify_matches__match_str.hvm.snap b/tests/snapshots/simplify_matches__match_str.hvm.snap index 6ba1af670..a88f78f14 100644 --- a/tests/snapshots/simplify_matches__match_str.hvm.snap +++ b/tests/snapshots/simplify_matches__match_str.hvm.snap @@ -2,6 +2,6 @@ source: tests/golden_tests.rs input_file: tests/golden_tests/simplify_matches/match_str.hvm --- -(is_as) = λa match a { (List.cons b c): (match b { 65: λd (match d { (List.cons f g): λh (match f { 115: λ* λj (match j { (List.cons * *): λ* 0; (List.nil): λ* 2 } *); *: λ* λ* 0 } h g); (List.nil): λ* 0 } *); 97: λhb (match hb { (List.cons jb kb): λlb (match jb { 115: λ* λnb (match nb { (List.cons * *): λ* 0; (List.nil): λ* 2 } *); *: λ* λ* 0 } lb kb); (List.nil): λ* 0 } *); *: λ* 0 } c); (List.nil): 1 } +(is_as) = λa match a { (String.cons b c): (match b { 65: λd (match d { (String.cons f g): λh (match f { 115: λ* λj (match j { (String.cons * *): λ* 0; (String.nil): λ* 2 } *); *: λ* λ* 0 } h g); (String.nil): λ* 0 } *); 97: λhb (match hb { (String.cons jb kb): λlb (match jb { 115: λ* λnb (match nb { (String.cons * *): λ* 0; (String.nil): λ* 2 } *); *: λ* λ* 0 } lb kb); (String.nil): λ* 0 } *); *: λ* 0 } c); (String.nil): 1 } (main) = *