-
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.
- Loading branch information
1 parent
8680e26
commit b748ee4
Showing
7 changed files
with
185 additions
and
71 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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 @@ | ||
export { transpile } from "./transpile.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 |
---|---|---|
@@ -1,9 +1,99 @@ | ||
import { assertEquals } from "../../../deps/std/testing.ts"; | ||
import { TextBuilder } from "./text_builder.ts"; | ||
import { Cartridge } from "../cartridge/mod.ts"; | ||
import { Cartridge, CartridgeEvent } from "../cartridge/mod.ts"; | ||
import { T } from "../tokenize/mod.ts"; | ||
|
||
Deno.test("text builder exports an empty string when nothing is appended", () => { | ||
const cartridge = new Cartridge(); | ||
const builder = new TextBuilder(cartridge); | ||
assertEquals(builder.export(), ""); | ||
}); | ||
|
||
Deno.test("text builder appends file_start event", async () => { | ||
const cartridge = new Cartridge(); | ||
cartridge.on(CartridgeEvent.FileStart, () => "ABC"); | ||
const builder = new TextBuilder(cartridge); | ||
await builder.append(CartridgeEvent.FileStart); | ||
assertEquals(builder.export(), "ABC"); | ||
}); | ||
|
||
Deno.test("text builder appends inline_comment event", async () => { | ||
const cartridge = new Cartridge(); | ||
cartridge.on(CartridgeEvent.InlineComment, () => "ABC"); | ||
const builder = new TextBuilder(cartridge); | ||
await builder.append( | ||
CartridgeEvent.InlineComment, | ||
[T.comment("; Example", 1, 1)], | ||
[], | ||
); | ||
assertEquals(builder.export(), "ABC"); | ||
}); | ||
|
||
Deno.test("text builder appends multiline_comment event", async () => { | ||
const cartridge = new Cartridge(); | ||
cartridge.on(CartridgeEvent.MultilineComment, () => "ABC"); | ||
const builder = new TextBuilder(cartridge); | ||
await builder.append( | ||
CartridgeEvent.MultilineComment, | ||
[T.multiline_comment( | ||
`/* | ||
This is a multiline comment! | ||
*/`, | ||
1, | ||
1, | ||
)], | ||
[], | ||
); | ||
assertEquals(builder.export(), "ABC"); | ||
}); | ||
|
||
Deno.test("text builder appends load event", async () => { | ||
const cartridge = new Cartridge(); | ||
cartridge.on(CartridgeEvent.Load, () => "ABC"); | ||
const builder = new TextBuilder(cartridge); | ||
await builder.append( | ||
CartridgeEvent.Load, | ||
/* tokens=*/ [], | ||
/* comments=*/ [], | ||
/* always undefined=*/ undefined, | ||
/* src=*/ "", | ||
/* dep1=*/ "", | ||
); | ||
assertEquals(builder.export(), "ABC"); | ||
}); | ||
|
||
Deno.test("text builder appends struct_open event", async () => { | ||
const cartridge = new Cartridge(); | ||
cartridge.on(CartridgeEvent.StructOpen, () => "ABC"); | ||
const builder = new TextBuilder(cartridge); | ||
await builder.append(CartridgeEvent.StructOpen, [], []); | ||
assertEquals(builder.export(), "ABC"); | ||
}); | ||
|
||
Deno.test("text builder appends set_property event", async () => { | ||
const cartridge = new Cartridge(); | ||
cartridge.on(CartridgeEvent.SetProperty, () => "ABC"); | ||
const builder = new TextBuilder(cartridge); | ||
await builder.append(CartridgeEvent.SetProperty, [], []); | ||
assertEquals(builder.export(), "ABC"); | ||
}); | ||
|
||
Deno.test("text builder appends struct_close event", async () => { | ||
const cartridge = new Cartridge(); | ||
cartridge.on(CartridgeEvent.StructClose, () => "ABC"); | ||
const builder = new TextBuilder(cartridge); | ||
await builder.append( | ||
CartridgeEvent.StructClose, | ||
[T.denest(1, 1)], | ||
[], | ||
); | ||
assertEquals(builder.export(), "ABC"); | ||
}); | ||
|
||
Deno.test("text builder appends file_end event", async () => { | ||
const cartridge = new Cartridge(); | ||
cartridge.on(CartridgeEvent.FileEnd, () => "ABC"); | ||
const builder = new TextBuilder(cartridge); | ||
await builder.append(CartridgeEvent.FileEnd, [], []); | ||
assertEquals(builder.export(), "ABC"); | ||
}); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,19 +1,28 @@ | ||
import { assertEquals } from "../../deps/std/testing.ts"; | ||
import { transpile } from "./transpile.ts"; | ||
import { TranspilationContext, transpile } from "./transpile.ts"; | ||
import { Cartridge, CartridgeEvent } from "./cartridge/mod.ts"; | ||
import type { CartridgeEventContext } from "./cartridge/mod.ts"; | ||
// import type { FartOptions } from "./transpile.ts"; | ||
import { TextBuilder } from "./text_builder/mod.ts"; | ||
import { tokenize } from "./tokenize/mod.ts"; | ||
|
||
Deno.test("empty string results in empty string", async () => { | ||
const fakeCart = new Cartridge(); | ||
fakeCart.on( | ||
CartridgeEvent.StructOpen, | ||
(event: CartridgeEventContext<CartridgeEvent.StructOpen>) => { | ||
assertEquals(event.data.name, "Example"); | ||
console.log({ event }); | ||
return ""; | ||
}, | ||
); | ||
const result = await transpile(`type Example {`, fakeCart); | ||
assertEquals(result, ""); | ||
Deno.test("create transpilation context without crashing", () => { | ||
const iterator = tokenize(""); | ||
const cartridge = new Cartridge(); | ||
const builder = new TextBuilder(cartridge); | ||
const ctx = new TranspilationContext(iterator, builder); | ||
assertEquals(ctx.started, false); | ||
}); | ||
|
||
// Deno.test("transpiles struct_open event", async () => { | ||
// const fakeCart = new Cartridge(); | ||
// fakeCart.on( | ||
// CartridgeEvent.StructOpen, | ||
// (event: CartridgeEventContext<CartridgeEvent.StructOpen>) => { | ||
// assertEquals(event.data.name, "Example"); | ||
// assertEquals(event.data.comments, []); | ||
// return "ABC"; | ||
// }, | ||
// ); | ||
// const result = await transpile(`type Example {`, fakeCart); | ||
// assertEquals(result, "ABC"); | ||
// }); |
Oops, something went wrong.
b748ee4
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Failed to deploy: