11import { describe , expect , it } from 'bun:test'
22import z from 'zod/v4'
33
4- import { coerceToArray } from '../utils'
4+ import { coerceToArray , normalizeReplacementAliases } from '../utils'
55
66describe ( 'coerceToArray' , ( ) => {
77 it ( 'passes through arrays unchanged' , ( ) => {
88 expect ( coerceToArray ( [ 'a' , 'b' ] ) ) . toEqual ( [ 'a' , 'b' ] )
9- expect ( coerceToArray ( [ { old : 'x' , new : 'y' } ] ) ) . toEqual ( [ { old : 'x' , new : 'y' } ] )
9+ expect ( coerceToArray ( [ { old : 'x' , new : 'y' } ] ) ) . toEqual ( [
10+ { old : 'x' , new : 'y' } ,
11+ ] )
1012 expect ( coerceToArray ( [ ] ) ) . toEqual ( [ ] )
1113 } )
1214
@@ -15,15 +17,20 @@ describe('coerceToArray', () => {
1517 } )
1618
1719 it ( 'wraps a single object in an array' , ( ) => {
18- expect ( coerceToArray ( { old : 'x' , new : 'y' } ) ) . toEqual ( [ { old : 'x' , new : 'y' } ] )
20+ expect ( coerceToArray ( { old : 'x' , new : 'y' } ) ) . toEqual ( [
21+ { old : 'x' , new : 'y' } ,
22+ ] )
1923 } )
2024
2125 it ( 'wraps a single number in an array' , ( ) => {
2226 expect ( coerceToArray ( 42 ) ) . toEqual ( [ 42 ] )
2327 } )
2428
2529 it ( 'parses a stringified JSON array' , ( ) => {
26- expect ( coerceToArray ( '["file1.ts", "file2.ts"]' ) ) . toEqual ( [ 'file1.ts' , 'file2.ts' ] )
30+ expect ( coerceToArray ( '["file1.ts", "file2.ts"]' ) ) . toEqual ( [
31+ 'file1.ts' ,
32+ 'file2.ts' ,
33+ ] )
2734 } )
2835
2936 it ( 'wraps a non-JSON string (does not parse as array)' , ( ) => {
@@ -116,3 +123,51 @@ describe('coerceToArray with Zod schemas', () => {
116123 expect ( coercedSchema ) . toEqual ( plainSchema )
117124 } )
118125} )
126+
127+ describe ( 'normalizeReplacementAliases' , ( ) => {
128+ it ( 'maps old_str and new_str onto the documented replacement keys' , ( ) => {
129+ expect (
130+ normalizeReplacementAliases ( {
131+ old_str : 'before' ,
132+ new_str : 'after' ,
133+ allowMultiple : true ,
134+ } ) ,
135+ ) . toEqual ( {
136+ old_str : 'before' ,
137+ new_str : 'after' ,
138+ old : 'before' ,
139+ new : 'after' ,
140+ allowMultiple : true ,
141+ } )
142+ } )
143+
144+ it ( 'maps old_string and new_string onto the documented replacement keys' , ( ) => {
145+ expect (
146+ normalizeReplacementAliases ( {
147+ old_string : 'before' ,
148+ new_string : 'after' ,
149+ } ) ,
150+ ) . toEqual ( {
151+ old_string : 'before' ,
152+ new_string : 'after' ,
153+ old : 'before' ,
154+ new : 'after' ,
155+ } )
156+ } )
157+
158+ it ( 'does not overwrite documented replacement keys' , ( ) => {
159+ expect (
160+ normalizeReplacementAliases ( {
161+ old : 'before' ,
162+ new : 'after' ,
163+ old_str : 'ignored' ,
164+ new_str : 'ignored' ,
165+ } ) ,
166+ ) . toEqual ( {
167+ old : 'before' ,
168+ new : 'after' ,
169+ old_str : 'ignored' ,
170+ new_str : 'ignored' ,
171+ } )
172+ } )
173+ } )
0 commit comments