Debian Codegraph @

tests/match/MatchSpec.js

raw symbols SCIP
1 /*global Autolinker, _, describe, beforeEach, afterEach, it, expect, jasmine */
2 describe( "Autolinker.match.Match", function() {
3 var Match = Autolinker.match.Match,
4 tagBuilder = new Autolinker.AnchorTagBuilder();
5
6
7 describe( 'getMatchedText()', function() {
8
9 it( "should return the configured `matchedText` if it was an empty string", function() {
10 var match = new Match( { tagBuilder: tagBuilder, matchedText: '', offset: 0 } );
11
12 expect( match.getMatchedText() ).toBe( '' );
13 } );
14
15
16 it( "should return the configured `matchedText` if it was a string other than an empty string", function() {
17 var match = new Match( { tagBuilder: tagBuilder, matchedText: 'abc', offset: 2 } );
18
19 expect( match.getMatchedText() ).toBe( 'abc' );
20 } );
21
22 } );
23
24
25 describe( 'getOffset()', function() {
26
27 it( "should return the configured `offset` if it was 0", function() {
28 var match = new Match( { tagBuilder: tagBuilder, matchedText: 'abc', offset: 0 } );
29
30 expect( match.getOffset() ).toBe( 0 );
31 } );
32
33
34 it( "should return the configured `offset` if it was a number other than 0", function() {
35 var match = new Match( { tagBuilder: tagBuilder, matchedText: 'abc', offset: 2 } );
36
37 expect( match.getOffset() ).toBe( 2 );
38 } );
39
40 } );
41
42
43 describe( 'buildTag()', function() {
44 var ConcreteMatch = Autolinker.Util.extend( Match, {
45 getType : function() { return 'concrete-match'; },
46 getAnchorHref : function() { return this.matchedText + '_href'; },
47 getAnchorText : function() { return this.matchedText + '_text'; }
48 } );
49
50
51 it( "should return an Autolinker.HtmlTag instance, configured for how the Match is configured", function() {
52 var match = new ConcreteMatch( { tagBuilder: tagBuilder, matchedText: 'abc', offset: 0 } ),
53 htmlTag = match.buildTag();
54
55 expect( htmlTag.toAnchorString() ).toBe( '<a href="abc_href">abc_text</a>' );
56 } );
57
58 } );
59
60 } );