@@ -24,6 +24,14 @@ test('Works with strings', t => {
24
24
) ;
25
25
} ) ;
26
26
27
+ test ( 'Works with arrays' , t => {
28
+ const input = [ 'hey there' , { value : 'you' } , 'again' ] ;
29
+ t . same (
30
+ replaceString ( input , 'hey' , x => ( { worked : x } ) ) ,
31
+ [ '' , { worked : 'hey' } , ' there' , { value : 'you' } , 'again' ]
32
+ ) ;
33
+ } ) ;
34
+
27
35
test ( 'Successfully escapes parens in strings' , t => {
28
36
t . same (
29
37
replaceString ( '(hey) there' , '(hey)' , x => ( { worked : x } ) ) ,
@@ -35,3 +43,47 @@ test('Successfully escapes parens in strings', t => {
35
43
[ 'hey ' , { worked : '((y)(you))' } , ' there' ]
36
44
) ;
37
45
} ) ;
46
+
47
+ test ( 'Can be called consecutively on returned result of previous call' , t => {
48
+ const originalTweet = 'Hey @iansinnott, check this link https://github.com/iansinnott/ #github' ;
49
+ let reactReplacedTweet ;
50
+
51
+ // Match URLs
52
+ reactReplacedTweet = replaceString ( originalTweet , / ( h t t p s ? : \/ \/ \S + ) / g, match => (
53
+ { type : 'url' , value : match }
54
+ ) ) ;
55
+
56
+ t . same ( reactReplacedTweet , [
57
+ 'Hey @iansinnott, check this link ' ,
58
+ { type : 'url' , value : 'https://github.com/iansinnott/' } ,
59
+ ' #github' ,
60
+ ] ) ;
61
+
62
+ // Match @-mentions
63
+ reactReplacedTweet = replaceString ( reactReplacedTweet , / ( @ \w + ) / g, match => (
64
+ { type : 'mention' , value : match }
65
+ ) ) ;
66
+
67
+ t . same ( reactReplacedTweet , [
68
+ 'Hey ' ,
69
+ { type : 'mention' , value : '@iansinnott' } ,
70
+ ', check this link ' ,
71
+ { type : 'url' , value : 'https://github.com/iansinnott/' } ,
72
+ ' #github' ,
73
+ ] ) ;
74
+
75
+ // Match hashtags
76
+ reactReplacedTweet = replaceString ( reactReplacedTweet , / ( # \w + ) / g, match => (
77
+ { type : 'hashtag' , value : match }
78
+ ) ) ;
79
+
80
+ t . same ( reactReplacedTweet , [
81
+ 'Hey ' ,
82
+ { type : 'mention' , value : '@iansinnott' } ,
83
+ ', check this link ' ,
84
+ { type : 'url' , value : 'https://github.com/iansinnott/' } ,
85
+ ' ' ,
86
+ { type : 'hashtag' , value : '#github' } ,
87
+ '' ,
88
+ ] ) ;
89
+ } ) ;
0 commit comments