1
0
Fork 0
mirror of https://github.com/rails/rails.git synced 2022-11-09 12:12:34 -05:00
rails--rails/actionpack/test/journey/route/definition/scanner_test.rb
Ryuta Kamizono c81af6ae72 Enable Layout/EmptyLinesAroundAccessModifier cop
We sometimes say "✂️ newline after `private`" in a code review (e.g.
https://github.com/rails/rails/pull/18546#discussion_r23188776,
https://github.com/rails/rails/pull/34832#discussion_r244847195).

Now `Layout/EmptyLinesAroundAccessModifier` cop have new enforced style
`EnforcedStyle: only_before` (https://github.com/rubocop-hq/rubocop/pull/7059).

That cop and enforced style will reduce the our code review cost.
2019-06-13 12:00:45 +09:00

79 lines
2.9 KiB
Ruby

# frozen_string_literal: true
require "abstract_unit"
module ActionDispatch
module Journey
module Definition
class TestScanner < ActiveSupport::TestCase
def setup
@scanner = Scanner.new
end
CASES = [
["/", [[: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|*foo", [
[:SLASH, "/"],
[:SYMBOL, ":page"],
[:OR, "|"],
[:STAR, "*foo"]
]],
["/(:page)", [
[:SLASH, "/"],
[:LPAREN, "("],
[:SYMBOL, ":page"],
[:RPAREN, ")"],
]],
["(/:action)", [
[:LPAREN, "("],
[:SLASH, "/"],
[:SYMBOL, ":action"],
[:RPAREN, ")"],
]],
["(())", [[:LPAREN, "("],
[:LPAREN, "("], [:RPAREN, ")"], [:RPAREN, ")"]]],
["(.:format)", [
[:LPAREN, "("],
[:DOT, "."],
[:SYMBOL, ":format"],
[:RPAREN, ")"],
]],
]
CASES.each do |pattern, expected_tokens|
test "Scanning `#{pattern}`" do
@scanner.scan_setup pattern
assert_tokens expected_tokens, @scanner, pattern
end
end
private
def assert_tokens(expected_tokens, scanner, pattern)
actual_tokens = []
while token = scanner.next_token
actual_tokens << token
end
assert_equal expected_tokens, actual_tokens, "Wrong tokens for `#{pattern}`"
end
end
end
end
end