summaryrefslogtreecommitdiff
path: root/spec/unit/pops/parser/lexer2_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/unit/pops/parser/lexer2_spec.rb')
-rw-r--r--spec/unit/pops/parser/lexer2_spec.rb25
1 files changed, 21 insertions, 4 deletions
diff --git a/spec/unit/pops/parser/lexer2_spec.rb b/spec/unit/pops/parser/lexer2_spec.rb
index 8ccdc2630..b9a0a916b 100644
--- a/spec/unit/pops/parser/lexer2_spec.rb
+++ b/spec/unit/pops/parser/lexer2_spec.rb
@@ -21,7 +21,7 @@ describe 'Lexer2' do
include EgrammarLexer2Spec
{
- :LBRACK => '[',
+ :LISTSTART => '[',
:RBRACK => ']',
:LBRACE => '{',
:RBRACE => '}',
@@ -69,6 +69,10 @@ describe 'Lexer2' do
end
end
+ it "should lex [ in position after non whitespace as LBRACK" do
+ tokens_scanned_from("a[").should match_tokens2(:NAME, :LBRACK)
+ end
+
{
"case" => :CASE,
"class" => :CLASS,
@@ -186,6 +190,16 @@ describe 'Lexer2' do
end
end
+ { "''" => [2, ""],
+ "'a'" => [3, "a"],
+ "'a\\'b'" => [6, "a'b"],
+ }.each do |source, expected|
+ it "should lex a single quoted STRING on the form #{source} as having length #{expected[0]}" do
+ length, value = expected
+ tokens_scanned_from(source).should match_tokens2([:STRING, value, {:line => 1, :pos=>1, :length=> length}])
+ end
+ end
+
{ '""' => '',
'"a"' => 'a',
'"a\'b"' => "a'b",
@@ -229,7 +243,7 @@ describe 'Lexer2' do
it "differentiates between foo[x] and foo [x] (whitespace)" do
tokens_scanned_from("$a[1]").should match_tokens2(:VARIABLE, :LBRACK, :NUMBER, :RBRACK)
- tokens_scanned_from("$a [1]").should match_tokens2(:VARIABLE, :LBRACK, :NUMBER, :RBRACK)
+ tokens_scanned_from("$a [1]").should match_tokens2(:VARIABLE, :LISTSTART, :NUMBER, :RBRACK)
tokens_scanned_from("a[1]").should match_tokens2(:NAME, :LBRACK, :NUMBER, :RBRACK)
tokens_scanned_from("a [1]").should match_tokens2(:NAME, :LISTSTART, :NUMBER, :RBRACK)
tokens_scanned_from(" if \n\r\t\nif if ").should match_tokens2(:IF, :IF, :IF)
@@ -257,7 +271,9 @@ describe 'Lexer2' do
"!~" => [:NOMATCH, "!~ /./"],
"," => [:COMMA, ", /./"],
"(" => [:LPAREN, "( /./"],
- "[" => [:LBRACK, "[ /./"],
+ "[" => [:LISTSTART, "[ /./"],
+ "[" => [[:NAME, :LBRACK], "a[ /./"],
+ "[" => [[:NAME, :LISTSTART], "a [ /./"],
"{" => [:LBRACE, "{ /./"],
"+" => [:PLUS, "+ /./"],
"-" => [:MINUS, "- /./"],
@@ -265,7 +281,8 @@ describe 'Lexer2' do
";" => [:SEMIC, "; /./"],
}.each do |token, entry|
it "should lex regexp after '#{token}'" do
- tokens_scanned_from(entry[1]).should match_tokens2(entry[0], :REGEX)
+ expected = [entry[0], :REGEX].flatten
+ tokens_scanned_from(entry[1]).should match_tokens2(*expected)
end
end