The best way to control Claude Code, Codex and more from any computer or phone
Mirrored from https://github.com/Camo67/t3code.git
Synced Nov 21, 06:00 UTC
| 1 | import { parse } from "@effect/graphql-generator/internal/Parser" |
| 2 | import { assert, describe, it } from "@effect/vitest" |
| 3 | import * as Result from "effect/Result" |
| 4 | import { assertDiagnostic, source } from "./utils/ast.ts" |
| 5 | |
| 6 | const failure = (body: string, path?: string) => { |
| 7 | const result = parse(source(body, path)) |
| 8 | assert(Result.isFailure(result), "expected a diagnostic") |
| 9 | return result.failure |
| 10 | } |
| 11 | |
| 12 | describe("Diagnostic", () => { |
| 13 | it("is a tagged error carrying the source path", () => { |
| 14 | const diagnostic = failure("{", "queries/viewer.graphql") |
| 15 | assert.strictEqual(diagnostic._tag, "Diagnostic") |
| 16 | assert.strictEqual(diagnostic.path, "queries/viewer.graphql") |
| 17 | assert.instanceOf(diagnostic, Error) |
| 18 | }) |
| 19 | |
| 20 | it("columns count UTF-16 code units", () => { |
| 21 | assertDiagnostic("{ f(s: \"😀\") ? }", { line: 1, column: 14, message: "Unexpected character: \"?\"." }) |
| 22 | }) |
| 23 | |
| 24 | it("code frame shows the neighbouring lines and a caret under the column", () => { |
| 25 | const diagnostic = failure("query Q {\n a(b: )\n}") |
| 26 | assert.strictEqual(diagnostic.line, 2) |
| 27 | assert.strictEqual(diagnostic.column, 8) |
| 28 | assert.strictEqual(diagnostic.message, "Unexpected \")\".") |
| 29 | assert.strictEqual( |
| 30 | diagnostic.codeFrame, |
| 31 | [ |
| 32 | "1 | query Q {", |
| 33 | "2 | a(b: )", |
| 34 | " | ^", |
| 35 | "3 | }" |
| 36 | ].join("\n") |
| 37 | ) |
| 38 | }) |
| 39 | |
| 40 | it("code frame right-aligns line numbers of different widths", () => { |
| 41 | const body = ["{", " a", " b", " c", " d", " e", " f", " g", " h", " ?"].join("\n") |
| 42 | const diagnostic = failure(body) |
| 43 | assert.strictEqual(diagnostic.line, 10) |
| 44 | assert.strictEqual(diagnostic.column, 3) |
| 45 | assert.strictEqual(diagnostic.codeFrame, [" 9 | h", "10 | ?", " | ^"].join("\n")) |
| 46 | }) |
| 47 | }) |