Skip to content

Commit

Permalink
oneOf test
Browse files Browse the repository at this point in the history
  • Loading branch information
hoxworth committed Jun 23, 2013
1 parent a073277 commit 9f44154
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions test/test_jsonschema_draft4.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1116,6 +1116,38 @@ def test_any_of
end


def test_one_of
schema = {
"$schema" => "http://json-schema.org/draft-04/schema#",
"oneOf" => [
{
"properties" => {"a" => {"type" => "string"}},
"required" => ["a"]
},
{
"properties" => {"b" => {"type" => "integer"}}
}
]
}

data = {"a" => "hello", "b" => 5}
assert(!JSON::Validator.validate(schema,data))

# This passes because b is not required, thus matches both schemas
data = {"a" => "hello"}
assert(!JSON::Validator.validate(schema,data))

data = {"a" => "hello", "b" => "taco"}
assert(JSON::Validator.validate(schema,data))

data = {"b" => 5}
assert(JSON::Validator.validate(schema,data))

data = {"a" => 5, "b" => "taco"}
assert(!JSON::Validator.validate(schema,data))
end


def test_not
# Start with a simple not
schema = {
Expand Down

0 comments on commit 9f44154

Please sign in to comment.