aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/journey/route/definition/scanner_test.rb
blob: 7a510f1e077ea16362554f0a43f9f114ba38e500 (plain) (blame)
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
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require 'abstract_unit'

module ActionDispatch
  module Journey
    module Definition
      class TestScanner < ActiveSupport::TestCase
        def setup
          @scanner = Scanner.new
        end

        # /page/:id(/:action)(.:format)
        def test_tokens
          [
            ['/',       [[:SLASH, '/']]],
            ['*omg',    [[:STAR, '*omg']]],
            ['/page',   [[:SLASH, '/'], [:LITERAL, 'page']]],
            ['/page!',  [[:SLASH, '/'], [:LITERAL, 'page!']]],
            ['/page$',  [[:SLASH, '/'], [:LITERAL, 'page$']]],
            ['/page&',  [[:SLASH, '/'], [:LITERAL, 'page&']]],
            ["/page'",  [[:SLASH, '/'], [:LITERAL, "page'"]]],
            ['/page*',  [[:SLASH, '/'], [:LITERAL, 'page*']]],
            ['/page+',  [[:SLASH, '/'], [:LITERAL, 'page+']]],
            ['/page,',  [[:SLASH, '/'], [:LITERAL, 'page,']]],
            ['/page;',  [[:SLASH, '/'], [:LITERAL, 'page;']]],
            ['/page=',  [[:SLASH, '/'], [:LITERAL, 'page=']]],
            ['/page@',  [[:SLASH, '/'], [:LITERAL, 'page@']]],
            ['/page\:', [[:SLASH, '/'], [:LITERAL, 'page:']]],
            ['/page\(', [[:SLASH, '/'], [:LITERAL, 'page(']]],
            ['/page\)', [[:SLASH, '/'], [:LITERAL, 'page)']]],
            ['/~page',  [[:SLASH, '/'], [:LITERAL, '~page']]],
            ['/pa-ge',  [[:SLASH, '/'], [:LITERAL, 'pa-ge']]],
            ['/:page',  [[:SLASH, '/'], [:SYMBOL, ':page']]],
            ['/(:page)', [
                          [:SLASH, '/'],
                          [:LPAREN, '('],
                          [:SYMBOL, ':page'],
                          [:RPAREN, ')'],
                        ]],
            ['(/:action)', [
                            [:LPAREN, '('],
                            [:SLASH, '/'],
                            [:SYMBOL, ':action'],
                            [:RPAREN, ')'],
                           ]],
            ['(())', [[:LPAREN, '('],
                     [:LPAREN, '('], [:RPAREN, ')'], [:RPAREN, ')']]],
            ['(.:format)', [
                            [:LPAREN, '('],
                            [:DOT, '.'],
                            [:SYMBOL, ':format'],
                            [:RPAREN, ')'],
                          ]],
          ].each do |str, expected|
            @scanner.scan_setup str
            assert_tokens expected, @scanner
          end
        end

        def assert_tokens tokens, scanner
          toks = []
          while tok = scanner.next_token
            toks << tok
          end
          assert_equal tokens, toks
        end
      end
    end
  end
end