File: MatchSpec.js

package info (click to toggle)
node-autolinker 1.8.3%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,344 kB
  • sloc: javascript: 6,128; makefile: 62
file content (60 lines) | stat: -rw-r--r-- 1,894 bytes parent folder | download | duplicates (3)
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
/*global Autolinker, _, describe, beforeEach, afterEach, it, expect, jasmine */
describe( "Autolinker.match.Match", function() {
	var Match = Autolinker.match.Match,
		tagBuilder = new Autolinker.AnchorTagBuilder();


	describe( 'getMatchedText()', function() {

		it( "should return the configured `matchedText` if it was an empty string", function() {
			var match = new Match( { tagBuilder: tagBuilder, matchedText: '', offset: 0 } );

			expect( match.getMatchedText() ).toBe( '' );
		} );


		it( "should return the configured `matchedText` if it was a string other than an empty string", function() {
			var match = new Match( { tagBuilder: tagBuilder, matchedText: 'abc', offset: 2 } );

			expect( match.getMatchedText() ).toBe( 'abc' );
		} );

	} );


	describe( 'getOffset()', function() {

		it( "should return the configured `offset` if it was 0", function() {
			var match = new Match( { tagBuilder: tagBuilder, matchedText: 'abc', offset: 0 } );

			expect( match.getOffset() ).toBe( 0 );
		} );


		it( "should return the configured `offset` if it was a number other than 0", function() {
			var match = new Match( { tagBuilder: tagBuilder, matchedText: 'abc', offset: 2 } );

			expect( match.getOffset() ).toBe( 2 );
		} );

	} );


	describe( 'buildTag()', function() {
		var ConcreteMatch = Autolinker.Util.extend( Match, {
			getType       : function() { return 'concrete-match'; },
			getAnchorHref : function() { return this.matchedText + '_href'; },
			getAnchorText : function() { return this.matchedText + '_text'; }
		} );


		it( "should return an Autolinker.HtmlTag instance, configured for how the Match is configured", function() {
			var match = new ConcreteMatch( { tagBuilder: tagBuilder, matchedText: 'abc', offset: 0 } ),
			    htmlTag = match.buildTag();

			expect( htmlTag.toAnchorString() ).toBe( '<a href="abc_href">abc_text</a>' );
		} );

	} );

} );