提交 b31bc384 编写于 作者: J Justin Collins

Add tests for branch limiting

上级 6bbe03cd
......@@ -262,6 +262,85 @@ class AliasProcessorTests < Test::Unit::TestCase
RUBY
end
def test_default_branch_limit_5
assert_alias "(6 or 7) or 8", <<-RUBY
x = 0
if something
x = 1
else
x = 2
end
x = 3 unless this
x = 4 if that
if another_thing
x = 5
else
x = 6
end
x = 7 if getting_crazy
x = 8 if so_crazy
x
RUBY
end
def test_default_branch_limit_not_reached
assert_alias "(((1 or 2) or 3) or 4)", <<-RUBY
x = 1
if something
x = 2
else
x = 3
end
x = 4 unless this
x
RUBY
end
def test_default_branch_limit_before_reset_with_option
expected_y = RubyParser.new.parse "((((0 or 1) or 2) or 3) or 4)"
expected_x = RubyParser.new.parse "5 or 6"
original_sexp = RubyParser.new.parse <<-RUBY
x = 0
if something
x = 1
else
x = 2
end
if another_thing
x = 3
else
x = 4
end
y = x
x = 5 if getting_crazy
x = 6 if so_crazy
[x, y]
RUBY
tracker = Struct.new("FakeTracker", :options).new(:branch_limit => 4)
assert_equal 4, tracker.options[:branch_limit]
processed_sexp = Brakeman::AliasProcessor.new(tracker).process_safely original_sexp
result = processed_sexp.last
assert_equal expected_x, result[1]
assert_equal expected_y, result[2]
end
def test_simple_block_args
assert_alias '1', <<-RUBY
y = 1
......
......@@ -352,4 +352,15 @@ class SexpTests < Test::Unit::TestCase
s.original_line = 100
assert_equal 100, s.original_line
end
def test_combine_and_or_depth
e = Sexp.new(:lit, 0)
3.times do |i|
e = e.combine(Sexp.new(:lit, i))
end
assert_equal s(:or, s(:or, s(:or, s(:lit, 0), s(:lit, 0)), s(:lit, 1)), s(:lit, 2)), e
assert_equal 3, e.or_depth
end
end
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册