Skip to content

Commit

Permalink
start writing test
Browse files Browse the repository at this point in the history
  • Loading branch information
ajgateno committed Oct 31, 2024
1 parent 8725478 commit a8fd1c7
Show file tree
Hide file tree
Showing 5 changed files with 33 additions and 2 deletions.
10 changes: 10 additions & 0 deletions generators/typescript/codegen/src/ast/__test__/TypeLiteral.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { ts } from "../..";

describe("TypeLiteral", () => {
describe("numberToString", () => {
it("Should generate a simple number", () => {
const literal = ts.TypeLiteral.number(7);
expect(literal.toStringFormatted()).toMatchSnapshot();
});
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html

exports[`TypeLiteral > numberToString > Should generate a simple number`] = `
"7
`;
17 changes: 16 additions & 1 deletion generators/typescript/codegen/src/ast/core/AstNode.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,18 @@
import { AbstractAstNode } from "@fern-api/generator-commons";
import { Writer } from "./Writer";
import * as prettier from "prettier";

export abstract class AstNode extends AbstractAstNode {}
export abstract class AstNode extends AbstractAstNode {
/**
* Writes the node to a string.
*/
public toString(): string {
const writer = new Writer();
this.write(writer);
return writer.toString();
}

public toStringFormatted(): string {
return prettier.format(this.toString(), { parser: "typescript", tabWidth: 4, printWidth: 120 });
}
}
1 change: 1 addition & 0 deletions generators/typescript/codegen/src/ast/index.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
export * from "./core";
export { CodeBlock } from "./CodeBlock";
export { Type } from "./Type";
export { TypeLiteral } from "./TypeLiteral";
export { Variable } from "./Variable";
2 changes: 1 addition & 1 deletion generators/typescript/codegen/src/typescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@ export function variable(arg: AST.Variable.Args): AST.Variable {
}

export * from "./ast";
export { Type as Types } from "./ast";
export { Type as Types, TypeLiteral } from "./ast";
export * from "./ast/core";

0 comments on commit a8fd1c7

Please sign in to comment.