Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80556 views
1
'use strict';
2
/*jshint asi: true */
3
4
var test = require('tap').test
5
, generator = require('inline-source-map')
6
, rx = require('..').commentRegex
7
, mapFileRx = require('..').mapFileCommentRegex
8
9
function comment(s) {
10
rx.lastIndex = 0;
11
return rx.test(s + 'sourceMappingURL=data:application/json;base64,eyJ2ZXJzaW9uIjozLCJmaWxlIjoiIiwic291cmNlcyI6WyJmdW5jdGlvbiBmb28oKSB7XG4gY29uc29sZS5sb2coXCJoZWxsbyBJIGFtIGZvb1wiKTtcbiBjb25zb2xlLmxvZyhcIndobyBhcmUgeW91XCIpO1xufVxuXG5mb28oKTtcbiJdLCJuYW1lcyI6W10sIm1hcHBpbmdzIjoiQUFBQSJ9')
12
}
13
14
test('comment regex old spec - @', function (t) {
15
[ '//@ '
16
, ' //@ '
17
, '\t//@ '
18
].forEach(function (x) { t.ok(comment(x), 'matches ' + x) });
19
20
[ '///@ '
21
, '}}//@ '
22
, ' @// @'
23
].forEach(function (x) { t.ok(!comment(x), 'does not match ' + x) })
24
t.end()
25
})
26
27
test('comment regex new spec - #', function (t) {
28
[ '//# '
29
, ' //# '
30
, '\t//# '
31
].forEach(function (x) { t.ok(comment(x), 'matches ' + x) });
32
33
[ '///# '
34
, '}}//# '
35
, ' #// #'
36
].forEach(function (x) { t.ok(!comment(x), 'does not match ' + x) })
37
t.end()
38
})
39
40
function mapFileComment(s) {
41
mapFileRx.lastIndex = 0;
42
return mapFileRx.test(s + 'sourceMappingURL=foo.js.map')
43
}
44
45
test('mapFileComment regex old spec - @', function (t) {
46
[ '//@ '
47
, ' //@ '
48
, '\t//@ '
49
].forEach(function (x) { t.ok(mapFileComment(x), 'matches ' + x) });
50
51
[ '///@ '
52
, '}}//@ '
53
, ' @// @'
54
].forEach(function (x) { t.ok(!mapFileComment(x), 'does not match ' + x) })
55
t.end()
56
})
57
58
test('mapFileComment regex new spec - #', function (t) {
59
[ '//# '
60
, ' //# '
61
, '\t//# '
62
].forEach(function (x) { t.ok(mapFileComment(x), 'matches ' + x) });
63
64
[ '///# '
65
, '}}//# '
66
, ' #// #'
67
].forEach(function (x) { t.ok(!mapFileComment(x), 'does not match ' + x) })
68
t.end()
69
})
70
71
function mapFileCommentWrap(s1, s2) {
72
mapFileRx.lastIndex = 0;
73
return mapFileRx.test(s1 + 'sourceMappingURL=foo.js.map' + s2)
74
}
75
76
test('mapFileComment regex /* */ old spec - @', function (t) {
77
[ [ '/*@ ', '*/' ]
78
, [' /*@ ', ' */ ' ]
79
, [ '\t/*@ ', ' \t*/\t ']
80
].forEach(function (x) { t.ok(mapFileCommentWrap(x[0], x[1]), 'matches ' + x.join(' :: ')) });
81
82
[ [ '/*/*@ ', '*/' ]
83
, ['}}/*@ ', ' */ ' ]
84
, [ ' @/*@ ', ' \t*/\t ']
85
].forEach(function (x) { t.ok(!mapFileCommentWrap(x[0], x[1]), 'does not match ' + x.join(' :: ')) });
86
t.end()
87
})
88
89
test('mapFileComment regex /* */ new spec - #', function (t) {
90
[ [ '/*# ', '*/' ]
91
, [' /*# ', ' */ ' ]
92
, [ '\t/*# ', ' \t*/\t ']
93
].forEach(function (x) { t.ok(mapFileCommentWrap(x[0], x[1]), 'matches ' + x.join(' :: ')) });
94
95
[ [ '/*/*# ', '*/' ]
96
, ['}}/*# ', ' */ ' ]
97
, [ ' #/*# ', ' \t*/\t ']
98
].forEach(function (x) { t.ok(!mapFileCommentWrap(x[0], x[1]), 'does not match ' + x.join(' :: ')) });
99
t.end()
100
})
101
102