From a4430f0fb86871ad15b1fce586f69a1486dc7844 Mon Sep 17 00:00:00 2001 From: Matthew Hall Date: Mon, 13 Mar 2023 13:54:48 +1300 Subject: Slightly more robust test case --- spec/parcom_spec.cr | 27 +++++++++++++++++++++++---- 1 file changed, 23 insertions(+), 4 deletions(-) diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr index feea102..25ae2e9 100644 --- a/spec/parcom_spec.cr +++ b/spec/parcom_spec.cr @@ -737,10 +737,29 @@ describe "Practical use" do arrs.map { |chars| chars.join } end - tokens = Tokens.from_string("test number 1 ") - result = tokenizer.parse(tokens) - result.value.should eq(["test", "number", "1"]) - result.tokens.empty?.should be_true + good_strings = [ + "test with no trailing whitespace", + " test with whitespace in the front", + "test with whitespace in the back", + " test surrounded by whitespace ", + ] + + good_strings.each do |s| + tokens = Tokens.from_string(s) + result = tokenizer.parse(tokens) + result.value.should eq(s.strip.split(/\s+/)) + result.tokens.empty?.should be_true + end + + bad_strings = [ + "", + " ", + ] + + bad_strings.each do |s| + tokens = Tokens.from_string(s) + expect_raises(ParserFail) { tokenizer.parse(tokens) } + end end end -- cgit v1.2.1