aboutsummaryrefslogtreecommitdiff
path: root/spec
diff options
context:
space:
mode:
Diffstat (limited to 'spec')
-rw-r--r--spec/parcom_spec.cr23
1 files changed, 23 insertions, 0 deletions
diff --git a/spec/parcom_spec.cr b/spec/parcom_spec.cr
index dde6f21..feea102 100644
--- a/spec/parcom_spec.cr
+++ b/spec/parcom_spec.cr
@@ -721,3 +721,26 @@ describe SepBy do
end
end
+describe "Practical use" do
+ describe "Use case: text surrounded by whitespace" do
+ space = Satisfy(Char).new { |c| c.whitespace? }
+ non_space = Satisfy(Char).new { |c| !c.whitespace? }
+
+ # TODO: Figure out why mapping on this parser breaks
+ # initialization of `body`.
+ word_chars = Some.new(non_space)
+ ws = Some.new(space)
+
+ bookend = Optional.new(ws)
+ body = SepBy.new(word_chars, ws)
+ tokenizer = (bookend >> body << bookend).map do |arrs|
+ 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
+ end
+end
+