jiffy 1.0.4 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.travis.yml +13 -0
- data/Gemfile.lock +1 -1
- data/README.md +27 -28
- data/Rakefile +17 -0
- data/bin/jiffy +28 -3
- data/jiffy.gemspec +15 -66
- data/lib/jiffy.rb +27 -27
- data/lib/jiffy/array_mimicking_io.rb +1 -1
- data/lib/jiffy/outputter.rb +85 -0
- data/lib/jiffy/outputters/json.rb +35 -0
- data/lib/jiffy/outputters/ruby.rb +35 -0
- data/lib/jiffy/parser.rb +17 -0
- data/lib/jiffy/parsers/json.rb +18 -42
- data/lib/jiffy/parsers/json.rl +10 -22
- data/lib/jiffy/parsers/json_array.rb +22 -29
- data/lib/jiffy/parsers/json_array.rl +11 -12
- data/lib/jiffy/parsers/json_float.rb +39 -21
- data/lib/jiffy/parsers/json_float.rl +15 -7
- data/lib/jiffy/parsers/json_object.rb +30 -49
- data/lib/jiffy/parsers/json_object.rl +13 -20
- data/lib/jiffy/parsers/json_string.rb +70 -27
- data/lib/jiffy/parsers/json_string.rl +21 -6
- data/lib/jiffy/parsers/json_value.rb +33 -52
- data/lib/jiffy/parsers/json_value.rl +15 -34
- data/lib/jiffy/version.rb +1 -1
- data/test/jiffy_test.rb +261 -34
- data/test/outputter_test.rb +155 -0
- data/test/outputters/json_test.rb +22 -0
- metadata +9 -60
- data/lib/jiffy/json_outputter.rb +0 -62
- data/test/negative-examples/hexadecimal.json +0 -3
- data/test/negative-examples/infinity-value.json +0 -3
- data/test/negative-examples/leading-comma.json +0 -3
- data/test/negative-examples/leading-zero.json +0 -3
- data/test/negative-examples/line-break.json +0 -4
- data/test/negative-examples/missing-colon.json +0 -3
- data/test/negative-examples/nan-value,json +0 -3
- data/test/negative-examples/positive-float.json +0 -3
- data/test/negative-examples/positive-integer.json +0 -3
- data/test/negative-examples/single-quote.json +0 -3
- data/test/negative-examples/string-as-root.json +0 -1
- data/test/negative-examples/tab-character.json +0 -3
- data/test/negative-examples/trailing-array-seperator.json +0 -3
- data/test/negative-examples/trailing-object-seperator.json +0 -3
- data/test/negative-examples/true-as-root.json +0 -1
- data/test/negative-examples/unclosed-array.json +0 -2
- data/test/negative-examples/unclosed-object.json +0 -2
- data/test/positive-examples/array-as-root.json +0 -3
- data/test/positive-examples/array-nested-inside-array.json +0 -5
- data/test/positive-examples/array-nested-inside-object.json +0 -5
- data/test/positive-examples/false-value.json +0 -3
- data/test/positive-examples/null-value.json +0 -3
- data/test/positive-examples/number-1.json +0 -3
- data/test/positive-examples/number-10.json +0 -3
- data/test/positive-examples/number-11.json +0 -3
- data/test/positive-examples/number-12.json +0 -3
- data/test/positive-examples/number-13.json +0 -3
- data/test/positive-examples/number-14.json +0 -3
- data/test/positive-examples/number-15.json +0 -3
- data/test/positive-examples/number-16.json +0 -3
- data/test/positive-examples/number-17.json +0 -3
- data/test/positive-examples/number-18.json +0 -3
- data/test/positive-examples/number-19.json +0 -3
- data/test/positive-examples/number-2.json +0 -3
- data/test/positive-examples/number-20.json +0 -3
- data/test/positive-examples/number-3.json +0 -3
- data/test/positive-examples/number-4.json +0 -3
- data/test/positive-examples/number-5.json +0 -3
- data/test/positive-examples/number-6.json +0 -3
- data/test/positive-examples/number-7.json +0 -3
- data/test/positive-examples/number-8.json +0 -3
- data/test/positive-examples/number-9.json +0 -3
- data/test/positive-examples/object-as-root.json +0 -3
- data/test/positive-examples/object-nested-inside-array.json +0 -5
- data/test/positive-examples/object-nested-inside-object.json +0 -5
- data/test/positive-examples/seperated-array-values.json +0 -4
- data/test/positive-examples/seperated-object-properties.json +0 -4
- data/test/positive-examples/string-backspace.json +0 -3
- data/test/positive-examples/string-carriage-return.json +0 -3
- data/test/positive-examples/string-formfeed.json +0 -3
- data/test/positive-examples/string-horizontal-tab.json +0 -3
- data/test/positive-examples/string-newline.json +0 -3
- data/test/positive-examples/string-quotation.json +0 -3
- data/test/positive-examples/string-reverse-solidus.json +0 -3
- data/test/positive-examples/string-solidus.json +0 -3
- data/test/positive-examples/string-trivial.json +0 -3
- data/test/positive-examples/string-unicode.json +0 -3
- data/test/positive-examples/true-value.json +0 -3
| @@ -1,12 +1,12 @@ | |
| 1 1 |  | 
| 2 2 | 
             
            # line 1 "json_value.rl"
         | 
| 3 3 |  | 
| 4 | 
            -
            # line  | 
| 4 | 
            +
            # line 32 "json_value.rl"
         | 
| 5 5 |  | 
| 6 6 |  | 
| 7 7 | 
             
            class Jiffy
         | 
| 8 8 | 
             
              module Parsers
         | 
| 9 | 
            -
                 | 
| 9 | 
            +
                class JsonValue < Parser
         | 
| 10 10 | 
             
                  def initialize(*args)
         | 
| 11 11 |  | 
| 12 12 | 
             
            # line 13 "json_value.rb"
         | 
| @@ -116,22 +116,27 @@ end | |
| 116 116 | 
             
            self.json_value_en_main = 1;
         | 
| 117 117 |  | 
| 118 118 |  | 
| 119 | 
            -
            # line  | 
| 119 | 
            +
            # line 39 "json_value.rl"
         | 
| 120 | 
            +
             | 
| 120 121 | 
             
                    super
         | 
| 121 122 | 
             
                  end
         | 
| 122 123 |  | 
| 123 | 
            -
                  def  | 
| 124 | 
            +
                  def parse
         | 
| 125 | 
            +
                    pe = :ignored
         | 
| 126 | 
            +
                    eof = :ignored
         | 
| 127 | 
            +
                    p = self.p
         | 
| 128 | 
            +
             | 
| 124 129 |  | 
| 125 | 
            -
            # line  | 
| 130 | 
            +
            # line 131 "json_value.rb"
         | 
| 126 131 | 
             
            begin
         | 
| 127 132 | 
             
            	p ||= 0
         | 
| 128 133 | 
             
            	pe ||= data.length
         | 
| 129 134 | 
             
            	cs = json_value_start
         | 
| 130 135 | 
             
            end
         | 
| 131 136 |  | 
| 132 | 
            -
            # line  | 
| 137 | 
            +
            # line 49 "json_value.rl"
         | 
| 133 138 |  | 
| 134 | 
            -
            # line  | 
| 139 | 
            +
            # line 140 "json_value.rb"
         | 
| 135 140 | 
             
            begin
         | 
| 136 141 | 
             
            	_klen, _trans, _keys, _acts, _nacts = nil
         | 
| 137 142 | 
             
            	_goto_level = 0
         | 
| @@ -161,7 +166,7 @@ begin | |
| 161 166 | 
             
            		_acts += 1
         | 
| 162 167 | 
             
            		case _json_value_actions[_acts - 1]
         | 
| 163 168 | 
             
            			when 4 then
         | 
| 164 | 
            -
            # line  | 
| 169 | 
            +
            # line 21 "json_value.rl"
         | 
| 165 170 | 
             
            		begin
         | 
| 166 171 | 
             
             p = p - 1; 	begin
         | 
| 167 172 | 
             
            		p += 1
         | 
| @@ -170,7 +175,7 @@ begin | |
| 170 175 | 
             
            		break
         | 
| 171 176 | 
             
            	end
         | 
| 172 177 | 
             
             		end
         | 
| 173 | 
            -
            # line  | 
| 178 | 
            +
            # line 179 "json_value.rb"
         | 
| 174 179 | 
             
            		end # from state action switch
         | 
| 175 180 | 
             
            	end
         | 
| 176 181 | 
             
            	if _trigger_goto
         | 
| @@ -238,75 +243,51 @@ when 0 then | |
| 238 243 | 
             
            # line 5 "json_value.rl"
         | 
| 239 244 | 
             
            		begin
         | 
| 240 245 |  | 
| 241 | 
            -
             | 
| 242 | 
            -
             | 
| 243 | 
            -
                  if np
         | 
| 244 | 
            -
                     begin p = (( np))-1; end
         | 
| 246 | 
            +
                   begin p = (( JsonString.new(p: p, data: data, yielder: yielder).parse))-1; end
         | 
| 245 247 |  | 
| 246 | 
            -
                  else
         | 
| 247 | 
            -
                    raise_unparseable p
         | 
| 248 | 
            -
                  end
         | 
| 249 248 | 
             
                		end
         | 
| 250 249 | 
             
            when 1 then
         | 
| 251 | 
            -
            # line  | 
| 250 | 
            +
            # line 9 "json_value.rl"
         | 
| 252 251 | 
             
            		begin
         | 
| 253 252 |  | 
| 254 | 
            -
             | 
| 255 | 
            -
             | 
| 256 | 
            -
                  if np
         | 
| 257 | 
            -
                     begin p = (( np))-1; end
         | 
| 253 | 
            +
                   begin p = (( JsonFloat.new(p: p, data: data, yielder: yielder).parse))-1; end
         | 
| 258 254 |  | 
| 259 | 
            -
                  else
         | 
| 260 | 
            -
                    raise_unparseable p
         | 
| 261 | 
            -
                  end
         | 
| 262 255 | 
             
                		end
         | 
| 263 256 | 
             
            when 2 then
         | 
| 264 | 
            -
            # line  | 
| 257 | 
            +
            # line 13 "json_value.rl"
         | 
| 265 258 | 
             
            		begin
         | 
| 266 259 |  | 
| 267 | 
            -
             | 
| 260 | 
            +
                   begin p = (( JsonArray.new(p: p, data: data, yielder: yielder).parse))-1; end
         | 
| 268 261 |  | 
| 269 | 
            -
                  if np
         | 
| 270 | 
            -
                     begin p = (( np))-1; end
         | 
| 271 | 
            -
             | 
| 272 | 
            -
                  else
         | 
| 273 | 
            -
                    raise_unparseable p
         | 
| 274 | 
            -
                  end
         | 
| 275 262 | 
             
                		end
         | 
| 276 263 | 
             
            when 3 then
         | 
| 277 | 
            -
            # line  | 
| 264 | 
            +
            # line 17 "json_value.rl"
         | 
| 278 265 | 
             
            		begin
         | 
| 279 266 |  | 
| 280 | 
            -
             | 
| 267 | 
            +
                   begin p = (( JsonObject.new(p: p, data: data, yielder: yielder).parse))-1; end
         | 
| 281 268 |  | 
| 282 | 
            -
                  if np
         | 
| 283 | 
            -
                     begin p = (( np))-1; end
         | 
| 284 | 
            -
             | 
| 285 | 
            -
                  else
         | 
| 286 | 
            -
                    raise_unparseable p
         | 
| 287 | 
            -
                  end
         | 
| 288 269 | 
             
                		end
         | 
| 289 270 | 
             
            when 5 then
         | 
| 290 | 
            -
            # line  | 
| 271 | 
            +
            # line 24 "json_value.rl"
         | 
| 291 272 | 
             
            		begin
         | 
| 292 | 
            -
              | 
| 273 | 
            +
             y << :null 		end
         | 
| 293 274 | 
             
            when 6 then
         | 
| 294 | 
            -
            # line  | 
| 275 | 
            +
            # line 25 "json_value.rl"
         | 
| 295 276 | 
             
            		begin
         | 
| 296 | 
            -
              | 
| 277 | 
            +
             y << :false 		end
         | 
| 297 278 | 
             
            when 7 then
         | 
| 298 | 
            -
            # line  | 
| 279 | 
            +
            # line 26 "json_value.rl"
         | 
| 299 280 | 
             
            		begin
         | 
| 300 | 
            -
              | 
| 281 | 
            +
             y << :true 		end
         | 
| 301 282 | 
             
            when 8 then
         | 
| 302 | 
            -
            # line  | 
| 283 | 
            +
            # line 28 "json_value.rl"
         | 
| 303 284 | 
             
            		begin
         | 
| 304 | 
            -
              | 
| 285 | 
            +
             y << :begin_string 		end
         | 
| 305 286 | 
             
            when 9 then
         | 
| 306 | 
            -
            # line  | 
| 287 | 
            +
            # line 28 "json_value.rl"
         | 
| 307 288 | 
             
            		begin
         | 
| 308 | 
            -
              | 
| 309 | 
            -
            # line  | 
| 289 | 
            +
             y << :end_string 		end
         | 
| 290 | 
            +
            # line 291 "json_value.rb"
         | 
| 310 291 | 
             
            			end # action switch
         | 
| 311 292 | 
             
            		end
         | 
| 312 293 | 
             
            	end
         | 
| @@ -333,7 +314,7 @@ when 9 then | |
| 333 314 | 
             
            	end
         | 
| 334 315 | 
             
            	end
         | 
| 335 316 |  | 
| 336 | 
            -
            # line  | 
| 317 | 
            +
            # line 50 "json_value.rl"
         | 
| 337 318 |  | 
| 338 319 | 
             
                    if cs >= json_value_first_final
         | 
| 339 320 | 
             
                      p
         | 
| @@ -3,53 +3,29 @@ | |
| 3 3 | 
             
                include json_common "json_common.rl";
         | 
| 4 4 |  | 
| 5 5 | 
             
                action parse_string {
         | 
| 6 | 
            -
                   | 
| 7 | 
            -
             | 
| 8 | 
            -
                  if np
         | 
| 9 | 
            -
                    fexec np;
         | 
| 10 | 
            -
                  else
         | 
| 11 | 
            -
                    raise_unparseable p
         | 
| 12 | 
            -
                  end
         | 
| 6 | 
            +
                  fexec JsonString.new(p: p, data: data, yielder: yielder).parse;
         | 
| 13 7 | 
             
                }
         | 
| 14 8 |  | 
| 15 9 | 
             
                action parse_number {
         | 
| 16 | 
            -
                   | 
| 17 | 
            -
             | 
| 18 | 
            -
                  if np
         | 
| 19 | 
            -
                    fexec np;
         | 
| 20 | 
            -
                  else
         | 
| 21 | 
            -
                    raise_unparseable p
         | 
| 22 | 
            -
                  end
         | 
| 10 | 
            +
                  fexec JsonFloat.new(p: p, data: data, yielder: yielder).parse;
         | 
| 23 11 | 
             
                }
         | 
| 24 12 |  | 
| 25 13 | 
             
                action parse_array {
         | 
| 26 | 
            -
                   | 
| 27 | 
            -
             | 
| 28 | 
            -
                  if np
         | 
| 29 | 
            -
                    fexec np;
         | 
| 30 | 
            -
                  else
         | 
| 31 | 
            -
                    raise_unparseable p
         | 
| 32 | 
            -
                  end
         | 
| 14 | 
            +
                  fexec JsonArray.new(p: p, data: data, yielder: yielder).parse;
         | 
| 33 15 | 
             
                }
         | 
| 34 16 |  | 
| 35 17 | 
             
                action parse_object {
         | 
| 36 | 
            -
                   | 
| 37 | 
            -
             | 
| 38 | 
            -
                  if np
         | 
| 39 | 
            -
                    fexec np;
         | 
| 40 | 
            -
                  else
         | 
| 41 | 
            -
                    raise_unparseable p
         | 
| 42 | 
            -
                  end
         | 
| 18 | 
            +
                  fexec JsonObject.new(p: p, data: data, yielder: yielder).parse;
         | 
| 43 19 | 
             
                }
         | 
| 44 20 |  | 
| 45 21 | 
             
                action exit { fhold; fbreak; }
         | 
| 46 22 |  | 
| 47 23 | 
             
                main := (
         | 
| 48 | 
            -
                    Vnull >{  | 
| 49 | 
            -
                    Vfalse >{  | 
| 50 | 
            -
                    Vtrue >{  | 
| 24 | 
            +
                    Vnull >{ y << :null } |
         | 
| 25 | 
            +
                    Vfalse >{ y << :false } |
         | 
| 26 | 
            +
                    Vtrue >{ y << :true } |
         | 
| 51 27 | 
             
                    begin_number >parse_number |
         | 
| 52 | 
            -
                    begin_string >{  | 
| 28 | 
            +
                    begin_string >{ y << :begin_string } >parse_string @{ y << :end_string } |
         | 
| 53 29 | 
             
                    begin_array >parse_array |
         | 
| 54 30 | 
             
                    begin_object >parse_object
         | 
| 55 31 | 
             
                ) %*exit;
         | 
| @@ -57,13 +33,18 @@ | |
| 57 33 |  | 
| 58 34 | 
             
            class Jiffy
         | 
| 59 35 | 
             
              module Parsers
         | 
| 60 | 
            -
                 | 
| 36 | 
            +
                class JsonValue < Parser
         | 
| 61 37 | 
             
                  def initialize(*args)
         | 
| 62 38 | 
             
                    %% write data;
         | 
| 39 | 
            +
             | 
| 63 40 | 
             
                    super
         | 
| 64 41 | 
             
                  end
         | 
| 65 42 |  | 
| 66 | 
            -
                  def  | 
| 43 | 
            +
                  def parse
         | 
| 44 | 
            +
                    pe = :ignored
         | 
| 45 | 
            +
                    eof = :ignored
         | 
| 46 | 
            +
                    p = self.p
         | 
| 47 | 
            +
             | 
| 67 48 | 
             
                    %% write init;
         | 
| 68 49 | 
             
                    %% write exec;
         | 
| 69 50 |  | 
    
        data/lib/jiffy/version.rb
    CHANGED
    
    
    
        data/test/jiffy_test.rb
    CHANGED
    
    | @@ -1,5 +1,3 @@ | |
| 1 | 
            -
            $:.unshift File.join(File.dirname(__FILE__), '..', 'lib')
         | 
| 2 | 
            -
             | 
| 3 1 | 
             
            require 'stringio'
         | 
| 4 2 | 
             
            require 'minitest/autorun'
         | 
| 5 3 | 
             
            require 'jiffy'
         | 
| @@ -8,6 +6,10 @@ valid_json = '["Valid JSON"]' | |
| 8 6 | 
             
            invalid_json = '["Invalid" "JSON"]'
         | 
| 9 7 | 
             
            incomplete_json = '["Incomplete JSON'
         | 
| 10 8 |  | 
| 9 | 
            +
            class DummyOutputter
         | 
| 10 | 
            +
              def process_token(*); end
         | 
| 11 | 
            +
            end
         | 
| 12 | 
            +
             | 
| 11 13 | 
             
            def it_should_properly_handle(exception, options)
         | 
| 12 14 | 
             
              io = Object.new.tap do |io|
         | 
| 13 15 | 
             
                io.define_singleton_method :readpartial do |*|
         | 
| @@ -16,13 +18,13 @@ def it_should_properly_handle(exception, options) | |
| 16 18 | 
             
              end
         | 
| 17 19 |  | 
| 18 20 | 
             
              it "should return false upon #{exception.inspect}" do
         | 
| 19 | 
            -
                assert_equal false, Jiffy.new(in: io | 
| 21 | 
            +
                assert_equal false, Jiffy.new(in: io).cl_format(err: StringIO.new, outputter: DummyOutputter.new)
         | 
| 20 22 | 
             
              end
         | 
| 21 23 |  | 
| 22 24 | 
             
              it "should write #{options[:with]} to :stderr upon #{exception.inspect}" do
         | 
| 23 25 | 
             
                err = StringIO.new
         | 
| 24 26 |  | 
| 25 | 
            -
                Jiffy.new(in: io | 
| 27 | 
            +
                Jiffy.new(in: io).cl_format(err: err, outputter: DummyOutputter.new)
         | 
| 26 28 |  | 
| 27 29 | 
             
                assert_includes err.string, options[:with]
         | 
| 28 30 | 
             
              end
         | 
| @@ -30,43 +32,256 @@ def it_should_properly_handle(exception, options) | |
| 30 32 | 
             
              it ":stderr should end with a newline upon #{exception.inspect}" do
         | 
| 31 33 | 
             
                err = StringIO.new
         | 
| 32 34 |  | 
| 33 | 
            -
                Jiffy.new(in: io | 
| 35 | 
            +
                Jiffy.new(in: io).cl_format(err: err, outputter: DummyOutputter.new)
         | 
| 34 36 |  | 
| 35 37 | 
             
                assert_equal "\n", err.string[-1]
         | 
| 36 38 | 
             
              end
         | 
| 37 39 | 
             
            end
         | 
| 38 40 |  | 
| 39 | 
            -
             | 
| 40 | 
            -
               | 
| 41 | 
            -
             | 
| 42 | 
            -
               | 
| 43 | 
            -
             | 
| 44 | 
            -
                  it "should format #{File.basename(example)} without raising an exception" do
         | 
| 45 | 
            -
                    out = StringIO.new
         | 
| 46 | 
            -
             | 
| 47 | 
            -
                    Jiffy.new(in: example, out: out).format
         | 
| 41 | 
            +
            def it_should_tokenize(json, *tokens)
         | 
| 42 | 
            +
              it "should tokenize #{json.inspect} to #{tokens.map(&:inspect).join ', '}" do
         | 
| 43 | 
            +
                assert_equal tokens, Jiffy.new(in: StringIO.new(json)).tokenize.to_a
         | 
| 44 | 
            +
              end
         | 
| 45 | 
            +
            end
         | 
| 48 46 |  | 
| 49 | 
            -
             | 
| 50 | 
            -
             | 
| 47 | 
            +
            def it_should_not_tokenize(json)
         | 
| 48 | 
            +
              it "should not tokenize #{json.inspect}" do
         | 
| 49 | 
            +
                assert_raises Jiffy::UnexpectedEndError, Jiffy::UnparseableError do
         | 
| 50 | 
            +
                  Jiffy.new(in: StringIO.new(json)).tokenize.to_a
         | 
| 51 51 | 
             
                end
         | 
| 52 | 
            +
              end
         | 
| 53 | 
            +
            end
         | 
| 52 54 |  | 
| 53 | 
            -
             | 
| 54 | 
            -
             | 
| 55 | 
            -
                 | 
| 56 | 
            -
                   | 
| 57 | 
            -
             | 
| 58 | 
            -
             | 
| 59 | 
            -
             | 
| 60 | 
            -
             | 
| 61 | 
            -
             | 
| 62 | 
            -
                   | 
| 63 | 
            -
             | 
| 55 | 
            +
            describe Jiffy do
         | 
| 56 | 
            +
              describe '#tokenize' do
         | 
| 57 | 
            +
                it_should_tokenize '{}',
         | 
| 58 | 
            +
                  :begin_object,
         | 
| 59 | 
            +
                  :end_object
         | 
| 60 | 
            +
             | 
| 61 | 
            +
                it_should_tokenize '{"":{}}',
         | 
| 62 | 
            +
                  :begin_object,
         | 
| 63 | 
            +
                  :begin_name,
         | 
| 64 | 
            +
                  :end_name,
         | 
| 65 | 
            +
                  :name_separator,
         | 
| 66 | 
            +
                  :begin_object,
         | 
| 67 | 
            +
                  :end_object,
         | 
| 68 | 
            +
                  :end_object
         | 
| 69 | 
            +
             | 
| 70 | 
            +
                it_should_tokenize '{"":"","":""}',
         | 
| 71 | 
            +
                  :begin_object,
         | 
| 72 | 
            +
                  :begin_name,
         | 
| 73 | 
            +
                  :end_name,
         | 
| 74 | 
            +
                  :name_separator,
         | 
| 75 | 
            +
                  :begin_string,
         | 
| 76 | 
            +
                  :end_string,
         | 
| 77 | 
            +
                  :value_separator,
         | 
| 78 | 
            +
                  :begin_name,
         | 
| 79 | 
            +
                  :end_name,
         | 
| 80 | 
            +
                  :name_separator,
         | 
| 81 | 
            +
                  :begin_string,
         | 
| 82 | 
            +
                  :end_string,
         | 
| 83 | 
            +
                  :end_object
         | 
| 84 | 
            +
             | 
| 85 | 
            +
                it_should_tokenize '[]',
         | 
| 86 | 
            +
                  :begin_array,
         | 
| 87 | 
            +
                  :end_array
         | 
| 88 | 
            +
             | 
| 89 | 
            +
                it_should_tokenize '[[]]',
         | 
| 90 | 
            +
                  :begin_array,
         | 
| 91 | 
            +
                  :begin_array,
         | 
| 92 | 
            +
                  :end_array,
         | 
| 93 | 
            +
                  :end_array
         | 
| 94 | 
            +
             | 
| 95 | 
            +
                it_should_tokenize '[{}]',
         | 
| 96 | 
            +
                  :begin_array,
         | 
| 97 | 
            +
                  :begin_object,
         | 
| 98 | 
            +
                  :end_object,
         | 
| 99 | 
            +
                  :end_array
         | 
| 100 | 
            +
             | 
| 101 | 
            +
                it_should_tokenize '{"":[]}',
         | 
| 102 | 
            +
                  :begin_object,
         | 
| 103 | 
            +
                  :begin_name,
         | 
| 104 | 
            +
                  :end_name,
         | 
| 105 | 
            +
                  :name_separator,
         | 
| 106 | 
            +
                  :begin_array,
         | 
| 107 | 
            +
                  :end_array,
         | 
| 108 | 
            +
                  :end_object
         | 
| 109 | 
            +
             | 
| 110 | 
            +
                it_should_tokenize '["",""]',
         | 
| 111 | 
            +
                  :begin_array,
         | 
| 112 | 
            +
                  :begin_string,
         | 
| 113 | 
            +
                  :end_string,
         | 
| 114 | 
            +
                  :value_separator,
         | 
| 115 | 
            +
                  :begin_string,
         | 
| 116 | 
            +
                  :end_string,
         | 
| 117 | 
            +
                  :end_array
         | 
| 118 | 
            +
             | 
| 119 | 
            +
                it_should_tokenize '[false]',
         | 
| 120 | 
            +
                  :begin_array,
         | 
| 121 | 
            +
                  :false,
         | 
| 122 | 
            +
                  :end_array
         | 
| 123 | 
            +
             | 
| 124 | 
            +
                it_should_tokenize '[true]',
         | 
| 125 | 
            +
                  :begin_array,
         | 
| 126 | 
            +
                  :true,
         | 
| 127 | 
            +
                  :end_array
         | 
| 128 | 
            +
             | 
| 129 | 
            +
                it_should_tokenize '[null]',
         | 
| 130 | 
            +
                  :begin_array,
         | 
| 131 | 
            +
                  :null,
         | 
| 132 | 
            +
                  :end_array
         | 
| 133 | 
            +
             | 
| 134 | 
            +
                it_should_tokenize '["foo"]',
         | 
| 135 | 
            +
                  :begin_array,
         | 
| 136 | 
            +
                  :begin_string,
         | 
| 137 | 
            +
                  [:char, "f"],
         | 
| 138 | 
            +
                  [:char, "o"],
         | 
| 139 | 
            +
                  [:char, "o"],
         | 
| 140 | 
            +
                  :end_string,
         | 
| 141 | 
            +
                  :end_array
         | 
| 142 | 
            +
             | 
| 143 | 
            +
                it_should_tokenize '["\b"]',
         | 
| 144 | 
            +
                  :begin_array,
         | 
| 145 | 
            +
                  :begin_string,
         | 
| 146 | 
            +
                  :escaped_backspace,
         | 
| 147 | 
            +
                  :end_string,
         | 
| 148 | 
            +
                  :end_array
         | 
| 149 | 
            +
             | 
| 150 | 
            +
                it_should_tokenize '["\r"]',
         | 
| 151 | 
            +
                  :begin_array,
         | 
| 152 | 
            +
                  :begin_string,
         | 
| 153 | 
            +
                  :escaped_carriage_return,
         | 
| 154 | 
            +
                  :end_string,
         | 
| 155 | 
            +
                  :end_array
         | 
| 156 | 
            +
             | 
| 157 | 
            +
                it_should_tokenize '["\f"]',
         | 
| 158 | 
            +
                  :begin_array,
         | 
| 159 | 
            +
                  :begin_string,
         | 
| 160 | 
            +
                  :escaped_formfeed,
         | 
| 161 | 
            +
                  :end_string,
         | 
| 162 | 
            +
                  :end_array
         | 
| 163 | 
            +
             | 
| 164 | 
            +
                it_should_tokenize '["\t"]',
         | 
| 165 | 
            +
                  :begin_array,
         | 
| 166 | 
            +
                  :begin_string,
         | 
| 167 | 
            +
                  :escaped_horizontal_tab,
         | 
| 168 | 
            +
                  :end_string,
         | 
| 169 | 
            +
                  :end_array
         | 
| 170 | 
            +
             | 
| 171 | 
            +
                it_should_tokenize '["\n"]',
         | 
| 172 | 
            +
                  :begin_array,
         | 
| 173 | 
            +
                  :begin_string,
         | 
| 174 | 
            +
                  :escaped_newline,
         | 
| 175 | 
            +
                  :end_string,
         | 
| 176 | 
            +
                  :end_array
         | 
| 177 | 
            +
             | 
| 178 | 
            +
                it_should_tokenize '["\""]',
         | 
| 179 | 
            +
                  :begin_array,
         | 
| 180 | 
            +
                  :begin_string,
         | 
| 181 | 
            +
                  :escaped_quotation_mark,
         | 
| 182 | 
            +
                  :end_string,
         | 
| 183 | 
            +
                  :end_array
         | 
| 184 | 
            +
             | 
| 185 | 
            +
                it_should_tokenize '["\\\\"]',
         | 
| 186 | 
            +
                  :begin_array,
         | 
| 187 | 
            +
                  :begin_string,
         | 
| 188 | 
            +
                  :escaped_reverse_solidus,
         | 
| 189 | 
            +
                  :end_string,
         | 
| 190 | 
            +
                  :end_array
         | 
| 191 | 
            +
             | 
| 192 | 
            +
                it_should_tokenize '["\/"]',
         | 
| 193 | 
            +
                  :begin_array,
         | 
| 194 | 
            +
                  :begin_string,
         | 
| 195 | 
            +
                  :escaped_solidus,
         | 
| 196 | 
            +
                  :end_string,
         | 
| 197 | 
            +
                  :end_array
         | 
| 198 | 
            +
             | 
| 199 | 
            +
                it_should_tokenize '["\u1111"]',
         | 
| 200 | 
            +
                  :begin_array,
         | 
| 201 | 
            +
                  :begin_string,
         | 
| 202 | 
            +
                  [:escaped_unicode, "1111"],
         | 
| 203 | 
            +
                  :end_string,
         | 
| 204 | 
            +
                  :end_array
         | 
| 205 | 
            +
             | 
| 206 | 
            +
                it_should_tokenize '[-100]',
         | 
| 207 | 
            +
                  :begin_array,
         | 
| 208 | 
            +
                  :minus,
         | 
| 209 | 
            +
                  [:number, 1],
         | 
| 210 | 
            +
                  [:number, 0],
         | 
| 211 | 
            +
                  [:number, 0],
         | 
| 212 | 
            +
                  :end_array
         | 
| 213 | 
            +
             | 
| 214 | 
            +
                it_should_tokenize '[1.123]',
         | 
| 215 | 
            +
                  :begin_array,
         | 
| 216 | 
            +
                  [:number, 1],
         | 
| 217 | 
            +
                  [:char, "."],
         | 
| 218 | 
            +
                  [:number, 1],
         | 
| 219 | 
            +
                  [:number, 2],
         | 
| 220 | 
            +
                  [:number, 3],
         | 
| 221 | 
            +
                  :end_array
         | 
| 222 | 
            +
             | 
| 223 | 
            +
                it_should_tokenize '[1.123e10]',
         | 
| 224 | 
            +
                  :begin_array,
         | 
| 225 | 
            +
                  [:number, 1],
         | 
| 226 | 
            +
                  [:char, "."],
         | 
| 227 | 
            +
                  [:number, 1],
         | 
| 228 | 
            +
                  [:number, 2],
         | 
| 229 | 
            +
                  [:number, 3],
         | 
| 230 | 
            +
                  :exponent,
         | 
| 231 | 
            +
                  [:number, 1],
         | 
| 232 | 
            +
                  [:number, 0],
         | 
| 233 | 
            +
                  :end_array
         | 
| 234 | 
            +
             | 
| 235 | 
            +
                it_should_tokenize '[-1.123e-10]',
         | 
| 236 | 
            +
                  :begin_array,
         | 
| 237 | 
            +
                  :minus,
         | 
| 238 | 
            +
                  [:number, 1],
         | 
| 239 | 
            +
                  [:char, "."],
         | 
| 240 | 
            +
                  [:number, 1],
         | 
| 241 | 
            +
                  [:number, 2],
         | 
| 242 | 
            +
                  [:number, 3],
         | 
| 243 | 
            +
                  :exponent,
         | 
| 244 | 
            +
                  :minus,
         | 
| 245 | 
            +
                  [:number, 1],
         | 
| 246 | 
            +
                  [:number, 0],
         | 
| 247 | 
            +
                  :end_array
         | 
| 248 | 
            +
             | 
| 249 | 
            +
                it_should_tokenize '[1.123E+10]',
         | 
| 250 | 
            +
                  :begin_array,
         | 
| 251 | 
            +
                  [:number, 1],
         | 
| 252 | 
            +
                  [:char, "."],
         | 
| 253 | 
            +
                  [:number, 1],
         | 
| 254 | 
            +
                  [:number, 2],
         | 
| 255 | 
            +
                  [:number, 3],
         | 
| 256 | 
            +
                  :exponent,
         | 
| 257 | 
            +
                  :plus,
         | 
| 258 | 
            +
                  [:number, 1],
         | 
| 259 | 
            +
                  [:number, 0],
         | 
| 260 | 
            +
                  :end_array
         | 
| 261 | 
            +
             | 
| 262 | 
            +
                it_should_not_tokenize '[0x00]'
         | 
| 263 | 
            +
                it_should_not_tokenize '[Infinity]'
         | 
| 264 | 
            +
                it_should_not_tokenize '[,""]'
         | 
| 265 | 
            +
                it_should_not_tokenize '["",]'
         | 
| 266 | 
            +
                it_should_not_tokenize '[01]'
         | 
| 267 | 
            +
                it_should_not_tokenize "[\"line\nbreak\"]"
         | 
| 268 | 
            +
                it_should_not_tokenize '{"" ""}'
         | 
| 269 | 
            +
                it_should_not_tokenize '[NaN]'
         | 
| 270 | 
            +
                it_should_not_tokenize '[+1.123]'
         | 
| 271 | 
            +
                it_should_not_tokenize '[+100]'
         | 
| 272 | 
            +
                it_should_not_tokenize "['single quoted string']"
         | 
| 273 | 
            +
                it_should_not_tokenize "[\"tab\tcharacter\"]"
         | 
| 274 | 
            +
                it_should_not_tokenize '{"":"",}'
         | 
| 275 | 
            +
                it_should_not_tokenize 'true'
         | 
| 276 | 
            +
                it_should_not_tokenize '""'
         | 
| 277 | 
            +
                it_should_not_tokenize '[true'
         | 
| 278 | 
            +
                it_should_not_tokenize '{"":""'
         | 
| 64 279 |  | 
| 65 280 | 
             
                it 'should raise UnexpectedEndError on valid, but incomplete JSON input' do
         | 
| 66 281 | 
             
                  example = StringIO.new incomplete_json
         | 
| 67 282 |  | 
| 68 283 | 
             
                  assert_raises Jiffy::UnexpectedEndError do
         | 
| 69 | 
            -
                    Jiffy.new(in: example | 
| 284 | 
            +
                    Jiffy.new(in: example).tokenize.to_a
         | 
| 70 285 | 
             
                  end
         | 
| 71 286 | 
             
                end
         | 
| 72 287 |  | 
| @@ -74,7 +289,7 @@ describe Jiffy do | |
| 74 289 | 
             
                  example = StringIO.new ""
         | 
| 75 290 |  | 
| 76 291 | 
             
                  assert_raises Jiffy::UnexpectedEndError do
         | 
| 77 | 
            -
                    Jiffy.new(in: example | 
| 292 | 
            +
                    Jiffy.new(in: example).tokenize.to_a
         | 
| 78 293 | 
             
                  end
         | 
| 79 294 | 
             
                end
         | 
| 80 295 |  | 
| @@ -82,13 +297,25 @@ describe Jiffy do | |
| 82 297 | 
             
                  example = StringIO.new invalid_json
         | 
| 83 298 |  | 
| 84 299 | 
             
                  assert_raises Jiffy::UnparseableError do
         | 
| 85 | 
            -
                    Jiffy.new(in: example | 
| 300 | 
            +
                    Jiffy.new(in: example).tokenize.to_a
         | 
| 86 301 | 
             
                  end
         | 
| 87 302 | 
             
                end
         | 
| 88 303 | 
             
              end
         | 
| 89 304 |  | 
| 90 305 | 
             
              describe '#initialize' do
         | 
| 91 | 
            -
                it 'should raise an error when :in is  | 
| 306 | 
            +
                it 'should not raise an error when :in is an instance of String' do
         | 
| 307 | 
            +
                  Jiffy.new(in: __FILE__)
         | 
| 308 | 
            +
                end
         | 
| 309 | 
            +
             | 
| 310 | 
            +
                it 'should not raise en error when :in responds to :readpartial' do
         | 
| 311 | 
            +
                  class Bar
         | 
| 312 | 
            +
                    def readpartial(*); end
         | 
| 313 | 
            +
                  end
         | 
| 314 | 
            +
             | 
| 315 | 
            +
                  Jiffy.new(in: Bar.new)
         | 
| 316 | 
            +
                end
         | 
| 317 | 
            +
             | 
| 318 | 
            +
                it 'should raise an error when :in is neither an instance of Strirng nor responds to :readpartial' do
         | 
| 92 319 | 
             
                  class Foo; end
         | 
| 93 320 |  | 
| 94 321 | 
             
                  assert_raises ArgumentError do
         | 
| @@ -107,7 +334,7 @@ describe Jiffy do | |
| 107 334 | 
             
                it 'should return true upon valid input' do
         | 
| 108 335 | 
             
                  example = StringIO.new valid_json
         | 
| 109 336 |  | 
| 110 | 
            -
                  assert_equal true, Jiffy.new(in: example | 
| 337 | 
            +
                  assert_equal true, Jiffy.new(in: example).cl_format(outputter: DummyOutputter.new)
         | 
| 111 338 | 
             
                end
         | 
| 112 339 |  | 
| 113 340 | 
             
                it 'should not write to :stderr upon valid input' do
         | 
| @@ -115,7 +342,7 @@ describe Jiffy do | |
| 115 342 |  | 
| 116 343 | 
             
                  err = StringIO.new
         | 
| 117 344 |  | 
| 118 | 
            -
                  Jiffy.new(in: example | 
| 345 | 
            +
                  Jiffy.new(in: example).cl_format(err: err, outputter: DummyOutputter.new)
         | 
| 119 346 |  | 
| 120 347 | 
             
                  assert_equal "", err.string
         | 
| 121 348 | 
             
                end
         | 
| @@ -125,7 +352,7 @@ describe Jiffy do | |
| 125 352 |  | 
| 126 353 | 
             
                  out = StringIO.new
         | 
| 127 354 |  | 
| 128 | 
            -
                  Jiffy.new(in: example | 
| 355 | 
            +
                  Jiffy.new(in: example).cl_format(outputter: Jiffy::Outputters::Json.new(out: out))
         | 
| 129 356 |  | 
| 130 357 | 
             
                  assert_equal "\n", out.string[-1]
         | 
| 131 358 | 
             
                end
         |