From 490acf0368a4a51c8bdde24a3a5302de88297ad2 Mon Sep 17 00:00:00 2001 From: Kenny Hoxworth Date: Mon, 24 Oct 2011 11:56:28 -0400 Subject: [PATCH] Adding dependency testing --- test/test_jsonschema_draft3.rb | 35 ++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) diff --git a/test/test_jsonschema_draft3.rb b/test/test_jsonschema_draft3.rb index 59d8550b..f4af631f 100644 --- a/test/test_jsonschema_draft3.rb +++ b/test/test_jsonschema_draft3.rb @@ -932,6 +932,41 @@ def test_schema assert(JSON::Validator.validate(schema,data)) end + def test_dependency + schema = { + "type" => "object", + "properties" => { + "a" => {"type" => "integer"}, + "b" => {"type" => "integer"} + }, + "dependencies" => { + "a" => "b" + } + } + + data = {"a" => 1, "b" => 2} + assert(JSON::Validator.validate(schema,data)) + data = {"a" => 1} + assert(!JSON::Validator.validate(schema,data)) + + schema = { + "type" => "object", + "properties" => { + "a" => {"type" => "integer"}, + "b" => {"type" => "integer"}, + "c" => {"type" => "integer"} + }, + "dependencies" => { + "a" => ["b","c"] + } + } + + data = {"a" => 1, "c" => 2} + assert(!JSON::Validator.validate(schema,data)) + data = {"a" => 1, "b" => 2, "c" => 3} + assert(JSON::Validator.validate(schema,data)) + end + end