@@ -64,11 +64,18 @@ genTests = (type) ->
6464 c_s = type .apply leftHas, right_
6565 assert .deepEqual s_c, c_s
6666
67- it ' throws when adding a string to a number' , ->
68- assert .throws -> type .apply 1 , [{p : [], na : ' a' }]
67+ describe ' strict' , ->
68+ beforeEach ->
69+ type .options .strict = true
6970
70- it ' throws when adding a number to a string' , ->
71- assert .throws -> type .apply ' a' , [{p : [], na : 1 }]
71+ afterEach ->
72+ type .options .strict = false
73+
74+ it ' throws when adding a string to a number' , ->
75+ assert .throws -> type .apply 1 , [{p : [], na : ' a' }]
76+
77+ it ' throws when adding a number to a string' , ->
78+ assert .throws -> type .apply ' a' , [{p : [], na : 1 }]
7279
7380 # Strings should be handled internally by the text type. We'll just do some basic sanity checks here.
7481 describe ' string' , ->
@@ -138,23 +145,30 @@ genTests = (type) ->
138145 assert .deepEqual [' a' , ' b' , ' c' ], type .apply [' b' , ' a' , ' c' ], [{p : [1 ], lm : 0 }]
139146 assert .deepEqual [' a' , ' b' , ' c' ], type .apply [' b' , ' a' , ' c' ], [{p : [0 ], lm : 1 }]
140147
141- it ' throws when keying a list replacement with a string' , ->
142- assert .throws -> type .apply [' a' , ' b' , ' c' ], [{p : [' 0' ], li : ' x' , ld : ' a' }]
148+ describe ' strict' , ->
149+ beforeEach ->
150+ type .options .strict = true
151+
152+ afterEach ->
153+ type .options .strict = false
143154
144- it ' throws when keying a list insertion with a string' , ->
145- assert .throws -> type .apply [' a' , ' b' , ' c' ], [{p : [' 0' ], li : ' x' }]
155+ it ' throws when keying a list replacement with a string' , ->
156+ assert .throws -> type .apply [' a' , ' b' , ' c' ], [{p : [' 0' ], li : ' x' , ld : ' a ' }]
146157
147- it ' throws when keying a list deletion with a string' , ->
148- assert .throws -> type .apply [' a' , ' b' , ' c' ], [{p : [' 0' ], ld : ' a ' }]
158+ it ' throws when keying a list insertion with a string' , ->
159+ assert .throws -> type .apply [' a' , ' b' , ' c' ], [{p : [' 0' ], li : ' x ' }]
149160
150- it ' throws when keying a list move with a string' , ->
151- assert .throws -> type .apply [' a' , ' b' , ' c' ], [{p : [' 0' ], lm : 0 }]
161+ it ' throws when keying a list deletion with a string' , ->
162+ assert .throws -> type .apply [' a' , ' b' , ' c' ], [{p : [' 0' ], ld : ' a ' }]
152163
153- it ' throws when specifying a string as a list move target ' , ->
154- assert .throws -> type .apply [' a' , ' b' , ' c' ], [{p : [1 ], lm : ' 0 ' }]
164+ it ' throws when keying a list move with a string ' , ->
165+ assert .throws -> type .apply [' a' , ' b' , ' c' ], [{p : [' 0 ' ], lm : 0 }]
155166
156- it ' throws when an array index part-way through the path is a string' , ->
157- assert .throws -> type .apply {arr : [{x : ' a' }]}, [{p : [' arr' , ' 0' , ' x' ], od : ' a' }]
167+ it ' throws when specifying a string as a list move target' , ->
168+ assert .throws -> type .apply [' a' , ' b' , ' c' ], [{p : [1 ], lm : ' 0' }]
169+
170+ it ' throws when an array index part-way through the path is a string' , ->
171+ assert .throws -> type .apply {arr : [{x : ' a' }]}, [{p : [' arr' , ' 0' , ' x' ], od : ' a' }]
158172
159173 ###
160174 'null moves compose to nops', ->
@@ -418,14 +432,21 @@ genTests = (type) ->
418432 assert .deepEqual [], type .transform [{p : [' k' ], od : ' x' }], [{p : [' k' ], od : ' x' }], ' left'
419433 assert .deepEqual [], type .transform [{p : [' k' ], od : ' x' }], [{p : [' k' ], od : ' x' }], ' right'
420434
421- it ' throws when the insertion key is a number' , ->
422- assert .throws -> type .apply {' 1' : ' a' }, [{p : [2 ], oi : ' a' }]
435+ describe ' strict' , ->
436+ beforeEach ->
437+ type .options .strict = true
438+
439+ afterEach ->
440+ type .options .strict = false
441+
442+ it ' throws when the insertion key is a number' , ->
443+ assert .throws -> type .apply {' 1' : ' a' }, [{p : [2 ], oi : ' a' }]
423444
424- it ' throws when the deletion key is a number' , ->
425- assert .throws -> type .apply {' 1' : ' a' }, [{p : [1 ], od : ' a' }]
445+ it ' throws when the deletion key is a number' , ->
446+ assert .throws -> type .apply {' 1' : ' a' }, [{p : [1 ], od : ' a' }]
426447
427- it ' throws when an object key part-way through the path is a number' , ->
428- assert .throws -> type .apply {' 1' : {x : ' a' }}, [{p : [1 , ' x' ], od : ' a' }]
448+ it ' throws when an object key part-way through the path is a number' , ->
449+ assert .throws -> type .apply {' 1' : {x : ' a' }}, [{p : [1 , ' x' ], od : ' a' }]
429450
430451 describe ' randomizer' , ->
431452 @ timeout 20000
0 commit comments