File tree Expand file tree Collapse file tree 2 files changed +26
-3
lines changed
Expand file tree Collapse file tree 2 files changed +26
-3
lines changed Original file line number Diff line number Diff line change @@ -123,6 +123,9 @@ def next_token
123123 value = self . yylval
124124 location = [ @line , @tok_column ]
125125
126+ # once location is stored, ensure next token starts in correct place
127+ @tok_column = @column
128+
126129 [ token , [ value , location ] ]
127130 end
128131
Original file line number Diff line number Diff line change 1818 expect_lines ( "=begin\n foo\n bar\n =end\n 42\n 43" ) . to eq ( [ 5 , 6 ] )
1919 end
2020
21+ it "sets correct column for each token" do
22+ expect_columns ( "1" ) . to eq ( [ 0 ] )
23+ expect_columns ( "1;2; 3" ) . to eq ( [ 0 , 2 , 5 ] )
24+ expect_columns ( " \t 3" ) . to eq ( [ 5 ] )
25+ end
26+
27+ it "sets the column to 0 on each new line" do
28+ expect_columns ( "1\n 2\n \n \n 3\n 4" ) . to eq ( [ 0 , 0 , 0 , 1 ] )
29+ end
30+
31+ it "sets column with regard to whitespace and other tokens before it" do
32+ expect_columns ( "true; false; self\n ni;" ) . to eq ( [ 0 , 7 , 15 , 2 ] )
33+ end
34+
2135 def expect_lines ( source )
22- parsed = Opal :: Parser . new . parse ( source )
23- nodes = parsed . type == :block ? parsed . children : [ parsed ]
36+ expect ( parsed_nodes ( source ) . map { | sexp | sexp . line } )
37+ end
2438
25- expect ( nodes . map { |sexp | sexp . line } )
39+ def expect_columns ( source )
40+ expect ( parsed_nodes ( source ) . map { |sexp | sexp . column } )
41+ end
42+
43+ def parsed_nodes ( source )
44+ parsed = Opal ::Parser . new . parse ( source )
45+ parsed . type == :block ? parsed . children : [ parsed ]
2646 end
2747end
You can’t perform that action at this time.
0 commit comments