Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download
80668 views
1
/**
2
* Copyright 2013 Facebook, Inc.
3
*
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
* you may not use this file except in compliance with the License.
6
* You may obtain a copy of the License at
7
*
8
* http://www.apache.org/licenses/LICENSE-2.0
9
*
10
* Unless required by applicable law or agreed to in writing, software
11
* distributed under the License is distributed on an "AS IS" BASIS,
12
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13
* See the License for the specific language governing permissions and
14
* limitations under the License.
15
*
16
* @emails [email protected] [email protected]
17
*/
18
19
describe('docblock', function() {
20
var os = require('os');
21
var docblock = require('../lib/parse/docblock');
22
23
it('should extract valid docblock', function() {
24
var code = '/**'+os.EOL+' * @providesModule foo'+os.EOL+'*/'+os.EOL+'var x = foo;';
25
expect(docblock.extract(code)).toBe('/**'+os.EOL+' * @providesModule foo'+os.EOL+'*/');
26
});
27
28
it('should extract valid docblock with more comments', function() {
29
var code = '/**'+os.EOL+' * @providesModule foo'+os.EOL+'*/'+os.EOL+'var x = foo;'+os.EOL+'/**foo*/';
30
expect(docblock.extract(code)).toBe('/**'+os.EOL+' * @providesModule foo'+os.EOL+'*/');
31
});
32
33
it('should return nothing for no docblock', function() {
34
var code = '/*'+os.EOL+' * @providesModule foo'+os.EOL+'*/'+os.EOL+'var x = foo;'+os.EOL+'/**foo*/';
35
expect(docblock.extract(code)).toBe('');
36
});
37
38
it('should return extract and parsedocblock', function() {
39
var code =
40
'/** @provides intern-fbtrace-css */'+os.EOL+'' +
41
''+os.EOL+'' +
42
'.dummy {}'+os.EOL+'';
43
44
expect(docblock.parse(docblock.extract(code))).toEqual([
45
['provides', 'intern-fbtrace-css']
46
]);
47
});
48
49
it('should parse directives out of a docblock', function() {
50
var code =
51
'/**'+os.EOL+'' +
52
' * @providesModule foo'+os.EOL+'' +
53
' * @css a b'+os.EOL+'' +
54
' * @preserve-whitespace'+os.EOL+'' +
55
' */';
56
expect(docblock.parse(code)).toEqual([
57
['providesModule', 'foo'],
58
['css', 'a b'],
59
['preserve-whitespace', '']
60
]);
61
});
62
63
it('should parse directives out of a docblock as an object', function() {
64
var code =
65
'/**'+os.EOL+'' +
66
' * @providesModule foo'+os.EOL+'' +
67
' * @css a b'+os.EOL+'' +
68
' * @preserve-whitespace'+os.EOL+'' +
69
' */';
70
expect(docblock.parseAsObject(code)).toEqual({
71
'providesModule': 'foo',
72
'css': 'a b',
73
'preserve-whitespace': ''
74
});
75
});
76
77
it('should parse directives out of a docblock with comments', function() {
78
var code =
79
'/**'+os.EOL+'' +
80
' * Copyright 2004-present Facebook. All Rights Reserved.'+os.EOL+'' +
81
' * @providesModule foo'+os.EOL+'' +
82
' * @css a b'+os.EOL+'' +
83
' *'+os.EOL+'' +
84
' * And some license here'+os.EOL+'' +
85
' * @preserve-whitespace'+os.EOL+'' +
86
' */';
87
expect(docblock.parse(code)).toEqual([
88
['providesModule', 'foo'],
89
['css', 'a b'],
90
['preserve-whitespace', '']
91
]);
92
});
93
94
it('should parse multiline directives', function() {
95
var code =
96
'/**'+os.EOL+'' +
97
' * Copyright 2004-present Facebook. All Rights Reserved.'+os.EOL+'' +
98
' * @class A long declaration of a class'+os.EOL+'' +
99
' * goes here, so we can read it and enjoy'+os.EOL+'' +
100
' *'+os.EOL+'' +
101
' * And some license here'+os.EOL+'' +
102
' * @preserve-whitespace'+os.EOL+'' +
103
' */';
104
expect(docblock.parse(code)).toEqual([
105
['class', 'A long declaration of a class goes here, ' +
106
'so we can read it and enjoy'],
107
['preserve-whitespace', '']
108
]);
109
});
110
});
111
112