|
2 | 2 | -author("Sean Cribbs <seancribbs@gmail.com>").
|
3 | 3 | -include_lib("eunit/include/eunit.hrl").
|
4 | 4 |
|
5 |
| -% Test the parser-combinators in the 'peg' module |
| 5 | +% Test the parser-combinators in the 'neotoma_peg' module |
6 | 6 | -define(STARTINDEX, {{line,1},{column,1}}).
|
7 | 7 | eof_test_() ->
|
8 | 8 | [
|
9 |
| - ?_assertEqual({fail,{expected,eof,?STARTINDEX}}, (peg:p_eof())("abc",?STARTINDEX)), |
10 |
| - ?_assertEqual({eof, [], ?STARTINDEX}, (peg:p_eof())("",?STARTINDEX)) |
| 9 | + ?_assertEqual({fail,{expected,eof,?STARTINDEX}}, (neotoma_peg:p_eof())("abc",?STARTINDEX)), |
| 10 | + ?_assertEqual({eof, [], ?STARTINDEX}, (neotoma_peg:p_eof())("",?STARTINDEX)) |
11 | 11 | ].
|
12 | 12 |
|
13 | 13 | optional_test_() ->
|
14 | 14 | [
|
15 |
| - ?_assertEqual({[], "xyz",?STARTINDEX}, (peg:p_optional(peg:p_string("abc")))("xyz",?STARTINDEX)), |
16 |
| - ?_assertEqual({"abc", "xyz",{{line,1},{column,4}}}, (peg:p_optional(peg:p_string("abc")))("abcxyz",?STARTINDEX)) |
| 15 | + ?_assertEqual({[], "xyz",?STARTINDEX}, (neotoma_peg:p_optional(neotoma_peg:p_string("abc")))("xyz",?STARTINDEX)), |
| 16 | + ?_assertEqual({"abc", "xyz",{{line,1},{column,4}}}, (neotoma_peg:p_optional(neotoma_peg:p_string("abc")))("abcxyz",?STARTINDEX)) |
17 | 17 | ].
|
18 | 18 |
|
19 | 19 | not_test_() ->
|
20 | 20 | [
|
21 |
| - ?_assertEqual({[], "xyzabc",?STARTINDEX}, (peg:p_not(peg:p_string("abc")))("xyzabc",?STARTINDEX)), |
22 |
| - ?_assertEqual({fail,{expected, {no_match, "abc"}, ?STARTINDEX}}, (peg:p_not(peg:p_string("abc")))("abcxyz",?STARTINDEX)) |
| 21 | + ?_assertEqual({[], "xyzabc",?STARTINDEX}, (neotoma_peg:p_not(neotoma_peg:p_string("abc")))("xyzabc",?STARTINDEX)), |
| 22 | + ?_assertEqual({fail,{expected, {no_match, "abc"}, ?STARTINDEX}}, (neotoma_peg:p_not(neotoma_peg:p_string("abc")))("abcxyz",?STARTINDEX)) |
23 | 23 | ].
|
24 | 24 |
|
25 | 25 | assert_test_() ->
|
26 | 26 | [
|
27 |
| - ?_assertEqual({fail,{expected, {string, "abc"}, ?STARTINDEX}}, (peg:p_assert(peg:p_string("abc")))("xyzabc",?STARTINDEX)), |
28 |
| - ?_assertEqual({[], "abcxyz",?STARTINDEX}, (peg:p_assert(peg:p_string("abc")))("abcxyz",?STARTINDEX)) |
| 27 | + ?_assertEqual({fail,{expected, {string, "abc"}, ?STARTINDEX}}, (neotoma_peg:p_assert(neotoma_peg:p_string("abc")))("xyzabc",?STARTINDEX)), |
| 28 | + ?_assertEqual({[], "abcxyz",?STARTINDEX}, (neotoma_peg:p_assert(neotoma_peg:p_string("abc")))("abcxyz",?STARTINDEX)) |
29 | 29 | ].
|
30 | 30 |
|
31 | 31 | seq_test_() ->
|
32 | 32 | [
|
33 |
| - ?_assertEqual({["abc","def"], "xyz",{{line,1},{column,7}}}, (peg:p_seq([peg:p_string("abc"), peg:p_string("def")]))("abcdefxyz",?STARTINDEX)), |
34 |
| - ?_assertEqual({fail,{expected, {string, "def"}, {{line,1},{column,4}}}}, (peg:p_seq([peg:p_string("abc"), peg:p_string("def")]))("abcxyz",?STARTINDEX)) |
| 33 | + ?_assertEqual({["abc","def"], "xyz",{{line,1},{column,7}}}, (neotoma_peg:p_seq([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("abcdefxyz",?STARTINDEX)), |
| 34 | + ?_assertEqual({fail,{expected, {string, "def"}, {{line,1},{column,4}}}}, (neotoma_peg:p_seq([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("abcxyz",?STARTINDEX)) |
35 | 35 | ].
|
36 | 36 |
|
37 | 37 | choose_test_() ->
|
38 | 38 | [
|
39 |
| - ?_assertEqual({"abc", "xyz", {{line,1},{column,4}}}, (peg:p_choose([peg:p_string("abc"), peg:p_string("def")]))("abcxyz",?STARTINDEX)), |
40 |
| - ?_assertEqual({"def", "xyz", {{line,1},{column,4}}}, (peg:p_choose([peg:p_string("abc"), peg:p_string("def")]))("defxyz",?STARTINDEX)), |
41 |
| - ?_assertEqual({"xyz", "xyz", {{line,1},{column,4}}}, (peg:p_choose([peg:p_string("abc"), peg:p_string("def"), peg:p_string("xyz")]))("xyzxyz",?STARTINDEX)), |
42 |
| - ?_assertEqual({fail,{expected,{string,"abc"},?STARTINDEX}}, (peg:p_choose([peg:p_string("abc"),peg:p_string("def")]))("xyz", ?STARTINDEX)) |
| 39 | + ?_assertEqual({"abc", "xyz", {{line,1},{column,4}}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("abcxyz",?STARTINDEX)), |
| 40 | + ?_assertEqual({"def", "xyz", {{line,1},{column,4}}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def")]))("defxyz",?STARTINDEX)), |
| 41 | + ?_assertEqual({"xyz", "xyz", {{line,1},{column,4}}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"), neotoma_peg:p_string("def"), neotoma_peg:p_string("xyz")]))("xyzxyz",?STARTINDEX)), |
| 42 | + ?_assertEqual({fail,{expected,{string,"abc"},?STARTINDEX}}, (neotoma_peg:p_choose([neotoma_peg:p_string("abc"),neotoma_peg:p_string("def")]))("xyz", ?STARTINDEX)) |
43 | 43 | ].
|
44 | 44 |
|
45 | 45 | zero_or_more_test_() ->
|
46 | 46 | [
|
47 |
| - ?_assertEqual({[], [], ?STARTINDEX}, (peg:p_zero_or_more(peg:p_string("abc")))("",?STARTINDEX)), |
48 |
| - ?_assertEqual({[], "def",?STARTINDEX}, (peg:p_zero_or_more(peg:p_string("abc")))("def",?STARTINDEX)), |
49 |
| - ?_assertEqual({["abc"], "def",{{line,1},{column,4}}}, (peg:p_zero_or_more(peg:p_string("abc")))("abcdef",?STARTINDEX)), |
50 |
| - ?_assertEqual({["abc", "abc"], "def",{{line,1},{column,7}}}, (peg:p_zero_or_more(peg:p_string("abc")))("abcabcdef",?STARTINDEX)) |
| 47 | + ?_assertEqual({[], [], ?STARTINDEX}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("",?STARTINDEX)), |
| 48 | + ?_assertEqual({[], "def",?STARTINDEX}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("def",?STARTINDEX)), |
| 49 | + ?_assertEqual({["abc"], "def",{{line,1},{column,4}}}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("abcdef",?STARTINDEX)), |
| 50 | + ?_assertEqual({["abc", "abc"], "def",{{line,1},{column,7}}}, (neotoma_peg:p_zero_or_more(neotoma_peg:p_string("abc")))("abcabcdef",?STARTINDEX)) |
51 | 51 | ].
|
52 | 52 |
|
53 | 53 | one_or_more_test_() ->
|
54 | 54 | [
|
55 |
| - ?_assertEqual({fail,{expected, {at_least_one, {string, "abc"}}, ?STARTINDEX}}, (peg:p_one_or_more(peg:p_string("abc")))("def",?STARTINDEX)), |
56 |
| - ?_assertEqual({["abc"], "def",{{line,1},{column,4}}}, (peg:p_one_or_more(peg:p_string("abc")))("abcdef",?STARTINDEX)), |
57 |
| - ?_assertEqual({["abc","abc"], "def",{{line,1},{column,7}}}, (peg:p_one_or_more(peg:p_string("abc")))("abcabcdef",?STARTINDEX)) |
| 55 | + ?_assertEqual({fail,{expected, {at_least_one, {string, "abc"}}, ?STARTINDEX}}, (neotoma_peg:p_one_or_more(neotoma_peg:p_string("abc")))("def",?STARTINDEX)), |
| 56 | + ?_assertEqual({["abc"], "def",{{line,1},{column,4}}}, (neotoma_peg:p_one_or_more(neotoma_peg:p_string("abc")))("abcdef",?STARTINDEX)), |
| 57 | + ?_assertEqual({["abc","abc"], "def",{{line,1},{column,7}}}, (neotoma_peg:p_one_or_more(neotoma_peg:p_string("abc")))("abcabcdef",?STARTINDEX)) |
58 | 58 | ].
|
59 | 59 |
|
60 | 60 | label_test_() ->
|
61 | 61 | [
|
62 |
| - ?_assertEqual({fail,{expected, {string, "!"}, ?STARTINDEX}}, (peg:p_label(bang, peg:p_string("!")))("?",?STARTINDEX)), |
63 |
| - ?_assertEqual({{bang, "!"}, "",{{line,1},{column,2}}}, (peg:p_label(bang, peg:p_string("!")))("!",?STARTINDEX)) |
| 62 | + ?_assertEqual({fail,{expected, {string, "!"}, ?STARTINDEX}}, (neotoma_peg:p_label(bang, neotoma_peg:p_string("!")))("?",?STARTINDEX)), |
| 63 | + ?_assertEqual({{bang, "!"}, "",{{line,1},{column,2}}}, (neotoma_peg:p_label(bang, neotoma_peg:p_string("!")))("!",?STARTINDEX)) |
64 | 64 | ].
|
65 | 65 |
|
66 | 66 | string_test_() ->
|
67 | 67 | [
|
68 |
| - ?_assertEqual({"abc", "def",{{line,1},{column,4}}}, (peg:p_string("abc"))("abcdef",?STARTINDEX)), |
69 |
| - ?_assertEqual({fail,{expected, {string, "abc"}, ?STARTINDEX}}, (peg:p_string("abc"))("defabc",?STARTINDEX)) |
| 68 | + ?_assertEqual({"abc", "def",{{line,1},{column,4}}}, (neotoma_peg:p_string("abc"))("abcdef",?STARTINDEX)), |
| 69 | + ?_assertEqual({fail,{expected, {string, "abc"}, ?STARTINDEX}}, (neotoma_peg:p_string("abc"))("defabc",?STARTINDEX)) |
70 | 70 | ].
|
71 | 71 |
|
72 | 72 | anything_test_() ->
|
73 | 73 | [
|
74 |
| - ?_assertEqual({$a,"bcde",{{line,1},{column,2}}}, (peg:p_anything())("abcde",?STARTINDEX)), |
75 |
| - ?_assertEqual({fail,{expected, any_character, ?STARTINDEX}}, (peg:p_anything())("",?STARTINDEX)) |
| 74 | + ?_assertEqual({$a,"bcde",{{line,1},{column,2}}}, (neotoma_peg:p_anything())("abcde",?STARTINDEX)), |
| 75 | + ?_assertEqual({fail,{expected, any_character, ?STARTINDEX}}, (neotoma_peg:p_anything())("",?STARTINDEX)) |
76 | 76 | ].
|
77 | 77 |
|
78 | 78 | charclass_test_() ->
|
79 | 79 | [
|
80 |
| - ?_assertEqual({$+,"----",{{line,1},{column,2}}}, (peg:p_charclass("[+]"))("+----",?STARTINDEX)), |
81 |
| - ?_assertEqual({fail,{expected, {character_class, "[+]"}, ?STARTINDEX}}, (peg:p_charclass("[+]"))("----",?STARTINDEX)) |
| 80 | + ?_assertEqual({$+,"----",{{line,1},{column,2}}}, (neotoma_peg:p_charclass("[+]"))("+----",?STARTINDEX)), |
| 81 | + ?_assertEqual({fail,{expected, {character_class, "[+]"}, ?STARTINDEX}}, (neotoma_peg:p_charclass("[+]"))("----",?STARTINDEX)) |
82 | 82 | ].
|
0 commit comments