1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00

Break up Journey's scanner test

This breaks up the one megatest for Journey's scanner into multiple test
cases, which also provides better output when there is a failure in the
scanner.

Before:

```
./bin/test test/journey/route/definition/scanner_test.rb
Run options: --seed 778

F

Failure:
ActionDispatch::Journey::Definition::TestScanner#test_tokens [/Users/vaidehijoshi/Code/tilde/rails/actionpack/test/journey/route/definition/scanner_test.rb:57]:
--- expected
+++ actual
@@ -1 +1 @@
-[[:SLASH, "/"], [:LITERAL, "page!!"]]
+[[:SLASH, "/"], [:LITERAL, "page!"]]

bin/test Users/vaidehijoshi/Code/tilde/rails/actionpack/test/journey/route/definition/scanner_test.rb:14

Finished in 0.090899s, 11.0012 runs/s, 44.0049 assertions/s.
1 runs, 4 assertions, 1 failures, 0 errors, 0 skips
```

After:

```
./bin/test test/journey/route/definition/scanner_test.rb
Run options: --seed 2230

....................F

Failure:
ActionDispatch::Journey::Definition::TestScanner#test_scanning_/page$ [/Users/vaidehijoshi/Code/tilde/rails/actionpack/test/journey/route/definition/scanner_test.rb:58]:
Wrong tokens for `/page$`.
--- expected
+++ actual
@@ -1 +1 @@
-[[:SLASH, "/"], [:LITERAL, "page$$"]]
+[[:SLASH, "/"], [:LITERAL, "page$"]]

bin/test Users/vaidehijoshi/Code/tilde/rails/actionpack/test/journey/route/definition/scanner_test.rb:56

F

Failure:
ActionDispatch::Journey::Definition::TestScanner#test_scanning_/page! [/Users/vaidehijoshi/Code/tilde/rails/actionpack/test/journey/route/definition/scanner_test.rb:58]:
Wrong tokens for `/page!`.
--- expected
+++ actual
@@ -1 +1 @@
-[[:SLASH, "/"], [:LITERAL, "page!!"]]
+[[:SLASH, "/"], [:LITERAL, "page!"]]

bin/test Users/vaidehijoshi/Code/tilde/rails/actionpack/test/journey/route/definition/scanner_test.rb:56

F

Failure:
ActionDispatch::Journey::Definition::TestScanner#test_scanning_/page& [/Users/vaidehijoshi/Code/tilde/rails/actionpack/test/journey/route/definition/scanner_test.rb:58]:
Wrong tokens for `/page&`.
--- expected
+++ actual
@@ -1 +1 @@
-[[:SLASH, "/"], [:LITERAL, "page&&"]]
+[[:SLASH, "/"], [:LITERAL, "page&"]]

bin/test Users/vaidehijoshi/Code/tilde/rails/actionpack/test/journey/route/definition/scanner_test.rb:56

Finished in 0.126447s, 181.8944 runs/s, 181.8944 assertions/s.
23 runs, 23 assertions, 3 failures, 0 errors, 0 skips
```
This commit is contained in:
vaidehijoshi 2018-04-24 15:24:44 -07:00
parent 3278bca877
commit 91f9d255b8

View file

@ -10,61 +10,64 @@ module ActionDispatch
@scanner = Scanner.new @scanner = Scanner.new
end end
# /page/:id(/:action)(.:format) CASES = [
def test_tokens ["/", [[:SLASH, "/"]]],
[ ["*omg", [[:STAR, "*omg"]]],
["/", [[:SLASH, "/"]]], ["/page", [[:SLASH, "/"], [:LITERAL, "page"]]],
["*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;"]]],
["/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, "/"], [:LITERAL, "~page"]]], ["/:page", [[:SLASH, "/"], [:SYMBOL, ":page"]]],
["/pa-ge", [[:SLASH, "/"], [:LITERAL, "pa-ge"]]], ["/(:page)", [
["/:page", [[:SLASH, "/"], [:SYMBOL, ":page"]]], [:SLASH, "/"],
["/(:page)", [ [:LPAREN, "("],
[:SLASH, "/"], [:SYMBOL, ":page"],
[:RPAREN, ")"],
]],
["(/:action)", [
[:LPAREN, "("], [:LPAREN, "("],
[:SYMBOL, ":page"], [:SLASH, "/"],
[:SYMBOL, ":action"],
[:RPAREN, ")"],
]],
["(())", [[:LPAREN, "("],
[:LPAREN, "("], [:RPAREN, ")"], [:RPAREN, ")"]]],
["(.:format)", [
[:LPAREN, "("],
[:DOT, "."],
[:SYMBOL, ":format"],
[:RPAREN, ")"], [:RPAREN, ")"],
]], ]],
["(/:action)", [ ]
[:LPAREN, "("],
[:SLASH, "/"], CASES.each do |pattern, expected_tokens|
[:SYMBOL, ":action"], test "Scanning `#{pattern}`" do
[:RPAREN, ")"], @scanner.scan_setup pattern
]], assert_tokens expected_tokens, @scanner, pattern
["(())", [[:LPAREN, "("],
[:LPAREN, "("], [:RPAREN, ")"], [:RPAREN, ")"]]],
["(.:format)", [
[:LPAREN, "("],
[:DOT, "."],
[:SYMBOL, ":format"],
[:RPAREN, ")"],
]],
].each do |str, expected|
@scanner.scan_setup str
assert_tokens expected, @scanner
end end
end end
def assert_tokens(tokens, scanner) private
toks = []
while tok = scanner.next_token def assert_tokens(expected_tokens, scanner, pattern)
toks << tok actual_tokens = []
while token = scanner.next_token
actual_tokens << token
end
assert_equal expected_tokens, actual_tokens, "Wrong tokens for `#{pattern}`"
end end
assert_equal tokens, toks
end
end end
end end
end end