1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44
|
describe Haml::RubyExpression do
describe '.syntax_error?' do
it { assert_equal(true, Haml::RubyExpression.syntax_error?('{ hash }')) }
it { assert_equal(false, Haml::RubyExpression.syntax_error?('{ a: b }')) }
end
describe '.string_literal?' do
def assert_literal(expected, code)
actual = Haml::RubyExpression.string_literal?(code)
assert_equal expected, actual
end
describe 'invalid expressions' do
it { assert_literal(false, %q|{ hash }|) }
it { assert_literal(false, %q|"hello".|) }
end
describe 'string literal' do
it { assert_literal(true, %q|''|) }
it { assert_literal(true, %q|""|) }
it { assert_literal(true, %Q|'\n'|) }
it { assert_literal(true, %q|''; |) }
it { assert_literal(true, %q| "" |) }
it { assert_literal(true, %q|'hello world'|) }
it { assert_literal(true, %q|"hello world"|) }
it { assert_literal(true, %q|"h#{ %Q[e#{ "llo wor" }l] }d"|) }
it { assert_literal(true, %q|%Q[nya]|) }
it { assert_literal(true, %q|%Q[#{123}]|) }
end
describe 'not string literal' do
it { assert_literal(false, %q|123|) }
it { assert_literal(false, %q|'hello' + ''|) }
it { assert_literal(false, %q|'hello'.to_s|) }
it { assert_literal(false, %Q|'' \\ \n ''|) }
it { assert_literal(false, %q|['']|) }
it { assert_literal(false, %q|return ''|) }
end
describe 'multiple instructions' do
it { assert_literal(false, %Q|''\n''|) }
end
end
end if RUBY_ENGINE != 'truffleruby' # truffleruby doesn't have Ripper.sexp
|