mirror of
https://github.com/ruby/ruby.git
synced 2025-09-22 03:53:58 +02:00
parent
9ed2cb26de
commit
db154b20cc
2 changed files with 23 additions and 1 deletions
|
@ -33,7 +33,7 @@ module Psych
|
||||||
|
|
||||||
# Check for a String type, being careful not to get caught by hash keys, hex values, and
|
# Check for a String type, being careful not to get caught by hash keys, hex values, and
|
||||||
# special floats (e.g., -.inf).
|
# special floats (e.g., -.inf).
|
||||||
if string.match?(/^[^\d\.:-]?[A-Za-z_\s!@#\$%\^&\*\(\)\{\}\<\>\|\/\\~;=]+/) || string.match?(/\n/)
|
if string.match?(%r{^[^\d.:-]?[[:alpha:]_\s!@#$%\^&*(){}<>|/\\~;=]+}) || string.match?(/\n/)
|
||||||
return string if string.length > 5
|
return string if string.length > 5
|
||||||
|
|
||||||
if string.match?(/^[^ytonf~]/i)
|
if string.match?(/^[^ytonf~]/i)
|
||||||
|
|
|
@ -156,5 +156,27 @@ module Psych
|
||||||
def test_scan_plus_dot
|
def test_scan_plus_dot
|
||||||
assert_equal '+.', ss.tokenize('+.')
|
assert_equal '+.', ss.tokenize('+.')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
class MatchCallCounter < String
|
||||||
|
attr_reader :match_call_count
|
||||||
|
|
||||||
|
def match?(pat)
|
||||||
|
@match_call_count ||= 0
|
||||||
|
@match_call_count += 1
|
||||||
|
super
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_scan_ascii_matches_quickly
|
||||||
|
ascii = MatchCallCounter.new('abcdefghijklmnopqrstuvwxyz')
|
||||||
|
ss.tokenize(ascii)
|
||||||
|
assert_equal 1, ascii.match_call_count
|
||||||
|
end
|
||||||
|
|
||||||
|
def test_scan_unicode_matches_quickly
|
||||||
|
unicode = MatchCallCounter.new('鳥かご関連用品')
|
||||||
|
ss.tokenize(unicode)
|
||||||
|
assert_equal 1, unicode.match_call_count
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue