1
+ // This file is part of arduino-check.
2
+ //
3
+ // Copyright 2020 ARDUINO SA (http://www.arduino.cc/)
4
+ //
5
+ // This software is released under the GNU General Public License version 3,
6
+ // which covers the main part of arduino-check.
7
+ // The terms of this license can be found at:
8
+ // https://www.gnu.org/licenses/gpl-3.0.en.html
9
+ //
10
+ // You can be released from the requirements of the above licenses by purchasing
11
+ // a commercial license. Buying such a license is mandatory if you want to
12
+ // modify or otherwise use the software for commercial activities involving the
13
+ // Arduino software without disclosing the source code of your own applications.
14
+ // To purchase a commercial license, send an email to [email protected] .
15
+
1
16
package schema
2
17
3
18
import (
@@ -17,6 +32,7 @@ var schemasPath *paths.Path
17
32
var validMap = map [string ]string {
18
33
"property1" : "foo" ,
19
34
"property2" : "bar" ,
35
+ "property3" : "baz" ,
20
36
}
21
37
22
38
var validPropertiesMap = properties .NewFromHashmap (validMap )
@@ -107,6 +123,46 @@ func TestPropertyPatternMismatch(t *testing.T) {
107
123
require .False (t , PropertyPatternMismatch ("property1" , validationResult , schemasPath ))
108
124
}
109
125
126
+ func TestPropertyLessThanMinLength (t * testing.T ) {
127
+ propertiesMap := properties .NewFromHashmap (validMap )
128
+ validationResult := Validate (propertiesMap , validSchemaWithReferences , schemasPath )
129
+ require .False (t , PropertyLessThanMinLength ("property1" , validationResult , schemasPath ))
130
+
131
+ propertiesMap .Set ("property1" , "a" )
132
+ validationResult = Validate (propertiesMap , validSchemaWithReferences , schemasPath )
133
+ require .True (t , PropertyLessThanMinLength ("property1" , validationResult , schemasPath ))
134
+ }
135
+
136
+ func TestPropertyGreaterThanMaxLength (t * testing.T ) {
137
+ propertiesMap := properties .NewFromHashmap (validMap )
138
+ validationResult := Validate (propertiesMap , validSchemaWithReferences , schemasPath )
139
+ require .False (t , PropertyGreaterThanMaxLength ("property1" , validationResult , schemasPath ))
140
+
141
+ propertiesMap .Set ("property1" , "12345" )
142
+ validationResult = Validate (propertiesMap , validSchemaWithReferences , schemasPath )
143
+ require .True (t , PropertyGreaterThanMaxLength ("property1" , validationResult , schemasPath ))
144
+ }
145
+
146
+ func TestPropertyEnumMismatch (t * testing.T ) {
147
+ propertiesMap := properties .NewFromHashmap (validMap )
148
+ validationResult := Validate (propertiesMap , validSchemaWithReferences , schemasPath )
149
+ require .False (t , PropertyEnumMismatch ("property3" , validationResult , schemasPath ))
150
+
151
+ propertiesMap .Set ("property3" , "invalid" )
152
+ validationResult = Validate (propertiesMap , validSchemaWithReferences , schemasPath )
153
+ require .True (t , PropertyEnumMismatch ("property3" , validationResult , schemasPath ))
154
+ }
155
+
156
+ func TestMisspelledOptionalPropertyFound (t * testing.T ) {
157
+ propertiesMap := properties .NewFromHashmap (validMap )
158
+ validationResult := Validate (propertiesMap , validSchemaWithReferences , schemasPath )
159
+ require .False (t , MisspelledOptionalPropertyFound (validationResult , schemasPath ))
160
+
161
+ propertiesMap .Set ("porperties" , "foo" )
162
+ validationResult = Validate (propertiesMap , validSchemaWithReferences , schemasPath )
163
+ require .True (t , MisspelledOptionalPropertyFound (validationResult , schemasPath ))
164
+ }
165
+
110
166
func TestValidationErrorMatch (t * testing.T ) {
111
167
propertiesMap := properties .NewFromHashmap (validMap )
112
168
validationResult := Validate (propertiesMap , validSchemaWithReferences , schemasPath )
0 commit comments