@@ -22,7 +22,9 @@ def test_peek_byte
2222 def test_scan_byte
2323 omit ( "not implemented on TruffleRuby" ) if RUBY_ENGINE == "truffleruby"
2424 s = create_string_scanner ( 'ab' )
25+ assert_equal ( 2 , s . match? ( /(?<a>ab)/ ) ) # set named_captures
2526 assert_equal ( 97 , s . scan_byte )
27+ assert_equal ( { } , s . named_captures )
2628 assert_equal ( 98 , s . scan_byte )
2729 assert_nil ( s . scan_byte )
2830
@@ -176,11 +178,13 @@ def test_bol?
176178 end
177179
178180 def test_string
181+ omit ( "not implemented on TruffleRuby" ) if RUBY_ENGINE == "truffleruby"
179182 s = create_string_scanner ( 'test string' )
180183 assert_equal ( 'test string' , s . string )
181- s . scan ( /test/ )
184+ s . scan ( /(?<t> test)/ ) # set named_captures
182185 assert_equal ( 'test string' , s . string )
183186 s . string = 'a'
187+ assert_equal ( { } , s . named_captures )
184188 assert_equal ( 'a' , s . string )
185189 s . scan ( /a/ )
186190 s . string = 'b'
@@ -366,8 +370,11 @@ def test_skip_with_begenning_of_line_anchor_match
366370 end
367371
368372 def test_getch
373+ omit ( "not implemented on TruffleRuby" ) if RUBY_ENGINE == "truffleruby"
369374 s = create_string_scanner ( 'abcde' )
375+ assert_equal ( 3 , s . match? ( /(?<a>abc)/ ) ) # set named_captures
370376 assert_equal ( 'a' , s . getch )
377+ assert_equal ( { } , s . named_captures )
371378 assert_equal ( 'b' , s . getch )
372379 assert_equal ( 'c' , s . getch )
373380 assert_equal ( 'd' , s . getch )
@@ -385,8 +392,11 @@ def test_getch
385392 end
386393
387394 def test_get_byte
395+ omit ( "not implemented on TruffleRuby" ) if RUBY_ENGINE == "truffleruby"
388396 s = create_string_scanner ( 'abcde' )
397+ assert_equal ( 3 , s . match? ( /(?<a>abc)/ ) ) # set named_captures
389398 assert_equal ( 'a' , s . get_byte )
399+ assert_equal ( { } , s . named_captures )
390400 assert_equal ( 'b' , s . get_byte )
391401 assert_equal ( 'c' , s . get_byte )
392402 assert_equal ( 'd' , s . get_byte )
@@ -602,18 +612,22 @@ def test_post_match_string
602612 end
603613
604614 def test_terminate
605- s = create_string_scanner ( 'ssss' )
606- s . getch
615+ omit ( "not implemented on TruffleRuby" ) if RUBY_ENGINE == "truffleruby"
616+ s = create_string_scanner ( 'abcd' )
617+ s . scan ( /(?<a>ab)/ ) # set named_captures
607618 s . terminate
619+ assert_equal ( { } , s . named_captures )
608620 assert_equal ( true , s . eos? )
609621 s . terminate
610622 assert_equal ( true , s . eos? )
611623 end
612624
613625 def test_reset
614- s = create_string_scanner ( 'ssss' )
615- s . getch
626+ omit ( "not implemented on TruffleRuby" ) if RUBY_ENGINE == "truffleruby"
627+ s = create_string_scanner ( 'abcd' )
628+ s . scan ( /(?<a>ab)/ ) # set named_captures
616629 s . reset
630+ assert_equal ( { } , s . named_captures )
617631 assert_equal ( 0 , s . pos )
618632 s . scan ( /\w +/ )
619633 s . reset
@@ -848,9 +862,11 @@ def test_peek
848862 end
849863
850864 def test_unscan
865+ omit ( "not implemented on TruffleRuby" ) if RUBY_ENGINE == "truffleruby"
851866 s = create_string_scanner ( 'test string' )
852- assert_equal ( "test" , s . scan ( / \w + /) )
867+ assert_equal ( 4 , s . skip ( /(?<t>test) /) ) # set named_captures
853868 s . unscan
869+ assert_equal ( { } , s . named_captures )
854870 assert_equal ( "te" , s . scan ( /../ ) )
855871 assert_equal ( nil , s . scan ( /\d / ) )
856872 assert_raise ( ScanError ) { s . unscan }
@@ -939,18 +955,22 @@ def test_scan_aref_repeatedly
939955 end
940956
941957 def test_named_captures
942- omit ( "not implemented on TruffleRuby" ) if [ "truffleruby" ] . include? ( RUBY_ENGINE )
958+ omit ( "not implemented on TruffleRuby" ) if RUBY_ENGINE == "truffleruby"
943959 scan = StringScanner . new ( "foobarbaz" )
944960 assert_equal ( { } , scan . named_captures )
945961 assert_equal ( 9 , scan . match? ( /(?<f>foo)(?<r>bar)(?<z>baz)/ ) )
946962 assert_equal ( { "f" => "foo" , "r" => "bar" , "z" => "baz" } , scan . named_captures )
963+ assert_equal ( 9 , scan . match? ( "foobarbaz" ) )
964+ assert_equal ( { } , scan . named_captures )
947965 end
948966
949967 def test_scan_integer
950968 omit ( "scan_integer isn't implemented on TruffleRuby yet" ) if RUBY_ENGINE == "truffleruby"
951969
952970 s = create_string_scanner ( 'abc' )
971+ assert_equal ( 3 , s . match? ( /(?<a>abc)/ ) ) # set named_captures
953972 assert_nil ( s . scan_integer )
973+ assert_equal ( { } , s . named_captures )
954974 assert_equal ( 0 , s . pos )
955975 refute_predicate ( s , :matched? )
956976
@@ -1022,7 +1042,9 @@ def test_scan_integer_base_16
10221042 assert_predicate ( s , :matched? )
10231043
10241044 s = create_string_scanner ( 'abc' )
1045+ assert_equal ( 3 , s . match? ( /(?<a>abc)/ ) ) # set named_captures
10251046 assert_equal ( 0xabc , s . scan_integer ( base : 16 ) )
1047+ assert_equal ( { } , s . named_captures )
10261048 assert_equal ( 3 , s . pos )
10271049 assert_predicate ( s , :matched? )
10281050
0 commit comments