4 ISO_8859_1_TO_UTF8 = Iconv.new('utf-8', 'iso-8859-15')
7 ISO_8859_1_TO_UTF8.iconv self
12 def initialize(n, freqs = {})
13 sum = freqs.inject(0.0) { |s, x| s + x.last }
14 freqs.each_key { |x| freqs[x] /= sum }
17 freqs[x] = s .. (s + t = freqs[x])
22 @alpha = (0..0xff).to_a
27 30.times { s << @alpha[rand(@alpha.size)] }
33 found = @freqs.find { |k, f| f.include? rand }
40 when k == Hash, k == Array
42 when k == true, k == false, k == nil
47 rand(2 ** 30) - 2 ** 29
49 rand(2 ** 70) - 2 ** 69
53 def fuzz(current = nil)
58 current = fuzz [ Hash, Array ][rand(2)].new
62 current << case p = make_pick
72 current[random_string] = case p = make_pick
85 class MyState < JSON.state
90 :indent => make_spaces,
91 :space => make_spaces,
92 :space_before => make_spaces,
93 :object_nl => make_spaces,
94 :array_nl => make_spaces,
101 rand(1).times { s << WS[rand(WS.size)] }
106 n = (ARGV.shift || 500).to_i
108 fuzzer = Fuzzer.new(n,
119 json = JSON.generate o1, MyState.new
127 o2 = JSON.parse(json, :max_nesting => false)
128 rescue JSON::ParserError => e
129 puts "Caught #{e.class}: #{e.message}\n#{e.backtrace * "\n"}"
130 puts "o1 = #{o1.inspect}", "json = #{json}", "json_str = #{json.inspect}"
131 puts "locals = #{local_variables.inspect}"
135 puts "mismatch", "o1 = #{o1.inspect}", "o2 = #{o2.inspect}",
136 "json = #{json}", "json_str = #{json.inspect}"
137 puts "locals = #{local_variables.inspect}"