From f5e87b41ffcb036c705c32b55161ae91a04c72e1 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Thu, 9 Mar 2023 01:44:06 +1300 Subject: Implement Token sequence parser --- spec/parcom_spec.cr | 23 ++++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) (limited to 'spec/parcom_spec.cr') 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 -- cgit v1.2.1