File: string_splitter_test.rb

package info (click to toggle)
ruby-haml 6.3.0-1
  • links: PTS, VCS
  • area: main
  • in suites: sid, trixie
  • size: 2,004 kB
  • sloc: ruby: 9,908; sh: 23; makefile: 11
file content (51 lines) | stat: -rw-r--r-- 2,134 bytes parent folder | download | duplicates (2)
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
45
46
47
48
49
50
51
describe Haml::StringSplitter do
  describe '.compile' do
    def assert_compile(expected, code)
      actual = Haml::StringSplitter.compile(code)
      assert_equal expected, actual
    end

    it { assert_compile([], %q|''|) }
    it { assert_compile([], %q|""|) }
    it { assert_compile([[:static, 'hello']], %q|"hello"|) }
    it { assert_compile([[:static, 'hello '], [:static, 'world']], %q|"hello #{}world"|) }
    it { assert_compile([[:dynamic, 'hello']], %q|"#{hello}"|) }
    it { assert_compile([[:static, 'nya'], [:dynamic, '123']], %q|"nya#{123}"|) }
    it { assert_compile([[:dynamic, '()'], [:static, '()']], %q|"#{()}()"|) }
    it { assert_compile([[:static, ' '], [:dynamic, %q[ " #{ '#{}' } " ]]], %q|" #{ " #{ '#{}' } " }"|) }
    it { assert_compile([[:static, 'a'], [:dynamic, 'b'], [:static, 'c'], [:dynamic, 'd'], [:static, 'e']], %q|%Q[a#{b}c#{d}e]|) }
    it { assert_compile([[:static, 'a#{b}c#{d}e']], %q|%q[a#{b}c#{d}e]|) }
    it { assert_compile([[:static, '#{}'], [:dynamic, '123']], %q|"\#{}#{123}"|) }
    it { assert_compile([[:dynamic, " '}' "]], %q|"#{ '}' }"|) }
    it { assert_compile([[:static, 'a']], %q| "a" # hello |) }
    it { assert_compile([[:static, '"']], %q|"\""|) }
    it { assert_compile([[:static, '\\"']], %q|"\\\\\\""|) }
    it { assert_compile([[:static, '\"']], %q|'\"'|) }
    it { assert_compile([[:static, '\"']], %q|'\\"'|) }
    it { assert_compile([[:static, '\\"']], %q|'\\\"'|) }

    describe 'invalid argument' do
      it 'raises internal error' do
        assert_raises Haml::InternalError do
          Haml::StringSplitter.compile('1')
        end
      end

      it 'raises internal error' do
        assert_raises Haml::InternalError do
          Haml::StringSplitter.compile('[]')
        end
      end

      it 'raises internal error' do
        if /java/ === RUBY_PLATFORM
          skip 'Ripper of JRuby is behaving in a different way'
        end

        assert_raises Haml::InternalError do
          Haml::StringSplitter.compile('"]')
        end
      end
    end
  end if RUBY_ENGINE != 'truffleruby' # truffleruby doesn't have Ripper.lex
end