Extract assert_error_tolerant
This commit is contained in:
parent
f178ff3933
commit
d9e2ef6000
Notes:
git
2022-10-09 19:05:53 +09:00
@ -581,14 +581,10 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_method_define
|
def test_error_tolerant_end_is_short_for_method_define
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
def m
|
def m
|
||||||
m2
|
m2
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:4
|
(SCOPE@1:0-2:4
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -615,14 +611,10 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_singleton_method_define
|
def test_error_tolerant_end_is_short_for_singleton_method_define
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
def obj.m
|
def obj.m
|
||||||
m2
|
m2
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:4
|
(SCOPE@1:0-2:4
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -647,27 +639,19 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_begin
|
def test_error_tolerant_end_is_short_for_begin
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
begin
|
begin
|
||||||
a = 1
|
a = 1
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:7 tbl: [:a] args: nil body: (LASGN@2:2-2:7 :a (LIT@2:6-2:7 1)))
|
(SCOPE@1:0-2:7 tbl: [:a] args: nil body: (LASGN@2:2-2:7 :a (LIT@2:6-2:7 1)))
|
||||||
EXP
|
EXP
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_if
|
def test_error_tolerant_end_is_short_for_if
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
if cond
|
if cond
|
||||||
a = 1
|
a = 1
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:7
|
(SCOPE@1:0-2:7
|
||||||
tbl: [:a]
|
tbl: [:a]
|
||||||
args: nil
|
args: nil
|
||||||
@ -675,15 +659,11 @@ dummy
|
|||||||
(IF@1:0-2:7 (VCALL@1:3-1:7 :cond) (LASGN@2:2-2:7 :a (LIT@2:6-2:7 1)) nil))
|
(IF@1:0-2:7 (VCALL@1:3-1:7 :cond) (LASGN@2:2-2:7 :a (LIT@2:6-2:7 1)) nil))
|
||||||
EXP
|
EXP
|
||||||
|
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
if cond
|
if cond
|
||||||
a = 1
|
a = 1
|
||||||
else
|
else
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-3:5
|
(SCOPE@1:0-3:5
|
||||||
tbl: [:a]
|
tbl: [:a]
|
||||||
args: nil
|
args: nil
|
||||||
@ -694,14 +674,10 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_unless
|
def test_error_tolerant_end_is_short_for_unless
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
unless cond
|
unless cond
|
||||||
a = 1
|
a = 1
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:7
|
(SCOPE@1:0-2:7
|
||||||
tbl: [:a]
|
tbl: [:a]
|
||||||
args: nil
|
args: nil
|
||||||
@ -710,15 +686,11 @@ dummy
|
|||||||
nil))
|
nil))
|
||||||
EXP
|
EXP
|
||||||
|
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
unless cond
|
unless cond
|
||||||
a = 1
|
a = 1
|
||||||
else
|
else
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-3:5
|
(SCOPE@1:0-3:5
|
||||||
tbl: [:a]
|
tbl: [:a]
|
||||||
args: nil
|
args: nil
|
||||||
@ -729,14 +701,10 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_while
|
def test_error_tolerant_end_is_short_for_while
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
while true
|
while true
|
||||||
m
|
m
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:3
|
(SCOPE@1:0-2:3
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -745,14 +713,10 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_until
|
def test_error_tolerant_end_is_short_for_until
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
until true
|
until true
|
||||||
m
|
m
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:3
|
(SCOPE@1:0-2:3
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -761,14 +725,10 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_case
|
def test_error_tolerant_end_is_short_for_case
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
case a
|
case a
|
||||||
when 1
|
when 1
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:6
|
(SCOPE@1:0-2:6
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -779,14 +739,10 @@ dummy
|
|||||||
EXP
|
EXP
|
||||||
|
|
||||||
|
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
case
|
case
|
||||||
when a == 1
|
when a == 1
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:11
|
(SCOPE@1:0-2:11
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -800,14 +756,10 @@ dummy
|
|||||||
EXP
|
EXP
|
||||||
|
|
||||||
|
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
case a
|
case a
|
||||||
in {a: String}
|
in {a: String}
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:14
|
(SCOPE@1:0-2:14
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -824,14 +776,10 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_for
|
def test_error_tolerant_end_is_short_for_for
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
for i in ary
|
for i in ary
|
||||||
m
|
m
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:3
|
(SCOPE@1:0-2:3
|
||||||
tbl: [:i]
|
tbl: [:i]
|
||||||
args: nil
|
args: nil
|
||||||
@ -856,13 +804,9 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_class
|
def test_error_tolerant_end_is_short_for_class
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
class C
|
class C
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-1:7
|
(SCOPE@1:0-1:7
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -873,13 +817,9 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_module
|
def test_error_tolerant_end_is_short_for_module
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
module M
|
module M
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-1:8
|
(SCOPE@1:0-1:8
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -890,14 +830,10 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_do
|
def test_error_tolerant_end_is_short_for_do
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
m do
|
m do
|
||||||
a
|
a
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:3
|
(SCOPE@1:0-2:3
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -908,14 +844,10 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_do_block
|
def test_error_tolerant_end_is_short_for_do_block
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
m 1 do
|
m 1 do
|
||||||
a
|
a
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:3
|
(SCOPE@1:0-2:3
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -926,14 +858,10 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_end_is_short_for_do_LAMBDA
|
def test_error_tolerant_end_is_short_for_do_LAMBDA
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
-> do
|
-> do
|
||||||
a
|
a
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-2:3
|
(SCOPE@1:0-2:3
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -958,7 +886,7 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_treat_end_as_keyword_based_on_indent
|
def test_error_tolerant_treat_end_as_keyword_based_on_indent
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
module Z
|
module Z
|
||||||
class Foo
|
class Foo
|
||||||
foo.
|
foo.
|
||||||
@ -968,10 +896,6 @@ dummy
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-8:3
|
(SCOPE@1:0-8:3
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -1009,15 +933,11 @@ dummy
|
|||||||
end
|
end
|
||||||
|
|
||||||
def test_error_tolerant_expr_value_can_be_error
|
def test_error_tolerant_expr_value_can_be_error
|
||||||
node = RubyVM::AbstractSyntaxTree.parse(<<~STR, error_tolerant: true)
|
assert_error_tolerant(<<~STR, <<~EXP)
|
||||||
def m
|
def m
|
||||||
if
|
if
|
||||||
end
|
end
|
||||||
STR
|
STR
|
||||||
|
|
||||||
str = ""
|
|
||||||
PP.pp(node, str, 80)
|
|
||||||
assert_equal(<<~EXP, str)
|
|
||||||
(SCOPE@1:0-3:3
|
(SCOPE@1:0-3:3
|
||||||
tbl: []
|
tbl: []
|
||||||
args: nil
|
args: nil
|
||||||
@ -1042,4 +962,11 @@ dummy
|
|||||||
body: (IF@2:2-3:3 (ERROR@3:0-3:3) nil nil))))
|
body: (IF@2:2-3:3 (ERROR@3:0-3:3) nil nil))))
|
||||||
EXP
|
EXP
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def assert_error_tolerant(src, expected)
|
||||||
|
node = RubyVM::AbstractSyntaxTree.parse(src, error_tolerant: true)
|
||||||
|
str = ""
|
||||||
|
PP.pp(node, str, 80)
|
||||||
|
assert_equal(expected, str)
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user