2007-06-04 08:31:26 -04:00
|
|
|
#!/usr/bin/env ruby
|
2009-09-01 13:34:50 -04:00
|
|
|
# -*- coding: utf-8 -*-
|
2007-06-04 08:31:26 -04:00
|
|
|
|
|
|
|
require 'test/unit'
|
2011-07-10 04:01:04 -04:00
|
|
|
require File.join(File.dirname(__FILE__), 'setup_variant')
|
2007-06-04 08:31:26 -04:00
|
|
|
|
|
|
|
class TC_JSONFixtures < Test::Unit::TestCase
|
|
|
|
def setup
|
|
|
|
fixtures = File.join(File.dirname(__FILE__), 'fixtures/*.json')
|
|
|
|
passed, failed = Dir[fixtures].partition { |f| f['pass'] }
|
|
|
|
@passed = passed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
|
|
|
@failed = failed.inject([]) { |a, f| a << [ f, File.read(f) ] }.sort
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_passing
|
|
|
|
for name, source in @passed
|
2011-07-10 04:01:04 -04:00
|
|
|
begin
|
|
|
|
assert JSON.parse(source),
|
|
|
|
"Did not pass for fixture '#{name}': #{source.inspect}"
|
|
|
|
rescue => e
|
|
|
|
warn "\nCaught #{e.class}(#{e}) for fixture '#{name}': #{source.inspect}\n#{e.backtrace * "\n"}"
|
|
|
|
raise e
|
|
|
|
end
|
2007-06-04 08:31:26 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_failing
|
|
|
|
for name, source in @failed
|
2009-09-01 13:34:50 -04:00
|
|
|
assert_raises(JSON::ParserError, JSON::NestingError,
|
2011-07-10 04:01:04 -04:00
|
|
|
"Did not fail for fixture '#{name}': #{source.inspect}") do
|
2007-06-04 08:31:26 -04:00
|
|
|
JSON.parse(source)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|