aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/test/journey/route/definition/parser_test.rb
blob: d7d7172a40b9b58a466ee0dfdb0bef8fdbbfef5b (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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
require 'abstract_unit'

module ActionDispatch
  module Journey
    module Definition
      class TestParser < ActiveSupport::TestCase
        def setup
          @parser = Parser.new
        end

        def test_slash
          assert_equal :SLASH, @parser.parse('/').type
          assert_round_trip '/'
        end

        def test_segment
          assert_round_trip '/foo'
        end

        def test_segments
          assert_round_trip '/foo/bar'
        end

        def test_segment_symbol
          assert_round_trip '/foo/:id'
        end

        def test_symbol
          assert_round_trip '/:foo'
        end

        def test_group
          assert_round_trip '(/:foo)'
        end

        def test_groups
          assert_round_trip '(/:foo)(/:bar)'
        end

        def test_nested_groups
          assert_round_trip '(/:foo(/:bar))'
        end

        def test_dot_symbol
          assert_round_trip('.:format')
        end

        def test_dot_literal
          assert_round_trip('.xml')
        end

        def test_segment_dot
          assert_round_trip('/foo.:bar')
        end

        def test_segment_group_dot
          assert_round_trip('/foo(.:bar)')
        end

        def test_segment_group
          assert_round_trip('/foo(/:action)')
        end

        def test_segment_groups
          assert_round_trip('/foo(/:action)(/:bar)')
        end

        def test_segment_nested_groups
          assert_round_trip('/foo(/:action(/:bar))')
        end

        def test_group_followed_by_path
          assert_round_trip('/foo(/:action)/:bar')
        end

        def test_star
          assert_round_trip('*foo')
          assert_round_trip('/*foo')
          assert_round_trip('/bar/*foo')
          assert_round_trip('/bar/(*foo)')
        end

        def test_or
          assert_round_trip('a|b')
          assert_round_trip('a|b|c')
          assert_round_trip('(a|b)|c')
          assert_round_trip('a|(b|c)')
          assert_round_trip('*a|(b|c)')
          assert_round_trip('*a|:b|c')
        end

        def test_arbitrary
          assert_round_trip('/bar/*foo#')
        end

        def test_literal_dot_paren
          assert_round_trip "/sprockets.js(.:format)"
        end

        def test_groups_with_dot
          assert_round_trip "/(:locale)(.:format)"
        end

        def assert_round_trip str
          assert_equal str, @parser.parse(str).to_s
        end
      end
    end
  end
end