jschema 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/lib/jschema.rb +41 -0
- data/lib/jschema/json_reference.rb +65 -0
- data/lib/jschema/schema.rb +84 -0
- data/lib/jschema/schema_ref.rb +13 -0
- data/lib/jschema/simple_validator.rb +86 -0
- data/lib/jschema/string_length_validator.rb +17 -0
- data/lib/jschema/validator.rb +14 -0
- data/lib/jschema/validator/all_of.rb +29 -0
- data/lib/jschema/validator/any_of.rb +29 -0
- data/lib/jschema/validator/dependencies.rb +63 -0
- data/lib/jschema/validator/enum.rb +23 -0
- data/lib/jschema/validator/format.rb +75 -0
- data/lib/jschema/validator/items.rb +79 -0
- data/lib/jschema/validator/max_items.rb +28 -0
- data/lib/jschema/validator/max_length.rb +23 -0
- data/lib/jschema/validator/max_properties.rb +31 -0
- data/lib/jschema/validator/maximum.rb +31 -0
- data/lib/jschema/validator/min_items.rb +28 -0
- data/lib/jschema/validator/min_length.rb +23 -0
- data/lib/jschema/validator/min_properties.rb +31 -0
- data/lib/jschema/validator/minimum.rb +31 -0
- data/lib/jschema/validator/multiple_of.rb +32 -0
- data/lib/jschema/validator/not.rb +23 -0
- data/lib/jschema/validator/one_of.rb +29 -0
- data/lib/jschema/validator/pattern.rb +36 -0
- data/lib/jschema/validator/properties.rb +106 -0
- data/lib/jschema/validator/required.rb +34 -0
- data/lib/jschema/validator/type.rb +57 -0
- data/lib/jschema/validator/unique_items.rb +27 -0
- data/test/assert_received.rb +15 -0
- data/test/string_length_validator_tests.rb +18 -0
- data/test/test_assert_received.rb +39 -0
- data/test/test_integration.rb +30 -0
- data/test/test_json_reference.rb +84 -0
- data/test/test_schema.rb +125 -0
- data/test/test_schema_ref.rb +11 -0
- data/test/test_validator.rb +29 -0
- data/test/validator/argument_is_array_of_schemas_tests.rb +22 -0
- data/test/validator/assertions.rb +56 -0
- data/test/validator/properties_limit_tests.rb +13 -0
- data/test/validator/schema_validation_helpers.rb +29 -0
- data/test/validator/test_all_of.rb +30 -0
- data/test/validator/test_any_of.rb +31 -0
- data/test/validator/test_dependencies.rb +106 -0
- data/test/validator/test_enum.rb +30 -0
- data/test/validator/test_format.rb +70 -0
- data/test/validator/test_items.rb +113 -0
- data/test/validator/test_max_items.rb +26 -0
- data/test/validator/test_max_length.rb +30 -0
- data/test/validator/test_max_properties.rb +29 -0
- data/test/validator/test_maximum.rb +58 -0
- data/test/validator/test_min_items.rb +27 -0
- data/test/validator/test_min_length.rb +30 -0
- data/test/validator/test_min_properties.rb +29 -0
- data/test/validator/test_minimum.rb +58 -0
- data/test/validator/test_multiple_of.rb +38 -0
- data/test/validator/test_not.rb +32 -0
- data/test/validator/test_one_of.rb +31 -0
- data/test/validator/test_pattern.rb +32 -0
- data/test/validator/test_properties.rb +136 -0
- data/test/validator/test_required.rb +30 -0
- data/test/validator/test_simple_validator.rb +100 -0
- data/test/validator/test_type.rb +97 -0
- data/test/validator/test_unique_items.rb +30 -0
- data/test/validator/validation_against_schemas_tests.rb +24 -0
- metadata +144 -0
@@ -0,0 +1,97 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'jschema'
|
3
|
+
|
4
|
+
require_relative 'assertions'
|
5
|
+
|
6
|
+
class TestType < Minitest::Test
|
7
|
+
include Assertions
|
8
|
+
|
9
|
+
def test_that_argument_is_a_string_or_an_array
|
10
|
+
assert_raises_unless 'type', :string, :array
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_that_argument_is_a_unique_string_array
|
14
|
+
assert_raises_unless_string_array 'type'
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_passing_string_validation
|
18
|
+
assert validator('string').valid?('str')
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_failing_string_validation
|
22
|
+
refute validator('string').valid?(1)
|
23
|
+
end
|
24
|
+
|
25
|
+
def test_passing_integer_validation
|
26
|
+
assert validator('integer').valid?(1)
|
27
|
+
assert validator('integer').valid?(2**64)
|
28
|
+
end
|
29
|
+
|
30
|
+
def test_failing_integer_validation
|
31
|
+
refute validator('integer').valid?('str')
|
32
|
+
end
|
33
|
+
|
34
|
+
def test_passing_array_validation
|
35
|
+
assert validator('array').valid?([])
|
36
|
+
end
|
37
|
+
|
38
|
+
def test_failing_array_validation
|
39
|
+
refute validator('array').valid?('str')
|
40
|
+
end
|
41
|
+
|
42
|
+
def test_passing_boolean_validation
|
43
|
+
assert validator('boolean').valid?(true)
|
44
|
+
assert validator('boolean').valid?(false)
|
45
|
+
end
|
46
|
+
|
47
|
+
def test_failing_boolean_validation
|
48
|
+
refute validator('boolean').valid?(nil)
|
49
|
+
refute validator('boolean').valid?(0)
|
50
|
+
end
|
51
|
+
|
52
|
+
def test_passing_null_validation
|
53
|
+
assert validator('null').valid?(nil)
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_failing_null_validation
|
57
|
+
refute validator('null').valid?(false)
|
58
|
+
refute validator('null').valid?('')
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_passing_object_validation
|
62
|
+
assert validator('object').valid?('test' => 123)
|
63
|
+
end
|
64
|
+
|
65
|
+
def test_failing_object_validation
|
66
|
+
refute validator('object').valid?([])
|
67
|
+
end
|
68
|
+
|
69
|
+
def test_passing_number_validation
|
70
|
+
assert validator('number').valid?(1)
|
71
|
+
assert validator('number').valid?(1.2)
|
72
|
+
assert validator('number').valid?(BigDecimal.new('1.2'))
|
73
|
+
assert validator('number').valid?(2**64)
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_failing_number_validation
|
77
|
+
refute validator('number').valid?('1')
|
78
|
+
end
|
79
|
+
|
80
|
+
def test_passing_multiple_type_validation
|
81
|
+
mvalidator = validator ['string', 'null']
|
82
|
+
assert mvalidator.valid?('str')
|
83
|
+
assert mvalidator.valid?(nil)
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_failing_multiple_type_validation
|
87
|
+
mvalidator = validator ['string', 'null']
|
88
|
+
refute mvalidator.valid?(1)
|
89
|
+
refute mvalidator.valid?(false)
|
90
|
+
end
|
91
|
+
|
92
|
+
private
|
93
|
+
|
94
|
+
def validator_class
|
95
|
+
JSchema::Validator::Type
|
96
|
+
end
|
97
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'minitest/autorun'
|
2
|
+
require 'jschema'
|
3
|
+
|
4
|
+
require_relative 'assertions'
|
5
|
+
|
6
|
+
class TestUniqueItems < Minitest::Test
|
7
|
+
include Assertions
|
8
|
+
|
9
|
+
def test_that_argument_is_boolean
|
10
|
+
assert_raises_unless 'uniqueItems', :boolean
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_passing_validation_when_unique_items_is_true
|
14
|
+
assert validator(true).valid?([1, 2])
|
15
|
+
end
|
16
|
+
|
17
|
+
def test_passing_validation_when_unique_items_is_false
|
18
|
+
assert validator(false).valid?([1, 1])
|
19
|
+
end
|
20
|
+
|
21
|
+
def test_failing_validation
|
22
|
+
refute validator(true).valid?([1, 1])
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def validator_class
|
28
|
+
JSchema::Validator::UniqueItems
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require_relative 'argument_is_array_of_schemas_tests'
|
2
|
+
|
3
|
+
module ValidationAgainstSchemasTests
|
4
|
+
include SchemaValidationHelpers
|
5
|
+
include ArgumentIsArrayOfSchemasTests
|
6
|
+
|
7
|
+
def test_passing_validation_against_one_schema
|
8
|
+
stub_schema_validations(true) do
|
9
|
+
assert validator([generate_schema]).valid?('test')
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def test_failing_validation_against_one_schema
|
14
|
+
stub_schema_validations(false) do
|
15
|
+
refute validator([generate_schema]).valid?('test')
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def test_failing_validation_all_validations_fail
|
20
|
+
stub_schema_validations(false, false) do
|
21
|
+
refute validator([generate_schema, generate_schema]).valid?('test')
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
metadata
ADDED
@@ -0,0 +1,144 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: jschema
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.2
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Konstantin Papkovskiy
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-12-29 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: Implementation of JSON Schema Draft 4
|
14
|
+
email: konstantin@papkovskiy.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/jschema.rb
|
20
|
+
- lib/jschema/json_reference.rb
|
21
|
+
- lib/jschema/schema.rb
|
22
|
+
- lib/jschema/schema_ref.rb
|
23
|
+
- lib/jschema/simple_validator.rb
|
24
|
+
- lib/jschema/string_length_validator.rb
|
25
|
+
- lib/jschema/validator.rb
|
26
|
+
- lib/jschema/validator/all_of.rb
|
27
|
+
- lib/jschema/validator/any_of.rb
|
28
|
+
- lib/jschema/validator/dependencies.rb
|
29
|
+
- lib/jschema/validator/enum.rb
|
30
|
+
- lib/jschema/validator/format.rb
|
31
|
+
- lib/jschema/validator/items.rb
|
32
|
+
- lib/jschema/validator/max_items.rb
|
33
|
+
- lib/jschema/validator/max_length.rb
|
34
|
+
- lib/jschema/validator/max_properties.rb
|
35
|
+
- lib/jschema/validator/maximum.rb
|
36
|
+
- lib/jschema/validator/min_items.rb
|
37
|
+
- lib/jschema/validator/min_length.rb
|
38
|
+
- lib/jschema/validator/min_properties.rb
|
39
|
+
- lib/jschema/validator/minimum.rb
|
40
|
+
- lib/jschema/validator/multiple_of.rb
|
41
|
+
- lib/jschema/validator/not.rb
|
42
|
+
- lib/jschema/validator/one_of.rb
|
43
|
+
- lib/jschema/validator/pattern.rb
|
44
|
+
- lib/jschema/validator/properties.rb
|
45
|
+
- lib/jschema/validator/required.rb
|
46
|
+
- lib/jschema/validator/type.rb
|
47
|
+
- lib/jschema/validator/unique_items.rb
|
48
|
+
- test/assert_received.rb
|
49
|
+
- test/string_length_validator_tests.rb
|
50
|
+
- test/test_assert_received.rb
|
51
|
+
- test/test_integration.rb
|
52
|
+
- test/test_json_reference.rb
|
53
|
+
- test/test_schema.rb
|
54
|
+
- test/test_schema_ref.rb
|
55
|
+
- test/test_validator.rb
|
56
|
+
- test/validator/argument_is_array_of_schemas_tests.rb
|
57
|
+
- test/validator/assertions.rb
|
58
|
+
- test/validator/properties_limit_tests.rb
|
59
|
+
- test/validator/schema_validation_helpers.rb
|
60
|
+
- test/validator/test_all_of.rb
|
61
|
+
- test/validator/test_any_of.rb
|
62
|
+
- test/validator/test_dependencies.rb
|
63
|
+
- test/validator/test_enum.rb
|
64
|
+
- test/validator/test_format.rb
|
65
|
+
- test/validator/test_items.rb
|
66
|
+
- test/validator/test_max_items.rb
|
67
|
+
- test/validator/test_max_length.rb
|
68
|
+
- test/validator/test_max_properties.rb
|
69
|
+
- test/validator/test_maximum.rb
|
70
|
+
- test/validator/test_min_items.rb
|
71
|
+
- test/validator/test_min_length.rb
|
72
|
+
- test/validator/test_min_properties.rb
|
73
|
+
- test/validator/test_minimum.rb
|
74
|
+
- test/validator/test_multiple_of.rb
|
75
|
+
- test/validator/test_not.rb
|
76
|
+
- test/validator/test_one_of.rb
|
77
|
+
- test/validator/test_pattern.rb
|
78
|
+
- test/validator/test_properties.rb
|
79
|
+
- test/validator/test_required.rb
|
80
|
+
- test/validator/test_simple_validator.rb
|
81
|
+
- test/validator/test_type.rb
|
82
|
+
- test/validator/test_unique_items.rb
|
83
|
+
- test/validator/validation_against_schemas_tests.rb
|
84
|
+
homepage: http://github.com/Soylent/jschema
|
85
|
+
licenses:
|
86
|
+
- MIT
|
87
|
+
metadata: {}
|
88
|
+
post_install_message:
|
89
|
+
rdoc_options: []
|
90
|
+
require_paths:
|
91
|
+
- lib
|
92
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ">="
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: 1.9.3
|
97
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
98
|
+
requirements:
|
99
|
+
- - ">="
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
requirements: []
|
103
|
+
rubyforge_project:
|
104
|
+
rubygems_version: 2.2.0
|
105
|
+
signing_key:
|
106
|
+
specification_version: 4
|
107
|
+
summary: JSON Schema implementation
|
108
|
+
test_files:
|
109
|
+
- test/assert_received.rb
|
110
|
+
- test/string_length_validator_tests.rb
|
111
|
+
- test/test_assert_received.rb
|
112
|
+
- test/test_integration.rb
|
113
|
+
- test/test_json_reference.rb
|
114
|
+
- test/test_schema.rb
|
115
|
+
- test/test_schema_ref.rb
|
116
|
+
- test/test_validator.rb
|
117
|
+
- test/validator/argument_is_array_of_schemas_tests.rb
|
118
|
+
- test/validator/assertions.rb
|
119
|
+
- test/validator/properties_limit_tests.rb
|
120
|
+
- test/validator/schema_validation_helpers.rb
|
121
|
+
- test/validator/test_all_of.rb
|
122
|
+
- test/validator/test_any_of.rb
|
123
|
+
- test/validator/test_dependencies.rb
|
124
|
+
- test/validator/test_enum.rb
|
125
|
+
- test/validator/test_format.rb
|
126
|
+
- test/validator/test_items.rb
|
127
|
+
- test/validator/test_max_items.rb
|
128
|
+
- test/validator/test_max_length.rb
|
129
|
+
- test/validator/test_max_properties.rb
|
130
|
+
- test/validator/test_maximum.rb
|
131
|
+
- test/validator/test_min_items.rb
|
132
|
+
- test/validator/test_min_length.rb
|
133
|
+
- test/validator/test_min_properties.rb
|
134
|
+
- test/validator/test_minimum.rb
|
135
|
+
- test/validator/test_multiple_of.rb
|
136
|
+
- test/validator/test_not.rb
|
137
|
+
- test/validator/test_one_of.rb
|
138
|
+
- test/validator/test_pattern.rb
|
139
|
+
- test/validator/test_properties.rb
|
140
|
+
- test/validator/test_required.rb
|
141
|
+
- test/validator/test_simple_validator.rb
|
142
|
+
- test/validator/test_type.rb
|
143
|
+
- test/validator/test_unique_items.rb
|
144
|
+
- test/validator/validation_against_schemas_tests.rb
|