File tree Expand file tree Collapse file tree 1 file changed +27
-0
lines changed
Expand file tree Collapse file tree 1 file changed +27
-0
lines changed Original file line number Diff line number Diff line change 1+ require File . expand_path ( '../spec_helper' , __FILE__ )
2+ require 'opal/parser'
3+
4+ describe Opal ::Lexer do
5+ it "sets correct line information for each token" do
6+ expect_lines ( "42" ) . to eq ( [ 1 ] )
7+ expect_lines ( "\n 3.142" ) . to eq ( [ 2 ] )
8+ expect_lines ( "3.142\n 42\n 57" ) . to eq ( [ 1 , 2 , 3 ] )
9+ end
10+
11+ it "increments the line count over multiple new lines" do
12+ expect_lines ( "1\n \n \n 2" ) . to eq ( [ 1 , 4 ] )
13+ expect_lines ( "\n \n \n 3\n \n 5\n \n " ) . to eq ( [ 4 , 6 ] )
14+ end
15+
16+ it "increments line numbers over =begin...=end blocks" do
17+ expect_lines ( "=begin\n =end\n 1" ) . to eq ( [ 3 ] )
18+ expect_lines ( "=begin\n foo\n bar\n =end\n 42\n 43" ) . to eq ( [ 5 , 6 ] )
19+ end
20+
21+ def expect_lines ( source )
22+ parsed = Opal ::Parser . new . parse ( source )
23+ nodes = parsed . type == :block ? parsed . children : [ parsed ]
24+
25+ expect ( nodes . map { |sexp | sexp . line } )
26+ end
27+ end
You can’t perform that action at this time.
0 commit comments