@darabonba/python-generator 1.2.19 → 2.0.0

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.
Files changed (129) hide show
  1. package/ChangeLog.md +0 -158
  2. package/lib/builtin.js +818 -0
  3. package/lib/generator.js +2704 -0
  4. package/lib/helper.js +422 -0
  5. package/package.json +6 -5
  6. package/tests/expected/alias/setup.py +79 -0
  7. package/tests/expected/alias/tea_python_tests/__init__.py +1 -0
  8. package/tests/expected/alias/tea_python_tests/client.py +35 -0
  9. package/tests/expected/annotation/tea_python_tests/__init__.py +1 -0
  10. package/tests/expected/annotation/tea_python_tests/client.py +93 -0
  11. package/tests/expected/annotation/tea_python_tests/models.py +37 -0
  12. package/tests/expected/api/tea_python_tests/__init__.py +1 -0
  13. package/tests/expected/api/tea_python_tests/client.py +106 -0
  14. package/tests/expected/builtin/tea_python_tests/client.py +685 -0
  15. package/tests/expected/comment/tea_python_tests/__init__.py +1 -0
  16. package/tests/expected/comment/tea_python_tests/client.py +288 -0
  17. package/tests/expected/comment/tea_python_tests/models.py +195 -0
  18. package/tests/expected/complex/tea_python_tests/__init__.py +1 -0
  19. package/tests/expected/complex/tea_python_tests/client.py +1168 -0
  20. package/tests/expected/complex/tea_python_tests/exceptions.py +39 -0
  21. package/tests/expected/complex/tea_python_tests/models.py +570 -0
  22. package/tests/expected/const/tea_python_tests/__init__.py +1 -0
  23. package/tests/expected/const/tea_python_tests/client.py +14 -0
  24. package/tests/expected/empty/setup.py +74 -0
  25. package/tests/expected/empty/tea_python_tests/__init__.py +1 -0
  26. package/tests/expected/empty/tea_python_tests/client.py +10 -0
  27. package/tests/expected/exec/tea_python_tests/__init__.py +1 -0
  28. package/tests/expected/exec/tea_python_tests/exec_client.py +21 -0
  29. package/tests/expected/function/tea_python_tests/__init__.py +1 -0
  30. package/tests/expected/function/tea_python_tests/client.py +64 -0
  31. package/tests/expected/import/setup.py +78 -0
  32. package/tests/expected/import/tea_python_tests/__init__.py +1 -0
  33. package/tests/expected/import/tea_python_tests/client.py +29 -0
  34. package/tests/expected/map/tea_python_tests/__init__.py +1 -0
  35. package/tests/expected/map/tea_python_tests/client.py +39 -0
  36. package/tests/expected/model/tea_python_tests/__init__.py +1 -0
  37. package/tests/expected/model/tea_python_tests/client.py +10 -0
  38. package/tests/expected/model/tea_python_tests/exceptions.py +28 -0
  39. package/tests/expected/model/tea_python_tests/models.py +780 -0
  40. package/tests/expected/multi/tea_python_tests/api.py +95 -0
  41. package/tests/expected/multi/tea_python_tests/client.py +40 -0
  42. package/tests/expected/multi/tea_python_tests/lib/util.py +19 -0
  43. package/tests/expected/multi/tea_python_tests/model/user.py +23 -0
  44. package/tests/expected/multi/tea_python_tests/model/user_exceptions.py +83 -0
  45. package/tests/expected/multi/tea_python_tests/model/user_models.py +145 -0
  46. package/tests/expected/statements/tea_python_tests/__init__.py +1 -0
  47. package/tests/expected/statements/tea_python_tests/client.py +86 -0
  48. package/tests/expected/super/tea_python_tests/__init__.py +1 -0
  49. package/tests/expected/super/tea_python_tests/client.py +16 -0
  50. package/tests/expected/typedef/setup.py +77 -0
  51. package/tests/expected/typedef/tea_python_tests/__init__.py +1 -0
  52. package/tests/expected/typedef/tea_python_tests/client.py +74 -0
  53. package/tests/expected/typedef/tea_python_tests/models.py +42 -0
  54. package/tests/fixtures/alias/Darafile +11 -0
  55. package/tests/fixtures/alias/libraries/Alias/Darafile +11 -0
  56. package/tests/fixtures/alias/libraries/Alias-Symbol/Darafile +11 -0
  57. package/tests/fixtures/builtin/Darafile +6 -0
  58. package/tests/fixtures/builtin/main.dara +333 -0
  59. package/tests/fixtures/complex/libraries/import.dara +18 -11
  60. package/tests/fixtures/complex/main.dara +451 -103
  61. package/tests/fixtures/import/libraries/Darafile +1 -1
  62. package/tests/fixtures/import/pack/Darafile +3 -0
  63. package/tests/fixtures/map/libraries/Darafile +3 -0
  64. package/tests/fixtures/map/libraries/import.dara +4 -0
  65. package/tests/fixtures/map/main.dara +17 -2
  66. package/tests/fixtures/model/.libraries.json +3 -0
  67. package/tests/fixtures/model/Darafile +5 -2
  68. package/tests/fixtures/model/libraries/Darafile +20 -0
  69. package/tests/fixtures/model/libraries/import.dara +27 -0
  70. package/tests/fixtures/model/main.dara +60 -42
  71. package/tests/fixtures/multi/.libraries.json +3 -0
  72. package/tests/fixtures/multi/Darafile +12 -0
  73. package/tests/fixtures/multi/api.dara +20 -0
  74. package/tests/fixtures/multi/lib/util.dara +5 -0
  75. package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/Teafile +62 -0
  76. package/tests/fixtures/multi/libraries/darabonba_Util_0.2.11/main.tea +244 -0
  77. package/tests/fixtures/multi/main.dara +32 -0
  78. package/tests/fixtures/multi/model/user.dara +33 -0
  79. package/tests/{python3.tests.js → main.tests.js} +107 -65
  80. package/tests/output/alias/setup.py +79 -0
  81. package/tests/output/alias/tea_python_tests/client.py +35 -0
  82. package/tests/output/annotation/setup.py +77 -0
  83. package/tests/output/annotation/tea_python_tests/client.py +93 -0
  84. package/tests/output/annotation/tea_python_tests/models.py +37 -0
  85. package/tests/output/api/setup.py +77 -0
  86. package/tests/output/api/tea_python_tests/client.py +106 -0
  87. package/tests/output/builtin/setup.py +77 -0
  88. package/tests/output/builtin/tea_python_tests/client.py +685 -0
  89. package/tests/output/comment/setup.py +77 -0
  90. package/tests/output/comment/tea_python_tests/client.py +288 -0
  91. package/tests/output/comment/tea_python_tests/models.py +195 -0
  92. package/tests/output/complex/setup.py +77 -0
  93. package/tests/output/complex/tea_python_tests/client.py +1168 -0
  94. package/tests/output/complex/tea_python_tests/exceptions.py +39 -0
  95. package/tests/output/complex/tea_python_tests/models.py +570 -0
  96. package/tests/output/const/setup.py +77 -0
  97. package/tests/output/const/tea_python_tests/client.py +14 -0
  98. package/tests/output/empty/setup.py +77 -0
  99. package/tests/output/empty/tea_python_tests/client.py +10 -0
  100. package/tests/output/exec/setup.py +77 -0
  101. package/tests/output/exec/tea_python_tests/exec_client.py +21 -0
  102. package/tests/output/function/setup.py +77 -0
  103. package/tests/output/function/tea_python_tests/client.py +64 -0
  104. package/tests/output/import/setup.py +78 -0
  105. package/tests/output/import/tea_python_tests/client.py +29 -0
  106. package/tests/output/map/setup.py +77 -0
  107. package/tests/output/map/tea_python_tests/client.py +39 -0
  108. package/tests/output/model/setup.py +77 -0
  109. package/tests/output/model/tea_python_tests/client.py +10 -0
  110. package/tests/output/model/tea_python_tests/exceptions.py +28 -0
  111. package/tests/output/model/tea_python_tests/models.py +780 -0
  112. package/tests/output/multi/setup.py +77 -0
  113. package/tests/output/multi/tea_python_tests/api.py +95 -0
  114. package/tests/output/multi/tea_python_tests/client.py +40 -0
  115. package/tests/output/multi/tea_python_tests/lib/util.py +19 -0
  116. package/tests/output/multi/tea_python_tests/model/user.py +23 -0
  117. package/tests/output/multi/tea_python_tests/model/user_exceptions.py +83 -0
  118. package/tests/output/multi/tea_python_tests/model/user_models.py +145 -0
  119. package/tests/output/statements/setup.py +77 -0
  120. package/tests/output/statements/tea_python_tests/client.py +86 -0
  121. package/tests/output/super/setup.py +77 -0
  122. package/tests/output/super/tea_python_tests/client.py +16 -0
  123. package/tests/output/typedef/setup.py +78 -0
  124. package/tests/output/typedef/tea_python_tests/client.py +74 -0
  125. package/tests/output/typedef/tea_python_tests/models.py +42 -0
  126. package/tests/common.tests.js +0 -244
  127. package/tests/lib.tests.js +0 -269
  128. package/tests/python2.tests.js +0 -283
  129. package/tests/resolver.tests.js +0 -434
@@ -0,0 +1,77 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Licensed to the Apache Software Foundation (ASF) under one
4
+ or more contributor license agreements. See the NOTICE file
5
+ distributed with this work for additional information
6
+ regarding copyright ownership. The ASF licenses this file
7
+ to you under the Apache License, Version 2.0 (the
8
+ "License"); you may not use this file except in compliance
9
+ with the License. You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing,
14
+ software distributed under the License is distributed on an
15
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ KIND, either express or implied. See the License for the
17
+ specific language governing permissions and limitations
18
+ under the License.
19
+ """
20
+
21
+ import os
22
+ from setuptools import setup, find_packages
23
+
24
+ """
25
+ setup module for tea_python_tests.
26
+
27
+ Created on *
28
+
29
+ @author: Alibaba
30
+ """
31
+
32
+ PACKAGE = "tea_python_tests"
33
+ NAME = "tea_python_tests"
34
+ DESCRIPTION = ""
35
+ AUTHOR = "Alibaba"
36
+ AUTHOR_EMAIL = "sdk-team@alibabacloud.com"
37
+ URL = "https://github.com/"
38
+ VERSION = __import__(PACKAGE).__version__
39
+ REQUIRES = [
40
+ "darabonba-core>=1.0.0, <2.0.0",
41
+
42
+ ]
43
+
44
+ LONG_DESCRIPTION = ''
45
+ if os.path.exists('./README.md'):
46
+ with open("README.md", encoding='utf-8') as fp:
47
+ LONG_DESCRIPTION = fp.read()
48
+
49
+ setup(
50
+ name=NAME,
51
+ version=VERSION,
52
+ description=DESCRIPTION,
53
+ long_description=LONG_DESCRIPTION,
54
+ long_description_content_type='text/markdown',
55
+ author=AUTHOR,
56
+ author_email=AUTHOR_EMAIL,
57
+ license="Apache License 2.0",
58
+ url=URL,
59
+ keywords=["tea","python","tests"],
60
+ packages=find_packages(exclude=["tests*"]),
61
+ include_package_data=True,
62
+ platforms="any",
63
+ install_requires=REQUIRES,
64
+ python_requires=">=3.6",
65
+ classifiers=(
66
+ "Development Status :: 4 - Beta",
67
+ "Intended Audience :: Developers",
68
+ "License :: OSI Approved :: Apache Software License",
69
+ "Programming Language :: Python",
70
+ "Programming Language :: Python :: 3",
71
+ "Programming Language :: Python :: 3.6",
72
+ "Programming Language :: Python :: 3.7",
73
+ "Programming Language :: Python :: 3.8",
74
+ "Programming Language :: Python :: 3.9",
75
+ "Topic :: Software Development"
76
+ )
77
+ )
@@ -0,0 +1,16 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is auto-generated, don't edit it. Thanks.
3
+ from __future__ import annotations
4
+ from Source.source_client import SourceClient
5
+ from Source import models as source_models
6
+
7
+
8
+
9
+
10
+ class Client(SourceClient):
11
+
12
+ def __init__(
13
+ self,
14
+ config: source_models.Config,
15
+ ):
16
+ super().__init__(config)
@@ -0,0 +1,78 @@
1
+ # -*- coding: utf-8 -*-
2
+ """
3
+ Licensed to the Apache Software Foundation (ASF) under one
4
+ or more contributor license agreements. See the NOTICE file
5
+ distributed with this work for additional information
6
+ regarding copyright ownership. The ASF licenses this file
7
+ to you under the Apache License, Version 2.0 (the
8
+ "License"); you may not use this file except in compliance
9
+ with the License. You may obtain a copy of the License at
10
+
11
+ http://www.apache.org/licenses/LICENSE-2.0
12
+
13
+ Unless required by applicable law or agreed to in writing,
14
+ software distributed under the License is distributed on an
15
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16
+ KIND, either express or implied. See the License for the
17
+ specific language governing permissions and limitations
18
+ under the License.
19
+ """
20
+
21
+ import os
22
+ from setuptools import setup, find_packages
23
+
24
+ """
25
+ setup module for tea_python_tests.
26
+
27
+ Created on *
28
+
29
+ @author: Alibaba
30
+ """
31
+
32
+ PACKAGE = "tea_python_tests"
33
+ NAME = "tea_python_tests"
34
+ DESCRIPTION = ""
35
+ AUTHOR = "Alibaba"
36
+ AUTHOR_EMAIL = "sdk-team@alibabacloud.com"
37
+ URL = "https://github.com/"
38
+ VERSION = __import__(PACKAGE).__version__
39
+ REQUIRES = [
40
+ "darabonba-core>=1.0.0, <2.0.0",
41
+ "requests>=2.21.0, <3.0.0",
42
+ "alibabacloud-tea>=0.2.9, <1.0.0"
43
+ ]
44
+
45
+ LONG_DESCRIPTION = ''
46
+ if os.path.exists('./README.md'):
47
+ with open("README.md", encoding='utf-8') as fp:
48
+ LONG_DESCRIPTION = fp.read()
49
+
50
+ setup(
51
+ name=NAME,
52
+ version=VERSION,
53
+ description=DESCRIPTION,
54
+ long_description=LONG_DESCRIPTION,
55
+ long_description_content_type='text/markdown',
56
+ author=AUTHOR,
57
+ author_email=AUTHOR_EMAIL,
58
+ license="Apache License 2.0",
59
+ url=URL,
60
+ keywords=["tea","python","tests"],
61
+ packages=find_packages(exclude=["tests*"]),
62
+ include_package_data=True,
63
+ platforms="any",
64
+ install_requires=REQUIRES,
65
+ python_requires=">=3.6",
66
+ classifiers=(
67
+ "Development Status :: 4 - Beta",
68
+ "Intended Audience :: Developers",
69
+ "License :: OSI Approved :: Apache Software License",
70
+ "Programming Language :: Python",
71
+ "Programming Language :: Python :: 3",
72
+ "Programming Language :: Python :: 3.6",
73
+ "Programming Language :: Python :: 3.7",
74
+ "Programming Language :: Python :: 3.8",
75
+ "Programming Language :: Python :: 3.9",
76
+ "Topic :: Software Development"
77
+ )
78
+ )
@@ -0,0 +1,74 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is auto-generated, don't edit it. Thanks.
3
+ from __future__ import annotations
4
+ from requests import Request
5
+ from Tea.model import TeaModel
6
+ from Source.source_client import SourceClient
7
+ from tea_python_tests import models as main_models
8
+ from requests import Response
9
+ from typing import Dict, Any
10
+
11
+
12
+ class Client:
13
+ _vid: Request = None
14
+ _model: TeaModel = None
15
+
16
+ def __init__(
17
+ self,
18
+ request: Request,
19
+ model: TeaModel,
20
+ ):
21
+ self._vid = request
22
+ self._model = model
23
+
24
+ def main(
25
+ self,
26
+ test_1: Request,
27
+ test_2: TeaModel,
28
+ ) -> None:
29
+ oss = SourceClient(test_1)
30
+ m = main_models.M(
31
+ a = test_1,
32
+ b = test_2
33
+ )
34
+ self._vid = test_1
35
+ self._model = test_2
36
+
37
+ async def main_async(
38
+ self,
39
+ test_1: Request,
40
+ test_2: TeaModel,
41
+ ) -> None:
42
+ oss = SourceClient(test_1)
43
+ m = main_models.M(
44
+ a = test_1,
45
+ b = test_2
46
+ )
47
+ self._vid = test_1
48
+ self._model = test_2
49
+
50
+ def test_http_request(
51
+ self,
52
+ req: Request,
53
+ ) -> Response:
54
+ return self.test_http_request_with('test', req)
55
+
56
+ async def test_http_request_async(
57
+ self,
58
+ req: Request,
59
+ ) -> Response:
60
+ return self.test_http_request_with('test', req)
61
+
62
+ @staticmethod
63
+ def test_http_request_with(
64
+ method: str,
65
+ req: Request,
66
+ ) -> Response:
67
+ raise Exception('Un-implemented')
68
+
69
+ @staticmethod
70
+ def test_http_header(
71
+ method: str,
72
+ headers: Dict[str, Any],
73
+ ) -> Response:
74
+ raise Exception('Un-implemented')
@@ -0,0 +1,42 @@
1
+ # -*- coding: utf-8 -*-
2
+ # This file is auto-generated, don't edit it. Thanks.
3
+ from __future__ import annotations
4
+ from darabonba.model import DaraModel
5
+ from requests import Request
6
+ from Tea.model import TeaModel
7
+
8
+
9
+
10
+
11
+ class M(DaraModel):
12
+ def __init__(
13
+ self,
14
+ a: Request = None,
15
+ b: TeaModel = None,
16
+ ):
17
+ self.a = a
18
+ self.b = b
19
+
20
+ def validate(self):
21
+ pass
22
+
23
+ def to_map(self):
24
+ _map = super().to_map()
25
+ if _map is not None:
26
+ return _map
27
+
28
+ result = dict()
29
+ if self.a is not None:
30
+ result['a'] = self.a
31
+ if self.b is not None:
32
+ result['b'] = self.b
33
+ return result
34
+
35
+ def from_map(self, m: dict = None):
36
+ m = m or dict()
37
+ if m.get('a') is not None:
38
+ self.a = m.get('a')
39
+ if m.get('b') is not None:
40
+ self.b = m.get('b')
41
+ return self
42
+
@@ -1,244 +0,0 @@
1
- 'use strict';
2
-
3
- const fs = require('fs');
4
- const mm = require('mm');
5
- const expect = require('chai').expect;
6
- require('mocha-sinon');
7
-
8
- const {
9
- Symbol,
10
- Modify
11
- } = require('../src/langs/common/enum');
12
-
13
- const {
14
- Counter,
15
- Grammer,
16
- GrammerCall,
17
- GrammerValue,
18
- GrammerSymbol,
19
- GrammerThrows,
20
- GrammerNewLine,
21
- GrammerCondition,
22
- NoteItem,
23
- ObjectItem,
24
- } = require('../src/langs/common/items');
25
-
26
- const PackageInfo = require('../src/langs/common/package_info');
27
-
28
- const Combinator = require('../src/langs/common/combinator');
29
- const Emitter = require('../src/lib/emitter');
30
-
31
- describe('common tests', function () {
32
- beforeEach(function () {
33
- this.sinon.stub(console, 'log');
34
- });
35
-
36
- it('enum should be ok', function () {
37
- // test Symbol enum
38
- expect(Symbol.eq()).to.be.eql('EQ');
39
- expect(Symbol.not()).to.be.eql('NOT');
40
- expect(Symbol.multi()).to.be.eql('MULTI');
41
- expect(Symbol.div()).to.be.eql('DIV');
42
- expect(Symbol.power()).to.be.eql('POWER');
43
- expect(Symbol.greaterEq()).to.be.eql('GREATER_EQ');
44
- expect(Symbol.less()).to.be.eql('LESS');
45
- expect(Symbol.lessEq()).to.be.eql('LESS_EQ');
46
- expect(Symbol.judge()).to.be.eql('JUDGE');
47
- expect(Symbol.risk()).to.be.eql('RISK');
48
-
49
- // test Modify enum
50
- expect(Modify.private()).to.be.eql('PRIVATE');
51
- expect(Modify.internal()).to.be.eql('INTERNAL');
52
- expect(Modify.final()).to.be.eql('FINAL');
53
- expect(Modify.abstract()).to.be.eql('ABSTRACT');
54
- });
55
-
56
- it('counter should be ok', function () {
57
- const counter = new Counter(-2);
58
- expect(counter.index).to.be.eql(-2);
59
- counter.step(2, 10);
60
- expect(counter.index).to.be.eql(18);
61
- counter.once();
62
- expect(counter.index).to.be.eql(19);
63
- });
64
-
65
- it('items : Item.getItemByIndex&getParent should be ok', function () {
66
- const parentGrammer = new Grammer();
67
- const childGrammer = new GrammerNewLine();
68
- const childGrammer2 = new GrammerSymbol();
69
- childGrammer.belong = parentGrammer.index;
70
-
71
- expect(function () {
72
- childGrammer.getItemByIndex(-100);
73
- }).to.be.throw('Index [-100] not exist in ItemSet');
74
-
75
- expect(childGrammer.getItemByIndex(parentGrammer.index)).to.be.eql(parentGrammer);
76
- expect(childGrammer.getParent()).to.be.eql(parentGrammer);
77
- expect(childGrammer2.getParent()).to.be.eql(parentGrammer);
78
- });
79
-
80
- it('items : GrammerCall.addPath should be ok', function () {
81
- const call = new GrammerCall();
82
- expect(function () {
83
- call.addPath({ type: 'invalid-type' });
84
- }).to.be.throw('invalid-type path.type should be parent|object|object_static|call|call_static|prop|prop_static|map|list');
85
- });
86
-
87
- it('items : NoteItem should be ok', function () {
88
- let noteItem = new NoteItem('', null);
89
- expect(noteItem.type).to.be.eql('null');
90
- expect(function () {
91
- noteItem = new NoteItem('', {});
92
- }).to.be.throw('Not suppoted type : object [number,string,boolean]');
93
- });
94
-
95
- it('items : ObjectItem should be ok', function () {
96
- const objectItem = new ObjectItem('client');
97
- expect(function () {
98
- objectItem.addBodyNode(null);
99
- }).to.be.throw('Only suppoted PropItem | FuncItem | ObjectItem | AnnotationItem | ConstructItem');
100
- objectItem.addModify(Modify.private());
101
- expect(objectItem.modify.indexOf('PRIVATE') !== -1).to.be.true;
102
- });
103
-
104
- it('package_info : render should be ok', function () {
105
- const packageInfo = new PackageInfo();
106
- expect(
107
- packageInfo.render('${key}', { key: 'render-key' })
108
- ).to.be.eql('render-key');
109
- });
110
-
111
- it('package_info : checkParams should be ok', function () {
112
- const packageInfo = new PackageInfo();
113
- const param = { key: 'value' };
114
- packageInfo.checkParams(param);
115
- try {
116
- packageInfo.checkParams(param, ['someRequeiredKey']);
117
- } catch (e) {
118
- expect(e.message).to.be.eql('need config packageInfo.someRequeiredKey');
119
- expect(console.log.calledWith(param)).to.be.true;
120
- }
121
- });
122
-
123
- it('package_info : renderAuto should be ok', function () {
124
- const packageInfo = new PackageInfo();
125
- mm(fs, 'readFileSync', function (filename) {
126
- return '${key}';
127
- });
128
- mm(fs, 'existsSync', function (filename) {
129
- return true;
130
- });
131
- mm(fs, 'writeFileSync', function (filename, content) {
132
- return true;
133
- });
134
- // not throw exception
135
- packageInfo.renderAuto('/tmp/template-file-path.tmpl', '/tmp/target-path.tmp', { key: 'RenderAutoKey' });
136
-
137
- mm(fs, 'existsSync', function (filename) {
138
- return false;
139
- });
140
- mm(fs, 'mkdirSync', function (filename) {
141
- return true;
142
- });
143
- // not throw exception
144
- packageInfo.renderAuto('/tmp/template-file-path.tmpl', '/tmp/target-path.tmp', { key: 'RenderAutoKey' });
145
- });
146
-
147
- it('package_info : resolveOutputDir should be ok', function () {
148
- const packageInfo = new PackageInfo();
149
- packageInfo.config = { dir: '/tmp/' };
150
- expect(packageInfo.resolveOutputDir({ outputDir: null }, './')).to.be.eql('/tmp/');
151
-
152
- mm(fs, 'existsSync', function (filename) {
153
- return false;
154
- });
155
- expect(packageInfo.resolveOutputDir({ outputDir: 'output/' }, './')).to.be.eql('/tmp/output/');
156
- mm.restore();
157
- });
158
-
159
- it('combinator : coreClass should be ok', function () {
160
- const combinator = new Combinator({ tea: {} });
161
- expect(function () {
162
- combinator.coreClass('test');
163
- }).to.be.throw('Unsupported core class name : test');
164
- });
165
-
166
- it('combinator : findThrows should be ok', function () {
167
- const combinator = new Combinator();
168
- const grammer = new GrammerCondition();
169
- expect(combinator.findThrows(grammer).length).to.be.eql(0);
170
- grammer.addBodyNode(new GrammerThrows());
171
- expect(combinator.findThrows(grammer).length).to.be.eql(1);
172
- const childGrammer = new GrammerCondition();
173
- childGrammer.addBodyNode(new GrammerThrows());
174
- grammer.addBodyNode(childGrammer);
175
- expect(combinator.findThrows(grammer).length).to.be.eql(2);
176
- });
177
-
178
- it('combinator : unimpelemented should be ok', function () {
179
- const combinator = new Combinator();
180
- expect(function () {
181
- combinator.init({});
182
- }).to.be.throw('unimpelemented');
183
- expect(function () {
184
- combinator.addModelInclude('foo');
185
- }).to.be.throw('unimpelemented');
186
- expect(function () {
187
- combinator.addInclude('foo');
188
- }).to.be.throw('unimpelemented');
189
- });
190
-
191
- it('combinator : systemfunc should be ok', function () {
192
- const combinator = new Combinator();
193
- const emitter = new Emitter();
194
- const gram = new GrammerCall();
195
- expect(function () {
196
- combinator.systemfunc(emitter, gram);
197
- }).to.be.throw('Invalid path. path list cannot be empty.');
198
- gram.addPath({ type: 'call', name: 'test' });
199
- expect(function () {
200
- combinator.systemfunc(emitter, gram);
201
- }).to.be.throw('unimpelemented sysTest(emitter, gram){} method\n');
202
-
203
- combinator.sysTest = function () {
204
- console.log('test call combinator.sysTest');
205
- return true;
206
- };
207
- combinator.systemfunc(emitter, gram);
208
- expect(console.log.calledWith('test call combinator.sysTest')).to.be.true;
209
- });
210
-
211
- it('combinator : grammerNewLine should be ok', function () {
212
- const combinator = new Combinator();
213
- const emitter = new Emitter();
214
- emitter.output = '';
215
- const grammerNewLine = new GrammerNewLine(2);
216
- combinator.grammerNewLine(emitter, grammerNewLine);
217
- expect(emitter.output).to.be.eql(emitter.eol + emitter.eol);
218
- });
219
-
220
- it('combinator : emitGrammerValue should be ok', function () {
221
- const combinator = new Combinator();
222
- combinator.grammerValue = function (emitter) {
223
- emitter.emit('test');
224
- };
225
- const grammerValue = new GrammerValue();
226
- expect(combinator.emitGrammerValue(grammerValue)).to.be.eql('test');
227
- });
228
-
229
- it('combinator : grammer should be ok', function () {
230
- const combinator = new Combinator();
231
- const emitter = new Emitter();
232
-
233
- emitter.output = '';
234
- const obj = new ObjectItem('client');
235
- expect(function () {
236
- combinator.grammer(emitter, obj);
237
- }).to.be.throw('Unsupported');
238
- expect(console.log.calledWith(obj)).to.be.true;
239
-
240
- expect(function () {
241
- combinator.grammer(emitter, new GrammerCondition());
242
- }).to.be.throw('Unimpelemented : grammerCondition');
243
- });
244
- });