spec/lib/hotcell/lexer_spec.rb in hotcell-0.1.0 vs spec/lib/hotcell/lexer_spec.rb in hotcell-0.2.0
- old
+ new
@@ -43,10 +43,12 @@
context 'flow' do
specify { expression('=').should == [[:ASSIGN, '=']] }
specify { expression('= =').should == [[:ASSIGN, '='], [:ASSIGN, '=']] }
specify { expression(',').should == [[:COMMA, ',']] }
specify { expression('.').should == [[:PERIOD, '.']] }
+ specify { expression('..').should == [[:RANGE, '..']] }
+ specify { expression('...').should == [[:RANGE, '...']] }
specify { expression(':').should == [[:COLON, ':']] }
specify { expression('?').should == [[:QUESTION, '?']] }
specify { expression('hello?').should == [[:IDENTIFER, 'hello?']] }
specify { expression('hello ?').should == [[:IDENTIFER, 'hello'], [:QUESTION, '?']] }
specify { expression(';').should == [[:SEMICOLON, ';']] }
@@ -81,11 +83,11 @@
specify { expression('0.42').should == [[:FLOAT, 0.42]] }
specify { expression('.42').should == [[:FLOAT, 0.42]] }
specify { expression('.42.').should == [[:FLOAT, 0.42], [:PERIOD, '.']] }
specify { expression('.42.foo').should == [[:FLOAT, 0.42], [:PERIOD, '.'], [:IDENTIFER, 'foo']] }
specify { expression('.42foo').should == [[:FLOAT, 0.42], [:IDENTIFER, 'foo']] }
- specify { expression('..42').should == [[:PERIOD, '.'], [:FLOAT, 0.42]] }
+ specify { expression('..42').should == [[:RANGE, '..'], [:INTEGER, 42]] }
end
end
context 'identifer' do
specify { expression('foo').should == [[:IDENTIFER, 'foo']] }
@@ -309,25 +311,34 @@
specify { scan('2 + 3 {{ 2 || 3 }} hello').should == [
[:TEMPLATE, "2 + 3 "], [:TOPEN, "{{"], [:INTEGER, 2],
[:OR, "||"], [:INTEGER, 3], [:TCLOSE, "}}"], [:TEMPLATE, " hello"]
] }
- context 'tag types' do
- specify { scan('{{hello}}').should == [
- [:TOPEN, "{{"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]
- ] }
- specify { scan('{{! hello}}').should == [
- [:TOPEN, "{{!"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]
- ] }
- specify { scan('{{ !hello}}').should == [
- [:TOPEN, "{{"], [:NOT, "!"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]
- ] }
- specify { scan('{{/ hello}}').should == [
- [:TOPEN, "{{"], [:DIVIDE, "/"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]
- ] }
- specify { scan('{{ /hello}}').should == [
- [:TOPEN, "{{"], [:DIVIDE, "/"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]
- ] }
+ context 'tag modifers' do
+ specify { scan('{{hello}}').should == [[:TOPEN, "{{"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+
+ specify { scan('{{! hello}}').should == [[:TOPEN, "{{!"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { scan('{{!hello}}').should == [[:TOPEN, "{{!"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { scan('{{ !hello}}').should == [[:TOPEN, "{{"], [:NOT, "!"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { scan('{{!}}').should == [[:TOPEN, "{{!"], [:TCLOSE, "}}"]] }
+
+ specify { scan('{{~ hello}}').should == [[:TOPEN, "{{~"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { scan('{{~hello}}').should == [[:TOPEN, "{{~"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { expect { scan('{{ ~hello}}') }.to raise_error Hotcell::UnexpectedSymbol }
+ specify { scan('{{~}}').should == [[:TOPEN, "{{~"], [:TCLOSE, "}}"]] }
+
+ specify { scan('{{^ hello}}').should == [[:TOPEN, "{{^"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { scan('{{^hello}}').should == [[:TOPEN, "{{^"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { expect { scan('{{ ^hello}}') }.to raise_error Hotcell::UnexpectedSymbol }
+ specify { scan('{{^}}').should == [[:TOPEN, "{{^"], [:TCLOSE, "}}"]] }
+
+ specify { scan('{{r hello}}').should == [[:TOPEN, "{{r "], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { scan('{{ r hello}}').should == [[:TOPEN, "{{"], [:IDENTIFER, "r"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { scan('{{rhello}}').should == [[:TOPEN, "{{"], [:IDENTIFER, "rhello"], [:TCLOSE, "}}"]] }
+
+ specify { scan('{{e hello}}').should == [[:TOPEN, "{{e "], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { scan('{{ e hello}}').should == [[:TOPEN, "{{"], [:IDENTIFER, "e"], [:IDENTIFER, "hello"], [:TCLOSE, "}}"]] }
+ specify { scan('{{ehello}}').should == [[:TOPEN, "{{"], [:IDENTIFER, "ehello"], [:TCLOSE, "}}"]] }
end
end
context 'template comments' do
specify { scan('{{#').should == [[:COMMENT, "{{#"]] }