circuitscript 0.0.22 → 0.0.25
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/dist/cjs/BaseVisitor.js +487 -0
- package/dist/cjs/SemanticTokenVisitor.js +218 -0
- package/dist/cjs/SymbolValidatorVisitor.js +233 -0
- package/dist/cjs/antlr/CircuitScriptLexer.js +302 -0
- package/dist/cjs/antlr/CircuitScriptParser.js +5128 -0
- package/dist/cjs/antlr/CircuitScriptVisitor.js +7 -0
- package/dist/cjs/draw_symbols.js +819 -0
- package/dist/cjs/execute.js +778 -0
- package/{src/export.ts → dist/cjs/export.js} +34 -56
- package/dist/cjs/fonts.js +4 -0
- package/dist/cjs/geometry.js +450 -0
- package/dist/cjs/globals.js +60 -0
- package/dist/cjs/helpers.js +269 -0
- package/dist/cjs/index.js +31 -0
- package/{src/layout.ts → dist/cjs/layout.js} +421 -1002
- package/dist/cjs/lexer.js +111 -0
- package/dist/cjs/logger.js +17 -0
- package/dist/cjs/main.js +82 -0
- package/dist/cjs/objects/ClassComponent.js +145 -0
- package/dist/cjs/objects/ExecutionScope.js +135 -0
- package/dist/cjs/objects/Frame.js +22 -0
- package/{src/objects/Net.ts → dist/cjs/objects/Net.js} +9 -24
- package/dist/cjs/objects/ParamDefinition.js +42 -0
- package/dist/cjs/objects/PinDefinition.js +31 -0
- package/dist/cjs/objects/PinTypes.js +11 -0
- package/dist/cjs/objects/Wire.js +9 -0
- package/dist/cjs/objects/types.js +15 -0
- package/dist/cjs/parser.js +70 -0
- package/dist/cjs/regenerate-tests.js +23 -0
- package/dist/cjs/render.js +155 -0
- package/{src/server.ts → dist/cjs/server.js} +15 -21
- package/dist/cjs/sizing.js +105 -0
- package/{src/utils.ts → dist/cjs/utils.js} +25 -35
- package/dist/cjs/validate.js +81 -0
- package/dist/cjs/visitor.js +844 -0
- package/dist/esm/BaseVisitor.mjs +488 -0
- package/dist/esm/SemanticTokenVisitor.mjs +215 -0
- package/dist/esm/SymbolValidatorVisitor.mjs +222 -0
- package/dist/esm/antlr/CircuitScriptLexer.mjs +276 -0
- package/dist/esm/antlr/CircuitScriptParser.mjs +5038 -0
- package/{build/src/antlr/CircuitScriptVisitor.js → dist/esm/antlr/CircuitScriptVisitor.mjs} +8 -3
- package/{build/src/draw_symbols.js → dist/esm/draw_symbols.mjs} +78 -33
- package/{build/src/execute.js → dist/esm/execute.mjs} +59 -60
- package/{build/src/export.js → dist/esm/export.mjs} +2 -2
- package/{build/src/geometry.js → dist/esm/geometry.mjs} +31 -15
- package/dist/esm/helpers.mjs +252 -0
- package/dist/esm/index.mjs +15 -0
- package/{build/src/layout.js → dist/esm/layout.mjs} +19 -11
- package/{build/src/lexer.js → dist/esm/lexer.mjs} +10 -10
- package/{build/src/main.js → dist/esm/main.mjs} +9 -14
- package/{build/src/objects/ClassComponent.js → dist/esm/objects/ClassComponent.mjs} +6 -3
- package/{build/src/objects/ExecutionScope.js → dist/esm/objects/ExecutionScope.mjs} +1 -0
- package/{build/src/objects/PinDefinition.js → dist/esm/objects/PinDefinition.mjs} +1 -1
- package/dist/esm/objects/types.mjs +12 -0
- package/dist/esm/parser.mjs +64 -0
- package/{build/src/regenerate-tests.js → dist/esm/regenerate-tests.mjs} +1 -1
- package/{build/src/render.js → dist/esm/render.mjs} +7 -24
- package/{build/src/sizing.js → dist/esm/sizing.mjs} +22 -8
- package/{src/main.ts → dist/esm/validate.mjs} +31 -62
- package/dist/esm/visitor.mjs +838 -0
- package/dist/types/BaseVisitor.d.ts +69 -0
- package/dist/types/SemanticTokenVisitor.d.ts +36 -0
- package/dist/types/SymbolValidatorVisitor.d.ts +61 -0
- package/{build/src → dist/types}/antlr/CircuitScriptLexer.d.ts +28 -27
- package/dist/types/antlr/CircuitScriptParser.d.ts +719 -0
- package/{build/src → dist/types}/antlr/CircuitScriptVisitor.d.ts +69 -59
- package/{build/src → dist/types}/draw_symbols.d.ts +11 -2
- package/{build/src → dist/types}/execute.d.ts +6 -9
- package/{build/src → dist/types}/geometry.d.ts +5 -1
- package/dist/types/helpers.d.ts +40 -0
- package/dist/types/index.d.ts +15 -0
- package/{build/src → dist/types}/layout.d.ts +10 -10
- package/{build/src → dist/types}/lexer.d.ts +2 -2
- package/{build/src → dist/types}/objects/ClassComponent.d.ts +2 -2
- package/{build/src → dist/types}/objects/ExecutionScope.d.ts +4 -1
- package/{build/src → dist/types}/objects/PinDefinition.d.ts +1 -1
- package/{build/src → dist/types}/objects/types.d.ts +5 -0
- package/dist/types/parser.d.ts +25 -0
- package/{build/src → dist/types}/render.d.ts +1 -1
- package/{build/src → dist/types}/sizing.d.ts +3 -1
- package/dist/types/validate.d.ts +2 -0
- package/dist/types/visitor.d.ts +80 -0
- package/libs/lib.cst +0 -2
- package/package.json +38 -15
- package/.editorconfig +0 -15
- package/.eslintignore +0 -1
- package/.eslintrc.json +0 -27
- package/.gitlab-ci.yml +0 -81
- package/.prettierignore +0 -8
- package/.prettierrc +0 -16
- package/__tests__/expectedResults.ts +0 -657
- package/__tests__/helpers.ts +0 -82
- package/__tests__/parseScripts.ts +0 -593
- package/__tests__/renderData/script1.cst +0 -58
- package/__tests__/renderData/script1.cst.svg +0 -1
- package/__tests__/renderData/script2.cst +0 -16
- package/__tests__/renderData/script2.cst.svg +0 -1
- package/__tests__/renderData/script3.cst +0 -30
- package/__tests__/renderData/script3.cst.svg +0 -1
- package/__tests__/renderData/script4.cst +0 -54
- package/__tests__/renderData/script4.cst.svg +0 -1
- package/__tests__/renderData/script5.cst +0 -23
- package/__tests__/renderData/script5.cst.svg +0 -1
- package/__tests__/renderData/script6.cst +0 -28
- package/__tests__/renderData/script6.cst.svg +0 -1
- package/__tests__/renderData/script7.cst +0 -26
- package/__tests__/renderData/script7.cst.svg +0 -1
- package/__tests__/renderData/script8.cst +0 -37
- package/__tests__/renderData/script8.cst.svg +0 -1
- package/__tests__/testCLI.ts +0 -68
- package/__tests__/testMathOps.ts +0 -36
- package/__tests__/testMergeWires.ts +0 -141
- package/__tests__/testParse.ts +0 -263
- package/__tests__/testRender.ts +0 -38
- package/build/src/antlr/CircuitScriptLexer.js +0 -287
- package/build/src/antlr/CircuitScriptParser.d.ts +0 -674
- package/build/src/antlr/CircuitScriptParser.js +0 -4841
- package/build/src/helpers.d.ts +0 -1
- package/build/src/helpers.js +0 -73
- package/build/src/objects/types.js +0 -6
- package/build/src/parser.js +0 -69
- package/build/src/visitor.d.ts +0 -133
- package/build/src/visitor.js +0 -1154
- package/documentation.md +0 -238
- package/examples/example_arduino_uno.cst +0 -1146
- package/examples/example_garden_pump.cst +0 -567
- package/examples/lib.cst +0 -185
- package/jest.config.js +0 -23
- package/refresh.html +0 -42
- package/server.cjs +0 -50
- package/src/antlr/CircuitScript.g4 +0 -209
- package/src/antlr/CircuitScriptLexer.ts +0 -317
- package/src/antlr/CircuitScriptParser.ts +0 -4979
- package/src/antlr/CircuitScriptVisitor.ts +0 -420
- package/src/draw_symbols.ts +0 -1085
- package/src/execute.ts +0 -1227
- package/src/fonts.ts +0 -1
- package/src/geometry.ts +0 -638
- package/src/globals.ts +0 -67
- package/src/helpers.ts +0 -114
- package/src/lexer.ts +0 -151
- package/src/logger.ts +0 -17
- package/src/objects/ClassComponent.ts +0 -223
- package/src/objects/ExecutionScope.ts +0 -201
- package/src/objects/Frame.ts +0 -20
- package/src/objects/ParamDefinition.ts +0 -49
- package/src/objects/PinDefinition.ts +0 -49
- package/src/objects/PinTypes.ts +0 -7
- package/src/objects/Wire.ts +0 -19
- package/src/objects/types.ts +0 -66
- package/src/parser.ts +0 -106
- package/src/regenerate-tests.ts +0 -25
- package/src/render.ts +0 -260
- package/src/sizing.ts +0 -96
- package/src/visitor.ts +0 -1691
- package/tsconfig.json +0 -27
- package/tsconfig.release.json +0 -8
- /package/{build/src/fonts.js → dist/esm/fonts.mjs} +0 -0
- /package/{build/src/globals.js → dist/esm/globals.mjs} +0 -0
- /package/{build/src/logger.js → dist/esm/logger.mjs} +0 -0
- /package/{build/src/objects/Frame.js → dist/esm/objects/Frame.mjs} +0 -0
- /package/{build/src/objects/Net.js → dist/esm/objects/Net.mjs} +0 -0
- /package/{build/src/objects/ParamDefinition.js → dist/esm/objects/ParamDefinition.mjs} +0 -0
- /package/{build/src/objects/PinTypes.js → dist/esm/objects/PinTypes.mjs} +0 -0
- /package/{build/src/objects/Wire.js → dist/esm/objects/Wire.mjs} +0 -0
- /package/{build/src/server.js → dist/esm/server.mjs} +0 -0
- /package/{build/src/utils.js → dist/esm/utils.mjs} +0 -0
- /package/{build/src → dist/types}/export.d.ts +0 -0
- /package/{build/src → dist/types}/fonts.d.ts +0 -0
- /package/{build/src → dist/types}/globals.d.ts +0 -0
- /package/{build/src → dist/types}/logger.d.ts +0 -0
- /package/{build/src → dist/types}/main.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Frame.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Net.d.ts +0 -0
- /package/{build/src → dist/types}/objects/ParamDefinition.d.ts +0 -0
- /package/{build/src → dist/types}/objects/PinTypes.d.ts +0 -0
- /package/{build/src → dist/types}/objects/Wire.d.ts +0 -0
- /package/{build/src → dist/types}/regenerate-tests.d.ts +0 -0
- /package/{build/src → dist/types}/server.d.ts +0 -0
- /package/{build/src → dist/types}/utils.d.ts +0 -0
package/__tests__/testCLI.ts
DELETED
|
@@ -1,68 +0,0 @@
|
|
|
1
|
-
import { execSync } from 'child_process';
|
|
2
|
-
import figlet from 'figlet';
|
|
3
|
-
import { existsSync, mkdirSync, readFileSync, unlinkSync } from 'fs';
|
|
4
|
-
|
|
5
|
-
describe('test cli program', () => {
|
|
6
|
-
|
|
7
|
-
const tmpFolder = '__tests__/tmp';
|
|
8
|
-
|
|
9
|
-
const baseCommand = 'node build/src/main.js';
|
|
10
|
-
|
|
11
|
-
test('start program and display help', () => {
|
|
12
|
-
const result = execSync(baseCommand).toString();
|
|
13
|
-
const circuitscriptText = figlet.textSync('circuitscript', {
|
|
14
|
-
font: 'Small Slant'
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
expect(result.includes(circuitscriptText)).toBe(true);
|
|
18
|
-
|
|
19
|
-
const options =
|
|
20
|
-
`Options:
|
|
21
|
-
-V, --version output the version number
|
|
22
|
-
-i, --input text <input text> Input text directly
|
|
23
|
-
-f, --input-file <path> Input file
|
|
24
|
-
-o, --output <path> Output path
|
|
25
|
-
-c, --current-directory <path> Set current directory
|
|
26
|
-
-k, --kicad-netlist <filename> Create KiCad netlist
|
|
27
|
-
-w, --watch Watch for file changes
|
|
28
|
-
-n, --dump-nets Dump out net information
|
|
29
|
-
-d, --dump-data Dump data during parsing
|
|
30
|
-
-s, --stats Show stats during generation
|
|
31
|
-
-h, --help display help for command`
|
|
32
|
-
|
|
33
|
-
expect(result.includes(options)).toBe(true);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('pass in file and output directly', () => {
|
|
37
|
-
const result = execSync(baseCommand + ' -f __tests__/renderData/script1.cst').toString();
|
|
38
|
-
const expected = readFileSync('__tests__/renderData/script1.cst.svg').toString();
|
|
39
|
-
expect(result.trim()).toBe(expected);
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
test.each([false, true])('pass in file and output file (with stats: %s)', (withStatsFlag: boolean) => {
|
|
43
|
-
const outputPath = '__tests__/tmp/result1.svg';
|
|
44
|
-
if (existsSync(outputPath)) {
|
|
45
|
-
unlinkSync(outputPath);
|
|
46
|
-
}
|
|
47
|
-
|
|
48
|
-
if (!existsSync(tmpFolder)) {
|
|
49
|
-
mkdirSync(tmpFolder);
|
|
50
|
-
}
|
|
51
|
-
|
|
52
|
-
const statsFlag = withStatsFlag ? ' -s ' : '';
|
|
53
|
-
|
|
54
|
-
const result = execSync(`${baseCommand} -f __tests__/renderData/script1.cst -o ${outputPath} ${statsFlag}`).toString();
|
|
55
|
-
|
|
56
|
-
const outputFile = readFileSync(outputPath).toString();
|
|
57
|
-
const expected = readFileSync('__tests__/renderData/script1.cst.svg').toString();
|
|
58
|
-
|
|
59
|
-
expect(outputFile.trim()).toBe(expected.trim());
|
|
60
|
-
|
|
61
|
-
expect(
|
|
62
|
-
result.includes('Lexing took:') &&
|
|
63
|
-
result.includes('Parsing took:') &&
|
|
64
|
-
result.includes('Layout took:') &&
|
|
65
|
-
result.includes('Render took:')
|
|
66
|
-
).toBe(withStatsFlag);
|
|
67
|
-
});
|
|
68
|
-
});
|
package/__tests__/testMathOps.ts
DELETED
|
@@ -1,36 +0,0 @@
|
|
|
1
|
-
import { runScript } from "./helpers.js";
|
|
2
|
-
|
|
3
|
-
const script1 = `
|
|
4
|
-
b = 10
|
|
5
|
-
a = -b
|
|
6
|
-
`
|
|
7
|
-
|
|
8
|
-
const script2 = `
|
|
9
|
-
b = 10
|
|
10
|
-
a = -b / 2 - 1
|
|
11
|
-
`
|
|
12
|
-
|
|
13
|
-
describe('Simple math tests', () => {
|
|
14
|
-
test.each([
|
|
15
|
-
["a = -1 + 2", 1],
|
|
16
|
-
["a = 1 + 2", 3],
|
|
17
|
-
["a = 1 + 2 * 3", 7],
|
|
18
|
-
["a = 5 - 1", 4],
|
|
19
|
-
["a = 5 - 1 * 2", 3],
|
|
20
|
-
["a = 10 / 2", 5],
|
|
21
|
-
["a = 1 + 9 / 3", 4],
|
|
22
|
-
["a = 1+20-2", 19],
|
|
23
|
-
["a = -1+2", 1],
|
|
24
|
-
["a = -123", -123],
|
|
25
|
-
["a = 0-123", -123],
|
|
26
|
-
[script1, -10],
|
|
27
|
-
[script2, -6]
|
|
28
|
-
])('math test - %s', async (script, expectedResult) => {
|
|
29
|
-
const {visitor, hasError} = await runScript(script);
|
|
30
|
-
|
|
31
|
-
expect(hasError).toBe(false);
|
|
32
|
-
|
|
33
|
-
const variables = visitor.dumpVariables();
|
|
34
|
-
expect(variables.get('a')).toBe(expectedResult);
|
|
35
|
-
});
|
|
36
|
-
})
|
|
@@ -1,141 +0,0 @@
|
|
|
1
|
-
import { Geometry } from "../src/geometry";
|
|
2
|
-
|
|
3
|
-
describe('geometry merge wires test', () => {
|
|
4
|
-
|
|
5
|
-
test('wire connected end to end', () => {
|
|
6
|
-
|
|
7
|
-
const wire1 = [
|
|
8
|
-
{ x: 100, y: 100 },
|
|
9
|
-
{ x: 200, y: 100 }
|
|
10
|
-
];
|
|
11
|
-
|
|
12
|
-
const wire2 = [
|
|
13
|
-
{ x: 200, y: 100 },
|
|
14
|
-
{ x: 200, y: 120 }
|
|
15
|
-
];
|
|
16
|
-
|
|
17
|
-
const { intersectPoints, segments } = Geometry.mergeWires([wire1, wire2]);
|
|
18
|
-
expect(segments).toStrictEqual([
|
|
19
|
-
[
|
|
20
|
-
[100, 100], [200, 100]
|
|
21
|
-
],
|
|
22
|
-
[
|
|
23
|
-
[200, 100], [200, 120],
|
|
24
|
-
]
|
|
25
|
-
]);
|
|
26
|
-
|
|
27
|
-
expect(intersectPoints).toStrictEqual([]);
|
|
28
|
-
});
|
|
29
|
-
|
|
30
|
-
test('wire connected at some point of wire 1', () => {
|
|
31
|
-
|
|
32
|
-
const wire1 = [
|
|
33
|
-
{ x: 100, y: 100 },
|
|
34
|
-
{ x: 200, y: 100 }
|
|
35
|
-
];
|
|
36
|
-
|
|
37
|
-
const wire2 = [
|
|
38
|
-
{ x: 160, y: 100 },
|
|
39
|
-
{ x: 160, y: 120 }
|
|
40
|
-
];
|
|
41
|
-
|
|
42
|
-
const { intersectPoints, segments } = Geometry.mergeWires([wire1, wire2]);
|
|
43
|
-
|
|
44
|
-
expect(segments).toStrictEqual([
|
|
45
|
-
[
|
|
46
|
-
[100, 100], [160, 100]
|
|
47
|
-
],
|
|
48
|
-
[
|
|
49
|
-
[160, 100], [200, 100],
|
|
50
|
-
],
|
|
51
|
-
[
|
|
52
|
-
[160, 100], [160, 120],
|
|
53
|
-
]
|
|
54
|
-
]);
|
|
55
|
-
|
|
56
|
-
expect(intersectPoints).toStrictEqual([
|
|
57
|
-
[160, 100, 3],
|
|
58
|
-
])
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
test('wire connected at some point of wire 2', () => {
|
|
62
|
-
|
|
63
|
-
const wire1 = [
|
|
64
|
-
{ x: 100, y: 100 },
|
|
65
|
-
{ x: 200, y: 100 }
|
|
66
|
-
];
|
|
67
|
-
|
|
68
|
-
const wire2 = [
|
|
69
|
-
{ x: 160, y: 100 },
|
|
70
|
-
{ x: 160, y: 120 }
|
|
71
|
-
];
|
|
72
|
-
|
|
73
|
-
const { intersectPoints, segments } = Geometry.mergeWires([wire2, wire1]);
|
|
74
|
-
|
|
75
|
-
expect(segments).toStrictEqual([
|
|
76
|
-
[
|
|
77
|
-
[160, 100], [160, 120]
|
|
78
|
-
],
|
|
79
|
-
[
|
|
80
|
-
[100, 100], [160, 100],
|
|
81
|
-
],
|
|
82
|
-
[
|
|
83
|
-
[160, 100], [200, 100],
|
|
84
|
-
]
|
|
85
|
-
]);
|
|
86
|
-
|
|
87
|
-
expect(intersectPoints).toStrictEqual([
|
|
88
|
-
[160, 100, 3],
|
|
89
|
-
])
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
test('overlapping wires', () => {
|
|
93
|
-
|
|
94
|
-
const wire1 = [
|
|
95
|
-
{ x: 100, y: 100 },
|
|
96
|
-
{ x: 140, y: 100 }
|
|
97
|
-
];
|
|
98
|
-
|
|
99
|
-
const wire2 = [
|
|
100
|
-
{ x: 120, y: 100 },
|
|
101
|
-
{ x: 160, y: 100 }
|
|
102
|
-
];
|
|
103
|
-
|
|
104
|
-
const { intersectPoints, segments } = Geometry.mergeWires([wire1, wire2]);
|
|
105
|
-
|
|
106
|
-
// No intersection points, because only have two segments
|
|
107
|
-
// connected at each point.
|
|
108
|
-
expect(intersectPoints).toStrictEqual([]);
|
|
109
|
-
|
|
110
|
-
expect(segments).toStrictEqual(
|
|
111
|
-
[
|
|
112
|
-
[[120, 100], [140, 100]],
|
|
113
|
-
[[100, 100], [120, 100]],
|
|
114
|
-
[[140, 100], [160, 100]]
|
|
115
|
-
]
|
|
116
|
-
);
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
test('reversed wires', () => {
|
|
120
|
-
|
|
121
|
-
const wire1 = [
|
|
122
|
-
{ x: 100, y: 100 },
|
|
123
|
-
{ x: 140, y: 100 }
|
|
124
|
-
];
|
|
125
|
-
|
|
126
|
-
const wire2 = [
|
|
127
|
-
{ x: 140, y: 100 },
|
|
128
|
-
{ x: 100, y: 100 }
|
|
129
|
-
];
|
|
130
|
-
|
|
131
|
-
const { intersectPoints, segments } = Geometry.mergeWires([wire1, wire2]);
|
|
132
|
-
|
|
133
|
-
expect(intersectPoints).toStrictEqual([]);
|
|
134
|
-
expect(segments).toStrictEqual(
|
|
135
|
-
[
|
|
136
|
-
[[100, 100], [140, 100]]
|
|
137
|
-
]
|
|
138
|
-
);
|
|
139
|
-
});
|
|
140
|
-
|
|
141
|
-
});
|
package/__tests__/testParse.ts
DELETED
|
@@ -1,263 +0,0 @@
|
|
|
1
|
-
|
|
2
|
-
import { findItem, findItemByRefDes, runScript } from './helpers.js';
|
|
3
|
-
import { script1, script10, script11, script12, script13, script14, script15, script16, script2,
|
|
4
|
-
script3, script6, script7, script8, script9 } from './parseScripts.js';
|
|
5
|
-
|
|
6
|
-
describe('test parsing', () => {
|
|
7
|
-
|
|
8
|
-
test.each([
|
|
9
|
-
["create component command", script1],
|
|
10
|
-
["function to create component and branching", script2],
|
|
11
|
-
["nested branching, add with pin selected", script3],
|
|
12
|
-
["'at' and 'to' commands will clone net components", script6],
|
|
13
|
-
["resolve instances in upper contexts", script7],
|
|
14
|
-
["components in function parameters", script8],
|
|
15
|
-
["resolve nets in local and upper contexts", script9],
|
|
16
|
-
["assignment in at/to/add statement", script10],
|
|
17
|
-
["net namespace local and global", script11],
|
|
18
|
-
["create component with __is_net", script12],
|
|
19
|
-
["corret nets after function call and also `join` keyword", script13],
|
|
20
|
-
["path with 'point' keyword", script14],
|
|
21
|
-
["path with 'parallel' keyword", script15],
|
|
22
|
-
["consecutive blocks with 'join' then 'point'", script16]
|
|
23
|
-
|
|
24
|
-
])('parse script - %s', async (description, scriptTest) => {
|
|
25
|
-
// Test only parsing, does not check the correctness of the
|
|
26
|
-
// parsed result!
|
|
27
|
-
|
|
28
|
-
// Access scripts like this to prevent having to
|
|
29
|
-
// define the script content before the test itself
|
|
30
|
-
const {hasError, componentPinNets} = await runScript(scriptTest.script);
|
|
31
|
-
|
|
32
|
-
expect(hasError).toBe(false);
|
|
33
|
-
expect(componentPinNets).toStrictEqual(scriptTest.expected);
|
|
34
|
-
});
|
|
35
|
-
|
|
36
|
-
test('component annotation', async () => {
|
|
37
|
-
const { hasError, visitor } = await runScript(`
|
|
38
|
-
import lib
|
|
39
|
-
|
|
40
|
-
variant = "MainVariantX"
|
|
41
|
-
gnd = dgnd()
|
|
42
|
-
|
|
43
|
-
at net("5V")
|
|
44
|
-
wire down 20
|
|
45
|
-
branch:
|
|
46
|
-
wire down 20
|
|
47
|
-
add res(10k) ..angle = 90
|
|
48
|
-
..place = (variant == "MainVariant")
|
|
49
|
-
wire down 20 to gnd
|
|
50
|
-
|
|
51
|
-
wire right 40
|
|
52
|
-
branch:
|
|
53
|
-
wire down 20
|
|
54
|
-
add res(20k) ..angle = 90
|
|
55
|
-
..place = true
|
|
56
|
-
wire down 20
|
|
57
|
-
to gnd
|
|
58
|
-
|
|
59
|
-
wire right 40
|
|
60
|
-
branch:
|
|
61
|
-
wire down 20
|
|
62
|
-
add cap(100n)
|
|
63
|
-
wire down 20
|
|
64
|
-
to gnd
|
|
65
|
-
`);
|
|
66
|
-
expect(hasError).toBe(false);
|
|
67
|
-
|
|
68
|
-
visitor.annotateComponents();
|
|
69
|
-
const instances = visitor.dumpInstances();
|
|
70
|
-
|
|
71
|
-
expect(findItem(instances, 'res', 'R1', 'numeric:10k')).not.toBeNull();
|
|
72
|
-
expect(findItem(instances, 'res', 'R2', 'numeric:20k')).not.toBeNull();
|
|
73
|
-
expect(findItem(instances, 'cap', 'C1', 'numeric:100n')).not.toBeNull();
|
|
74
|
-
});
|
|
75
|
-
|
|
76
|
-
test('component annotation with custom type param', async () => {
|
|
77
|
-
|
|
78
|
-
const script = `
|
|
79
|
-
import lib
|
|
80
|
-
|
|
81
|
-
v5v = supply("5V")
|
|
82
|
-
gnd = dgnd()
|
|
83
|
-
|
|
84
|
-
a = create component:
|
|
85
|
-
type: "X"
|
|
86
|
-
pins: 2
|
|
87
|
-
|
|
88
|
-
a2 = create component:
|
|
89
|
-
type: "X"
|
|
90
|
-
pins: 3
|
|
91
|
-
|
|
92
|
-
at v5v
|
|
93
|
-
wire down 20 right 20
|
|
94
|
-
to a pin 1
|
|
95
|
-
|
|
96
|
-
at v5v
|
|
97
|
-
wire down 20 right 20
|
|
98
|
-
to a2 pin 3
|
|
99
|
-
|
|
100
|
-
`
|
|
101
|
-
const {hasError, visitor} = await runScript(script);
|
|
102
|
-
expect(hasError).toBe(false);
|
|
103
|
-
|
|
104
|
-
visitor.annotateComponents();
|
|
105
|
-
|
|
106
|
-
const instances = visitor.dumpInstances();
|
|
107
|
-
|
|
108
|
-
expect(findItemByRefDes(instances, 'X', 'X1')).not.toBeNull();
|
|
109
|
-
expect(findItemByRefDes(instances, 'X', 'X2')).not.toBeNull();
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
test('component annotation with defined refdes', async () => {
|
|
113
|
-
|
|
114
|
-
const script = `
|
|
115
|
-
import lib
|
|
116
|
-
|
|
117
|
-
v5v = supply("5V")
|
|
118
|
-
gnd = dgnd()
|
|
119
|
-
|
|
120
|
-
at v5v
|
|
121
|
-
wire down 10
|
|
122
|
-
add res(10k)
|
|
123
|
-
..refdes = "R2"
|
|
124
|
-
|
|
125
|
-
wire down 10
|
|
126
|
-
add res(20k)
|
|
127
|
-
|
|
128
|
-
wire down 10
|
|
129
|
-
add res(30k)
|
|
130
|
-
|
|
131
|
-
wire down 10
|
|
132
|
-
add res(40k)
|
|
133
|
-
..refdes = "R100"
|
|
134
|
-
`
|
|
135
|
-
const {hasError, visitor} = await runScript(script);
|
|
136
|
-
expect(hasError).toBe(false);
|
|
137
|
-
|
|
138
|
-
visitor.annotateComponents();
|
|
139
|
-
|
|
140
|
-
const instances = visitor.dumpInstances();
|
|
141
|
-
|
|
142
|
-
expect(findItem(instances, 'res', 'R2', 'numeric:10k')).not.toBeNull();
|
|
143
|
-
expect(findItem(instances, 'res', 'R1', 'numeric:20k')).not.toBeNull();
|
|
144
|
-
expect(findItem(instances, 'res', 'R3', 'numeric:30k')).not.toBeNull();
|
|
145
|
-
expect(findItem(instances, 'res', 'R100',
|
|
146
|
-
'numeric:40k')).not.toBeNull();
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
test('indents in function definition', async() => {
|
|
150
|
-
// Check that indents within parantheses/brackets are ignored.
|
|
151
|
-
const script = `
|
|
152
|
-
def test1(a,
|
|
153
|
-
b,
|
|
154
|
-
c):
|
|
155
|
-
return a + b + c
|
|
156
|
-
|
|
157
|
-
print(test1(1,2,3))
|
|
158
|
-
`
|
|
159
|
-
const { hasError, visitor } = await runScript(script);
|
|
160
|
-
expect(hasError).toBe(false);
|
|
161
|
-
|
|
162
|
-
expect(visitor.printStream[0]).toBe(6);
|
|
163
|
-
});
|
|
164
|
-
|
|
165
|
-
test('double dot syntax', async () => {
|
|
166
|
-
// Check that the double dot syntax works for 'place' parameter
|
|
167
|
-
|
|
168
|
-
const script = `
|
|
169
|
-
import lib
|
|
170
|
-
gnd = dgnd()
|
|
171
|
-
|
|
172
|
-
at net("5V")
|
|
173
|
-
wire down 20
|
|
174
|
-
|
|
175
|
-
add res(10k)
|
|
176
|
-
..place = false
|
|
177
|
-
|
|
178
|
-
wire down 20
|
|
179
|
-
|
|
180
|
-
add res(20k)
|
|
181
|
-
..place = true
|
|
182
|
-
wire down 20
|
|
183
|
-
to gnd
|
|
184
|
-
`
|
|
185
|
-
const {hasError, visitor} = await runScript(script);
|
|
186
|
-
expect(hasError).toBe(false);
|
|
187
|
-
|
|
188
|
-
visitor.annotateComponents();
|
|
189
|
-
const instances = visitor.dumpInstances();
|
|
190
|
-
|
|
191
|
-
const item1 = findItem(instances, 'res', 'R1', 'numeric:10k');
|
|
192
|
-
expect(item1.parameters.get('place')).toBe(false);
|
|
193
|
-
|
|
194
|
-
const item2 = findItem(instances, 'res', 'R2', 'numeric:20k');
|
|
195
|
-
expect(item2.parameters.get('place')).toBe(true);
|
|
196
|
-
});
|
|
197
|
-
|
|
198
|
-
test('instance assignment syntax', async () => {
|
|
199
|
-
|
|
200
|
-
const script = `
|
|
201
|
-
import lib
|
|
202
|
-
gnd = dgnd()
|
|
203
|
-
|
|
204
|
-
at supply("5V")
|
|
205
|
-
wire down 20
|
|
206
|
-
add R1 = res(10k)
|
|
207
|
-
wire down 20
|
|
208
|
-
to gnd
|
|
209
|
-
|
|
210
|
-
# update resistor value
|
|
211
|
-
R1.value = 20k
|
|
212
|
-
R1.place = false
|
|
213
|
-
R1.mpn = "res-12345"
|
|
214
|
-
`;
|
|
215
|
-
|
|
216
|
-
const {hasError, visitor} = await runScript(script);
|
|
217
|
-
expect(hasError).toBe(false);
|
|
218
|
-
|
|
219
|
-
visitor.annotateComponents();
|
|
220
|
-
const instances = visitor.dumpInstances();
|
|
221
|
-
|
|
222
|
-
const item1 = findItem(instances, 'res', 'R1', 'numeric:20k');
|
|
223
|
-
expect(item1.parameters.get('place')).toBe(false);
|
|
224
|
-
expect(item1.parameters.get('mpn')).toBe('res-12345');
|
|
225
|
-
});
|
|
226
|
-
|
|
227
|
-
test('unary minus operator', async () => {
|
|
228
|
-
const script = `
|
|
229
|
-
b = 20
|
|
230
|
-
print(b)
|
|
231
|
-
print(-b)
|
|
232
|
-
print(--b)
|
|
233
|
-
print(---b)
|
|
234
|
-
`;
|
|
235
|
-
|
|
236
|
-
const { hasError, visitor } = await runScript(script);
|
|
237
|
-
expect(hasError).toBe(false);
|
|
238
|
-
|
|
239
|
-
expect(visitor.printStream).toStrictEqual([20, -20, 20, -20]);
|
|
240
|
-
});
|
|
241
|
-
});
|
|
242
|
-
|
|
243
|
-
// This tests that an error is generated at the right position for
|
|
244
|
-
// overlapping connections
|
|
245
|
-
`
|
|
246
|
-
import lib
|
|
247
|
-
import { async } from '../src/sizing';
|
|
248
|
-
v5v = supply("5v")
|
|
249
|
-
gnd = dgnd()
|
|
250
|
-
|
|
251
|
-
c1 = cap(100n)
|
|
252
|
-
|
|
253
|
-
at v5v
|
|
254
|
-
wire down 20
|
|
255
|
-
branch:
|
|
256
|
-
wire down 20
|
|
257
|
-
add c1
|
|
258
|
-
wire down 20
|
|
259
|
-
to gnd
|
|
260
|
-
|
|
261
|
-
wire down 40 # error should be here
|
|
262
|
-
to c1 pin 1
|
|
263
|
-
`
|
package/__tests__/testRender.ts
DELETED
|
@@ -1,38 +0,0 @@
|
|
|
1
|
-
import { readFileSync } from 'fs';
|
|
2
|
-
|
|
3
|
-
import { LayoutEngine } from "../src/layout.js";
|
|
4
|
-
import { generateSVG2 } from "../src/render.js";
|
|
5
|
-
import { runScript } from "./helpers.js";
|
|
6
|
-
|
|
7
|
-
const mainPath = '__tests__/renderData/';
|
|
8
|
-
|
|
9
|
-
describe('Render tests', () => {
|
|
10
|
-
|
|
11
|
-
test.each([
|
|
12
|
-
['variant and branch rendering', 'script1.cst'],
|
|
13
|
-
['simple function', 'script2.cst'],
|
|
14
|
-
['simple frame', 'script3.cst'],
|
|
15
|
-
['drawing functions for graphics', 'script4.cst'],
|
|
16
|
-
['drawing 180 deg flipped components', 'script5.cst'],
|
|
17
|
-
['join command', 'script6.cst'],
|
|
18
|
-
['parallel command', 'script7.cst'],
|
|
19
|
-
['point block command', 'script8.cst']
|
|
20
|
-
|
|
21
|
-
])('render - %s (%s)', async (title, scriptPath) => {
|
|
22
|
-
|
|
23
|
-
const script = readFileSync(mainPath + scriptPath, { encoding: 'utf8' });
|
|
24
|
-
const { hasError, visitor } = await runScript(script);
|
|
25
|
-
expect(hasError).toBe(false);
|
|
26
|
-
visitor.annotateComponents();
|
|
27
|
-
|
|
28
|
-
const { sequence, nets } = visitor.getGraph();
|
|
29
|
-
|
|
30
|
-
const layoutEngine = new LayoutEngine();
|
|
31
|
-
const graph = await layoutEngine.runLayout(sequence, nets);
|
|
32
|
-
|
|
33
|
-
const svgOutput = generateSVG2(graph);
|
|
34
|
-
|
|
35
|
-
const expectedSvgOutput = readFileSync(mainPath + scriptPath + ".svg", { encoding: 'utf8' });
|
|
36
|
-
expect(svgOutput).toBe(expectedSvgOutput);
|
|
37
|
-
});
|
|
38
|
-
});
|