-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
presentWordAsEnv
-- improve snapshot test -- use formatEnv
- Loading branch information
Showing
6 changed files
with
76 additions
and
22 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { indent } from "../../utils/indent" | ||
import { formatNet } from "../net/formatNet" | ||
import { netIsEmpty } from "../net/netIsEmpty" | ||
import { formatValue } from "../value" | ||
import { Env } from "./Env" | ||
|
||
export function formatEnv(env: Env): string { | ||
const netText = netIsEmpty(env.net) | ||
? "net end" | ||
: [`net`, indent(formatNet(env.net)), `end`].join("\n") | ||
|
||
const stackText = | ||
env.stack.length === 0 | ||
? "stack end" | ||
: [`stack`, indent(env.stack.map(formatValue).join(" ")), `end`].join( | ||
"\n", | ||
) | ||
|
||
const localsText = | ||
env.locals.size === 0 | ||
? "locals end" | ||
: [ | ||
`locals`, | ||
indent( | ||
Array.from(env.locals.entries()) | ||
.map(([name, value]) => `${formatValue(value)} $${name}`) | ||
.join("\n"), | ||
), | ||
`end`, | ||
].join("\n") | ||
|
||
return [ | ||
`env`, | ||
indent(netText), | ||
indent(stackText), | ||
indent(localsText), | ||
`end`, | ||
].join("\n") | ||
} |
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 +1,3 @@ | ||
export * from "./Env" | ||
export * from "./createEnv" | ||
export * from "./formatEnv" |
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,5 @@ | ||
import { Net } from "./Net" | ||
|
||
export function netIsEmpty(net: Net): boolean { | ||
return net.activeEdges.length === 0 && net.nodeEntries.size === 0 | ||
} |
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