diff options
| author | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-09 01:44:06 +1300 |
|---|---|---|
| committer | Matthew Hall <hallmatthew314@gmail.com> | 2023-03-09 01:44:06 +1300 |
| commit | f5e87b41ffcb036c705c32b55161ae91a04c72e1 (patch) | |
| tree | 334cdcc5b8ee1c773a9ee0418b4e744f7d7f2f73 /spec | |
| parent | 27a2d4281c5b270d6f3bba06ff1fd82ebfb94df6 (diff) | |
Implement Token sequence parser
Diffstat (limited to 'spec')
| -rw-r--r-- | spec/parcom_spec.cr | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr index 5be59b9..937c43c 100644 --- a/spec/parcom_spec.cr +++ b/spec/parcom_spec.cr @@ -378,7 +378,28 @@ describe Optional do end end -pending Tokens do +describe Tokens do + p = Tokens.new("test".chars) + + describe "#parse" do + it "fails if the input stream is too short" do + input = TokenStream.from_string("") + expect_raises(ParserException) { p.parse(input) } + end + + it "fails if it encounters an unexpected token" do + input = TokenStream.from_string("text") + expect_raises(ParserException) { p.parse(input) } + end + + it "succeeds if the input starts with the expected tokens" do + input = TokenStream.from_string("testing") + result = p.parse(input) + + result.tokens.should eq(input[4..]) + result.value.should eq("test".chars) + end + end end pending Many do |
