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
|
import helper from '../../src/main/js/components/source-viewer/helpers/code-with-issue-locations-helper';
let expect = require('chai').expect;
describe('Source Viewer', function () {
describe('Code With Issue Locations Helper', function () {
it('should be a function', function () {
expect(helper).to.be.a('function');
});
it('should mark one location', function () {
var code = '<span class="k">if</span> (<span class="sym-2 sym">a</span> + <span class="c">1</span>) {',
locations = [{ from: 1, to: 5 }],
result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="k">i</span>',
'<span class="k x">f</span>',
'<span class=" x"> (</span>',
'<span class="sym-2 sym x">a</span>',
'<span class=""> + </span>',
'<span class="c">1</span>',
'<span class="">) {</span>'
].join(''));
});
it('should mark two locations', function () {
var code = 'abcdefghijklmnopqrst',
locations = [
{ from: 1, to: 6 },
{ from: 11, to: 16 }
],
result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="">a</span>',
'<span class=" x">bcdef</span>',
'<span class="">ghijk</span>',
'<span class=" x">lmnop</span>',
'<span class="">qrst</span>'
].join(''));
});
it('should mark one locations', function () {
var code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>',
locations = [{ from: 15, to: 20 }],
result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="cppd"> * Copyright (C</span>',
'<span class="cppd x">) 200</span>',
'<span class="cppd">8-2014 SonarSource</span>'
].join(''));
});
it('should mark two locations', function () {
var code = '<span class="cppd"> * Copyright (C) 2008-2014 SonarSource</span>',
locations = [
{ from: 24, to: 29 },
{ from: 15, to: 20 }
],
result = helper(code, locations, 'x');
expect(result).to.equal([
'<span class="cppd"> * Copyright (C</span>',
'<span class="cppd x">) 200</span>',
'<span class="cppd">8-20</span>',
'<span class="cppd x">14 So</span>',
'<span class="cppd">narSource</span>'
].join(''));
});
it('should parse line with < and >', function () {
var code = '<span class="j">#include <stdio.h></span>',
result = helper(code, []);
expect(result).to.equal('<span class="j">#include <stdio.h></span>');
});
// TODO SONAR-7365
it.skip('should parse syntax and usage highlighting', function () {
var code = '<span class="k"><span class="sym-3 sym">this</span></span>',
result = helper(code, []);
expect(result).to.equal(code);
});
// TODO SONAR-7365
it.skip('should parse nested tags', function () {
var code = '<span class="k"><span class="sym-3 sym">this</span> is</span>',
result = helper(code, []);
expect(result).to.equal(code);
});
});
});
|