@needle-tools/needle-component-compiler 1.9.3 → 1.10.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.
- package/Changelog.md +8 -0
- package/package.json +1 -1
- package/src/component-compiler.js +40 -16
- package/src/component-compiler.ts +32 -7
- package/src/types.js +1 -1
- package/COMPILE.bat +0 -1
- package/DEV.bat +0 -1
- package/INSTALL.bat +0 -1
- package/PUBLISH.bat +0 -8
- package/RUN_MANUAL_TEST.bat +0 -1
- package/RUN_TESTS.bat +0 -1
- package/src/test.js +0 -194
- package/src/test.ts +0 -234
- package/test/component.basic.test.js +0 -26
- package/test/component.basic.test.ts +0 -52
- package/test/component.methods.test.js +0 -82
- package/test/component.methods.test.ts +0 -185
- package/test/component.nonserialized.test.js +0 -20
- package/test/component.nonserialized.test.ts +0 -45
- package/test/component.primitives.test.js +0 -47
- package/test/component.primitives.test.ts +0 -123
- package/test/helpers.js +0 -54
- package/test/helpers.ts +0 -72
|
@@ -1,123 +0,0 @@
|
|
|
1
|
-
import { compareCodegen, compareCodegenWithDefaultContext } from './helpers';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
describe('Typescript with fields', () => {
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
it('should generate component with number', () => {
|
|
8
|
-
compareCodegenWithDefaultContext("number",
|
|
9
|
-
// INPUT
|
|
10
|
-
`export class MyComponent extends Behaviour {
|
|
11
|
-
public myField: number;
|
|
12
|
-
}
|
|
13
|
-
`,
|
|
14
|
-
// EXPECTED
|
|
15
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
16
|
-
{
|
|
17
|
-
public float @myField;
|
|
18
|
-
}`
|
|
19
|
-
);
|
|
20
|
-
});
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
it('should generate component with string', () => {
|
|
25
|
-
compareCodegenWithDefaultContext("string",
|
|
26
|
-
// INPUT
|
|
27
|
-
`export class MyComponent extends Behaviour {
|
|
28
|
-
public myField: string;
|
|
29
|
-
}
|
|
30
|
-
`,
|
|
31
|
-
// EXPECTED
|
|
32
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
33
|
-
{
|
|
34
|
-
public string @myField;
|
|
35
|
-
}`
|
|
36
|
-
);
|
|
37
|
-
});
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
it('should generate component with string array', () => {
|
|
43
|
-
compareCodegenWithDefaultContext("stringArray",
|
|
44
|
-
// INPUT
|
|
45
|
-
`export class MyComponent extends Behaviour {
|
|
46
|
-
public myField: string[];
|
|
47
|
-
}
|
|
48
|
-
`,
|
|
49
|
-
// EXPECTED
|
|
50
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
51
|
-
{
|
|
52
|
-
public string[] @myField;
|
|
53
|
-
}`
|
|
54
|
-
);
|
|
55
|
-
});
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
it('should generate component with boolean', () => {
|
|
61
|
-
compareCodegenWithDefaultContext("bool",
|
|
62
|
-
// INPUT
|
|
63
|
-
`export class MyComponent extends Behaviour {
|
|
64
|
-
public myField: boolean;
|
|
65
|
-
}
|
|
66
|
-
`,
|
|
67
|
-
// EXPECTED
|
|
68
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
69
|
-
{
|
|
70
|
-
public bool @myField;
|
|
71
|
-
}`
|
|
72
|
-
);
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
it('should generate component with object', () => {
|
|
79
|
-
compareCodegenWithDefaultContext("object",
|
|
80
|
-
// INPUT
|
|
81
|
-
`export class MyComponent extends Behaviour {
|
|
82
|
-
public myField: object;
|
|
83
|
-
}
|
|
84
|
-
`,
|
|
85
|
-
// EXPECTED
|
|
86
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
87
|
-
{
|
|
88
|
-
public UnityEngine.Object @myField;
|
|
89
|
-
}`
|
|
90
|
-
);
|
|
91
|
-
});
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
it('should generate component with default values', () => {
|
|
97
|
-
compareCodegenWithDefaultContext("fields with default values",
|
|
98
|
-
// INPUT
|
|
99
|
-
`export class MyComponent extends Behaviour {
|
|
100
|
-
public myField: number = 42;
|
|
101
|
-
public myField2: string = "hello";
|
|
102
|
-
public myField3: boolean = true;
|
|
103
|
-
public myField4: object = null;
|
|
104
|
-
public myVector2: Vector2 = new Vector2(1, .5);
|
|
105
|
-
}
|
|
106
|
-
`,
|
|
107
|
-
// EXPECTED
|
|
108
|
-
`public partial class MyComponent : UnityEngine.MonoBehaviour
|
|
109
|
-
{
|
|
110
|
-
public float @myField = 42f;
|
|
111
|
-
public string @myField2 = "hello";
|
|
112
|
-
public bool @myField3 = true;
|
|
113
|
-
public UnityEngine.Object @myField4;
|
|
114
|
-
public UnityEngine.Vector2 @myVector2 = new UnityEngine.Vector2(1f, .5f);
|
|
115
|
-
}`
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
});
|
package/test/helpers.js
DELETED
|
@@ -1,54 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
exports.__esModule = true;
|
|
3
|
-
exports.compareCodegenWithDefaultContext = exports.compareCodegen = exports.testCompile = void 0;
|
|
4
|
-
var component_compiler_1 = require("../src/component-compiler");
|
|
5
|
-
var chai_1 = require("chai");
|
|
6
|
-
var fs = require("fs");
|
|
7
|
-
var TestOptions = /** @class */ (function () {
|
|
8
|
-
function TestOptions() {
|
|
9
|
-
this.ignoreWhiteSpace = true;
|
|
10
|
-
}
|
|
11
|
-
return TestOptions;
|
|
12
|
-
}());
|
|
13
|
-
function testCompile(code) {
|
|
14
|
-
var res = (0, component_compiler_1.compile)(code, "test", null, false);
|
|
15
|
-
var output = (res === null || res === void 0 ? void 0 : res.length) > 0 ? res[0] : "";
|
|
16
|
-
return output;
|
|
17
|
-
}
|
|
18
|
-
exports.testCompile = testCompile;
|
|
19
|
-
function compareByLine(output, expected) {
|
|
20
|
-
var splitCode = /\r?\n/;
|
|
21
|
-
if (output == null) {
|
|
22
|
-
(0, chai_1.expect)(expected).to.equal(output);
|
|
23
|
-
}
|
|
24
|
-
else {
|
|
25
|
-
var outputLines = output.split(splitCode);
|
|
26
|
-
var expectedLines = expected.split(splitCode);
|
|
27
|
-
for (var i = 0; i < outputLines.length; i++) {
|
|
28
|
-
var outputLine = outputLines[i].trim();
|
|
29
|
-
var expectedLine = expectedLines[i].trim();
|
|
30
|
-
(0, chai_1.expect)(outputLine).to.equal(expectedLine, "Line ".concat(i, " does not match"));
|
|
31
|
-
}
|
|
32
|
-
}
|
|
33
|
-
}
|
|
34
|
-
function compareCodegen(id, input, expected) {
|
|
35
|
-
var baseDir = "test/codegen";
|
|
36
|
-
if (!fs.existsSync(baseDir))
|
|
37
|
-
fs.mkdirSync(baseDir);
|
|
38
|
-
var dir = "".concat(baseDir, "/").concat(id);
|
|
39
|
-
if (!fs.existsSync(dir))
|
|
40
|
-
fs.mkdirSync(dir);
|
|
41
|
-
fs.writeFileSync("".concat(dir, "\\input.ts"), input);
|
|
42
|
-
var result = testCompile(input);
|
|
43
|
-
if (result !== null)
|
|
44
|
-
fs.writeFileSync("".concat(dir, "\\output.cs"), result);
|
|
45
|
-
fs.writeFileSync("".concat(dir, "\\expected.cs"), expected);
|
|
46
|
-
compareByLine(result, expected);
|
|
47
|
-
// expect(result).to.equal(expected);
|
|
48
|
-
}
|
|
49
|
-
exports.compareCodegen = compareCodegen;
|
|
50
|
-
function compareCodegenWithDefaultContext(id, input, expected) {
|
|
51
|
-
expected = "// NEEDLE_CODEGEN_START\n // auto generated code - do not edit directly\n \n #pragma warning disable\n \n namespace Needle.Typescript.GeneratedComponents\n {\n \t" + expected + "\n }\n \n // NEEDLE_CODEGEN_END";
|
|
52
|
-
return compareCodegen(id, input, expected);
|
|
53
|
-
}
|
|
54
|
-
exports.compareCodegenWithDefaultContext = compareCodegenWithDefaultContext;
|
package/test/helpers.ts
DELETED
|
@@ -1,72 +0,0 @@
|
|
|
1
|
-
import { compile } from "../src/component-compiler";
|
|
2
|
-
import { expect } from 'chai';
|
|
3
|
-
import * as fs from "fs";
|
|
4
|
-
import { debuglog } from "util";
|
|
5
|
-
|
|
6
|
-
class TestOptions {
|
|
7
|
-
ignoreWhiteSpace: boolean = true;
|
|
8
|
-
}
|
|
9
|
-
|
|
10
|
-
export function testCompile(code: string): string | null {
|
|
11
|
-
|
|
12
|
-
const res = compile(code, "test", null, false);
|
|
13
|
-
const output = res?.length > 0 ? res[0] : "";
|
|
14
|
-
|
|
15
|
-
return output;
|
|
16
|
-
|
|
17
|
-
}
|
|
18
|
-
|
|
19
|
-
function compareByLine(output: string, expected: string) {
|
|
20
|
-
const splitCode = /\r?\n/;
|
|
21
|
-
|
|
22
|
-
if (output == null) {
|
|
23
|
-
|
|
24
|
-
expect(expected).to.equal(output);
|
|
25
|
-
}
|
|
26
|
-
else {
|
|
27
|
-
|
|
28
|
-
const outputLines = output.split(splitCode);
|
|
29
|
-
const expectedLines = expected.split(splitCode);
|
|
30
|
-
for (let i = 0; i < outputLines.length; i++) {
|
|
31
|
-
const outputLine = outputLines[i].trim();
|
|
32
|
-
const expectedLine = expectedLines[i].trim();
|
|
33
|
-
expect(outputLine).to.equal(expectedLine, `Line ${i} does not match`);
|
|
34
|
-
}
|
|
35
|
-
}
|
|
36
|
-
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
export function compareCodegen(id: string, input: string, expected: string) {
|
|
40
|
-
const baseDir = "test/codegen";
|
|
41
|
-
if (!fs.existsSync(baseDir))
|
|
42
|
-
fs.mkdirSync(baseDir);
|
|
43
|
-
const dir = `${baseDir}/${id}`;
|
|
44
|
-
if (!fs.existsSync(dir))
|
|
45
|
-
fs.mkdirSync(dir);
|
|
46
|
-
fs.writeFileSync(`${dir}\\input.ts`, input);
|
|
47
|
-
const result = testCompile(input);
|
|
48
|
-
if (result !== null)
|
|
49
|
-
fs.writeFileSync(`${dir}\\output.cs`, result);
|
|
50
|
-
fs.writeFileSync(`${dir}\\expected.cs`, expected);
|
|
51
|
-
|
|
52
|
-
compareByLine(result, expected);
|
|
53
|
-
|
|
54
|
-
// expect(result).to.equal(expected);
|
|
55
|
-
}
|
|
56
|
-
|
|
57
|
-
export function compareCodegenWithDefaultContext(id: string, input: string, expected: string) {
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
expected = `// NEEDLE_CODEGEN_START
|
|
61
|
-
// auto generated code - do not edit directly
|
|
62
|
-
|
|
63
|
-
#pragma warning disable
|
|
64
|
-
|
|
65
|
-
namespace Needle.Typescript.GeneratedComponents
|
|
66
|
-
{
|
|
67
|
-
\t` + expected + `
|
|
68
|
-
}
|
|
69
|
-
|
|
70
|
-
// NEEDLE_CODEGEN_END`;
|
|
71
|
-
return compareCodegen(id, input, expected);
|
|
72
|
-
}
|