1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95
|
###
### $Rev$
### $Release: 0.7.2 $
### copyright(c) 2005-2010 kuwata-lab all rights reserved.
###
require File.dirname(__FILE__) '/test.rb'
class ValidatorTest < Test::Unit::TestCase
## define test methods
filename = __FILE__.sub(/\.rb$/, '.yaml')
load_yaml_testdata(filename, :lang=>'ruby')
## execute test
def _test()
return if $target && $target != @name
## Syck parser
schema = YAML.load(@schema)
validator = Kwalify::Validator.new(schema)
error2 = @error.gsub(/\(line \d \)/, '')
_test_by_syck_parser(validator, @valid, '' )
_test_by_syck_parser(validator, @invalid, error2)
## Kwalify::YamlParser
schema = Kwalify::YamlParser.new(@schema).parse()
validator = Kwalify::Validator.new(schema)
_test_by_kwalify_yamlparser(validator, @valid, '' )
_test_by_kwalify_yamlparser(validator, @invalid, @error)
## Kwalify::Yaml::Parser
schema = Kwalify::Yaml::Parser.new().parse(@schema)
validator = Kwalify::Validator.new(schema)
_test_by_kwalify_yaml_parser(validator, @valid, '' )
_test_by_kwalify_yaml_parser(validator, @invalid, @error2 || @error)
end
def _test_by_kwalify_yamlparser(validator, input, expected)
parser = Kwalify::YamlParser.new(input)
document = parser.parse()
error_list = validator.validate(document)
parser.set_errors_linenum(error_list)
error_list.sort!
actual = ''
error_list.each do |error|
e = error
args = [e.error_symbol.inspect, e.linenum, e.path, e.message]
actual << "%-20s: (line %d)[%s] %s\n" % args
end
if $print
print actual
else
assert_text_equal(expected, actual)
end
end
def _test_by_kwalify_yaml_parser(validator, input, expected)
parser = Kwalify::Yaml::Parser.new(validator)
document = parser.parse(input)
error_list = parser.errors()
error_list.sort!
actual = ''
error_list.each do |error|
e = error
args = [e.error_symbol.inspect, e.linenum, e.column, e.path, e.message]
#actual << "%-20s: (line %d)[%s] %s\n" % args
actual << "%-20s: %d:%d:[%s] %s\n" % args
end
if $print
print actual
else
assert_text_equal(expected, actual)
end
end
def _test_by_syck_parser(validator, input, expected)
document = YAML.load(input)
error_list = validator.validate(document)
expected = expected.lines.sort.join()
actual = error_list.collect { |e|
"%-20s: [%s] %s\n" % [e.error_symbol.inspect, e.path, e.message]
}.sort.join()
if $print
print actual
else
assert_text_equal(expected, actual)
end
end
end
|