From c5e9cf215517aafc1a55b20d9f4dde7f75f90293 Mon Sep 17 00:00:00 2001 From: MadMaurice Date: Sat, 10 Apr 2021 01:26:07 +0200 Subject: [PATCH] Fix lexer: Strings can be empty --- lib/Minilisp.pm | 2 +- t/strings.t | 4 +++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/lib/Minilisp.pm b/lib/Minilisp.pm index a5d042f..4186e56 100644 --- a/lib/Minilisp.pm +++ b/lib/Minilisp.pm @@ -75,7 +75,7 @@ sub tokenize { value => $1, }; } - elsif($str =~ s/^"(([^"\\]|\\.)+)"//) + elsif($str =~ s/^"(([^"\\]|\\.)*)"//) { $debug->("String '$1'"); my $value = $1; diff --git a/t/strings.t b/t/strings.t index 9533044..9714cae 100644 --- a/t/strings.t +++ b/t/strings.t @@ -1,7 +1,9 @@ -(plan 4) +(plan 5) (expect "length of string" (= (length "hello") 5)) +(expect "empty strings" (= (length "") 0)) + (expect "string-upcase" (string= (string-upcase "helLo") "HELLO")) (expect "string-downcase" (string= (string-downcase "HEllO") "hello"))