| 1 | import { assert, describe, it } from "@effect/vitest" |
| 2 | import * as Lexer from "effect/cli/internal/lexer" |
| 3 | |
| 4 | describe("Lexer", () => { |
| 5 | it("preserves every equals sign in a long option's inline value", () => { |
| 6 | const result = Lexer.lex(["--query=left=right"]) |
| 7 | |
| 8 | assert.deepStrictEqual(result.tokens, [{ |
| 9 | _tag: "LongOption", |
| 10 | name: "query", |
| 11 | raw: "--query=left=right", |
| 12 | value: "left=right" |
| 13 | }]) |
| 14 | }) |
| 15 | |
| 16 | it("lexes negative numbers as values", () => { |
| 17 | const result = Lexer.lex(["--lon", "-3.70", "-2", "-.5", "-1e3"]) |
| 18 | |
| 19 | assert.deepStrictEqual(result.tokens, [ |
| 20 | { _tag: "LongOption", name: "lon", raw: "--lon" }, |
| 21 | { _tag: "Value", value: "-3.70" }, |
| 22 | { _tag: "Value", value: "-2" }, |
| 23 | { _tag: "Value", value: "-.5" }, |
| 24 | { _tag: "Value", value: "-1e3" } |
| 25 | ]) |
| 26 | }) |
| 27 | |
| 28 | it("still lexes short options that are not negative numbers", () => { |
| 29 | const result = Lexer.lex(["-1a", "-e"]) |
| 30 | |
| 31 | assert.deepStrictEqual(result.tokens, [ |
| 32 | { _tag: "ShortOption", flag: "1", raw: "-1" }, |
| 33 | { _tag: "ShortOption", flag: "a", raw: "-a" }, |
| 34 | { _tag: "ShortOption", flag: "e", raw: "-e" } |
| 35 | ]) |
| 36 | }) |
| 37 | }) |