@@ -19,6 +19,7 @@ import (
1919 "regexp"
2020 "testing"
2121
22+ "github.com/arduino/arduino-lint/internal/project/general"
2223 "github.com/arduino/arduino-lint/internal/rule/schema/testdata"
2324 "github.com/arduino/go-properties-orderedmap"
2425 "github.com/ory/jsonschema/v3"
@@ -46,23 +47,6 @@ func init() {
4647 )
4748}
4849
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-
6650func TestCompile (t * testing.T ) {
6751 require .Panics (t , func () {
6852 Compile ("valid-schema-with-references.json" , []string {"nonexistent.json" }, testdata .Asset )
@@ -99,87 +83,87 @@ func TestCompile(t *testing.T) {
9983func TestValidate (t * testing.T ) {
10084 schemaObject := Compile ("valid-schema.json" , []string {}, testdata .Asset )
10185 propertiesMap := properties .NewFromHashmap (validMap )
102- validationResult := Validate (propertiesToMap (propertiesMap ), schemaObject )
86+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), schemaObject )
10387 require .Nil (t , validationResult .Result )
10488
105- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
89+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
10690 require .Nil (t , validationResult .Result )
10791
10892 propertiesMap .Set ("property1" , "a" )
109- validationResult = Validate (propertiesToMap (propertiesMap ), schemaObject )
93+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), schemaObject )
11094 require .Equal (t , "#/property1" , validationResult .Result .InstancePtr )
11195 require .Equal (t , "#/properties/property1/minLength" , validationResult .Result .SchemaPtr )
11296}
11397
11498func TestRequiredPropertyMissing (t * testing.T ) {
11599 propertiesMap := properties .NewFromHashmap (validMap )
116- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
100+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
117101 require .False (t , RequiredPropertyMissing ("property1" , validationResult ))
118102
119103 propertiesMap .Remove ("property1" )
120- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
104+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
121105 require .True (t , RequiredPropertyMissing ("property1" , validationResult ))
122106}
123107
124108func TestPropertyPatternMismatch (t * testing.T ) {
125109 propertiesMap := properties .NewFromHashmap (validMap )
126- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
110+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
127111 require .False (t , PropertyPatternMismatch ("property2" , validationResult ))
128112
129113 propertiesMap .Set ("property2" , "fOo" )
130- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
114+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
131115 require .True (t , PropertyPatternMismatch ("property2" , validationResult ))
132116
133117 require .False (t , PropertyPatternMismatch ("property1" , validationResult ))
134118}
135119
136120func TestPropertyLessThanMinLength (t * testing.T ) {
137121 propertiesMap := properties .NewFromHashmap (validMap )
138- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
122+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
139123 require .False (t , PropertyLessThanMinLength ("property1" , validationResult ))
140124
141125 propertiesMap .Set ("property1" , "a" )
142- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
126+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
143127 require .True (t , PropertyLessThanMinLength ("property1" , validationResult ))
144128}
145129
146130func TestPropertyGreaterThanMaxLength (t * testing.T ) {
147131 propertiesMap := properties .NewFromHashmap (validMap )
148- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
132+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
149133 require .False (t , PropertyGreaterThanMaxLength ("property1" , validationResult ))
150134
151135 propertiesMap .Set ("property1" , "12345" )
152- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
136+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
153137 require .True (t , PropertyGreaterThanMaxLength ("property1" , validationResult ))
154138}
155139
156140func TestPropertyEnumMismatch (t * testing.T ) {
157141 propertiesMap := properties .NewFromHashmap (validMap )
158- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
142+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
159143 require .False (t , PropertyEnumMismatch ("property3" , validationResult ))
160144
161145 propertiesMap .Set ("property3" , "invalid" )
162- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
146+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
163147 require .True (t , PropertyEnumMismatch ("property3" , validationResult ))
164148}
165149
166150func TestMisspelledOptionalPropertyFound (t * testing.T ) {
167151 propertiesMap := properties .NewFromHashmap (validMap )
168- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
152+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
169153 require .False (t , MisspelledOptionalPropertyFound (validationResult ))
170154
171155 propertiesMap .Set ("porperties" , "foo" )
172- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
156+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
173157 require .True (t , MisspelledOptionalPropertyFound (validationResult ))
174158}
175159
176160func TestValidationErrorMatch (t * testing.T ) {
177161 propertiesMap := properties .NewFromHashmap (validMap )
178- validationResult := Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
162+ validationResult := Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
179163 require .False (t , ValidationErrorMatch ("" , "" , "" , "" , validationResult ))
180164
181165 propertiesMap .Set ("property2" , "fOo" )
182- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
166+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
183167 require .False (t , ValidationErrorMatch ("nomatch" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
184168 require .False (t , ValidationErrorMatch ("^#/property2$" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
185169 require .False (t , ValidationErrorMatch ("^#/property2$" , "/pattern$" , "nomatch" , "nomatch" , validationResult ))
@@ -188,12 +172,12 @@ func TestValidationErrorMatch(t *testing.T) {
188172 require .True (t , ValidationErrorMatch ("" , "" , "" , "" , validationResult ))
189173
190174 propertiesMap .Set ("property3" , "bAz" )
191- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
175+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
192176 require .True (t , ValidationErrorMatch ("^#/property3$" , "/pattern$" , "" , "" , validationResult ), "Match pointer below logic inversion keyword" )
193177
194178 propertiesMap = properties .NewFromHashmap (validMap )
195179 propertiesMap .Remove ("property1" )
196- validationResult = Validate (propertiesToMap (propertiesMap ), validSchemaWithReferences )
180+ validationResult = Validate (general . PropertiesToMap (propertiesMap , 0 ), validSchemaWithReferences )
197181 require .False (t , ValidationErrorMatch ("nomatch" , "nomatch" , "nomatch" , "nomatch" , validationResult ))
198182 require .True (t , ValidationErrorMatch ("" , "" , "" , "^#/property1$" , validationResult ))
199183}
0 commit comments