diff options
author | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-05-26 11:33:40 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <nobu@ruby-lang.org> | 2019-05-26 16:24:33 +0900 |
commit | 02b39daef834890981689f1f697c7c25cad55dd6 (patch) | |
tree | 638b2d98375489298bfb0cb11706438c9c073921 /test/ripper | |
parent | f20af9543f278ab602d001dace850dcf4411cfa6 (diff) | |
download | ruby-02b39daef834890981689f1f697c7c25cad55dd6.tar.gz |
Fix scanner event at invalid syntax
* parse.y (parser_yyerror, parser_compile_error): revert
r67224 (e5d10cda07b23682e5e4e64d1324e4d3247d4785) "Flush erred
token".
Diffstat (limited to 'test/ripper')
-rw-r--r-- | test/ripper/test_scanner_events.rb | 16 |
1 files changed, 14 insertions, 2 deletions
diff --git a/test/ripper/test_scanner_events.rb b/test/ripper/test_scanner_events.rb index bb98e5d3d9..5fab5649ee 100644 --- a/test/ripper/test_scanner_events.rb +++ b/test/ripper/test_scanner_events.rb @@ -19,9 +19,16 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase end end - def scan(target, str) + def scan(target, str, &error) sym = "on_#{target}".intern - Ripper.lex(str).select {|_1,type,_2| type == sym }.map {|_1,_2,tok| tok } + lexer = Ripper::Lexer.new(str) + if error + lexer.singleton_class.class_eval do + define_method(:compile_error, error) + define_method(:on_parse_error, error) + end + end + lexer.lex.select {|_1,type,_2| type == sym }.map {|_1,_2,tok| tok } end def test_tokenize @@ -927,6 +934,11 @@ class TestRipper::ScannerEvents < Test::Unit::TestCase scan('CHAR', "?a") assert_equal [], scan('CHAR', "@ivar") + + assert_equal ["?\\M-H"], scan('CHAR', '?\\M-H') + err = nil + assert_equal ["?\\M"], scan('CHAR', '?\\M ') {|e| err = [__callee__, e]} + assert_equal([:on_parse_error, "Invalid escape character syntax"], err) end def test_label |