tools/fuzz.rb in json-1.1.2 vs tools/fuzz.rb in json-1.1.3
- old
+ new
@@ -1,8 +1,16 @@
$KCODE='UTF8'
require 'json'
+require 'iconv'
+ISO_8859_1_TO_UTF8 = Iconv.new('utf-8', 'iso-8859-15')
+class ::String
+ def to_utf8
+ ISO_8859_1_TO_UTF8.iconv self
+ end
+end
+
class Fuzzer
def initialize(n, freqs = {})
sum = freqs.inject(0.0) { |s, x| s + x.last }
freqs.each_key { |x| freqs[x] /= sum }
s = 0.0
@@ -10,16 +18,16 @@
freqs[x] = s .. (s + t = freqs[x])
s += t
end
@freqs = freqs
@n = n
- @alpha = (0..0x7f).to_a
+ @alpha = (0..0xff).to_a
end
def random_string
s = ''
30.times { s << @alpha[rand(@alpha.size)] }
- s
+ s.to_utf8
end
def pick
r = rand
found = @freqs.find { |k, f| f.include? rand }