1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120
|
/*global Autolinker, _, describe, beforeEach, afterEach, it, expect, jasmine */
describe( "Autolinker.matcher.Email", function() {
var MatchChecker = Autolinker.match.MatchChecker,
matcher;
beforeEach( function() {
matcher = new Autolinker.matcher.Email( {
tagBuilder : new Autolinker.AnchorTagBuilder()
} );
} );
describe( 'parseMatches()', function() {
it( 'should return an empty array if there are no matches for email addresses', function() {
expect( matcher.parseMatches( '' ) ).toEqual( [] );
expect( matcher.parseMatches( 'asdf' ) ).toEqual( [] );
expect( matcher.parseMatches( '@asdf' ) ).toEqual( [] );
expect( matcher.parseMatches( 'Hello @asdf.com' ) ).toEqual( [] ); // not a valid email address
} );
it( 'should return an array of a single email address match when the string is the email address itself', function() {
var matches = matcher.parseMatches( 'asdf@asdf.com' );
expect( matches.length ).toBe( 1 );
MatchChecker.expectEmailMatch( matches[ 0 ], 'asdf@asdf.com', 0 );
} );
it( 'should return an array of a single email address match when the email address is in the middle of the string', function() {
var matches = matcher.parseMatches( 'Hello asdf@asdf.com my good friend' );
expect( matches.length ).toBe( 1 );
MatchChecker.expectEmailMatch( matches[ 0 ], 'asdf@asdf.com', 6 );
} );
it( 'should return an array of a single email address match when the email address is at the end of the string', function() {
var matches = matcher.parseMatches( 'Hello asdf@asdf.com' );
expect( matches.length ).toBe( 1 );
MatchChecker.expectEmailMatch( matches[ 0 ], 'asdf@asdf.com', 6 );
} );
it( 'should return an array of multiple email addresses when there are more than one within the string', function() {
var matches = matcher.parseMatches( 'Talk to asdf@asdf.com or fdsa@fdsa.com' );
expect( matches.length ).toBe( 2 );
MatchChecker.expectEmailMatch( matches[ 0 ], 'asdf@asdf.com', 8 );
MatchChecker.expectEmailMatch( matches[ 1 ], 'fdsa@fdsa.com', 25 );
} );
it( 'a match within parenthesis should be parsed correctly', function() {
var matches = matcher.parseMatches( 'Hello (asdf@asdf.com)' );
expect( matches.length ).toBe( 1 );
MatchChecker.expectEmailMatch( matches[ 0 ], 'asdf@asdf.com', 7 );
} );
it( 'a match with underscores should be parsed correctly', function() {
var matches = matcher.parseMatches( 'Hello asdf_fdsa_asdf@asdf.com' );
expect( matches.length ).toBe( 1 );
MatchChecker.expectEmailMatch( matches[ 0 ], 'asdf_fdsa_asdf@asdf.com', 6 );
} );
it( 'a match with an \' should be parsed correctly', function() {
var matches = matcher.parseMatches( 'o\'donnel@asdf.com' );
expect( matches.length ).toBe( 1 );
MatchChecker.expectEmailMatch( matches[ 0 ], 'o\'donnel@asdf.com', 0 );
} );
it( 'should *not* match email with incorrect domain beginning with "-"', function() {
var matches = matcher.parseMatches( 'asdf@-asdf.com' );
expect( matches.length ).toBe( 0 );
} );
it( 'should *not* match email with incorrect domain ending with "-"', function() {
var matches = matcher.parseMatches( 'asdf@asdf-.com' );
expect( matches.length ).toBe( 0 );
} );
it( 'should *not* match email with incorrect domain beginning with "."', function() {
var matches = matcher.parseMatches( 'asdf@.asdf.com' );
expect( matches.length ).toBe( 0 );
} );
it( 'should *not* match email with incorrect local part beginning with "."', function() {
var matches = matcher.parseMatches( '.asdf@asdf.com' );
expect( matches.length ).toBe( 1 );
MatchChecker.expectEmailMatch( matches[ 0 ], 'asdf@asdf.com', 1 );
} );
it( 'should *not* match email with incorrect local part ending with "."', function() {
var matches = matcher.parseMatches( 'asdf.@asdf.com' );
expect( matches.length ).toBe( 0 );
} );
it( 'should match email skipping incorrect local part tailing with ".."', function() {
var matches = matcher.parseMatches( 'asdf..asdf@asdf.com' );
expect( matches.length ).toBe( 1 );
MatchChecker.expectEmailMatch( matches[ 0 ], 'asdf@asdf.com', 6 );
} );
} );
} );
|