@@ -123,6 +123,76 @@ suite('Error Helpers', function() {
123
123
}
124
124
) ;
125
125
126
+ suite ( 'validateParameters: argument tree' , function ( ) {
127
+ // should not throw a validation error for the same kind of wrong args
128
+ // more than once. This prevents repetetive validation logs for a
129
+ // function that is called in a loop or draw()
130
+ testUnMinified (
131
+ 'no repeated validation error for the same wrong arguments' ,
132
+ function ( ) {
133
+ assert . validationError ( function ( ) {
134
+ myp5 . color ( ) ;
135
+ } ) ;
136
+
137
+ assert . doesNotThrow (
138
+ function ( ) {
139
+ myp5 . color ( ) ; // Same type of wrong arguments as above
140
+ } ,
141
+ p5 . ValidationError ,
142
+ 'got unwanted ValidationError'
143
+ ) ;
144
+ }
145
+ ) ;
146
+
147
+ testUnMinified (
148
+ 'should throw validation errors for different wrong args' ,
149
+ function ( ) {
150
+ assert . validationError ( function ( ) {
151
+ myp5 . color ( ) ;
152
+ } ) ;
153
+
154
+ assert . validationError ( function ( ) {
155
+ myp5 . color ( false ) ;
156
+ } ) ;
157
+ }
158
+ ) ;
159
+
160
+ testUnMinified ( 'arg tree is built properly' , function ( ) {
161
+ let myArgTree = p5 . _getValidateParamsArgTree ( ) ;
162
+ myp5 . random ( ) ;
163
+ myp5 . random ( 50 ) ;
164
+ myp5 . random ( [ 50 , 70 , 10 ] ) ;
165
+ assert . strictEqual (
166
+ myArgTree . random . seen ,
167
+ true ,
168
+ 'tree built correctly for random()'
169
+ ) ;
170
+ assert . strictEqual (
171
+ myArgTree . random . number . seen ,
172
+ true ,
173
+ 'tree built correctly for random(min: Number)'
174
+ ) ;
175
+ assert . strictEqual (
176
+ myArgTree . random . as . number . number . number . seen ,
177
+ true ,
178
+ 'tree built correctly for random(choices: Array)'
179
+ ) ;
180
+
181
+ let c = myp5 . color ( 10 ) ;
182
+ myp5 . alpha ( c ) ;
183
+ assert . strictEqual (
184
+ myArgTree . color . number . seen ,
185
+ true ,
186
+ 'tree built correctly for color(gray: Number)'
187
+ ) ;
188
+ assert . strictEqual (
189
+ myArgTree . alpha . Color . seen ,
190
+ true ,
191
+ 'tree built correctly for alpha(color: p5.Color)'
192
+ ) ;
193
+ } ) ;
194
+ } ) ;
195
+
126
196
suite ( 'validateParameters: multi-format' , function ( ) {
127
197
test ( 'color(): no friendly-err-msg' , function ( ) {
128
198
assert . doesNotThrow (
0 commit comments