diff options
Diffstat (limited to 'spec/parcom_spec.cr')
| -rw-r--r-- | spec/parcom_spec.cr | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr index 76be4c2..c586a7c 100644 --- a/spec/parcom_spec.cr +++ b/spec/parcom_spec.cr @@ -409,6 +409,21 @@ describe Parser do end end + describe "#and_then" do + p_string = ->(s : String) do + Parser.token_sequence(s.chars).map(&.join) + end + p_any_word = Parser(Char, Array(Char)).satisfy(&.letter?).some.map(&.join) + space = Parser(Char, Array(Char)).satisfy(&.whitespace?).some + # Parses two of the same word, with whitespace between: + two_words = (p_any_word << space).and_then(p_string) + + tokens = Tokens.from_string("foo foo") + result = two_words.parse(tokens) + + result.value.should eq("foo") + end + describe "#many" do p = Parser(Char, Char).token('a').many |
