2017-07-24 16:20:53 -04:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
require "abstract_unit"
|
2012-12-19 15:54:47 -05:00
|
|
|
|
|
|
|
module ActionDispatch
|
|
|
|
module Journey
|
|
|
|
module NFA
|
2012-12-31 12:36:30 -05:00
|
|
|
class TestTransitionTable < ActiveSupport::TestCase
|
2012-12-19 15:54:47 -05:00
|
|
|
def setup
|
|
|
|
@parser = Journey::Parser.new
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_eclosure
|
2016-08-06 12:54:50 -04:00
|
|
|
table = tt "/"
|
2012-12-19 15:54:47 -05:00
|
|
|
assert_equal [0], table.eclosure(0)
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
table = tt ":a|:b"
|
2012-12-19 15:54:47 -05:00
|
|
|
assert_equal 3, table.eclosure(0).length
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
table = tt "(:a|:b)"
|
2012-12-19 15:54:47 -05:00
|
|
|
assert_equal 5, table.eclosure(0).length
|
|
|
|
assert_equal 5, table.eclosure([0]).length
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_following_states_one
|
2016-08-06 12:54:50 -04:00
|
|
|
table = tt "/"
|
2012-12-19 15:54:47 -05:00
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_equal [1], table.following_states(0, "/")
|
|
|
|
assert_equal [1], table.following_states([0], "/")
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_following_states_group
|
2016-08-06 12:54:50 -04:00
|
|
|
table = tt "a|b"
|
2012-12-19 15:54:47 -05:00
|
|
|
states = table.eclosure 0
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_equal 1, table.following_states(states, "a").length
|
|
|
|
assert_equal 1, table.following_states(states, "b").length
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_following_states_multi
|
2016-08-06 12:54:50 -04:00
|
|
|
table = tt "a|a"
|
2012-12-19 15:54:47 -05:00
|
|
|
states = table.eclosure 0
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_equal 2, table.following_states(states, "a").length
|
|
|
|
assert_equal 0, table.following_states(states, "b").length
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_following_states_regexp
|
2016-08-06 12:54:50 -04:00
|
|
|
table = tt "a|:a"
|
2012-12-19 15:54:47 -05:00
|
|
|
states = table.eclosure 0
|
|
|
|
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_equal 1, table.following_states(states, "a").length
|
2012-12-19 15:54:47 -05:00
|
|
|
assert_equal 1, table.following_states(states, /[^\.\/\?]+/).length
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_equal 0, table.following_states(states, "b").length
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_alphabet
|
2016-10-28 23:05:58 -04:00
|
|
|
table = tt "a|:a"
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_equal [/[^\.\/\?]+/, "a"], table.alphabet
|
2012-12-19 15:54:47 -05:00
|
|
|
|
2016-10-28 23:05:58 -04:00
|
|
|
table = tt "a|a"
|
2016-08-06 12:54:50 -04:00
|
|
|
assert_equal ["a"], table.alphabet
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
|
|
|
|
private
|
2016-08-06 14:20:22 -04:00
|
|
|
def tt(string)
|
2016-08-06 13:55:02 -04:00
|
|
|
ast = @parser.parse string
|
|
|
|
builder = Builder.new ast
|
|
|
|
builder.transition_table
|
|
|
|
end
|
2012-12-19 15:54:47 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|