tangled
alpha
login
or
join now
maxine.puppykitty.racing
/
typelex
forked from
danabra.mov/typelex
0
fork
atom
An experimental TypeSpec syntax for Lexicon
0
fork
atom
overview
issues
pulls
pipelines
add test for @external
danabra.mov
5 months ago
cc7be569
9bfd449a
+88
-3
6 changed files
expand all
collapse all
unified
split
packages
emitter
src
emitter.ts
test
spec
basic
output
com
example
other.json
external
input
test
external.tsp
normal.tsp
output
test
normal.json
spec.test.ts
+10
-2
packages/emitter/src/emitter.ts
···
544
544
545
545
// Model reference union (including empty union with unknown)
546
546
if (variants.unionRefs.length > 0 || variants.hasUnknown) {
547
547
-
if (variants.stringLiterals.length > 0 || variants.knownValueRefs.length > 0) {
547
547
+
if (
548
548
+
variants.stringLiterals.length > 0 ||
549
549
+
variants.knownValueRefs.length > 0
550
550
+
) {
548
551
this.program.reportDiagnostic({
549
552
code: "union-mixed-refs-literals",
550
553
severity: "error",
···
1483
1486
model: Model,
1484
1487
fullyQualified = false,
1485
1488
): string | null {
1486
1486
-
return this.getReference(model, model.name, model.namespace, fullyQualified);
1489
1489
+
return this.getReference(
1490
1490
+
model,
1491
1491
+
model.name,
1492
1492
+
model.namespace,
1493
1493
+
fullyQualified,
1494
1494
+
);
1487
1495
}
1488
1496
1489
1497
private getUnionReference(union: Union): string | null {
+23
-1
packages/emitter/test/spec.test.ts
···
106
106
assert.deepStrictEqual(actual, expected);
107
107
});
108
108
} else {
109
109
-
it.skip(`TODO: ${expectedPath} (add ${inputPath})`, function () {});
109
109
+
it(`should emit ${expectedPath}`, function () {
110
110
+
assert.fail(
111
111
+
`Expected output file ${expectedPath} has no corresponding input file ${inputPath}. ` +
112
112
+
`Either add the input file or remove the expected output.`
113
113
+
);
114
114
+
});
110
115
}
111
116
}
117
117
+
118
118
+
// Check for unexpected emitted files
119
119
+
it("should not emit unexpected files", function () {
120
120
+
const emittedFiles = Object.keys(emitResult.files).filter(f => f.endsWith(".json"));
121
121
+
const expectedPaths = Object.keys(expectedFiles)
122
122
+
.filter(f => f.endsWith(".json"))
123
123
+
.map(normalizePathToPosix);
124
124
+
125
125
+
const unexpected = emittedFiles.filter(f => !expectedPaths.includes(f));
126
126
+
127
127
+
if (unexpected.length > 0) {
128
128
+
assert.fail(
129
129
+
`Unexpected files were emitted: ${unexpected.join(", ")}. ` +
130
130
+
`Either add expected output files or ensure these should not be emitted.`
131
131
+
);
132
132
+
}
133
133
+
});
112
134
});
113
135
}
114
136
});
+21
packages/emitter/test/spec/basic/output/com/example/other.json
···
1
1
+
{
2
2
+
"lexicon": 1,
3
3
+
"id": "com.example.other",
4
4
+
"defs": {
5
5
+
"main": {
6
6
+
"type": "object",
7
7
+
"properties": {}
8
8
+
},
9
9
+
"someDef": {
10
10
+
"type": "object",
11
11
+
"required": [
12
12
+
"value"
13
13
+
],
14
14
+
"properties": {
15
15
+
"value": {
16
16
+
"type": "string"
17
17
+
}
18
18
+
}
19
19
+
}
20
20
+
}
21
21
+
}
+13
packages/emitter/test/spec/external/input/test/external.tsp
···
1
1
+
import "@typelex/emitter";
2
2
+
3
3
+
@external
4
4
+
namespace test.external {
5
5
+
model Main {
6
6
+
shouldNotEmit: string;
7
7
+
}
8
8
+
9
9
+
model AlsoNotEmitted {
10
10
+
@required
11
11
+
value: boolean;
12
12
+
}
13
13
+
}
+7
packages/emitter/test/spec/external/input/test/normal.tsp
···
1
1
+
import "@typelex/emitter";
2
2
+
3
3
+
namespace test.normal {
4
4
+
model Main {
5
5
+
name?: string;
6
6
+
}
7
7
+
}
+14
packages/emitter/test/spec/external/output/test/normal.json
···
1
1
+
{
2
2
+
"lexicon": 1,
3
3
+
"id": "test.normal",
4
4
+
"defs": {
5
5
+
"main": {
6
6
+
"type": "object",
7
7
+
"properties": {
8
8
+
"name": {
9
9
+
"type": "string"
10
10
+
}
11
11
+
}
12
12
+
}
13
13
+
}
14
14
+
}