diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-03-30 17:12:38 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2023-03-30 19:47:36 +0900 |
commit | 6f122965cf8704f019445faead58040e9be2effb (patch) | |
tree | 5a7c1caa7740e34c3cd13c6bc7a134007df338ec /test | |
parent | cbfd02998597f652940def034e490c2428baef09 (diff) | |
download | ruby-6f122965cf8704f019445faead58040e9be2effb.tar.gz |
[Bug #19547] Add token for unescaped backslash
This token is exposed only when `RubyVM::AbstractSyntaxTree` with
`keep_tokens` option.
Diffstat (limited to 'test')
-rw-r--r-- | test/ruby/test_ast.rb | 18 |
1 files changed, 16 insertions, 2 deletions
diff --git a/test/ruby/test_ast.rb b/test/ruby/test_ast.rb index 875cf7138e..8b565f531d 100644 --- a/test/ruby/test_ast.rb +++ b/test/ruby/test_ast.rb @@ -645,6 +645,12 @@ dummy assert_equal(expected, node.all_tokens.map { [_2, _3]}) end + def test_keep_tokens_unexpected_backslash + assert_raise_with_message(SyntaxError, /unexpected backslash/) do + RubyVM::AbstractSyntaxTree.parse("\\", keep_tokens: true) + end + end + def test_encoding_with_keep_script_lines # Stop a warning "possibly useless use of a literal in void context" verbose_bak, $VERBOSE = $VERBOSE, nil @@ -1069,10 +1075,17 @@ dummy EXP end - def assert_error_tolerant(src, expected) + def test_error_tolerant_unexpected_backslash + node = assert_error_tolerant("\\", <<~EXP, keep_tokens: true) + (SCOPE@1:0-1:1 tbl: [] args: nil body: (ERROR@1:0-1:1)) + EXP + assert_equal([[0, :backslash, "\\", [1, 0, 1, 1]]], node.children.last.tokens) + end + + def assert_error_tolerant(src, expected, keep_tokens: false) begin verbose_bak, $VERBOSE = $VERBOSE, false - node = RubyVM::AbstractSyntaxTree.parse(src, error_tolerant: true) + node = RubyVM::AbstractSyntaxTree.parse(src, error_tolerant: true, keep_tokens: keep_tokens) ensure $VERBOSE = verbose_bak end @@ -1080,5 +1093,6 @@ dummy str = "" PP.pp(node, str, 80) assert_equal(expected, str) + node end end |