@@ -19,6 +19,7 @@ import (
19
19
"regexp"
20
20
"testing"
21
21
22
+ "github.com/arduino/arduino-lint/internal/project/general"
22
23
"github.com/arduino/arduino-lint/internal/rule/schema/testdata"
23
24
"github.com/arduino/go-properties-orderedmap"
24
25
"github.com/ory/jsonschema/v3"
@@ -46,23 +47,6 @@ func init() {
46
47
)
47
48
}
48
49
49
- // propertiesToMap converts properties.Map data structures to map[string]interface.
50
- func propertiesToMap (propertiesInput * properties.Map ) map [string ]interface {} {
51
- mapOutput := make (map [string ]interface {})
52
- keys := propertiesInput .FirstLevelKeys ()
53
- for _ , key := range keys {
54
- subTree := propertiesInput .SubTree (key )
55
- if subTree .Size () > 0 {
56
- // This key contains a map, recurse it.
57
- mapOutput [key ] = propertiesToMap (subTree )
58
- } else {
59
- // This key contains a string, no more recursion is possible.
60
- mapOutput [key ] = propertiesInput .Get (key )
61
- }
62
- }
63
- return mapOutput
64
- }
65
-
66
50
func TestCompile (t * testing.T ) {
67
51
require .Panics (t , func () {
68
52
Compile ("valid-schema-with-references.json" , []string {"nonexistent.json" }, testdata .Asset )
@@ -99,87 +83,87 @@ func TestCompile(t *testing.T) {
99
83
func TestValidate (t * testing.T ) {
100
84
schemaObject := Compile ("valid-schema.json" , []string {}, testdata .Asset )
101
85
propertiesMap := properties .NewFromHashmap (validMap )
102
- validationResult := Validate (propertiesToMap (propertiesMap ), schemaObject )
86
+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), schemaObject )
103
87
require .Nil (t , validationResult .Result )
104
88
105
- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
89
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
106
90
require .Nil (t , validationResult .Result )
107
91
108
92
propertiesMap .Set ("property1" , "a" )
109
- validationResult = Validate (propertiesToMap (propertiesMap ), schemaObject )
93
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), schemaObject )
110
94
require .Equal (t , "#/property1" , validationResult .Result .InstancePtr )
111
95
require .Equal (t , "#/properties/property1/minLength" , validationResult .Result .SchemaPtr )
112
96
}
113
97
114
98
func TestRequiredPropertyMissing (t * testing.T ) {
115
99
propertiesMap := properties .NewFromHashmap (validMap )
116
- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
100
+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
117
101
require .False (t , RequiredPropertyMissing ("property1" , validationResult ))
118
102
119
103
propertiesMap .Remove ("property1" )
120
- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
104
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
121
105
require .True (t , RequiredPropertyMissing ("property1" , validationResult ))
122
106
}
123
107
124
108
func TestPropertyPatternMismatch (t * testing.T ) {
125
109
propertiesMap := properties .NewFromHashmap (validMap )
126
- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
110
+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
127
111
require .False (t , PropertyPatternMismatch ("property2" , validationResult ))
128
112
129
113
propertiesMap .Set ("property2" , "fOo" )
130
- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
114
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
131
115
require .True (t , PropertyPatternMismatch ("property2" , validationResult ))
132
116
133
117
require .False (t , PropertyPatternMismatch ("property1" , validationResult ))
134
118
}
135
119
136
120
func TestPropertyLessThanMinLength (t * testing.T ) {
137
121
propertiesMap := properties .NewFromHashmap (validMap )
138
- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
122
+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
139
123
require .False (t , PropertyLessThanMinLength ("property1" , validationResult ))
140
124
141
125
propertiesMap .Set ("property1" , "a" )
142
- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
126
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
143
127
require .True (t , PropertyLessThanMinLength ("property1" , validationResult ))
144
128
}
145
129
146
130
func TestPropertyGreaterThanMaxLength (t * testing.T ) {
147
131
propertiesMap := properties .NewFromHashmap (validMap )
148
- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
132
+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
149
133
require .False (t , PropertyGreaterThanMaxLength ("property1" , validationResult ))
150
134
151
135
propertiesMap .Set ("property1" , "12345" )
152
- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
136
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
153
137
require .True (t , PropertyGreaterThanMaxLength ("property1" , validationResult ))
154
138
}
155
139
156
140
func TestPropertyEnumMismatch (t * testing.T ) {
157
141
propertiesMap := properties .NewFromHashmap (validMap )
158
- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
142
+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
159
143
require .False (t , PropertyEnumMismatch ("property3" , validationResult ))
160
144
161
145
propertiesMap .Set ("property3" , "invalid" )
162
- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
146
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
163
147
require .True (t , PropertyEnumMismatch ("property3" , validationResult ))
164
148
}
165
149
166
150
func TestMisspelledOptionalPropertyFound (t * testing.T ) {
167
151
propertiesMap := properties .NewFromHashmap (validMap )
168
- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
152
+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
169
153
require .False (t , MisspelledOptionalPropertyFound (validationResult ))
170
154
171
155
propertiesMap .Set ("porperties" , "foo" )
172
- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
156
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
173
157
require .True (t , MisspelledOptionalPropertyFound (validationResult ))
174
158
}
175
159
176
160
func TestValidationErrorMatch (t * testing.T ) {
177
161
propertiesMap := properties .NewFromHashmap (validMap )
178
- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
162
+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
179
163
require .False (t , ValidationErrorMatch ("" , "" , "" , "" , validationResult ))
180
164
181
165
propertiesMap .Set ("property2" , "fOo" )
182
- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
166
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
183
167
require .False (t , ValidationErrorMatch ("nomatch" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
184
168
require .False (t , ValidationErrorMatch ("^#/property2$" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
185
169
require .False (t , ValidationErrorMatch ("^#/property2$" , "/pattern$" , "nomatch" , "nomatch" , validationResult ))
@@ -188,12 +172,12 @@ func TestValidationErrorMatch(t *testing.T) {
188
172
require .True (t , ValidationErrorMatch ("" , "" , "" , "" , validationResult ))
189
173
190
174
propertiesMap .Set ("property3" , "bAz" )
191
- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
175
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
192
176
require .True (t , ValidationErrorMatch ("^#/property3$" , "/pattern$" , "" , "" , validationResult ), "Match pointer below logic inversion keyword" )
193
177
194
178
propertiesMap = properties .NewFromHashmap (validMap )
195
179
propertiesMap .Remove ("property1" )
196
- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
180
+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
197
181
require .False (t , ValidationErrorMatch ("nomatch" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
198
182
require .True (t , ValidationErrorMatch ("" , "" , "" , "^#/property1$" , validationResult ))
199
183
}
0 commit comments