diff options
author | Andrew White <andyw@pixeltrix.co.uk> | 2012-12-19 20:54:47 +0000 |
---|---|---|
committer | Andrew White <andyw@pixeltrix.co.uk> | 2012-12-19 22:13:08 +0000 |
commit | 56fee39c392788314c44a575b3fd66e16a50c8b5 (patch) | |
tree | e12603fff0d1e7c69d021f822b4077a74b91ddc4 /actionpack/test/journey/route | |
parent | b225693a0d86f2e33c66049a69e5148e5c93b7cd (diff) | |
download | rails-56fee39c392788314c44a575b3fd66e16a50c8b5.tar.gz rails-56fee39c392788314c44a575b3fd66e16a50c8b5.tar.bz2 rails-56fee39c392788314c44a575b3fd66e16a50c8b5.zip |
Integrate Journey into Action Dispatch
Move the Journey code underneath the ActionDispatch namespace so
that we don't pollute the global namespace with names that may
be used for models.
Fixes rails/journey#49.
Diffstat (limited to 'actionpack/test/journey/route')
-rw-r--r-- | actionpack/test/journey/route/definition/parser_test.rb | 110 | ||||
-rw-r--r-- | actionpack/test/journey/route/definition/scanner_test.rb | 56 |
2 files changed, 166 insertions, 0 deletions
diff --git a/actionpack/test/journey/route/definition/parser_test.rb b/actionpack/test/journey/route/definition/parser_test.rb new file mode 100644 index 0000000000..580235c6a1 --- /dev/null +++ b/actionpack/test/journey/route/definition/parser_test.rb @@ -0,0 +1,110 @@ +require 'abstract_unit' + +module ActionDispatch + module Journey + module Definition + class TestParser < MiniTest::Unit::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 diff --git a/actionpack/test/journey/route/definition/scanner_test.rb b/actionpack/test/journey/route/definition/scanner_test.rb new file mode 100644 index 0000000000..110baf9977 --- /dev/null +++ b/actionpack/test/journey/route/definition/scanner_test.rb @@ -0,0 +1,56 @@ +require 'abstract_unit' + +module ActionDispatch + module Journey + module Definition + class TestScanner < MiniTest::Unit::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']]], + ['/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 |