@@ -30,6 +30,8 @@ const DEFAULT_VALUES = {
3030 myProp6 : [ 0.1 , 0.2 , 0.3 , 0.4 , 0.5 ] ,
3131 myProp7 : MY_ENUM . FIRST ,
3232 myProp8 : [ 1 , 2 , 3 ] ,
33+ myProp9 : null ,
34+ // myProp10: null,
3335} ;
3436
3537// ----------------------------------------------------------------------------
@@ -58,6 +60,12 @@ function extend(publicAPI, model, initialValues = {}) {
5860 // setArray macros with default value
5961 macro . setGetArray ( publicAPI , model , [ 'myProp8' ] , 3 , 0 ) ;
6062
63+ // setArray macros with no initial value
64+ macro . setGetArray ( publicAPI , model , [ 'myProp9' ] , 3 ) ;
65+
66+ // setArray macros with no size
67+ macro . setGetArray ( publicAPI , model , [ 'myProp10' ] ) ;
68+
6169 // Object specific methods
6270 myClass ( publicAPI , model ) ;
6371
@@ -180,12 +188,24 @@ test('Macro methods array tests', (t) => {
180188
181189 // Test default values
182190 t . ok ( myTestClass . setMyProp8 ( ) , 'OK to set no argument' ) ;
183- t . ok ( myTestClass . setMyProp8 ( 1 ) , 'OK to set not enough argument' ) ;
184- t . ok ( myTestClass . setMyProp8 ( [ 2 , 3 ] ) , 'OK to set too-short array argument' ) ;
185- t . ok (
186- myTestClass . setMyProp8 ( new Float64Array ( 2 ) ) ,
191+ t . equal (
192+ myTestClass . setMyProp8 ( [ ] ) ,
193+ false ,
194+ 'OK to set same empty array as argument'
195+ ) ;
196+ t . equal (
197+ myTestClass . setMyProp8 ( new Uint8Array ( ) ) ,
198+ false ,
199+ 'OK to set same empty typedarray as argument'
200+ ) ;
201+ t . ok ( myTestClass . setMyProp8 ( 10 ) , 'OK to set not enough argument' ) ;
202+ t . equal (
203+ myTestClass . setMyProp8 ( new Float64Array ( [ 10 ] ) ) ,
204+ false ,
187205 'OK to set too short typed array argument'
188206 ) ;
207+ t . ok ( myTestClass . setMyProp8 ( [ 2 , 3 ] ) , 'OK to set too-short array argument' ) ;
208+
189209 t . throws (
190210 ( ) => myTestClass . setMyProp8 ( 1 , 2 , 3 , 4 ) ,
191211 / R a n g e E r r o r / ,
@@ -202,6 +222,38 @@ test('Macro methods array tests', (t) => {
202222 'Too large array should throw'
203223 ) ;
204224
225+ t . throws (
226+ ( ) => newInstance ( { myProp9 : [ ] } ) ,
227+ / R a n g e E r r o r / ,
228+ 'Empty array should throw'
229+ ) ;
230+
231+ t . equal ( myTestClass . setMyProp9 ( null ) , false ) ;
232+ t . equal ( myTestClass . setMyProp9 ( [ 0 , 1 , 2 ] ) , true ) ;
233+ t . throws (
234+ ( ) => myTestClass . setMyProp9 ( ) ,
235+ / R a n g e E r r o r / ,
236+ 'Empty array should throw'
237+ ) ;
238+ t . throws (
239+ ( ) => myTestClass . setMyProp9 ( [ ] ) ,
240+ / R a n g e E r r o r / ,
241+ 'Empty array should throw'
242+ ) ;
243+
244+ t . ok (
245+ myTestClass . setMyProp10 ( [ 0 , 1 , 2 ] ) ,
246+ 'Test setting array from undefined to unlimited size'
247+ ) ;
248+ t . ok (
249+ myTestClass . setMyProp10 ( [ 0 , 1 , 2 , 3 ] ) ,
250+ 'Test setting larger array for unlimited size array'
251+ ) ;
252+ t . ok (
253+ myTestClass . setMyProp10 ( [ 0 , 1 , 2 ] ) ,
254+ 'Test setting smaller array for unlimited size array'
255+ ) ;
256+
205257 t . end ( ) ;
206258} ) ;
207259
0 commit comments