diff options
Diffstat (limited to 'actionpack/test/journey/route/definition/scanner_test.rb')
-rw-r--r-- | actionpack/test/journey/route/definition/scanner_test.rb | 69 |
1 files changed, 69 insertions, 0 deletions
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..7a510f1e07 --- /dev/null +++ b/actionpack/test/journey/route/definition/scanner_test.rb @@ -0,0 +1,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 |