Skip to content

Commit

Permalink
feat: add convergent test in webapp
Browse files Browse the repository at this point in the history
  • Loading branch information
Enter-tainer committed Mar 15, 2024
1 parent 1340939 commit b55d7ea
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
11 changes: 8 additions & 3 deletions web/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,18 @@ const { div, textarea, input, label, p, a } = van.tags;
const App = () => {
const input_val = van.state("")
const output = van.state("")
const error_message = van.state("")
const columns = van.state(80)
van.derive(
() => {
try {
output.val = pretty_print_wasm(input_val.val, columns.val)
} catch (e) {
output.val = e as string
error_message.val = ""
if (pretty_print_wasm(output.val, columns.val) !== output.val) {
throw new Error("Format doesn't converge! This means formatting the output again will result in a different output. This is a bug in the formatter. Please report it to https://github.com/Enter-tainer/typst-geshihua with the input code.")
}
} catch (e: any) {
error_message.val = e.message
}
}
)
Expand Down Expand Up @@ -47,7 +52,7 @@ const App = () => {
columns.val = parseInt((event.target! as HTMLInputElement).value)
}
})
)
), div(p({ class: "error-message" }, error_message.val))
)
}

Expand Down
6 changes: 6 additions & 0 deletions web/src/style.css
Original file line number Diff line number Diff line change
Expand Up @@ -101,3 +101,9 @@ textarea {
transition: border-color 0.25s;
width: 40%;
}

.error-message {
color: #ff4d4f;
margin-top: 0.5em;
font-family: monospace;
}

0 comments on commit b55d7ea

Please sign in to comment.