spec/lib/hotcell/parser_spec.rb in hotcell-0.0.1 vs spec/lib/hotcell/parser_spec.rb in hotcell-0.1.0
- old
+ new
@@ -30,22 +30,22 @@
specify { parse('{{ }}').should be_equal_node_to JOINER(TAG(mode: :normal)) }
specify { parse('hello {{ }}').should be_equal_node_to JOINER('hello ', TAG(mode: :normal)) }
specify { parse('{{ }}hello').should be_equal_node_to JOINER(TAG(mode: :normal), 'hello') }
specify { parse('hello{{ }} hello').should be_equal_node_to JOINER('hello', TAG(mode: :normal), ' hello') }
specify { parse('hello {{ hello(\'world\') }} hello').should be_equal_node_to JOINER(
- 'hello ', TAG(METHOD(nil, 'hello', 'world'), mode: :normal), ' hello'
+ 'hello ', TAG(METHOD('hello', nil, 'world'), mode: :normal), ' hello'
) }
specify { parse('hello {{ hello(\'world\') }} hello {{! a = 5; }} {}').should be_equal_node_to JOINER(
- 'hello ', TAG(METHOD(nil, 'hello', 'world'), mode: :normal),
+ 'hello ', TAG(METHOD('hello', nil, 'world'), mode: :normal),
' hello ', TAG(ASSIGN('a', 5), mode: :silence), ' {}'
) }
specify { parse('{{ hello(\'world\') }} hello {{! a = 5; }} {}').should be_equal_node_to JOINER(
- TAG(METHOD(nil, 'hello', 'world'), mode: :normal),
+ TAG(METHOD('hello', nil, 'world'), mode: :normal),
' hello ', TAG(ASSIGN('a', 5), mode: :silence), ' {}'
) }
specify { parse('{{ hello(\'world\') }} hello {{! a = 5; }}').should be_equal_node_to JOINER(
- TAG(METHOD(nil, 'hello', 'world'), mode: :normal),
+ TAG(METHOD('hello', nil, 'world'), mode: :normal),
' hello ', TAG(ASSIGN('a', 5), mode: :silence)
) }
end
context 'multiline' do
@@ -64,11 +64,11 @@
foo = (3; 5)
bar = 3; 5
}}
TPL
).should be_equal_node_to JOINER(' ', TAG(
- METHOD(nil, 'hello'),
+ METHOD('hello'),
42,
ARRAY(1, 2, 3),
'hello',
HASH(),
SEQUENCE(/regexp/, 43),
@@ -113,154 +113,164 @@
'world'
}
}}
TPL
).should be_equal_node_to JOINER(' ', TAG(
- METHOD(nil, 'foo'),
- METHOD(nil, 'hello', 7, 8),
+ METHOD('foo'),
+ METHOD('hello', nil, 7, 8),
false,
ARRAY(),
- PLUS(2, METHOD(nil, 'foo')),
- MINUS(46, METHOD(nil, 'moo')),
+ PLUS(2, METHOD('foo')),
+ MINUS(46, METHOD('moo')),
46,
- UMINUS(METHOD(nil, 'moo')),
- POWER(2, METHOD(nil, 'bar')),
+ UMINUS(METHOD('moo')),
+ POWER(2, METHOD('bar')),
nil,
- GTE(METHOD(nil, 'baz'), 5),
+ GTE(METHOD('baz'), 5),
ASSIGN('foo', 10),
HASH(),
ARRAY(42, 43, 44),
HASH(PAIR('foo', 'hello'), PAIR('bar', 'world')),
mode: :normal), "\n") }
end
context 'expressions' do
- specify { parse('{{ 2 + hello }}').should be_equal_node_to JOINER(TAG(PLUS(2, METHOD(nil, 'hello')), mode: :normal)) }
+ specify { parse('{{ 2 + hello }}').should be_equal_node_to JOINER(TAG(PLUS(2, METHOD('hello')), mode: :normal)) }
specify { parse('{{ --2 }}').should be_equal_node_to JOINER(TAG(2, mode: :normal)) }
- specify { parse('{{ --hello }}').should be_equal_node_to JOINER(TAG(UMINUS(UMINUS(METHOD(nil, 'hello'))), mode: :normal)) }
+ specify { parse('{{ --hello }}').should be_equal_node_to JOINER(TAG(UMINUS(UMINUS(METHOD('hello'))), mode: :normal)) }
specify { parse('{{ \'hello\' + \'world\' }}').should be_equal_node_to JOINER(TAG('helloworld', mode: :normal)) }
- specify { parse('{{ 2 - hello }}').should be_equal_node_to JOINER(TAG(MINUS(2, METHOD(nil, 'hello')), mode: :normal)) }
- specify { parse('{{ 2 * hello }}').should be_equal_node_to JOINER(TAG(MULTIPLY(2, METHOD(nil, 'hello')), mode: :normal)) }
- specify { parse('{{ 2 / hello }}').should be_equal_node_to JOINER(TAG(DIVIDE(2, METHOD(nil, 'hello')), mode: :normal)) }
- specify { parse('{{ 2 % hello }}').should be_equal_node_to JOINER(TAG(MODULO(2, METHOD(nil, 'hello')), mode: :normal)) }
- specify { parse('{{ 2 ** hello }}').should be_equal_node_to JOINER(TAG(POWER(2, METHOD(nil, 'hello')), mode: :normal)) }
- specify { parse('{{ -hello }}').should be_equal_node_to JOINER(TAG(UMINUS(METHOD(nil, 'hello')), mode: :normal)) }
- specify { parse('{{ +hello }}').should be_equal_node_to JOINER(TAG(UPLUS(METHOD(nil, 'hello')), mode: :normal)) }
+ specify { parse('{{ 2 - hello }}').should be_equal_node_to JOINER(TAG(MINUS(2, METHOD('hello')), mode: :normal)) }
+ specify { parse('{{ 2 * hello }}').should be_equal_node_to JOINER(TAG(MULTIPLY(2, METHOD('hello')), mode: :normal)) }
+ specify { parse('{{ 2 / hello }}').should be_equal_node_to JOINER(TAG(DIVIDE(2, METHOD('hello')), mode: :normal)) }
+ specify { parse('{{ 2 % hello }}').should be_equal_node_to JOINER(TAG(MODULO(2, METHOD('hello')), mode: :normal)) }
+ specify { parse('{{ 2 ** hello }}').should be_equal_node_to JOINER(TAG(POWER(2, METHOD('hello')), mode: :normal)) }
+ specify { parse('{{ -hello }}').should be_equal_node_to JOINER(TAG(UMINUS(METHOD('hello')), mode: :normal)) }
+ specify { parse('{{ +hello }}').should be_equal_node_to JOINER(TAG(UPLUS(METHOD('hello')), mode: :normal)) }
specify { parse('{{ -2 }}').should be_equal_node_to JOINER(TAG(-2, mode: :normal)) }
specify { parse('{{ +2 }}').should be_equal_node_to JOINER(TAG(2, mode: :normal)) }
- specify { parse('{{ 2 + lol * 2 }}').should be_equal_node_to JOINER(TAG(PLUS(2, MULTIPLY(METHOD(nil, 'lol'), 2)), mode: :normal)) }
- specify { parse('{{ 2 + lol - 2 }}').should be_equal_node_to JOINER(TAG(MINUS(PLUS(2, METHOD(nil, 'lol')), 2), mode: :normal)) }
- specify { parse('{{ 2 ** foo * 2 }}').should be_equal_node_to JOINER(TAG(MULTIPLY(POWER(2, METHOD(nil, 'foo')), 2), mode: :normal)) }
- specify { parse('{{ 1 ** foo ** 3 }}').should be_equal_node_to JOINER(TAG(POWER(1, POWER(METHOD(nil, 'foo'), 3)), mode: :normal)) }
- specify { parse('{{ (2 + foo) * 2 }}').should be_equal_node_to JOINER(TAG(MULTIPLY(PLUS(2, METHOD(nil, 'foo')), 2), mode: :normal)) }
+ specify { parse('{{ 2 + lol * 2 }}').should be_equal_node_to JOINER(TAG(PLUS(2, MULTIPLY(METHOD('lol'), 2)), mode: :normal)) }
+ specify { parse('{{ 2 + lol - 2 }}').should be_equal_node_to JOINER(TAG(MINUS(PLUS(2, METHOD('lol')), 2), mode: :normal)) }
+ specify { parse('{{ 2 ** foo * 2 }}').should be_equal_node_to JOINER(TAG(MULTIPLY(POWER(2, METHOD('foo')), 2), mode: :normal)) }
+ specify { parse('{{ 1 ** foo ** 3 }}').should be_equal_node_to JOINER(TAG(POWER(1, POWER(METHOD('foo'), 3)), mode: :normal)) }
+ specify { parse('{{ (2 + foo) * 2 }}').should be_equal_node_to JOINER(TAG(MULTIPLY(PLUS(2, METHOD('foo')), 2), mode: :normal)) }
specify { parse('{{ (nil) }}').should be_equal_node_to JOINER(TAG(nil, mode: :normal)) }
specify { parse('{{ (3) }}').should be_equal_node_to JOINER(TAG(3, mode: :normal)) }
specify { parse('{{ (\'hello\') }}').should be_equal_node_to JOINER(TAG('hello', mode: :normal)) }
specify { parse('{{ () }}').should be_equal_node_to JOINER(TAG(nil, mode: :normal)) }
- specify { parse('{{ bar > 2 }}').should be_equal_node_to JOINER(TAG(GT(METHOD(nil, 'bar'), 2), mode: :normal)) }
- specify { parse('{{ 2 < bar }}').should be_equal_node_to JOINER(TAG(LT(2, METHOD(nil, 'bar')), mode: :normal)) }
- specify { parse('{{ 2 >= tru }}').should be_equal_node_to JOINER(TAG(GTE(2, METHOD(nil, 'tru')), mode: :normal)) }
- specify { parse('{{ some <= 2 }}').should be_equal_node_to JOINER(TAG(LTE(METHOD(nil, 'some'), 2), mode: :normal)) }
+ specify { parse('{{ bar > 2 }}').should be_equal_node_to JOINER(TAG(GT(METHOD('bar'), 2), mode: :normal)) }
+ specify { parse('{{ 2 < bar }}').should be_equal_node_to JOINER(TAG(LT(2, METHOD('bar')), mode: :normal)) }
+ specify { parse('{{ 2 >= tru }}').should be_equal_node_to JOINER(TAG(GTE(2, METHOD('tru')), mode: :normal)) }
+ specify { parse('{{ some <= 2 }}').should be_equal_node_to JOINER(TAG(LTE(METHOD('some'), 2), mode: :normal)) }
specify { parse('{{ 2 && false }}').should be_equal_node_to JOINER(TAG(false, mode: :normal)) }
specify { parse('{{ null || 2 }}').should be_equal_node_to JOINER(TAG(2, mode: :normal)) }
- specify { parse('{{ 2 > bar < 2 }}').should be_equal_node_to JOINER(TAG(LT(GT(2, METHOD(nil, 'bar')), 2), mode: :normal)) }
- specify { parse('{{ 2 || bar && 2 }}').should be_equal_node_to JOINER(TAG(OR(2, AND(METHOD(nil, 'bar'), 2)), mode: :normal)) }
- specify { parse('{{ 2 && foo || 2 }}').should be_equal_node_to JOINER(TAG(OR(AND(2, METHOD(nil, 'foo')), 2), mode: :normal)) }
- specify { parse('{{ !2 && moo }}').should be_equal_node_to JOINER(TAG(AND(false, METHOD(nil, 'moo')), mode: :normal)) }
- specify { parse('{{ !(2 && moo) }}').should be_equal_node_to JOINER(TAG(NOT(AND(2, METHOD(nil, 'moo'))), mode: :normal)) }
+ specify { parse('{{ 2 > bar < 2 }}').should be_equal_node_to JOINER(TAG(LT(GT(2, METHOD('bar')), 2), mode: :normal)) }
+ specify { parse('{{ 2 || bar && 2 }}').should be_equal_node_to JOINER(TAG(OR(2, AND(METHOD('bar'), 2)), mode: :normal)) }
+ specify { parse('{{ 2 && foo || 2 }}').should be_equal_node_to JOINER(TAG(OR(AND(2, METHOD('foo')), 2), mode: :normal)) }
+ specify { parse('{{ !2 && moo }}').should be_equal_node_to JOINER(TAG(AND(false, METHOD('moo')), mode: :normal)) }
+ specify { parse('{{ !(2 && moo) }}').should be_equal_node_to JOINER(TAG(NOT(AND(2, METHOD('moo'))), mode: :normal)) }
- specify { parse('{{ hello = bzz + 2 }}').should be_equal_node_to JOINER(TAG(ASSIGN('hello', PLUS(METHOD(nil, 'bzz'), 2)), mode: :normal)) }
- specify { parse('{{ hello = 2 ** bar }}').should be_equal_node_to JOINER(TAG(ASSIGN('hello', POWER(2, METHOD(nil, 'bar'))), mode: :normal)) }
+ specify { parse('{{ hello = bzz + 2 }}').should be_equal_node_to JOINER(TAG(ASSIGN('hello', PLUS(METHOD('bzz'), 2)), mode: :normal)) }
+ specify { parse('{{ hello = 2 ** bar }}').should be_equal_node_to JOINER(TAG(ASSIGN('hello', POWER(2, METHOD('bar'))), mode: :normal)) }
specify { parse('{{ hello = 2 == 2 }}').should be_equal_node_to JOINER(TAG(ASSIGN('hello', true), mode: :normal)) }
- specify { parse('{{ hello = 2 && var }}').should be_equal_node_to JOINER(TAG(ASSIGN('hello', AND(2, METHOD(nil, 'var'))), mode: :normal)) }
- specify { parse('{{ hello = world() }}').should be_equal_node_to JOINER(TAG(ASSIGN('hello', METHOD(nil, 'world')), mode: :normal)) }
+ specify { parse('{{ hello = 2 && var }}').should be_equal_node_to JOINER(TAG(ASSIGN('hello', AND(2, METHOD('var'))), mode: :normal)) }
+ specify { parse('{{ hello = world() }}').should be_equal_node_to JOINER(TAG(ASSIGN('hello', METHOD('world')), mode: :normal)) }
specify { parse('{{ !hello = 2 >= 2 }}').should be_equal_node_to JOINER(TAG(NOT(ASSIGN('hello', true)), mode: :normal)) }
- specify { parse('{{ !foo ** 2 + 3 }}').should be_equal_node_to JOINER(TAG(PLUS(POWER(NOT(METHOD(nil, 'foo')), 2), 3), mode: :normal)) }
- specify { parse('{{ -bla ** 2 }}').should be_equal_node_to JOINER(TAG(UMINUS(POWER(METHOD(nil, 'bla'), 2)), mode: :normal)) }
- specify { parse('{{ -2 % bla }}').should be_equal_node_to JOINER(TAG(MODULO(-2, METHOD(nil, 'bla')), mode: :normal)) }
- specify { parse('{{ -hello ** 2 }}').should be_equal_node_to JOINER(TAG(UMINUS(POWER(METHOD(nil, 'hello'), 2)), mode: :normal)) }
- specify { parse('{{ -hello * 2 }}').should be_equal_node_to JOINER(TAG(MULTIPLY(UMINUS(METHOD(nil, 'hello')), 2), mode: :normal)) }
- specify { parse('{{ haha + 2 == 2 * 2 }}').should be_equal_node_to JOINER(TAG(EQUAL(PLUS(METHOD(nil, 'haha'), 2), 4), mode: :normal)) }
- specify { parse('{{ 2 * foo != 2 && bar }}').should be_equal_node_to JOINER(TAG(AND(INEQUAL(MULTIPLY(2, METHOD(nil, 'foo')), 2), METHOD(nil, 'bar')), mode: :normal)) }
+ specify { parse('{{ !foo ** 2 + 3 }}').should be_equal_node_to JOINER(TAG(PLUS(POWER(NOT(METHOD('foo')), 2), 3), mode: :normal)) }
+ specify { parse('{{ -bla ** 2 }}').should be_equal_node_to JOINER(TAG(UMINUS(POWER(METHOD('bla'), 2)), mode: :normal)) }
+ specify { parse('{{ -2 % bla }}').should be_equal_node_to JOINER(TAG(MODULO(-2, METHOD('bla')), mode: :normal)) }
+ specify { parse('{{ -hello ** 2 }}').should be_equal_node_to JOINER(TAG(UMINUS(POWER(METHOD('hello'), 2)), mode: :normal)) }
+ specify { parse('{{ -hello * 2 }}').should be_equal_node_to JOINER(TAG(MULTIPLY(UMINUS(METHOD('hello')), 2), mode: :normal)) }
+ specify { parse('{{ haha + 2 == 2 * 2 }}').should be_equal_node_to JOINER(TAG(EQUAL(PLUS(METHOD('haha'), 2), 4), mode: :normal)) }
+ specify { parse('{{ 2 * foo != 2 && bar }}').should be_equal_node_to JOINER(TAG(AND(INEQUAL(MULTIPLY(2, METHOD('foo')), 2), METHOD('bar')), mode: :normal)) }
context 'method call' do
specify { parse('{{ foo.bar.baz }}').should be_equal_node_to JOINER(TAG(
- METHOD(METHOD(METHOD(nil, 'foo'), 'bar'), 'baz'),
+ METHOD('baz', METHOD('bar', METHOD('foo'))),
mode: :normal)) }
+ specify { parse('{{ -bar.baz }}').should be_equal_node_to JOINER(TAG(
+ UMINUS(METHOD('baz', METHOD('bar'))),
+ mode: :normal)) }
+ specify { parse('{{ -42.baz }}').should be_equal_node_to JOINER(TAG(
+ METHOD('baz', -42),
+ mode: :normal)) }
+ specify { parse('{{ - 42.baz }}').should be_equal_node_to JOINER(TAG(
+ UMINUS(METHOD('baz', 42)),
+ mode: :normal)) }
+ specify { parse('{{ -42.42.baz }}').should be_equal_node_to JOINER(TAG(
+ METHOD('baz', -42.42),
+ mode: :normal)) }
specify { parse('{{ foo(\'hello\').bar[2].baz(-42) }}').should be_equal_node_to JOINER(TAG(
- METHOD(
- METHOD(
- METHOD(
- METHOD(
- nil, 'foo', 'hello'
- ), 'bar'
- ), '[]', 2
- ), 'baz', -42
+ METHOD('baz',
+ METHOD('manipulator_brackets',
+ METHOD('bar',
+ METHOD('foo', nil, 'hello')
+ ), 2
+ ), -42
),
mode: :normal)) }
end
end
context 'arrays' do
specify { parse('{{ [] }}').should be_equal_node_to JOINER(TAG(ARRAY(), mode: :normal)) }
specify { parse('{{ [ 2 ] }}').should be_equal_node_to JOINER(TAG(ARRAY(2), mode: :normal)) }
specify { parse('{{ [ 2, 3 ] }}').should be_equal_node_to JOINER(TAG(ARRAY(2, 3), mode: :normal)) }
- specify { parse('{{ [2, 3][42] }}').should be_equal_node_to JOINER(TAG(METHOD(ARRAY(2, 3), '[]', 42), mode: :normal)) }
- specify { parse('{{ [2 + foo, (2 * bar)] }}').should be_equal_node_to JOINER(TAG(ARRAY(PLUS(2, METHOD(nil, 'foo')), MULTIPLY(2, METHOD(nil, 'bar'))), mode: :normal)) }
+ specify { parse('{{ [2, 3][42] }}').should be_equal_node_to JOINER(TAG(METHOD('manipulator_brackets', ARRAY(2, 3), 42), mode: :normal)) }
+ specify { parse('{{ [2 + foo, (2 * bar)] }}').should be_equal_node_to JOINER(TAG(ARRAY(PLUS(2, METHOD('foo')), MULTIPLY(2, METHOD('bar'))), mode: :normal)) }
specify { parse('{{ [[2, 3], 42] }}').should be_equal_node_to JOINER(TAG(ARRAY(ARRAY(2, 3), 42), mode: :normal)) }
end
context 'hashes' do
specify { parse('{{ {} }}').should be_equal_node_to JOINER(TAG(HASH(), mode: :normal)) }
specify { parse('{{ { hello: \'world\' } }}').should be_equal_node_to(
JOINER(TAG(HASH(PAIR('hello', 'world')), mode: :normal))
) }
specify { parse('{{ {hello: \'world\'}[\'hello\'] }}').should be_equal_node_to(
- JOINER(TAG(METHOD(HASH(PAIR('hello', 'world')), '[]', 'hello'), mode: :normal))
+ JOINER(TAG(METHOD('manipulator_brackets', HASH(PAIR('hello', 'world')), 'hello'), mode: :normal))
) }
specify { parse('{{ { hello: 3, world: 6 * foo } }}').should be_equal_node_to(
JOINER(TAG(HASH(
PAIR('hello', 3),
- PAIR('world', MULTIPLY(6, METHOD(nil, 'foo')))
+ PAIR('world', MULTIPLY(6, METHOD('foo')))
), mode: :normal))
) }
end
context '[]' do
- specify { parse('{{ hello[3] }}').should be_equal_node_to JOINER(TAG(METHOD(METHOD(nil, 'hello'), '[]', 3), mode: :normal)) }
- specify { parse('{{ \'boom\'[3] }}').should be_equal_node_to JOINER(TAG(METHOD('boom', '[]', 3), mode: :normal)) }
- specify { parse('{{ 7[3] }}').should be_equal_node_to JOINER(TAG(METHOD(7, '[]', 3), mode: :normal)) }
- specify { parse('{{ 3 + 5[7] }}').should be_equal_node_to JOINER(TAG(PLUS(3, METHOD(5, '[]', 7)), mode: :normal)) }
- specify { parse('{{ (3 + 5)[7] }}').should be_equal_node_to JOINER(TAG(METHOD(8, '[]', 7), mode: :normal)) }
+ specify { parse('{{ hello[3] }}').should be_equal_node_to JOINER(TAG(METHOD('manipulator_brackets', METHOD('hello'), 3), mode: :normal)) }
+ specify { parse('{{ \'boom\'[3] }}').should be_equal_node_to JOINER(TAG(METHOD('manipulator_brackets', 'boom', 3), mode: :normal)) }
+ specify { parse('{{ 7[3] }}').should be_equal_node_to JOINER(TAG(METHOD('manipulator_brackets', 7, 3), mode: :normal)) }
+ specify { parse('{{ 3 + 5[7] }}').should be_equal_node_to JOINER(TAG(PLUS(3, METHOD('manipulator_brackets', 5, 7)), mode: :normal)) }
+ specify { parse('{{ (3 + 5)[7] }}').should be_equal_node_to JOINER(TAG(METHOD('manipulator_brackets', 8, 7), mode: :normal)) }
end
context 'function arguments' do
- specify { parse('{{ hello() }}').should be_equal_node_to JOINER(TAG(METHOD(nil, 'hello'), mode: :normal)) }
+ specify { parse('{{ hello() }}').should be_equal_node_to JOINER(TAG(METHOD('hello'), mode: :normal)) }
specify { parse('{{ hello(2 * foo) }}').should be_equal_node_to(
- JOINER(TAG(METHOD(nil, 'hello', MULTIPLY(2, METHOD(nil, 'foo'))), mode: :normal))
+ JOINER(TAG(METHOD('hello', nil, MULTIPLY(2, METHOD('foo'))), mode: :normal))
) }
specify { parse('{{ hello([2 * car]) }}').should be_equal_node_to(
- JOINER(TAG(METHOD(nil, 'hello', ARRAY(MULTIPLY(2, METHOD(nil, 'car')))), mode: :normal))
+ JOINER(TAG(METHOD('hello', nil, ARRAY(MULTIPLY(2, METHOD('car')))), mode: :normal))
) }
specify { parse('{{ hello({hello: \'world\'}) }}').should be_equal_node_to(
- JOINER(TAG(METHOD(nil, 'hello', HASH(PAIR('hello', 'world'))), mode: :normal))
+ JOINER(TAG(METHOD('hello', nil, HASH(PAIR('hello', 'world'))), mode: :normal))
) }
specify { parse('{{ hello(hello: \'world\') }}').should be_equal_node_to(
- JOINER(TAG(METHOD(nil, 'hello', HASH(PAIR('hello', 'world'))), mode: :normal))
+ JOINER(TAG(METHOD('hello', nil, HASH(PAIR('hello', 'world'))), mode: :normal))
) }
specify { parse('{{ hello(2 * foo, \'bla\', {hello: \'world\'}) }}').should be_equal_node_to(
- JOINER(TAG(METHOD(nil, 'hello',
- MULTIPLY(2, METHOD(nil, 'foo')),
+ JOINER(TAG(METHOD('hello', nil,
+ MULTIPLY(2, METHOD('foo')),
'bla',
HASH(PAIR('hello', 'world'))
), mode: :normal))
) }
specify { parse('{{ hello(moo * 3, \'bla\', hello: \'world\') }}').should be_equal_node_to(
- JOINER(TAG(METHOD(nil, 'hello',
- MULTIPLY(METHOD(nil, 'moo'), 3),
+ JOINER(TAG(METHOD('hello', nil,
+ MULTIPLY(METHOD('moo'), 3),
'bla',
HASH(PAIR('hello', 'world'))
), mode: :normal))
) }
end
@@ -278,105 +288,124 @@
specify { parse('{{ ; 42; 43 }}').should be_equal_node_to JOINER(TAG(42, 43, mode: :normal)) }
specify { parse('{{ 42; 43; 44 }}').should be_equal_node_to JOINER(TAG(42, 43, 44, mode: :normal)) }
specify { parse('{{ 42; \'hello\'; 44; }}').should be_equal_node_to JOINER(TAG(42, 'hello', 44, mode: :normal)) }
specify { parse('{{ (42; \'hello\'); 44; }}').should be_equal_node_to JOINER(TAG(SEQUENCE(42, 'hello'), 44, mode: :normal)) }
specify { parse('{{ 42; (\'hello\'; 44;) }}').should be_equal_node_to JOINER(TAG(42, SEQUENCE('hello', 44), mode: :normal)) }
- specify { parse('{{ hello(42, (43; 44), 45) }}').should be_equal_node_to JOINER(TAG(METHOD(nil, 'hello', 42, SEQUENCE(43, 44), 45), mode: :normal)) }
- specify { parse('{{ hello(42, ((43; 44)), 45) }}').should be_equal_node_to JOINER(TAG(METHOD(nil, 'hello', 42, SEQUENCE(43, 44), 45), mode: :normal)) }
- specify { parse('{{ hello((42)) }}').should be_equal_node_to JOINER(TAG(METHOD(nil, 'hello', 42), mode: :normal)) }
+ specify { parse('{{ hello(42, (43; 44), 45) }}').should be_equal_node_to JOINER(TAG(METHOD('hello', nil, 42, SEQUENCE(43, 44), 45), mode: :normal)) }
+ specify { parse('{{ hello(42, ((43; 44)), 45) }}').should be_equal_node_to JOINER(TAG(METHOD('hello', nil, 42, SEQUENCE(43, 44), 45), mode: :normal)) }
+ specify { parse('{{ hello((42)) }}').should be_equal_node_to JOINER(TAG(METHOD('hello', nil, 42), mode: :normal)) }
end
context 'comments' do
specify { parse('hello # world').should be_equal_node_to JOINER('hello # world') }
specify { parse('hello {{# world').should be_equal_node_to JOINER('hello ') }
specify { parse('hello {{# world #}} friend').should be_equal_node_to JOINER('hello ', ' friend') }
specify { parse('hello {{!# world #}}').should be_equal_node_to JOINER('hello ', TAG(mode: :silence)) }
specify { parse('hello {{ # world}}').should be_equal_node_to JOINER('hello ', TAG(mode: :normal)) }
specify { parse('hello {{ # world; foo}}').should be_equal_node_to JOINER('hello ', TAG(mode: :normal)) }
- specify { parse("hello {{ # world\n foo}}").should be_equal_node_to JOINER('hello ', TAG(METHOD(nil, 'foo'), mode: :normal)) }
+ specify { parse("hello {{ # world\n foo}}").should be_equal_node_to JOINER('hello ', TAG(METHOD('foo'), mode: :normal)) }
+ specify { parse("hello {{ world# foo}}").should be_equal_node_to JOINER('hello ', TAG(METHOD('world'), mode: :normal)) }
end
context 'commands' do
+ let(:include_tag) { Class.new(Hotcell::Command) }
+ let(:snippet_tag) { Class.new(Hotcell::Command) }
+ let(:commands) do
+ {
+ include: include_tag,
+ snippet: snippet_tag
+ }.stringify_keys
+ end
+
specify { parse("{{ include 'some/partial' }}",
- commands: [:include, :snippet]).should be_equal_node_to JOINER(
- COMMAND('include', 'some/partial', mode: :normal)
+ commands: commands).should be_equal_node_to JOINER(
+ TAG(include_tag.build('include', 'some/partial'), mode: :normal)
) }
specify { parse("{{ include }}",
- commands: [:include, :snippet]).should be_equal_node_to JOINER(
- COMMAND('include', mode: :normal)
+ commands: commands).should be_equal_node_to JOINER(
+ TAG(include_tag.build('include'), mode: :normal)
) }
specify { parse("{{! include 'some/partial' }}\n{{ snippet 'sidebar' }}",
- commands: [:include, :snippet]).should be_equal_node_to JOINER(
- COMMAND('include', 'some/partial', mode: :silence),
+ commands: commands).should be_equal_node_to JOINER(
+ TAG(include_tag.build('include', 'some/partial'), mode: :silence),
"\n",
- COMMAND('snippet', 'sidebar', mode: :normal),
+ TAG(snippet_tag.build('snippet', 'sidebar'), mode: :normal),
) }
specify { parse("{{! variable = include }}",
- commands: [:include, :snippet]).should be_equal_node_to JOINER(
- COMMAND('include', mode: :silence, assign: 'variable')
+ commands: commands).should be_equal_node_to JOINER(
+ TAG(ASSIGN('variable', include_tag.build('include')), mode: :silence)
) }
specify { parse("{{ variable = include 'some/partial' }}",
- commands: [:include, :snippet]).should be_equal_node_to JOINER(
- COMMAND('include', 'some/partial', mode: :normal, assign: 'variable')
+ commands: commands).should be_equal_node_to JOINER(
+ TAG(ASSIGN('variable', include_tag.build('include', 'some/partial')), mode: :normal)
) }
end
context 'blocks' do
- specify { parse("{{ scoped var: 'hello' }}{{ endscoped }}",
- blocks: [:scoped, :for]).should be_equal_node_to JOINER(
- BLOCK('scoped', HASH(PAIR('var', 'hello')), mode: :normal)
- ) }
+ let(:scoped_tag) { Class.new(Hotcell::Block) }
+ let(:each_tag) { Class.new(Hotcell::Block) }
+ let(:blocks) do
+ {
+ scoped: scoped_tag,
+ each: each_tag
+ }.stringify_keys
+ end
+
specify { parse("{{ scoped }}{{ end scoped }}",
- blocks: [:scoped, :for]).should be_equal_node_to JOINER(
- BLOCK('scoped', mode: :normal)
+ blocks: blocks).should be_equal_node_to JOINER(
+ TAG(scoped_tag.build('scoped'), mode: :normal)
) }
- specify { parse("<article>\n{{ for post, in: posts }}\n<h1>{{ post.title }}</h1>\n{{ end for }}\n</article>",
- blocks: [:scoped, :for]).should be_equal_node_to JOINER(
+ specify { parse("{{ scoped var: 'hello' }}{{ endscoped }}",
+ blocks: blocks).should be_equal_node_to JOINER(
+ TAG(scoped_tag.build('scoped', HASH(PAIR('var', 'hello'))), mode: :normal)
+ ) }
+ specify { parse("<article>\n{{ each post, in: posts }}\n<h1>{{ post.title }}</h1>\n{{ end each }}\n</article>",
+ blocks: blocks).should be_equal_node_to JOINER(
"<article>\n",
- BLOCK('for',
- METHOD(nil, 'post'),
- HASH(PAIR('in', METHOD(nil, 'posts'))),
- mode: :normal,
+ TAG(each_tag.build('each',
+ METHOD('post'),
+ HASH(PAIR('in', METHOD('posts'))),
subnodes: [JOINER(
"\n<h1>",
- TAG(METHOD(METHOD(nil, 'post'), 'title'), mode: :normal),
+ TAG(METHOD('title', METHOD('post')), mode: :normal),
"</h1>\n"
)]
- ),
+ ), mode: :normal),
"\n</article>"
) }
- specify { parse("{{! posts = for post, in: posts }}\n<h1>{{ post.title }}</h1>\n{{ end for }}",
- blocks: [:scoped, :for]).should be_equal_node_to JOINER(
- BLOCK('for',
- METHOD(nil, 'post'),
- HASH(PAIR('in', METHOD(nil, 'posts'))),
- mode: :silence,
- assign: 'posts',
+ specify { parse("{{! iter = each post, in: posts }}\n<h1>{{ post.title }}</h1>\n{{ end each }}",
+ blocks: blocks).should be_equal_node_to JOINER(
+ TAG(ASSIGN('iter', each_tag.build('each',
+ METHOD('post'),
+ HASH(PAIR('in', METHOD('posts'))),
subnodes: [JOINER(
"\n<h1>",
- TAG(METHOD(METHOD(nil, 'post'), 'title'), mode: :normal),
+ TAG(METHOD('title', METHOD('post')), mode: :normal),
"</h1>\n"
)]
- ),
+ )), mode: :silence),
) }
- specify { parse("{{ capture = scoped }} hello {{ for post, in: posts }} {{ loop }} {{ end for }}{{ endscoped }}",
- blocks: [:scoped, :for]).should be_equal_node_to JOINER(
- BLOCK('scoped',
- mode: :normal,
- assign: 'capture',
+ specify { parse("{{ capture = scoped }} hello {{ each post, in: posts }} {{ loop }} {{ end each }}{{ endscoped }}",
+ blocks: blocks).should be_equal_node_to JOINER(
+ TAG(ASSIGN('capture', scoped_tag.build('scoped',
subnodes: [JOINER(
' hello ',
- BLOCK('for',
- METHOD(nil, 'post'),
- HASH(PAIR('in', METHOD(nil, 'posts'))),
- mode: :normal,
+ TAG(each_tag.build('each',
+ METHOD('post'),
+ HASH(PAIR('in', METHOD('posts'))),
subnodes: [JOINER(
' ',
- TAG(METHOD(nil, 'loop'), mode: :normal),
+ TAG(METHOD('loop'), mode: :normal),
' '
)]
- )
+ ), mode: :normal)
)]
- )
+ )), mode: :normal)
) }
+ end
+
+ context 'errors' do
+ let(:error) { Hotcell::UnexpectedLexem }
+
+ specify { expect { parse("{{ var = 3 * 5; hello(, 3) }}") }.to raise_error error, 'Unexpected COMMA `,` at 1:23' }
end
end