/
PropertyTest.js
131 lines (112 loc) · 4.12 KB
/
PropertyTest.js
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
/**
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the MIT license found in the
* LICENSE file in the root directory of this source tree.
*/
import {Property} from '../src/Property.js';
test('parses required primitive prop', () => {
let obj = {
'name': 'lineNumber',
'type': 'integer',
'description': 'Line number in the script (0-based).',
};
let prop = Property.create('Debugger', obj);
expect(prop.domain).toBe('Debugger');
expect(prop.name).toBe('lineNumber');
expect(prop.type).toBe('integer');
expect(prop.optional).toBeUndefined();
expect(prop.description).toBe('Line number in the script (0-based).');
expect(prop.getFullCppType()).toBe('int');
expect(prop.getCppIdentifier()).toBe('lineNumber');
expect(prop.getInitializer()).toBe('{}');
});
test('parses optional primitive prop', () => {
let obj = {
'name': 'samplingInterval',
'type': 'number',
'optional': true,
'description': 'Average sample interval in bytes.',
};
let prop = Property.create('HeapProfiler', obj);
expect(prop.domain).toBe('HeapProfiler');
expect(prop.name).toBe('samplingInterval');
expect(prop.type).toBe('number');
expect(prop.optional).toBe(true);
expect(prop.description).toBe('Average sample interval in bytes.');
expect(prop.getFullCppType()).toBe('folly::Optional<double>');
expect(prop.getCppIdentifier()).toBe('samplingInterval');
expect(prop.getInitializer()).toBe('');
});
test('parses optional ref prop', () => {
let obj = {
'name': 'exceptionDetails',
'optional': true,
'$ref': 'Runtime.ExceptionDetails',
'description': 'Exception details if any.',
};
let prop = Property.create('Debugger', obj);
expect(prop.domain).toBe('Debugger');
expect(prop.name).toBe('exceptionDetails');
expect(prop.optional).toBe(true);
expect(prop.$ref).toBe('Runtime.ExceptionDetails');
expect(prop.description).toBe('Exception details if any.');
expect(prop.getFullCppType()).toBe('folly::Optional<runtime::ExceptionDetails>');
expect(prop.getCppIdentifier()).toBe('exceptionDetails');
expect(prop.getInitializer()).toBe('');
});
test('parses recursive ref prop', () => {
let obj = {
'name': 'parent',
'$ref': 'StackTrace',
'optional': true,
'recursive': true,
'description': 'Asynchronous JavaScript stack trace...',
};
let prop = Property.create('Runtime', obj);
expect(prop.domain).toBe('Runtime');
expect(prop.name).toBe('parent');
expect(prop.optional).toBe(true);
expect(prop.recursive).toBe(true);
expect(prop.$ref).toBe('StackTrace');
expect(prop.description).toBe('Asynchronous JavaScript stack trace...');
expect(prop.getFullCppType()).toBe('std::unique_ptr<runtime::StackTrace>');
expect(prop.getCppIdentifier()).toBe('parent');
expect(prop.getInitializer()).toBe('');
});
test('parses optional array items prop', () => {
let obj = {
'name': 'hitBreakpoints',
'type': 'array',
'optional': true,
'items': { 'type': 'string' },
'description': 'Hit breakpoints IDs',
};
let prop = Property.create('Debugger', obj);
expect(prop.domain).toBe('Debugger');
expect(prop.name).toBe('hitBreakpoints');
expect(prop.type).toBe('array');
expect(prop.optional).toBe(true);
expect(prop.items).toEqual({ 'type': 'string' });
expect(prop.description).toBe('Hit breakpoints IDs');
expect(prop.getFullCppType()).toBe('folly::Optional<std::vector<std::string>>');
expect(prop.getCppIdentifier()).toBe('hitBreakpoints');
expect(prop.getInitializer()).toBe('');
});
test('parses array ref prop', () => {
let obj = {
'name': 'domains',
'type': 'array',
'items': { '$ref': 'Domain' },
'description': 'List of supported domains.',
};
let prop = Property.create('Schema', obj);
expect(prop.domain).toBe('Schema');
expect(prop.name).toBe('domains');
expect(prop.type).toBe('array');
expect(prop.items).toEqual({ $ref: 'Domain' });
expect(prop.description).toBe('List of supported domains.');
expect(prop.getFullCppType()).toBe('std::vector<schema::Domain>');
expect(prop.getCppIdentifier()).toBe('domains');
expect(prop.getInitializer()).toBe('');
});