-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
291 additions
and
3 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
name: Bun CI | ||
|
||
on: [push, pull_request] | ||
|
||
jobs: | ||
test: | ||
runs-on: ubuntu-latest | ||
steps: | ||
- uses: actions/checkout@v3 | ||
- uses: antongolub/[email protected] | ||
with: | ||
bun-version: v1.x # Uses latest bun 1 | ||
- run: bun x jsr add @cross/test @std/assert @cross/runtime # Installs dependencies | ||
- run: bun test # Runs the tests |
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,22 @@ | ||
name: Node.js CI | ||
|
||
on: | ||
push: | ||
branches: [ main ] | ||
pull_request: | ||
branches: [ main ] | ||
|
||
jobs: | ||
build: | ||
|
||
runs-on: ubuntu-latest | ||
|
||
strategy: | ||
matrix: | ||
node-version: [18.x, 21.x] | ||
|
||
steps: | ||
- uses: actions/checkout@v3 | ||
- run: npx jsr add @cross/test @std/assert @cross/runtime | ||
- run: "echo '{ \"type\": \"module\" }' > package.json" # Needed for tsx to work | ||
- run: npx --yes tsx --test utils/*.test.ts |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
export { exit } from "./utils/exit.ts"; | ||
export { args } from "./utils/args.ts"; | ||
export { args, ArgsParser } from "./utils/args.ts"; | ||
export { Colors, Cursor, stripAnsi } from "./utils/ansi.ts"; |
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,11 +1,30 @@ | ||
import { test } from "@cross/test"; | ||
import { assertEquals } from "@std/assert"; | ||
|
||
import { stripAnsi } from "./ansi.ts"; | ||
import { Colors, Cursor, stripAnsi } from "./ansi.ts"; | ||
|
||
test("Strip ansi characters", () => { | ||
const text = | ||
"\x1b[31mThis is colored\x1b[0m and \x1b[2J\x1b[1;20Hsome more text"; | ||
const strippedText = stripAnsi(text); | ||
assertEquals(strippedText, "This is colored and some more text"); | ||
}); | ||
|
||
test("Apply bold formatting", () => { | ||
assertEquals(Colors.bold("hello"), "\x1b[1mhello\x1b[0m"); | ||
}); | ||
|
||
test("Set foreground color (RGB)", () => { | ||
assertEquals( | ||
Colors.rgb(255, 128, 0, "orange"), | ||
"\x1b[38;2;255;128;0morange\x1b[0m", | ||
); | ||
}); | ||
|
||
test("Set background color (green)", () => { | ||
assertEquals(Colors.bgGreen("grass"), "\x1b[42mgrass\x1b[0m"); | ||
}); | ||
|
||
test("Move cursor up", () => { | ||
assertEquals(Cursor.up(3), "\x1b[3A"); | ||
}); |
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,113 @@ | ||
import { test } from "@cross/test"; | ||
import { assertEquals } from "@std/assert"; | ||
|
||
import { ArgsParser } from "./args.ts"; | ||
|
||
test("Parse arguments using space as separator", () => { | ||
const cmdArgs = ["--port", "8080", "-v", "--configFile", "app.config"]; | ||
const parsedArgs = ArgsParser.parseArgs(cmdArgs); | ||
|
||
assertEquals(parsedArgs, { | ||
args: { | ||
port: ["8080"], | ||
v: [true], | ||
configFile: ["app.config"], | ||
}, | ||
loose: [], | ||
}); | ||
}); | ||
|
||
test("Parse arguments using equal sign as separator", () => { | ||
const cmdArgs = ["--arg=asd"]; | ||
const parsedArgs = ArgsParser.parseArgs(cmdArgs); | ||
|
||
assertEquals(parsedArgs, { | ||
args: { | ||
arg: ["asd"], | ||
}, | ||
loose: [], | ||
}); | ||
}); | ||
|
||
test("Handle flags with no values", () => { | ||
const cmdArgs = ["-v", "--debug"]; | ||
const parsedArgs = ArgsParser.parseArgs(cmdArgs); | ||
|
||
assertEquals(parsedArgs, { | ||
args: { | ||
v: [true], | ||
debug: [true], | ||
}, | ||
loose: [], | ||
}); | ||
}); | ||
|
||
test("Handle an argument at the end", () => { | ||
const cmdArgs = ["--port", "8080", "app.config"]; | ||
const parsedArgs = ArgsParser.parseArgs(cmdArgs); | ||
|
||
assertEquals(parsedArgs, { | ||
args: { | ||
port: ["8080"], | ||
}, | ||
loose: ["app.config"], | ||
}); | ||
}); | ||
|
||
test("Handle empty arguments", () => { | ||
const cmdArgs = ["--flag", ""]; | ||
const parsedArgs = ArgsParser.parseArgs(cmdArgs); | ||
|
||
assertEquals(parsedArgs, { | ||
args: { | ||
flag: [""], | ||
}, | ||
loose: [], | ||
}); | ||
}); | ||
|
||
test("Handle arguments with embedded equals signs", () => { | ||
const cmdArgs = ["--path", "/my/path=with/equals"]; | ||
const parsedArgs = ArgsParser.parseArgs(cmdArgs); | ||
|
||
assertEquals(parsedArgs, { | ||
args: { | ||
path: ["/my/path=with/equals"], | ||
}, | ||
loose: [], | ||
}); | ||
}); | ||
|
||
test("Handle multiple occurrences of a flag", () => { | ||
const cmdArgs = ["-v", "-v", "--config", "prod.config"]; | ||
const parsedArgs = ArgsParser.parseArgs(cmdArgs); | ||
|
||
assertEquals(parsedArgs, { | ||
args: { | ||
v: [true, true], | ||
config: ["prod.config"], | ||
}, | ||
loose: [], | ||
}); | ||
}); | ||
|
||
test("Test ArgsParser methods", () => { | ||
const cmdArgs = [ | ||
"-v", | ||
"-v", | ||
"--port", | ||
"8080", | ||
"--config-file", | ||
"prod.config", | ||
"file.txt", | ||
]; | ||
const parser = new ArgsParser(cmdArgs); | ||
|
||
assertEquals(parser.getArray("v"), [true, true]); | ||
assertEquals(parser.get("port"), "8080"); | ||
assertEquals(parser.count("config-file"), 1); | ||
assertEquals(parser.count("nonexistent"), 0); | ||
|
||
// Add a method to get loose arguments for completeness (optional) | ||
assertEquals(parser.getLoose(), ["file.txt"]); | ||
}); |
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