-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
#31, type accessors and structure sets, part 5.
- Loading branch information
Showing
8 changed files
with
285 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
199 changes: 199 additions & 0 deletions
199
stage_2_fullset/spec-snapshot/source/structures/TypeAccessorProperties.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,199 @@ | ||
import { | ||
CodeBlockWriter | ||
} from "ts-morph"; | ||
|
||
import { | ||
ClassDeclarationImpl, | ||
TypeStructureKind, | ||
WriterTypeStructureImpl, | ||
} from "#stage_two/snapshot/source/exports.js"; | ||
|
||
import { | ||
TypeStructuresBase | ||
} from "#stage_two/snapshot/source/internal-exports.js"; | ||
|
||
describe("Type accessor properties work", () => { | ||
let writerCount = 0; | ||
function writerFunction( | ||
writer: CodeBlockWriter | ||
): void { | ||
writerCount++; | ||
writer.write("hello"); | ||
} | ||
|
||
const writerTypeStructure = new WriterTypeStructureImpl(writerFunction); | ||
|
||
let classDecl: ClassDeclarationImpl; | ||
beforeEach(() => { | ||
classDecl = new ClassDeclarationImpl; | ||
writerCount = 0; | ||
}); | ||
|
||
it("starting out undefined", () => { | ||
expect(classDecl.extends).toBe(undefined); | ||
expect(classDecl.extendsStructure).toBe(undefined); | ||
}); | ||
|
||
describe("with direct type access", () => { | ||
it("setting a literal", () => { | ||
classDecl.extends = "boolean"; | ||
expect(classDecl.extendsStructure).toBe("boolean"); | ||
expect(classDecl.extends).toBe("boolean"); | ||
}); | ||
|
||
it("setting a writer function", () => { | ||
classDecl.extends = writerFunction; | ||
expect(classDecl.extendsStructure).toBe(writerTypeStructure); | ||
expect(classDecl.extends).toBe(writerFunction); | ||
expect(writerCount).toBe(0); | ||
}); | ||
|
||
it("setting back to undefined after setting the type", () => { | ||
classDecl.extends = "never"; | ||
classDecl.extends = undefined; | ||
expect(classDecl.extends).toBe(undefined); | ||
expect(classDecl.extendsStructure).toBe(undefined); | ||
|
||
classDecl.extends = writerFunction; | ||
classDecl.extends = undefined; | ||
expect(classDecl.extends).toBe(undefined); | ||
expect(classDecl.extendsStructure).toBe(undefined); | ||
}); | ||
|
||
it("setting back to undefined after setting the type structure", () => { | ||
classDecl.extendsStructure = "never"; | ||
classDecl.extends = undefined; | ||
expect(classDecl.extends).toBe(undefined); | ||
expect(classDecl.extendsStructure as unknown).toBe(undefined); | ||
|
||
classDecl.extendsStructure = writerTypeStructure; | ||
classDecl.extends = undefined; | ||
expect(classDecl.extends).toBe(undefined); | ||
expect(classDecl.extendsStructure as unknown).toBe(undefined); | ||
}); | ||
}); | ||
|
||
describe("with type structure access", () => { | ||
it("setting a literal", () => { | ||
classDecl.extendsStructure = "boolean"; | ||
expect(classDecl.extends).toBe("boolean"); | ||
expect(classDecl.extendsStructure).toBe("boolean"); | ||
}); | ||
|
||
it("setting a type structure", () => { | ||
classDecl.extendsStructure = writerTypeStructure; | ||
expect(classDecl.extends).toBe(writerFunction); | ||
expect(classDecl.extendsStructure).toBe(writerTypeStructure); | ||
expect(writerCount).toBe(0); | ||
}); | ||
|
||
it("setting back to undefined after setting the type", () => { | ||
classDecl.extends = "never"; | ||
classDecl.extendsStructure = undefined; | ||
expect(classDecl.extends as unknown).toBe(undefined); | ||
expect(classDecl.extendsStructure).toBe(undefined); | ||
|
||
classDecl.extends = writerFunction; | ||
classDecl.extendsStructure = undefined; | ||
expect(classDecl.extends as unknown).toBe(undefined); | ||
expect(classDecl.extendsStructure).toBe(undefined); | ||
}); | ||
|
||
it("setting back to undefined after setting the type structure", () => { | ||
classDecl.extendsStructure = "never"; | ||
classDecl.extendsStructure = undefined; | ||
expect(classDecl.extends).toBe(undefined); | ||
expect(classDecl.extendsStructure).toBe(undefined); | ||
|
||
classDecl.extendsStructure = writerTypeStructure; | ||
classDecl.extendsStructure = undefined; | ||
expect(classDecl.extends).toBe(undefined); | ||
expect(classDecl.extendsStructure).toBe(undefined); | ||
}); | ||
}); | ||
|
||
describe("with static clone()", () => { | ||
let cloneDecl: ClassDeclarationImpl; | ||
it("starting from undefined", () => { | ||
cloneDecl = ClassDeclarationImpl.clone(classDecl); | ||
expect(cloneDecl.extends).toBe(undefined); | ||
expect(cloneDecl.extendsStructure).toBe(undefined); | ||
}); | ||
|
||
it("with a string type", () => { | ||
classDecl.extends = "boolean"; | ||
cloneDecl = ClassDeclarationImpl.clone(classDecl); | ||
expect(cloneDecl.extends).toBe("boolean"); | ||
expect(cloneDecl.extendsStructure).toBe("boolean"); | ||
}); | ||
|
||
it("with a writer function", () => { | ||
classDecl.extends = writerFunction; | ||
cloneDecl = ClassDeclarationImpl.clone(classDecl); | ||
expect(cloneDecl.extends).toBe(writerFunction); | ||
expect(cloneDecl.extendsStructure).not.toBe(writerTypeStructure); | ||
expect(typeof classDecl.extendsStructure).toBe("object"); | ||
if (typeof classDecl.extendsStructure === "object") { | ||
expect(classDecl.extendsStructure.kind).toBe(TypeStructureKind.Writer); | ||
expect(classDecl.extendsStructure.writerFunction).toBe(writerFunction); | ||
} | ||
|
||
expect( | ||
TypeStructuresBase.getTypeStructureForCallback(writerFunction) | ||
).toBe(writerTypeStructure); | ||
expect(writerCount).toBe(0); | ||
}); | ||
|
||
it("with a string type structure", () => { | ||
classDecl.extendsStructure = "boolean"; | ||
cloneDecl = ClassDeclarationImpl.clone(classDecl); | ||
expect(cloneDecl.extends).toBe("boolean"); | ||
expect(cloneDecl.extendsStructure).toBe("boolean"); | ||
}); | ||
|
||
it("with a writer type structure", () => { | ||
classDecl.extendsStructure = writerTypeStructure; | ||
cloneDecl = ClassDeclarationImpl.clone(classDecl); | ||
expect(cloneDecl.extends).toBe(writerFunction); | ||
expect(cloneDecl.extendsStructure).not.toBe(writerTypeStructure); | ||
expect(typeof classDecl.extendsStructure).toBe("object"); | ||
if (typeof classDecl.extendsStructure === "object") { | ||
expect(classDecl.extendsStructure.kind).toBe(TypeStructureKind.Writer); | ||
expect(classDecl.extendsStructure.writerFunction).toBe(writerFunction); | ||
} | ||
|
||
expect( | ||
TypeStructuresBase.getTypeStructureForCallback(writerFunction) | ||
).toBe(writerTypeStructure); | ||
expect(writerCount).toBe(0); | ||
}); | ||
}); | ||
|
||
describe("with .toJSON()", () => { | ||
it("starting out undefined", () => { | ||
expect("extends" in classDecl.toJSON()).toBe(false); | ||
}); | ||
|
||
it("and a string type field", () => { | ||
classDecl.extends = "boolean"; | ||
expect(classDecl.toJSON().extends).toBe("boolean"); | ||
}); | ||
|
||
it("and a writer function type field", () => { | ||
classDecl.extends = writerFunction; | ||
expect(classDecl.toJSON().extends).toBe("hello"); | ||
expect(writerCount).toBe(1); | ||
}); | ||
|
||
it("and a string typeStructure field", () => { | ||
classDecl.extendsStructure = "boolean"; | ||
expect(classDecl.toJSON().extends).toBe("boolean"); | ||
}); | ||
|
||
it("and an object typeStructure field", () => { | ||
classDecl.extendsStructure = writerTypeStructure; | ||
expect(classDecl.toJSON().extends).toBe("hello"); | ||
expect(writerCount).toBe(1); | ||
}); | ||
}); | ||
}); |
34 changes: 34 additions & 0 deletions
34
stage_2_fullset/spec-snapshot/source/structures/TypeStructureSetProperties.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
/* | ||
import { | ||
ClassDeclarationImpl, | ||
StringTypeStructureImpl, | ||
WriterTypeStructureImpl, | ||
} from "#stage_two/snapshot/source/exports.js"; | ||
describe("Type structure set properties work", () => { | ||
const stringTypeStructure = new StringTypeStructureImpl("NumberStringType"); | ||
const writerTypeStructure = new WriterTypeStructureImpl(writer => writer.write("NumberStringType")); | ||
let classDecl: ClassDeclarationImpl; | ||
beforeEach(() => classDecl = new ClassDeclarationImpl); | ||
describe("with direct type access", () => { | ||
}); | ||
describe("with type structure access", () => { | ||
}); | ||
describe("with static clone()", () => { | ||
}); | ||
describe("with .toJSON()", () => { | ||
}); | ||
}); | ||
*/ | ||
xit("TypeStructureSet", () => { | ||
expect(false).toBe(true); | ||
}); |