Skip to content

Commit 044d056

Browse files
committed
Add an extra test for hashtag matches in the replaceFn
1 parent bed730b commit 044d056

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

src/matchParser/MatchParser.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,7 @@ Autolinker.matchParser.MatchParser = Autolinker.Util.extend( Object, {
108108
matcherRegex : (function() {
109109
var twitterRegex = /(^|[^\w])@(\w{1,15})/, // For matching a twitter handle. Ex: @gregory_jacobs
110110

111-
hashtagRegex = /(^|[^\w])#(\w{1,139})/, // For matching a Hashtag. Ex: #games
111+
hashtagRegex = /(^|[^\w])#(\w{1,139})/, // For matching a Hashtag. Ex: #games
112112

113113
emailRegex = /(?:[\-;:&=\+\$,\w\.]+@)/, // something@ for email addresses (a.k.a. local-part)
114114
phoneRegex = /(?:(\+)?\d{1,3}[-\040.])?\(?\d{3}\)?[-\040.]?\d{3}[-\040.]\d{4}/, // ex: (123) 456-7890, 123 456 7890, 123-456-7890, etc.

tests/AutolinkerSpec.js

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1645,6 +1645,23 @@ describe( "Autolinker", function() {
16451645
} );
16461646

16471647

1648+
it( "should populate a HashtagMatch object with the appropriate properties", function() {
1649+
var replaceFnCallCount = 0;
1650+
var result = Autolinker.link( "Hashtag: #myHashtag ", { // purposeful trailing space
1651+
hashtag: 'twitter',
1652+
replaceFn : function( autolinker, match ) {
1653+
replaceFnCallCount++;
1654+
1655+
expect( match.getType() ).toBe( 'hashtag' );
1656+
expect( match.getMatchedText() ).toBe( '#myHashtag' );
1657+
expect( match.getHashtag() ).toBe( 'myHashtag' );
1658+
}
1659+
} );
1660+
1661+
expect( replaceFnCallCount ).toBe( 1 ); // make sure the replaceFn was called
1662+
} );
1663+
1664+
16481665
it( "should populate a TwitterMatch object with the appropriate properties", function() {
16491666
var replaceFnCallCount = 0;
16501667
var result = Autolinker.link( "Twitter: @myTwitter ", { // purposeful trailing space

0 commit comments

Comments
 (0)