OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 var AssertTrue = requireNative('assert').AssertTrue; | 5 var AssertTrue = requireNative('assert').AssertTrue; |
6 var JSONSchemaValidator = require('json_schema').JSONSchemaValidator; | 6 var JSONSchemaValidator = require('json_schema').JSONSchemaValidator; |
7 var LOG = requireNative('logging').LOG; | 7 var LOG = requireNative('logging').LOG; |
8 | 8 |
9 function assertValid(type, instance, schema, types) { | 9 function assertValid(type, instance, schema, types) { |
10 var validator = new JSONSchemaValidator(); | 10 var validator = new JSONSchemaValidator(); |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 assertValid("", instance, schema); | 131 assertValid("", instance, schema); |
132 | 132 |
133 instance[0].id = 0; | 133 instance[0].id = 0; |
134 assertNotValid("", instance, schema, | 134 assertNotValid("", instance, schema, |
135 [formatError("numberMinValue", | 135 [formatError("numberMinValue", |
136 [schema.items[0].properties.id.minimum])]); | 136 [schema.items[0].properties.id.minimum])]); |
137 } | 137 } |
138 | 138 |
139 function testEnum() { | 139 function testEnum() { |
140 var schema = { | 140 var schema = { |
141 enum: [{"name": "foo"}, 42, false] | 141 enum: ["foo", 42, false] |
142 }; | 142 }; |
143 | 143 |
144 assertValid("", "foo", schema); | 144 assertValid("", "foo", schema); |
145 assertValid("", 42, schema); | 145 assertValid("", 42, schema); |
146 assertValid("", false, schema); | 146 assertValid("", false, schema); |
147 var enum_values = ["foo", 42, false]; | |
148 assertNotValid("", "42", schema, [formatError("invalidEnum", | 147 assertNotValid("", "42", schema, [formatError("invalidEnum", |
149 [enum_values.join(", ")])]); | 148 [schema.enum.join(", ")])]); |
150 assertNotValid("", null, schema, [formatError("invalidEnum", | 149 assertNotValid("", null, schema, [formatError("invalidEnum", |
151 [enum_values.join(", ")])]); | 150 [schema.enum.join(", ")])]); |
152 } | 151 } |
153 | 152 |
154 function testChoices() { | 153 function testChoices() { |
155 var schema = { | 154 var schema = { |
156 choices: [ | 155 choices: [ |
157 { type: "null" }, | 156 { type: "null" }, |
158 { type: "undefined" }, | 157 { type: "undefined" }, |
159 { type: "integer", minimum:42, maximum:42 }, | 158 { type: "integer", minimum:42, maximum:42 }, |
160 { type: "object", properties: { foo: { type: "string" } } } | 159 { type: "object", properties: { foo: { type: "string" } } } |
161 ] | 160 ] |
(...skipping 498 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 exports.testArrayNonTuple = testArrayNonTuple; | 659 exports.testArrayNonTuple = testArrayNonTuple; |
661 exports.testString = testString; | 660 exports.testString = testString; |
662 exports.testNumber = testNumber; | 661 exports.testNumber = testNumber; |
663 exports.testIntegerBounds = testIntegerBounds; | 662 exports.testIntegerBounds = testIntegerBounds; |
664 exports.testType = testType; | 663 exports.testType = testType; |
665 exports.testTypeReference = testTypeReference; | 664 exports.testTypeReference = testTypeReference; |
666 exports.testGetAllTypesForSchema = testGetAllTypesForSchema; | 665 exports.testGetAllTypesForSchema = testGetAllTypesForSchema; |
667 exports.testIsValidSchemaType = testIsValidSchemaType; | 666 exports.testIsValidSchemaType = testIsValidSchemaType; |
668 exports.testCheckSchemaOverlap = testCheckSchemaOverlap; | 667 exports.testCheckSchemaOverlap = testCheckSchemaOverlap; |
669 exports.testInstanceOf = testInstanceOf; | 668 exports.testInstanceOf = testInstanceOf; |
OLD | NEW |