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
|
module ObjectValidation
module AdditionalPropertiesTests
def test_additional_properties_false
schema = {
'properties' => {
'a' => { 'type' => 'integer' }
},
'additionalProperties' => false
}
assert_valid schema, {'a' => 1}
refute_valid schema, {'a' => 1, 'b' => 2}
end
def test_additional_properties_schema
schema = {
'properties' => {
'a' => { 'type' => 'integer' }
},
'additionalProperties' => { 'type' => 'string' }
}
assert_valid schema, {'a' => 1}
assert_valid schema, {'a' => 1, 'b' => 'hi'}
refute_valid schema, {'a' => 1, 'b' => 2}
end
end
module PatternPropertiesTests
def test_pattern_properties
schema = {
'patternProperties' => {
"\\d+ taco" => { 'type' => 'integer' }
}
}
assert_valid schema, {'1 taco' => 1, '20 taco' => 20}
assert_valid schema, {'foo' => true, '1 taco' => 1}
refute_valid schema, {'1 taco' => 'yum'}
end
def test_pattern_properties_additional_properties_false
schema = {
'patternProperties' => {
"\\d+ taco" => { 'type' => 'integer' }
},
'additionalProperties' => false
}
assert_valid schema, {'1 taco' => 1}
refute_valid schema, {'1 taco' => 'yum'}
refute_valid schema, {'1 taco' => 1, 'foo' => true}
end
def test_pattern_properties_additional_properties_schema
schema = {
'patternProperties' => {
"\\d+ taco" => { 'type' => 'integer' }
},
'additionalProperties' => { 'type' => 'string' }
}
assert_valid schema, {'1 taco' => 1}
assert_valid schema, {'1 taco' => 1, 'foo' => 'bar'}
refute_valid schema, {'1 taco' => 1, 'foo' => 2}
end
end
end
|