@darabonba/python-generator 1.2.19 → 2.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ChangeLog.md +0 -158
- package/lib/builtin.js +818 -0
- package/lib/generator.js +2708 -0
- package/lib/helper.js +422 -0
- package/package.json +6 -5
- package/tests/expected/alias/setup.py +79 -0
- package/tests/expected/alias/tea_python_tests/__init__.py +1 -0
- package/tests/expected/alias/tea_python_tests/client.py +35 -0
- package/tests/expected/annotation/tea_python_tests/__init__.py +1 -0
- package/tests/expected/annotation/tea_python_tests/client.py +93 -0
- package/tests/expected/annotation/tea_python_tests/models.py +37 -0
- package/tests/expected/api/tea_python_tests/__init__.py +1 -0
- package/tests/expected/api/tea_python_tests/client.py +106 -0
- package/tests/expected/builtin/tea_python_tests/client.py +685 -0
- package/tests/expected/comment/tea_python_tests/__init__.py +1 -0
- package/tests/expected/comment/tea_python_tests/client.py +288 -0
- package/tests/expected/comment/tea_python_tests/models.py +195 -0
- package/tests/expected/complex/tea_python_tests/__init__.py +1 -0
- package/tests/expected/complex/tea_python_tests/client.py +1169 -0
- package/tests/expected/complex/tea_python_tests/exceptions.py +39 -0
- package/tests/expected/complex/tea_python_tests/models.py +570 -0
- package/tests/expected/const/tea_python_tests/__init__.py +1 -0
- package/tests/expected/const/tea_python_tests/client.py +14 -0
- package/{src/langs/python/files/setup.py.tmpl → tests/expected/empty/setup.py} +11 -11
- package/tests/expected/empty/tea_python_tests/__init__.py +1 -0
- package/tests/expected/empty/tea_python_tests/client.py +10 -0
- package/tests/expected/exec/tea_python_tests/__init__.py +1 -0
- package/tests/expected/exec/tea_python_tests/exec_client.py +21 -0
- package/tests/expected/function/tea_python_tests/__init__.py +1 -0
- package/tests/expected/function/tea_python_tests/client.py +64 -0
- package/tests/expected/import/setup.py +78 -0
- package/tests/expected/import/tea_python_tests/__init__.py +1 -0
- package/tests/expected/import/tea_python_tests/client.py +29 -0
- package/tests/expected/map/tea_python_tests/__init__.py +1 -0
- package/tests/expected/map/tea_python_tests/client.py +39 -0
- package/tests/expected/model/tea_python_tests/__init__.py +1 -0
- package/tests/expected/model/tea_python_tests/client.py +10 -0
- package/tests/expected/model/tea_python_tests/exceptions.py +28 -0
- package/tests/expected/model/tea_python_tests/models.py +780 -0
- package/tests/expected/multi/tea_python_tests/api.py +95 -0
- package/tests/expected/multi/tea_python_tests/client.py +40 -0
- package/tests/expected/multi/tea_python_tests/lib/util.py +19 -0
- package/tests/expected/multi/tea_python_tests/model/user.py +26 -0
- package/tests/expected/multi/tea_python_tests/model/user_exceptions.py +83 -0
- package/tests/expected/multi/tea_python_tests/model/user_models.py +145 -0
- package/tests/expected/statements/tea_python_tests/__init__.py +1 -0
- package/tests/expected/statements/tea_python_tests/client.py +86 -0
- package/tests/expected/super/tea_python_tests/__init__.py +1 -0
- package/tests/expected/super/tea_python_tests/client.py +16 -0
- package/tests/expected/typedef/setup.py +77 -0
- package/tests/expected/typedef/tea_python_tests/__init__.py +1 -0
- package/tests/expected/typedef/tea_python_tests/client.py +74 -0
- package/tests/expected/typedef/tea_python_tests/models.py +42 -0
- package/tests/fixtures/alias/Darafile +11 -0
- package/tests/fixtures/alias/libraries/Alias/Darafile +11 -0
- package/tests/fixtures/alias/libraries/Alias-Symbol/Darafile +11 -0
- package/tests/fixtures/builtin/Darafile +6 -0
- package/tests/fixtures/builtin/main.dara +333 -0
- package/tests/fixtures/complex/libraries/import.dara +18 -11
- package/tests/fixtures/complex/main.dara +452 -103
- package/tests/fixtures/import/libraries/Darafile +1 -1
- package/tests/fixtures/import/pack/Darafile +3 -0
- package/tests/fixtures/map/libraries/Darafile +3 -0
- package/tests/fixtures/map/libraries/import.dara +4 -0
- package/tests/fixtures/map/main.dara +17 -2
- package/tests/fixtures/model/.libraries.json +3 -0
- package/tests/fixtures/model/Darafile +5 -2
- package/tests/fixtures/model/libraries/Darafile +20 -0
- package/tests/fixtures/model/libraries/import.dara +27 -0
- package/tests/fixtures/model/main.dara +60 -42
- package/tests/fixtures/multi/.libraries.json +3 -0
- package/tests/fixtures/multi/Darafile +12 -0
- package/tests/fixtures/multi/api.dara +20 -0
- package/tests/fixtures/multi/lib/util.dara +5 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile +68 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/main.tea +244 -0
- package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/util.tea +2 -0
- package/tests/fixtures/multi/main.dara +32 -0
- package/tests/fixtures/multi/model/user.dara +35 -0
- package/tests/{python3.tests.js → main.tests.js} +107 -65
- package/tests/output/alias/setup.py +79 -0
- package/tests/output/alias/tea_python_tests/client.py +35 -0
- package/{src/langs/python2/files/setup.py.tmpl → tests/output/annotation/setup.py} +19 -24
- package/tests/output/annotation/tea_python_tests/client.py +93 -0
- package/tests/output/annotation/tea_python_tests/models.py +37 -0
- package/tests/output/api/setup.py +77 -0
- package/tests/output/api/tea_python_tests/client.py +106 -0
- package/tests/output/builtin/setup.py +77 -0
- package/tests/output/builtin/tea_python_tests/client.py +685 -0
- package/tests/output/comment/setup.py +77 -0
- package/tests/output/comment/tea_python_tests/client.py +288 -0
- package/tests/output/comment/tea_python_tests/models.py +195 -0
- package/tests/output/complex/setup.py +77 -0
- package/tests/output/complex/tea_python_tests/client.py +1169 -0
- package/tests/output/complex/tea_python_tests/exceptions.py +39 -0
- package/tests/output/complex/tea_python_tests/models.py +570 -0
- package/tests/output/const/setup.py +77 -0
- package/tests/output/const/tea_python_tests/client.py +14 -0
- package/tests/output/empty/setup.py +77 -0
- package/tests/output/empty/tea_python_tests/client.py +10 -0
- package/tests/output/exec/setup.py +77 -0
- package/tests/output/exec/tea_python_tests/exec_client.py +21 -0
- package/tests/output/function/setup.py +77 -0
- package/tests/output/function/tea_python_tests/client.py +64 -0
- package/tests/output/import/setup.py +78 -0
- package/tests/output/import/tea_python_tests/client.py +29 -0
- package/tests/output/map/setup.py +77 -0
- package/tests/output/map/tea_python_tests/client.py +39 -0
- package/tests/output/model/setup.py +77 -0
- package/tests/output/model/tea_python_tests/client.py +10 -0
- package/tests/output/model/tea_python_tests/exceptions.py +28 -0
- package/tests/output/model/tea_python_tests/models.py +780 -0
- package/tests/output/multi/setup.py +77 -0
- package/tests/output/multi/tea_python_tests/api.py +95 -0
- package/tests/output/multi/tea_python_tests/client.py +40 -0
- package/tests/output/multi/tea_python_tests/lib/util.py +19 -0
- package/tests/output/multi/tea_python_tests/model/user.py +26 -0
- package/tests/output/multi/tea_python_tests/model/user_exceptions.py +83 -0
- package/tests/output/multi/tea_python_tests/model/user_models.py +145 -0
- package/tests/output/statements/setup.py +77 -0
- package/tests/output/statements/tea_python_tests/client.py +86 -0
- package/tests/output/super/setup.py +77 -0
- package/tests/output/super/tea_python_tests/client.py +16 -0
- package/tests/output/typedef/setup.py +78 -0
- package/tests/output/typedef/tea_python_tests/client.py +74 -0
- package/tests/output/typedef/tea_python_tests/models.py +42 -0
- package/src/generator.js +0 -231
- package/src/langs/common/combinator.js +0 -193
- package/src/langs/common/config.js +0 -60
- package/src/langs/common/enum.js +0 -179
- package/src/langs/common/items.js +0 -551
- package/src/langs/common/package_info.js +0 -53
- package/src/langs/python/combinator.js +0 -1898
- package/src/langs/python/config.js +0 -169
- package/src/langs/python/files/.gitignore.tmpl +0 -5
- package/src/langs/python/files/__init__.py.tmpl +0 -1
- package/src/langs/python/package_info.js +0 -78
- package/src/langs/python2/combinator.js +0 -1770
- package/src/langs/python2/config.js +0 -162
- package/src/langs/python2/files/.gitignore.tmpl +0 -5
- package/src/langs/python2/files/__init__.py.tmpl +0 -1
- package/src/langs/python2/package_info.js +0 -78
- package/src/lib/debug.js +0 -55
- package/src/lib/emitter.js +0 -95
- package/src/lib/helper.js +0 -207
- package/src/resolver/base.js +0 -282
- package/src/resolver/client.js +0 -1013
- package/src/resolver/model.js +0 -159
- package/tests/common.tests.js +0 -244
- package/tests/lib.tests.js +0 -269
- package/tests/python2.tests.js +0 -283
- package/tests/resolver.tests.js +0 -434
package/tests/python2.tests.js
DELETED
|
@@ -1,283 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const path = require('path');
|
|
4
|
-
const fs = require('fs');
|
|
5
|
-
const assert = require('assert');
|
|
6
|
-
|
|
7
|
-
const DSL = require('@darabonba/parser');
|
|
8
|
-
|
|
9
|
-
let Generator = require('../src/generator');
|
|
10
|
-
|
|
11
|
-
const lang = 'python2';
|
|
12
|
-
|
|
13
|
-
const expectedDir = path.join(__dirname, 'expected/python2/');
|
|
14
|
-
const fixturesDir = path.join(__dirname, 'fixtures/');
|
|
15
|
-
const outputDir = path.join(__dirname, '../', 'output/tests/python2/');
|
|
16
|
-
|
|
17
|
-
function check(moduleName, expectedFiles = [], option = {}) {
|
|
18
|
-
const mainFilePath = path.join(fixturesDir, moduleName, 'main.dara') ? path.join(fixturesDir, moduleName, 'main.dara') : path.join(fixturesDir, moduleName, 'main.tea');
|
|
19
|
-
const moduleOutputDir = path.join(outputDir, moduleName);
|
|
20
|
-
const prefixDir = path.join(fixturesDir, moduleName);
|
|
21
|
-
const pkgContent = fs.readFileSync(
|
|
22
|
-
fs.existsSync(path.join(prefixDir, 'Darafile')) ? path.join(prefixDir, 'Darafile') : path.join(prefixDir, 'Teafile'), 'utf8');
|
|
23
|
-
const pkgInfo = JSON.parse(pkgContent);
|
|
24
|
-
const config = {
|
|
25
|
-
outputDir: moduleOutputDir,
|
|
26
|
-
pkgDir: path.join(fixturesDir, moduleName),
|
|
27
|
-
...pkgInfo,
|
|
28
|
-
...option
|
|
29
|
-
};
|
|
30
|
-
const generator = new Generator(config, lang);
|
|
31
|
-
|
|
32
|
-
const dsl = fs.readFileSync(mainFilePath, 'utf8');
|
|
33
|
-
const ast = DSL.parse(dsl, mainFilePath);
|
|
34
|
-
generator.visit(ast);
|
|
35
|
-
expectedFiles.forEach(element => {
|
|
36
|
-
const outputFilePath = path.join(outputDir, moduleName, element);
|
|
37
|
-
const expectedFilePath = path.join(expectedDir, moduleName, element);
|
|
38
|
-
const expected = fs.readFileSync(expectedFilePath, 'utf8');
|
|
39
|
-
assert.deepStrictEqual(fs.readFileSync(outputFilePath, 'utf8'), expected);
|
|
40
|
-
});
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
describe('Python Generator', function () {
|
|
44
|
-
it('alias should ok', function () {
|
|
45
|
-
check('alias', [
|
|
46
|
-
'tea_python_tests/client.py'
|
|
47
|
-
],
|
|
48
|
-
{
|
|
49
|
-
python2: {
|
|
50
|
-
package: 'tea_python_tests',
|
|
51
|
-
clientName: 'client',
|
|
52
|
-
packageInfo: {
|
|
53
|
-
name: 'tea_python_tests',
|
|
54
|
-
desc: 'Generate setup.py',
|
|
55
|
-
github: 'https://github.com/',
|
|
56
|
-
author: 'Alibaba',
|
|
57
|
-
email: 'sdk-team@alibabacloud.com'
|
|
58
|
-
}
|
|
59
|
-
}
|
|
60
|
-
});
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it('add annotation should ok', function () {
|
|
64
|
-
check('annotation', [
|
|
65
|
-
'tea_python_tests/client.py',
|
|
66
|
-
'tea_python_tests/models.py'
|
|
67
|
-
],
|
|
68
|
-
{
|
|
69
|
-
python2: {
|
|
70
|
-
package: 'tea_python_tests',
|
|
71
|
-
clientName: 'client'
|
|
72
|
-
}
|
|
73
|
-
});
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
it('api should ok', function () {
|
|
77
|
-
check('api', [
|
|
78
|
-
'tea_python_tests/client.py'
|
|
79
|
-
],
|
|
80
|
-
{
|
|
81
|
-
python2: {
|
|
82
|
-
package: 'tea_python_tests',
|
|
83
|
-
clientName: 'client'
|
|
84
|
-
}
|
|
85
|
-
});
|
|
86
|
-
});
|
|
87
|
-
|
|
88
|
-
it('add comments should ok', function () {
|
|
89
|
-
check('comment', [
|
|
90
|
-
'tea_python_tests/client.py',
|
|
91
|
-
'tea_python_tests/models.py'
|
|
92
|
-
],
|
|
93
|
-
{
|
|
94
|
-
python2: {
|
|
95
|
-
package: 'tea_python_tests',
|
|
96
|
-
clientName: 'client'
|
|
97
|
-
}
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('complex should ok', function () {
|
|
102
|
-
check('complex', [
|
|
103
|
-
'tea_python_tests/client.py',
|
|
104
|
-
'tea_python_tests/models.py'
|
|
105
|
-
],
|
|
106
|
-
{
|
|
107
|
-
python2: {
|
|
108
|
-
package: 'tea_python_tests',
|
|
109
|
-
clientName: 'client'
|
|
110
|
-
}
|
|
111
|
-
});
|
|
112
|
-
});
|
|
113
|
-
|
|
114
|
-
it('const should ok', function () {
|
|
115
|
-
check('const', [
|
|
116
|
-
'tea_python_tests/client.py'
|
|
117
|
-
],
|
|
118
|
-
{
|
|
119
|
-
python2: {
|
|
120
|
-
package: 'tea_python_tests',
|
|
121
|
-
clientName: 'client'
|
|
122
|
-
}
|
|
123
|
-
});
|
|
124
|
-
});
|
|
125
|
-
|
|
126
|
-
it('empty should ok', function () {
|
|
127
|
-
check('empty', [
|
|
128
|
-
'tea_python_tests/client.py',
|
|
129
|
-
'.gitignore'
|
|
130
|
-
],
|
|
131
|
-
{
|
|
132
|
-
python2: {
|
|
133
|
-
package: 'tea_python_tests',
|
|
134
|
-
clientName: 'client',
|
|
135
|
-
packageInfo: {
|
|
136
|
-
name: 'tea_python_tests',
|
|
137
|
-
desc: 'Generate setup.py',
|
|
138
|
-
github: 'https://github.com/',
|
|
139
|
-
author: 'Alibaba',
|
|
140
|
-
email: 'sdk-team@alibabacloud.com'
|
|
141
|
-
}
|
|
142
|
-
}
|
|
143
|
-
});
|
|
144
|
-
});
|
|
145
|
-
|
|
146
|
-
it('function should ok', function () {
|
|
147
|
-
check('function', [
|
|
148
|
-
'tea_python_tests/client.py'
|
|
149
|
-
],
|
|
150
|
-
{
|
|
151
|
-
python2: {
|
|
152
|
-
package: 'tea_python_tests',
|
|
153
|
-
clientName: 'client'
|
|
154
|
-
}
|
|
155
|
-
});
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
it('import should ok', function () {
|
|
159
|
-
check('import', [
|
|
160
|
-
'tea_python_tests/client.py'
|
|
161
|
-
],
|
|
162
|
-
{
|
|
163
|
-
python2: {
|
|
164
|
-
package: 'tea_python_tests',
|
|
165
|
-
clientName: 'client',
|
|
166
|
-
packageInfo: {
|
|
167
|
-
name: 'tea_python_tests',
|
|
168
|
-
desc: 'Generate setup.py',
|
|
169
|
-
github: 'https://github.com/',
|
|
170
|
-
author: 'Alibaba',
|
|
171
|
-
email: 'sdk-team@alibabacloud.com'
|
|
172
|
-
}
|
|
173
|
-
}
|
|
174
|
-
});
|
|
175
|
-
const expected = fs.readFileSync(path.join(expectedDir, 'import', 'setup.py'), 'utf8');
|
|
176
|
-
const output = fs.readFileSync(path.join(outputDir, 'import', 'setup.py'), 'utf8');
|
|
177
|
-
assert.deepStrictEqual(output.replace(new RegExp('\\d{2}\\/\\d{2}\\/\\d{4}'), '*'), expected);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
it('map should ok', function () {
|
|
181
|
-
check('map', [
|
|
182
|
-
'tea_python_tests/client.py'
|
|
183
|
-
],
|
|
184
|
-
{
|
|
185
|
-
python2: {
|
|
186
|
-
package: 'tea_python_tests',
|
|
187
|
-
clientName: 'client'
|
|
188
|
-
}
|
|
189
|
-
});
|
|
190
|
-
});
|
|
191
|
-
|
|
192
|
-
it('model should ok', function () {
|
|
193
|
-
check('model', [
|
|
194
|
-
'tea_python_tests/client.py',
|
|
195
|
-
'tea_python_tests/models.py'
|
|
196
|
-
],
|
|
197
|
-
{
|
|
198
|
-
python2: {
|
|
199
|
-
package: 'tea_python_tests',
|
|
200
|
-
clientName: 'client'
|
|
201
|
-
}
|
|
202
|
-
});
|
|
203
|
-
});
|
|
204
|
-
|
|
205
|
-
it('statements should ok', function () {
|
|
206
|
-
check('statements', [
|
|
207
|
-
'tea_python_tests/client.py'
|
|
208
|
-
],
|
|
209
|
-
{
|
|
210
|
-
python2: {
|
|
211
|
-
package: 'tea_python_tests',
|
|
212
|
-
clientName: 'client'
|
|
213
|
-
}
|
|
214
|
-
});
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it('super should ok', function () {
|
|
218
|
-
check('super', [
|
|
219
|
-
'tea_python_tests/client.py'
|
|
220
|
-
],
|
|
221
|
-
{
|
|
222
|
-
python2: {
|
|
223
|
-
package: 'tea_python_tests',
|
|
224
|
-
clientName: 'client'
|
|
225
|
-
}
|
|
226
|
-
});
|
|
227
|
-
});
|
|
228
|
-
|
|
229
|
-
it('exec should ok', function () {
|
|
230
|
-
check('exec', [
|
|
231
|
-
'tea_python_tests/exec_client.py'
|
|
232
|
-
],
|
|
233
|
-
{
|
|
234
|
-
exec: true,
|
|
235
|
-
python2: {
|
|
236
|
-
package: 'tea_python_tests',
|
|
237
|
-
clientName: 'exec_client'
|
|
238
|
-
}
|
|
239
|
-
});
|
|
240
|
-
});
|
|
241
|
-
it('typedef should ok', function () {
|
|
242
|
-
check('typedef', [
|
|
243
|
-
'tea_python_tests/client.py',
|
|
244
|
-
'tea_python_tests/models.py'
|
|
245
|
-
],
|
|
246
|
-
{
|
|
247
|
-
python2: {
|
|
248
|
-
package: 'tea_python_tests',
|
|
249
|
-
clientName: 'client',
|
|
250
|
-
packageInfo: {
|
|
251
|
-
name: 'tea_python_tests',
|
|
252
|
-
desc: 'Generate setup.py',
|
|
253
|
-
github: 'https://github.com/',
|
|
254
|
-
author: 'Alibaba',
|
|
255
|
-
email: 'sdk-team@alibabacloud.com'
|
|
256
|
-
},
|
|
257
|
-
typedef: {
|
|
258
|
-
HttpResponse: {
|
|
259
|
-
import: 'requests',
|
|
260
|
-
type: 'Response',
|
|
261
|
-
package: 'requests:2.21.0'
|
|
262
|
-
},
|
|
263
|
-
HttpHeader: {
|
|
264
|
-
import: null,
|
|
265
|
-
type: 'Dict[str, Any]',
|
|
266
|
-
package: null
|
|
267
|
-
},
|
|
268
|
-
TeaModel: {
|
|
269
|
-
import: 'Tea.model',
|
|
270
|
-
type: 'TeaModel',
|
|
271
|
-
package: 'alibabacloud-tea-py2:0.0.4'
|
|
272
|
-
},
|
|
273
|
-
TeaException: {
|
|
274
|
-
import: 'Tea.exceptions',
|
|
275
|
-
type: 'TeaException',
|
|
276
|
-
package: 'alibabacloud-tea-py2:0.0.4'
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}
|
|
280
|
-
|
|
281
|
-
});
|
|
282
|
-
});
|
|
283
|
-
});
|
package/tests/resolver.tests.js
DELETED
|
@@ -1,434 +0,0 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
const mm = require('mm');
|
|
4
|
-
const expect = require('chai').expect;
|
|
5
|
-
require('mocha-sinon');
|
|
6
|
-
|
|
7
|
-
const ModelResolver = require('../src/resolver/model');
|
|
8
|
-
const ClientResolver = require('../src/resolver/client');
|
|
9
|
-
|
|
10
|
-
const {
|
|
11
|
-
PropItem,
|
|
12
|
-
AnnotationItem,
|
|
13
|
-
BehaviorDoAction,
|
|
14
|
-
GrammerValue,
|
|
15
|
-
FuncItem
|
|
16
|
-
} = require('../src/langs/common/items');
|
|
17
|
-
const { _deepClone } = require('../src/lib/helper');
|
|
18
|
-
|
|
19
|
-
const lang = 'python';
|
|
20
|
-
const Combinator = require(`../src/langs/${lang}/combinator.js`);
|
|
21
|
-
const config = require(`../src/langs/${lang}/config.js`);
|
|
22
|
-
|
|
23
|
-
describe('client resolver should be ok', function () {
|
|
24
|
-
beforeEach(function () {
|
|
25
|
-
this.sinon.stub(console, 'log');
|
|
26
|
-
});
|
|
27
|
-
|
|
28
|
-
it('resolve should be ok', function () {
|
|
29
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
30
|
-
package: 'test', model: { dir: 'Models' }
|
|
31
|
-
}), {});
|
|
32
|
-
const code = new ClientResolver({ moduleBody: { nodes: [] } }, combinator, {});
|
|
33
|
-
mm(code, 'initAnnotation', function () { return; });
|
|
34
|
-
mm(code, 'resolveProps', function () { return; });
|
|
35
|
-
mm(code.combinator, 'addInclude', function (className) { return className; });
|
|
36
|
-
code.config.baseClient = 'BaseClient';
|
|
37
|
-
code.resolve();
|
|
38
|
-
expect(code.object.extends).to.be.eql(['BaseClient']);
|
|
39
|
-
|
|
40
|
-
mm.restore();
|
|
41
|
-
});
|
|
42
|
-
|
|
43
|
-
it('resolveInitBody should be ok', function () {
|
|
44
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
45
|
-
package: 'test', model: { dir: 'Models' }
|
|
46
|
-
}), {});
|
|
47
|
-
const code = new ClientResolver({}, combinator, {});
|
|
48
|
-
mm(code.combinator, 'addModelInclude', function (modelName) {
|
|
49
|
-
expect(modelName).to.be.eql('modelType');
|
|
50
|
-
});
|
|
51
|
-
mm(code.combinator, 'addInclude', function (className) {
|
|
52
|
-
return className;
|
|
53
|
-
});
|
|
54
|
-
code.config.baseClient = 'BaseClient';
|
|
55
|
-
let init = {
|
|
56
|
-
type: 'init', params: {
|
|
57
|
-
params: [{
|
|
58
|
-
paramType: {
|
|
59
|
-
idType: 'model',
|
|
60
|
-
lexeme: 'modelType'
|
|
61
|
-
},
|
|
62
|
-
paramName: {
|
|
63
|
-
lexeme: 'modelName'
|
|
64
|
-
}
|
|
65
|
-
}, {
|
|
66
|
-
paramType: {
|
|
67
|
-
idType: 'module',
|
|
68
|
-
lexeme: 'moduleType'
|
|
69
|
-
},
|
|
70
|
-
paramName: {
|
|
71
|
-
lexeme: 'moduleName'
|
|
72
|
-
}
|
|
73
|
-
}]
|
|
74
|
-
}
|
|
75
|
-
};
|
|
76
|
-
code.resolveInitBody(init);
|
|
77
|
-
mm.restore();
|
|
78
|
-
});
|
|
79
|
-
|
|
80
|
-
it('resolveFunc should be ok', function () {
|
|
81
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
82
|
-
package: 'test', model: { dir: 'Models' }
|
|
83
|
-
}), {});
|
|
84
|
-
const code = new ClientResolver({}, combinator, {});
|
|
85
|
-
const funcItem = new FuncItem();
|
|
86
|
-
|
|
87
|
-
mm(code.combinator, 'addInclude', function (className) {
|
|
88
|
-
return className;
|
|
89
|
-
});
|
|
90
|
-
code.resolveFunc(funcItem, {
|
|
91
|
-
params: { params: [] },
|
|
92
|
-
returnType: {
|
|
93
|
-
idType: 'module',
|
|
94
|
-
lexeme: 'object',
|
|
95
|
-
}
|
|
96
|
-
}, {});
|
|
97
|
-
code.resolveFunc(funcItem, {
|
|
98
|
-
params: {
|
|
99
|
-
params: [
|
|
100
|
-
{
|
|
101
|
-
paramType: { type: 'moduleModel', subType: { lexeme: '' }, path: ['a'] },
|
|
102
|
-
paramName: { lexeme: 'test' }
|
|
103
|
-
}
|
|
104
|
-
]
|
|
105
|
-
},
|
|
106
|
-
returnType: {
|
|
107
|
-
idType: 'module',
|
|
108
|
-
lexeme: 'object',
|
|
109
|
-
}
|
|
110
|
-
}, {});
|
|
111
|
-
|
|
112
|
-
mm.restore();
|
|
113
|
-
});
|
|
114
|
-
|
|
115
|
-
it('code : requestBody should be ok', function () {
|
|
116
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
117
|
-
package: 'test', model: { dir: 'Models' }
|
|
118
|
-
}), {});
|
|
119
|
-
const code = new ClientResolver({}, combinator, {});
|
|
120
|
-
mm(code, 'visitStmt', function (func) {
|
|
121
|
-
expect(func.name).to.be.eql('testFuncName');
|
|
122
|
-
});
|
|
123
|
-
const funcItem = new FuncItem();
|
|
124
|
-
funcItem.name = 'testFuncName';
|
|
125
|
-
code.requestBody({}, {
|
|
126
|
-
body: {},
|
|
127
|
-
}, funcItem);
|
|
128
|
-
mm.restore();
|
|
129
|
-
mm(code, 'visitStmt', function (func, item) {
|
|
130
|
-
expect(item).to.be.eql('https');
|
|
131
|
-
});
|
|
132
|
-
code.requestBody({}, {
|
|
133
|
-
protocol: ['https']
|
|
134
|
-
}, funcItem);
|
|
135
|
-
});
|
|
136
|
-
|
|
137
|
-
it('renderGrammerValue should be ok', function () {
|
|
138
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
139
|
-
package: 'test', model: { dir: 'Models' }
|
|
140
|
-
}), {});
|
|
141
|
-
const code = new ClientResolver({}, combinator, {});
|
|
142
|
-
expect(function () {
|
|
143
|
-
code.renderGrammerValue(null, { type: 'invalid' });
|
|
144
|
-
}).to.be.throw('unimpelemented : invalid');
|
|
145
|
-
|
|
146
|
-
expect(function () {
|
|
147
|
-
code.renderGrammerValue(null, {
|
|
148
|
-
type: 'map_access',
|
|
149
|
-
accessKey: {
|
|
150
|
-
id: '',
|
|
151
|
-
value: { lexeme: '' }
|
|
152
|
-
}
|
|
153
|
-
});
|
|
154
|
-
}).to.be.throw('');
|
|
155
|
-
|
|
156
|
-
let grammerValue = code.renderGrammerValue(null, {
|
|
157
|
-
type: 'map_access',
|
|
158
|
-
id: { lexeme: 'test' },
|
|
159
|
-
accessKey: {
|
|
160
|
-
id: 'test',
|
|
161
|
-
value: { lexeme: 'test' }
|
|
162
|
-
}
|
|
163
|
-
});
|
|
164
|
-
expect(grammerValue.value.path.length).to.be.eql(2);
|
|
165
|
-
|
|
166
|
-
expect(function () {
|
|
167
|
-
code.renderGrammerValue(null, {
|
|
168
|
-
type: 'call',
|
|
169
|
-
left: {
|
|
170
|
-
type: 'invalid'
|
|
171
|
-
}
|
|
172
|
-
});
|
|
173
|
-
}).to.be.throw('');
|
|
174
|
-
|
|
175
|
-
expect(function () {
|
|
176
|
-
code.renderGrammerValue(null, {
|
|
177
|
-
type: 'call',
|
|
178
|
-
left: {
|
|
179
|
-
type: 'static_call',
|
|
180
|
-
id: { type: 'invalid' }
|
|
181
|
-
}
|
|
182
|
-
});
|
|
183
|
-
}).to.be.throw('');
|
|
184
|
-
|
|
185
|
-
expect(function () {
|
|
186
|
-
code.renderGrammerValue(null, {
|
|
187
|
-
type: 'call',
|
|
188
|
-
left: {
|
|
189
|
-
type: 'instance_call',
|
|
190
|
-
id: { type: 'invalid', lexeme: 'test' }
|
|
191
|
-
}
|
|
192
|
-
});
|
|
193
|
-
}).to.be.throw('Unsupported object.left.id.type : invalid');
|
|
194
|
-
|
|
195
|
-
grammerValue = code.renderGrammerValue(null, {
|
|
196
|
-
type: 'call',
|
|
197
|
-
left: {
|
|
198
|
-
type: 'instance_call',
|
|
199
|
-
id: { lexeme: '@test' }
|
|
200
|
-
}
|
|
201
|
-
});
|
|
202
|
-
expect(grammerValue.value.path.length).to.be.eql(1);
|
|
203
|
-
|
|
204
|
-
grammerValue = code.renderGrammerValue(null, {
|
|
205
|
-
type: 'call',
|
|
206
|
-
left: {
|
|
207
|
-
type: 'method_call',
|
|
208
|
-
id: { type: 'module', lexeme: 'Util' }
|
|
209
|
-
}
|
|
210
|
-
});
|
|
211
|
-
expect(grammerValue.value.path.length).to.be.eql(2);
|
|
212
|
-
|
|
213
|
-
mm(code.combinator, 'addModelInclude', function (modelName) {
|
|
214
|
-
return modelName;
|
|
215
|
-
});
|
|
216
|
-
grammerValue = code.renderGrammerValue(null, {
|
|
217
|
-
type: 'construct_model',
|
|
218
|
-
aliasId: {
|
|
219
|
-
lexeme: 'test'
|
|
220
|
-
},
|
|
221
|
-
propertyPath: [{ lexeme: 'a' }, { lexeme: 'b' }]
|
|
222
|
-
});
|
|
223
|
-
expect(grammerValue.value.name).to.be.eql('test.a.b');
|
|
224
|
-
|
|
225
|
-
grammerValue = code.renderGrammerValue(null, {
|
|
226
|
-
type: 'property_access',
|
|
227
|
-
id: {
|
|
228
|
-
inferred: 'map',
|
|
229
|
-
lexeme: '__module'
|
|
230
|
-
},
|
|
231
|
-
propertyPath: [{ lexeme: 'test' }],
|
|
232
|
-
propertyPathTypes: [{ name: 'test' }],
|
|
233
|
-
needCast: true
|
|
234
|
-
});
|
|
235
|
-
expect(grammerValue.type).to.be.eql('behavior');
|
|
236
|
-
|
|
237
|
-
grammerValue = code.renderGrammerValue(null, {
|
|
238
|
-
type: 'object',
|
|
239
|
-
fields: [
|
|
240
|
-
{ expr: { type: 'object', fields: [{ expr: { type: 'null' } }] } }
|
|
241
|
-
]
|
|
242
|
-
});
|
|
243
|
-
expect(grammerValue.type).to.be.eql('array');
|
|
244
|
-
|
|
245
|
-
mm.restore();
|
|
246
|
-
});
|
|
247
|
-
|
|
248
|
-
it('visitStmt should be ok', function () {
|
|
249
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
250
|
-
package: 'test', model: { dir: 'Models' }
|
|
251
|
-
}), {});
|
|
252
|
-
const code = new ClientResolver({}, combinator, {});
|
|
253
|
-
const obj = new BehaviorDoAction();
|
|
254
|
-
|
|
255
|
-
expect(function () {
|
|
256
|
-
code.visitStmt(obj, {});
|
|
257
|
-
}).to.be.throw('');
|
|
258
|
-
expect(console.log.calledWith({})).to.be.true;
|
|
259
|
-
|
|
260
|
-
let stmt = { type: 'while', condition: [{}] };
|
|
261
|
-
mm(code, 'renderGrammerValue', function () {
|
|
262
|
-
return new GrammerValue('string', 'test');
|
|
263
|
-
});
|
|
264
|
-
code.visitStmt(obj, stmt);
|
|
265
|
-
expect(obj.body.length).to.be.eql(1);
|
|
266
|
-
|
|
267
|
-
stmt = { type: 'virtualCall' };
|
|
268
|
-
code.visitStmt(obj, stmt);
|
|
269
|
-
expect(obj.body.length).to.be.eql(2);
|
|
270
|
-
|
|
271
|
-
stmt = { type: 'throw', expr: [{}] };
|
|
272
|
-
mm(code.combinator, 'addInclude', function (className) {
|
|
273
|
-
return className;
|
|
274
|
-
});
|
|
275
|
-
code.visitStmt(obj, stmt);
|
|
276
|
-
expect(obj.body.length).to.be.eql(3);
|
|
277
|
-
|
|
278
|
-
stmt = { type: 'elseIfRequestAssign' };
|
|
279
|
-
mm(code, 'visitIfElse', function () { return 'visitIfElse'; });
|
|
280
|
-
code.visitStmt(obj, stmt);
|
|
281
|
-
expect(obj.body.length).to.be.eql(4);
|
|
282
|
-
|
|
283
|
-
stmt = {
|
|
284
|
-
type: 'requestAssign',
|
|
285
|
-
left: {
|
|
286
|
-
id: { lexeme: 'test' },
|
|
287
|
-
}
|
|
288
|
-
};
|
|
289
|
-
code.predefined = {
|
|
290
|
-
'$Request': {
|
|
291
|
-
modelBody: { nodes: [{ fieldName: { lexeme: 'test' }, fieldValue: '' }] }
|
|
292
|
-
}
|
|
293
|
-
};
|
|
294
|
-
code.visitStmt(obj, stmt);
|
|
295
|
-
expect(obj.body.length).to.be.eql(5);
|
|
296
|
-
|
|
297
|
-
stmt = {
|
|
298
|
-
type: 'requestAssign',
|
|
299
|
-
left: {
|
|
300
|
-
type: 'request_property_assign',
|
|
301
|
-
id: { lexeme: 'test' },
|
|
302
|
-
propertyPath: [{ lexeme: 'a' }, { lexeme: 'b' }]
|
|
303
|
-
}
|
|
304
|
-
};
|
|
305
|
-
code.visitStmt(obj, stmt);
|
|
306
|
-
expect(obj.body.length).to.be.eql(6);
|
|
307
|
-
mm.restore();
|
|
308
|
-
});
|
|
309
|
-
|
|
310
|
-
it('visitIfConfition should be ok', function () {
|
|
311
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
312
|
-
package: 'test', model: { dir: 'Models' }
|
|
313
|
-
}), {});
|
|
314
|
-
const code = new ClientResolver({}, combinator, {});
|
|
315
|
-
const stmtCondition = { left: {}, type: 'invalid' };
|
|
316
|
-
expect(function () {
|
|
317
|
-
code.visitIfConfition(stmtCondition);
|
|
318
|
-
}).to.be.throw('');
|
|
319
|
-
expect(console.log.calledWith(stmtCondition)).to.be.true;
|
|
320
|
-
|
|
321
|
-
stmtCondition.type = 'call';
|
|
322
|
-
mm(code, 'renderGrammerValue', function () {
|
|
323
|
-
return 'render grammer value';
|
|
324
|
-
});
|
|
325
|
-
expect(code.visitIfConfition(stmtCondition)).to.be.eql('render grammer value');
|
|
326
|
-
|
|
327
|
-
stmtCondition.type = 'not';
|
|
328
|
-
expect(code.visitIfConfition(stmtCondition).opt).to.be.eql('NOT');
|
|
329
|
-
mm.restore();
|
|
330
|
-
});
|
|
331
|
-
|
|
332
|
-
it('visitIfElse should be ok', function () {
|
|
333
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
334
|
-
package: 'test', model: { dir: 'Models' }
|
|
335
|
-
}), {});
|
|
336
|
-
const code = new ClientResolver({}, combinator, {});
|
|
337
|
-
expect(function () {
|
|
338
|
-
code.visitIfElse({});
|
|
339
|
-
}).to.be.throw('');
|
|
340
|
-
expect(console.log.calledWith({})).to.be.true;
|
|
341
|
-
|
|
342
|
-
let stmt = { stmts: [] };
|
|
343
|
-
expect(function () {
|
|
344
|
-
code.visitIfElse(stmt);
|
|
345
|
-
}).to.be.throw('');
|
|
346
|
-
expect(console.log.calledWith(stmt)).to.be.true;
|
|
347
|
-
|
|
348
|
-
stmt = {
|
|
349
|
-
stmts: { type: 'stmts', stmts: [{ type: 'return', expr: { type: 'null' } }] },
|
|
350
|
-
elseAssigns: [{ stmts: { type: 'stmts', stmts: [{ type: 'return', expr: { type: 'null' } }] } }]
|
|
351
|
-
};
|
|
352
|
-
const grammer = code.visitIfElse(stmt);
|
|
353
|
-
expect(grammer.elseItem.length).to.be.eql(1);
|
|
354
|
-
});
|
|
355
|
-
});
|
|
356
|
-
|
|
357
|
-
describe('model resolver should be ok', function () {
|
|
358
|
-
it('resolve should be ok', function () {
|
|
359
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
360
|
-
package: 'test', model: { dir: 'Models' }
|
|
361
|
-
}), {});
|
|
362
|
-
const model = new ModelResolver({
|
|
363
|
-
type: 'model',
|
|
364
|
-
modelName: { lexeme: 'test' },
|
|
365
|
-
modelBody: { nodes: [] },
|
|
366
|
-
tokenRange: [1, 100]
|
|
367
|
-
}, combinator, {});
|
|
368
|
-
mm(model, 'initAnnotation', function () { return; });
|
|
369
|
-
mm(model.combinator, 'addInclude', function (modelName) { return modelName; });
|
|
370
|
-
mm(model, 'initProp', function () { return; });
|
|
371
|
-
mm(model, 'resolveAnnotations', function () { return [new AnnotationItem()]; });
|
|
372
|
-
mm(model, 'getBetweenComments', function () { return; });
|
|
373
|
-
model.resolve();
|
|
374
|
-
expect(model.object.body.length).to.be.eql(1);
|
|
375
|
-
});
|
|
376
|
-
|
|
377
|
-
it('initProp should be ok', function () {
|
|
378
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
379
|
-
package: 'test', model: { dir: 'Models' }
|
|
380
|
-
}), {});
|
|
381
|
-
const model = new ModelResolver({}, combinator, {});
|
|
382
|
-
expect(function () {
|
|
383
|
-
model.initProp([{
|
|
384
|
-
fieldValue: {
|
|
385
|
-
fieldType: null
|
|
386
|
-
}
|
|
387
|
-
}]);
|
|
388
|
-
}).to.be.throw('');
|
|
389
|
-
|
|
390
|
-
mm(model.combinator, 'addModelInclude', function (modelName) {
|
|
391
|
-
expect(modelName).to.be.eql('a');
|
|
392
|
-
});
|
|
393
|
-
model.initProp([{
|
|
394
|
-
fieldValue: {
|
|
395
|
-
type: 'fieldType',
|
|
396
|
-
fieldType: { type: 'moduleModel', path: [{ lexeme: 'a' }] }
|
|
397
|
-
},
|
|
398
|
-
fieldName: {
|
|
399
|
-
lexeme: 'test'
|
|
400
|
-
},
|
|
401
|
-
attrs: [{ attrValue: { value: 'test' }, attrName: { lexeme: 'name' } }]
|
|
402
|
-
}]);
|
|
403
|
-
mm.restore();
|
|
404
|
-
mm(model, 'findSubModelsUsed', function () {
|
|
405
|
-
return;
|
|
406
|
-
});
|
|
407
|
-
model.initProp([{
|
|
408
|
-
type: 'modelField',
|
|
409
|
-
fieldValue: { type: 'fieldType', fieldType: 'array', fieldItemType: { lexeme: 'string' } },
|
|
410
|
-
fieldName: { lexeme: 'test' },
|
|
411
|
-
attrs: []
|
|
412
|
-
}]);
|
|
413
|
-
expect(model.object.body.filter(item => item instanceof PropItem).length).to.be.eql(2);
|
|
414
|
-
mm.restore();
|
|
415
|
-
});
|
|
416
|
-
|
|
417
|
-
it('findSubModelsUsed should be ok', function () {
|
|
418
|
-
const combinator = new Combinator(Object.assign(_deepClone(config), {
|
|
419
|
-
package: 'test', model: { dir: 'Models' }
|
|
420
|
-
}), {});
|
|
421
|
-
const model = new ModelResolver({}, combinator, {});
|
|
422
|
-
const subModelUsed = [];
|
|
423
|
-
model.findSubModelsUsed({
|
|
424
|
-
fieldName: { lexeme: 'test' },
|
|
425
|
-
fieldValue: {
|
|
426
|
-
nodes: [{
|
|
427
|
-
fieldValue: { nodes: [] },
|
|
428
|
-
fieldName: { lexeme: 'foo' },
|
|
429
|
-
}]
|
|
430
|
-
}
|
|
431
|
-
}, subModelUsed);
|
|
432
|
-
expect(subModelUsed.length).to.be.eql(2);
|
|
433
|
-
});
|
|
434
|
-
});
|