1- /* eslint-disable import/no-extraneous-dependencies */
2- import test from 'ava' ;
1+ import { test , expect } from 'bun:test' ;
32import replaceString from './' ;
43import reactStringReplace from '.' ;
54
6- test ( "Doesn't throw if not given invalid input" , t => {
7- t . notThrows ( ( ) => replaceString ( ) ) ;
8- t . notThrows ( ( ) => replaceString ( '' ) ) ;
5+ test ( "Doesn't throw if not given invalid input" , ( ) => {
6+ expect ( ( ) => replaceString ( ) ) . not . toThrow ( ) ;
7+ expect ( ( ) => replaceString ( '' ) ) . not . toThrow ( ) ;
98} ) ;
109
11- test ( 'Returns an array' , t => {
12- t . true ( Array . isArray ( replaceString ( 'blah' , 'blah' , x => x ) ) ) ;
10+ test ( 'Returns an array' , ( ) => {
11+ expect ( Array . isArray ( replaceString ( 'blah' , 'blah' , x => x ) ) ) . toBe ( true ) ;
1312} ) ;
1413
15- test ( 'Returns correct character offsets' , t => {
14+ test ( 'Returns correct character offsets' , ( ) => {
1615 const correctOffsets = [ 6 , 17 ] ;
1716 const charOffsets = [ ] ;
1817
1918 replaceString ( 'Hey there, stranger' , 'er' , ( m , i , o ) => charOffsets . push ( o ) ) ;
20- t . deepEqual ( charOffsets , correctOffsets ) ;
19+ expect ( charOffsets ) . toEqual ( correctOffsets ) ;
2120} ) ;
2221
23- test ( 'Works with matching groups' , t => {
24- t . deepEqual (
25- replaceString ( 'hey there' , / ( h e y ) / g, x => ( { worked : x } ) ) ,
26- [ '' , { worked : 'hey' } , ' there' ]
27- ) ;
22+ test ( 'Works with matching groups' , ( ) => {
23+ expect (
24+ replaceString ( 'hey there' , / ( h e y ) / g, x => ( { worked : x } ) )
25+ ) . toEqual ( [ '' , { worked : 'hey' } , ' there' ] ) ;
2826} ) ;
2927
30- test ( 'Respects global flag to replace multiple matches' , t => {
28+ test ( 'Respects global flag to replace multiple matches' , ( ) => {
3129 const str = 'Hey @ian_sinn and @other_handle, check out this link https://github.com/iansinnott/' ;
32- t . deepEqual (
33- replaceString ( str , / @ ( \w + ) / g, x => ( { worked : x } ) ) ,
34- [ 'Hey ' , { worked : 'ian_sinn' } , ' and ' , { worked : 'other_handle' } , ', check out this link https://github.com/iansinnott/' ]
35- ) ;
30+ expect (
31+ replaceString ( str , / @ ( \w + ) / g, x => ( { worked : x } ) )
32+ ) . toEqual ( [ 'Hey ' , { worked : 'ian_sinn' } , ' and ' , { worked : 'other_handle' } , ', check out this link https://github.com/iansinnott/' ] ) ;
3633} ) ;
3734
38- test ( 'Works with strings' , t => {
39- t . deepEqual (
40- replaceString ( 'hey there' , 'hey' , x => ( { worked : x } ) ) ,
41- [ '' , { worked : 'hey' } , ' there' ]
42- ) ;
35+ test ( 'Works with strings' , ( ) => {
36+ expect (
37+ replaceString ( 'hey there' , 'hey' , x => ( { worked : x } ) )
38+ ) . toEqual ( [ '' , { worked : 'hey' } , ' there' ] ) ;
4339} ) ;
4440
45- test ( 'Works with arrays' , t => {
41+ test ( 'Works with arrays' , ( ) => {
4642 const input = [ 'hey there' , { value : 'you' } , 'again' ] ;
47- t . deepEqual (
48- replaceString ( input , 'hey' , x => ( { worked : x } ) ) ,
49- [ '' , { worked : 'hey' } , ' there' , { value : 'you' } , 'again' ]
50- ) ;
43+ expect (
44+ replaceString ( input , 'hey' , x => ( { worked : x } ) )
45+ ) . toEqual ( [ '' , { worked : 'hey' } , ' there' , { value : 'you' } , 'again' ] ) ;
5146} ) ;
5247
53- test ( 'Successfully escapes parens in strings' , t => {
54- t . deepEqual (
55- replaceString ( '(hey) there' , '(hey)' , x => ( { worked : x } ) ) ,
56- [ '' , { worked : '(hey)' } , ' there' ]
57- ) ;
48+ test ( 'Successfully escapes parens in strings' , ( ) => {
49+ expect (
50+ replaceString ( '(hey) there' , '(hey)' , x => ( { worked : x } ) )
51+ ) . toEqual ( [ '' , { worked : '(hey)' } , ' there' ] ) ;
5852
59- t . deepEqual (
60- replaceString ( 'hey ((y)(you)) there' , '((y)(you))' , x => ( { worked : x } ) ) ,
61- [ 'hey ' , { worked : '((y)(you))' } , ' there' ]
62- ) ;
53+ expect (
54+ replaceString ( 'hey ((y)(you)) there' , '((y)(you))' , x => ( { worked : x } ) )
55+ ) . toEqual ( [ 'hey ' , { worked : '((y)(you))' } , ' there' ] ) ;
6356} ) ;
6457
65- test ( 'Can be called consecutively on returned result of previous call' , t => {
58+ test ( 'Can be called consecutively on returned result of previous call' , ( ) => {
6659 const originalTweet = 'Hey @iansinnott, check out this link https://github.com/iansinnott/ Hope to see you at #reactconf' ;
6760 let reactReplacedTweet ;
6861
@@ -71,7 +64,7 @@ test('Can be called consecutively on returned result of previous call', t => {
7164 { type : 'url' , value : match }
7265 ) ) ;
7366
74- t . deepEqual ( reactReplacedTweet , [
67+ expect ( reactReplacedTweet ) . toEqual ( [
7568 'Hey @iansinnott, check out this link ' ,
7669 { type : 'url' , value : 'https://github.com/iansinnott/' } ,
7770 ' Hope to see you at #reactconf' ,
@@ -82,7 +75,7 @@ test('Can be called consecutively on returned result of previous call', t => {
8275 { type : 'mention' , value : match }
8376 ) ) ;
8477
85- t . deepEqual ( reactReplacedTweet , [
78+ expect ( reactReplacedTweet ) . toEqual ( [
8679 'Hey ' ,
8780 { type : 'mention' , value : '@iansinnott' } ,
8881 ', check out this link ' ,
@@ -95,7 +88,7 @@ test('Can be called consecutively on returned result of previous call', t => {
9588 { type : 'hashtag' , value : match }
9689 ) ) ;
9790
98- t . deepEqual ( reactReplacedTweet , [
91+ expect ( reactReplacedTweet ) . toEqual ( [
9992 'Hey ' ,
10093 { type : 'mention' , value : '@iansinnott' } ,
10194 ', check out this link ' ,
@@ -112,15 +105,15 @@ test('Can be called consecutively on returned result of previous call', t => {
112105 * ''. This was causing an error where I was checking for !str, even though an
113106 * empty string should actually be allwed.
114107 */
115- test ( 'Allows empty strings within results' , t => {
108+ test ( 'Allows empty strings within results' , ( ) => {
116109 let replacedContent ;
117110 const string = '@username http://a_photo.jpg' ;
118111
119112 replacedContent = replaceString ( string , / ( h t t p ? : \/ \/ .* \. (?: p n g | j p g ) ) / g, match => {
120113 return { key : 'image' , match } ;
121114 } ) ;
122115
123- t . deepEqual ( replacedContent , [
116+ expect ( replacedContent ) . toEqual ( [
124117 '@username ' ,
125118 { key : 'image' , match : 'http://a_photo.jpg' } ,
126119 '' ,
@@ -130,7 +123,7 @@ test('Allows empty strings within results', t => {
130123 return { key : 'text' , match } ;
131124 } ) ;
132125
133- t . deepEqual ( replacedContent , [
126+ expect ( replacedContent ) . toEqual ( [
134127 '' ,
135128 { key : 'text' , match : 'username' } ,
136129 ' ' ,
@@ -139,60 +132,60 @@ test('Allows empty strings within results', t => {
139132 ] ) ;
140133} ) ;
141134
142- test ( 'Will not through if first element of input is empty string' , t => {
135+ test ( 'Will not throw if first element of input is empty string' , ( ) => {
143136 const string = 'http://a_photo.jpg some string' ;
144137 const replacedContent = replaceString ( string , / ( h t t p ? : \/ \/ .* \. (?: p n g | j p g ) ) / g, match => {
145138 return { key : 'image' , match } ;
146139 } ) ;
147140
148- t . deepEqual ( replacedContent , [
141+ expect ( replacedContent ) . toEqual ( [
149142 '' ,
150143 { key : 'image' , match : 'http://a_photo.jpg' } ,
151144 ' some string' ,
152145 ] ) ;
153146
154147 // This replacement would not actually give a new result from above, but it is
155148 // simply to test that passing in an empty string as the first arg is OK
156- t . notThrows ( ( ) => {
149+ expect ( ( ) => {
157150 replaceString ( replacedContent , / @ ( \w + ) / g, match => {
158151 return { key : 'text' , match } ;
159152 } ) ;
160- } ) ;
153+ } ) . not . toThrow ( ) ;
161154} ) ;
162155
163- test ( "Avoids undefined values due to regex" , ( t ) => {
156+ test ( "Avoids undefined values due to regex" , ( ) => {
164157 const string = `hey you there` ;
165158 const re = / ( h e y ) | ( y o u ) / ;
166159
167160 // Normal splits include undefined if you do this
168- t . deepEqual ( string . split ( re ) , [ "" , "hey" , undefined , " " , undefined , "you" , " there" ] ) ;
161+ expect ( string . split ( re ) ) . toEqual ( [ "" , "hey" , undefined , " " , undefined , "you" , " there" ] ) ;
169162
170- t . notThrows ( ( ) => {
163+ expect ( ( ) => {
171164 replaceString ( string , / ( h e y ) | ( y o u ) / , x => x ) ;
172- } ) ;
165+ } ) . not . toThrow ( ) ;
173166} ) ;
174167
175- test ( "Fixed number of string replacements" , ( t ) => {
168+ test ( "Fixed number of string replacements" , ( ) => {
176169 const string = `Test hey test hey test` ;
177170 const replacedContent = reactStringReplace ( string , 'hey' , match => {
178171 return 'lo' ;
179- } , 1 ) ;
180- t . deepEqual ( replacedContent , [
172+ } , 1 ) ;
173+ expect ( replacedContent ) . toEqual ( [
181174 'Test ' ,
182175 'lo' ,
183176 ' test ' ,
184177 'hey' ,
185178 ' test'
186- ] )
179+ ] ) ;
187180} ) ;
188181
189- test ( "Indexes start at 0 and are contiguous" , t => {
182+ test ( "Indexes start at 0 and are contiguous" , ( ) => {
190183 const string = 'Hello there general Kenobi' ;
191184 const re = / ( \w + ) / ;
192185
193186 let expectedIndex = 0 ;
194187 replaceString ( string , re , ( match , index ) => {
195- t . deepEqual ( expectedIndex , index ) ;
188+ expect ( index ) . toEqual ( expectedIndex ) ;
196189 expectedIndex ++ ;
197190 } ) ;
198- } ) ;
191+ } ) ;
0 commit comments