An experimental TypeSpec syntax for Lexicon

add test for @external

+88 -3
+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 - if (variants.stringLiterals.length > 0 || variants.knownValueRefs.length > 0) { 547 + if ( 548 + variants.stringLiterals.length > 0 || 549 + variants.knownValueRefs.length > 0 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 - return this.getReference(model, model.name, model.namespace, fullyQualified); 1489 + return this.getReference( 1490 + model, 1491 + model.name, 1492 + model.namespace, 1493 + fullyQualified, 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 - it.skip(`TODO: ${expectedPath} (add ${inputPath})`, function () {}); 109 + it(`should emit ${expectedPath}`, function () { 110 + assert.fail( 111 + `Expected output file ${expectedPath} has no corresponding input file ${inputPath}. ` + 112 + `Either add the input file or remove the expected output.` 113 + ); 114 + }); 110 115 } 111 116 } 117 + 118 + // Check for unexpected emitted files 119 + it("should not emit unexpected files", function () { 120 + const emittedFiles = Object.keys(emitResult.files).filter(f => f.endsWith(".json")); 121 + const expectedPaths = Object.keys(expectedFiles) 122 + .filter(f => f.endsWith(".json")) 123 + .map(normalizePathToPosix); 124 + 125 + const unexpected = emittedFiles.filter(f => !expectedPaths.includes(f)); 126 + 127 + if (unexpected.length > 0) { 128 + assert.fail( 129 + `Unexpected files were emitted: ${unexpected.join(", ")}. ` + 130 + `Either add expected output files or ensure these should not be emitted.` 131 + ); 132 + } 133 + }); 112 134 }); 113 135 } 114 136 });
+21
packages/emitter/test/spec/basic/output/com/example/other.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "com.example.other", 4 + "defs": { 5 + "main": { 6 + "type": "object", 7 + "properties": {} 8 + }, 9 + "someDef": { 10 + "type": "object", 11 + "required": [ 12 + "value" 13 + ], 14 + "properties": { 15 + "value": { 16 + "type": "string" 17 + } 18 + } 19 + } 20 + } 21 + }
+13
packages/emitter/test/spec/external/input/test/external.tsp
··· 1 + import "@typelex/emitter"; 2 + 3 + @external 4 + namespace test.external { 5 + model Main { 6 + shouldNotEmit: string; 7 + } 8 + 9 + model AlsoNotEmitted { 10 + @required 11 + value: boolean; 12 + } 13 + }
+7
packages/emitter/test/spec/external/input/test/normal.tsp
··· 1 + import "@typelex/emitter"; 2 + 3 + namespace test.normal { 4 + model Main { 5 + name?: string; 6 + } 7 + }
+14
packages/emitter/test/spec/external/output/test/normal.json
··· 1 + { 2 + "lexicon": 1, 3 + "id": "test.normal", 4 + "defs": { 5 + "main": { 6 + "type": "object", 7 + "properties": { 8 + "name": { 9 + "type": "string" 10 + } 11 + } 12 + } 13 + } 14 + }