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, 04:45 UTC
| 1 | /** |
| 2 | * Lexical semantics observed through the parser. Positions below count from |
| 3 | * the `{ f(s: ` prefix that `stringValue` wraps literals in, so a literal |
| 4 | * starts at column 8. |
| 5 | */ |
| 6 | import { assert, describe, it } from "@effect/vitest" |
| 7 | import { argumentValue, assertDiagnostic, parseOrThrow, stringValue } from "./utils/ast.ts" |
| 8 | |
| 9 | describe("Lexical", () => { |
| 10 | it("strings decode escape sequences, including surrogate pairs and variable-width escapes", () => { |
| 11 | assert.strictEqual(stringValue("\"\\\" \\n \\u0041 \\uD83D\\uDE00 \\u{1F600}\""), "\" \n A 😀 😀") |
| 12 | }) |
| 13 | |
| 14 | it("a lone surrogate escape is invalid", () => { |
| 15 | assertDiagnostic("{ f(s: \"\\uD83D\") }", { |
| 16 | line: 1, |
| 17 | column: 9, |
| 18 | message: "Invalid Unicode escape sequence: \"\\uD83D\"." |
| 19 | }) |
| 20 | }) |
| 21 | |
| 22 | it("a string cannot span lines", () => { |
| 23 | assertDiagnostic("{ f(s: \"ab\ncd\") }", { line: 1, column: 11, message: "Unterminated string." }) |
| 24 | }) |
| 25 | |
| 26 | it("block strings are dedented as in the spec's example", () => { |
| 27 | assert.strictEqual( |
| 28 | stringValue("\"\"\"\n Hello,\n World!\n\n Yours,\n GraphQL.\n \"\"\""), |
| 29 | "Hello,\n World!\n\nYours,\n GraphQL." |
| 30 | ) |
| 31 | }) |
| 32 | |
| 33 | it("block strings escape only the triple quote", () => { |
| 34 | assert.strictEqual(stringValue("\"\"\"a \\\"\"\" \\n\"\"\""), "a \"\"\" \\n") |
| 35 | }) |
| 36 | |
| 37 | it("numbers with a fraction or exponent are floats", () => { |
| 38 | assert.strictEqual(argumentValue("-12")._tag, "IntValue") |
| 39 | assert.strictEqual(argumentValue("-0.5e-3")._tag, "FloatValue") |
| 40 | }) |
| 41 | |
| 42 | it("a number cannot have a leading zero", () => { |
| 43 | assertDiagnostic("{ f(s: 01) }", { |
| 44 | line: 1, |
| 45 | column: 9, |
| 46 | message: "Invalid number, unexpected digit after 0: \"1\"." |
| 47 | }) |
| 48 | }) |
| 49 | |
| 50 | it("comments accept astral and control characters", () => { |
| 51 | assert.strictEqual(parseOrThrow("{ a } # 😀 \u0007\n{ b }").definitions.length, 2) |
| 52 | }) |
| 53 | |
| 54 | it("unpaired surrogates are rejected, even in comments", () => { |
| 55 | assertDiagnostic("{ a } # \uD800", { line: 1, column: 9, message: "Invalid character: U+D800." }) |
| 56 | }) |
| 57 | }) |