Skip to content

Commit 6f2e78a

Browse files
authored
Merge pull request #15 from InDieTasten/copilot/fix-8
Migrate tests to busted framework and add CI workflow
2 parents d8ab65e + e5ff03d commit 6f2e78a

File tree

10 files changed

+256
-167
lines changed

10 files changed

+256
-167
lines changed

.busted

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
return {
2+
default = {
3+
ROOT = {"spec"},
4+
pattern = "_spec",
5+
verbose = true
6+
}
7+
}

.github/workflows/ci.yml

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
jobs:
10+
test:
11+
runs-on: ubuntu-latest
12+
13+
steps:
14+
- uses: actions/checkout@v4
15+
16+
- name: Install Lua and LuaRocks
17+
run: |
18+
sudo apt-get update
19+
sudo apt-get install -y lua5.3 liblua5.3-dev luarocks
20+
21+
- name: Install busted testing framework
22+
run: |
23+
sudo luarocks install busted
24+
25+
- name: Run tests
26+
run: |
27+
busted

README.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,4 +124,20 @@ luajit sequence.lua --color1 FF0000 --targetcolor1 00FFFF \
124124
- **Flexible Input**: Accepts hex colors with or without `#` prefix.
125125
- **Defaults**: Black → Gray → White (`000000``808080``FFFFFF`) if not specified.
126126
- **Error Handling**: Invalid hex values will show a clear error message.
127-
- **Backwards Compatible**: Defaults to grayscale if no color options are provided.
127+
- **Backwards Compatible**: Defaults to grayscale if no color options are provided.
128+
129+
## Development
130+
131+
### Running Tests
132+
133+
The project uses the [busted](https://olivinelabs.com/busted/) testing framework. To run all tests:
134+
135+
```bash
136+
# Install busted (requires luarocks)
137+
sudo luarocks install busted
138+
139+
# Run all tests
140+
busted
141+
```
142+
143+
Tests are located in the `spec/` directory and follow the `*_spec.lua` naming convention.

lib/cli-command-tests.lua

Lines changed: 0 additions & 34 deletions
This file was deleted.

lib/color-tests.lua

Lines changed: 0 additions & 55 deletions
This file was deleted.

lib/complex-tests.lua

Lines changed: 0 additions & 44 deletions
This file was deleted.

spec/cli_command_spec.lua

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
local cli = require("lib/cli-command")
2+
3+
describe("CLI command parsing", function()
4+
it("should build command string from arguments", function()
5+
local args = {"arg1", "arg2", "arg3"}
6+
local result = cli.buildCommandString(args)
7+
assert.are.equal("arg1 arg2 arg3", result)
8+
end)
9+
10+
describe("getSwitch", function()
11+
it("should detect switches correctly", function()
12+
assert.is_truthy(cli.getSwitch("-b", "b", "black"))
13+
end)
14+
15+
it("should parse complex command strings correctly", function()
16+
local commandString = "-a -bc --long --typooo"
17+
assert.is_truthy(cli.getSwitch(commandString, "a", "aaa"))
18+
assert.is_truthy(cli.getSwitch(commandString, "b", "bbb"))
19+
assert.is_truthy(cli.getSwitch(commandString, "c", "ccc"))
20+
assert.is_truthy(cli.getSwitch(commandString, "l", "long"))
21+
assert.is_falsy(cli.getSwitch(commandString, "d", "ddd"))
22+
assert.is_falsy(cli.getSwitch(commandString, "t", "typo"))
23+
assert.is_truthy(cli.getSwitch(commandString, "t", "typooo"))
24+
end)
25+
end)
26+
27+
describe("getArgument", function()
28+
local commandString = "-a value -bc -d 1 -e -0.4 --long longvalue --typooo=typovalue -q \"some quoted' value\" -s 'another quoted\" value'"
29+
30+
it("should parse simple arguments", function()
31+
assert.are.equal("value", cli.getArgument(commandString, "a", "aaa"))
32+
assert.are.equal("1", cli.getArgument(commandString, "d", "ddd"))
33+
assert.are.equal("longvalue", cli.getArgument(commandString, "l", "long"))
34+
end)
35+
36+
it("should handle switches without values as true", function()
37+
assert.are.equal(true, cli.getArgument(commandString, "b", "bbb"))
38+
assert.are.equal(true, cli.getArgument(commandString, "c", "ccc"))
39+
end)
40+
41+
it("should handle negative numbers", function()
42+
assert.are.equal("-0.4", cli.getArgument(commandString, "e", "eee"))
43+
end)
44+
45+
it("should handle quoted values", function()
46+
assert.are.equal("some quoted' value", cli.getArgument(commandString, "q", "quoted"))
47+
assert.are.equal("another quoted\" value", cli.getArgument(commandString, "s", "singlequoted"))
48+
end)
49+
50+
it("should return nil for non-existent arguments", function()
51+
assert.is_nil(cli.getArgument(commandString, "t", "typo"))
52+
end)
53+
end)
54+
end)

spec/color_spec.lua

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
local color = require("lib/color")
2+
3+
describe("Color operations", function()
4+
describe("parseHex", function()
5+
it("should parse basic color hex values", function()
6+
local red = color.parseHex("FF0000")
7+
assert.are.equal(255, red.r)
8+
assert.are.equal(0, red.g)
9+
assert.are.equal(0, red.b)
10+
11+
local green = color.parseHex("00FF00")
12+
assert.are.equal(0, green.r)
13+
assert.are.equal(255, green.g)
14+
assert.are.equal(0, green.b)
15+
16+
local blue = color.parseHex("0000FF")
17+
assert.are.equal(0, blue.r)
18+
assert.are.equal(0, blue.g)
19+
assert.are.equal(255, blue.b)
20+
end)
21+
22+
it("should handle hex values with # prefix", function()
23+
local white = color.parseHex("#FFFFFF")
24+
assert.are.equal(255, white.r)
25+
assert.are.equal(255, white.g)
26+
assert.are.equal(255, white.b)
27+
end)
28+
29+
it("should parse black correctly", function()
30+
local black = color.parseHex("000000")
31+
assert.are.equal(0, black.r)
32+
assert.are.equal(0, black.g)
33+
assert.are.equal(0, black.b)
34+
end)
35+
end)
36+
37+
describe("interpolate", function()
38+
local red = {r = 255, g = 0, b = 0}
39+
local blue = {r = 0, g = 0, b = 255}
40+
41+
it("should interpolate between colors at midpoint", function()
42+
local mid = color.interpolate(red, blue, 0.5)
43+
assert.are.equal(127, mid.r)
44+
assert.are.equal(0, mid.g)
45+
assert.are.equal(127, mid.b)
46+
end)
47+
48+
it("should return start color at t=0", function()
49+
local start = color.interpolate(red, blue, 0)
50+
assert.are.equal(255, start.r)
51+
assert.are.equal(0, start.g)
52+
assert.are.equal(0, start.b)
53+
end)
54+
55+
it("should return end color at t=1", function()
56+
local end_color = color.interpolate(red, blue, 1)
57+
assert.are.equal(0, end_color.r)
58+
assert.are.equal(0, end_color.g)
59+
assert.are.equal(255, end_color.b)
60+
end)
61+
end)
62+
63+
describe("getGradientColor", function()
64+
local red = {r = 255, g = 0, b = 0}
65+
local green = {r = 0, g = 255, b = 0}
66+
local blue = {r = 0, g = 0, b = 255}
67+
local gradient = {red, green, blue}
68+
69+
it("should return first color at start", function()
70+
local start = color.getGradientColor(gradient, 0)
71+
assert.are.equal(255, start.r)
72+
assert.are.equal(0, start.g)
73+
assert.are.equal(0, start.b)
74+
end)
75+
76+
it("should return middle color at midpoint", function()
77+
local mid = color.getGradientColor(gradient, 0.5)
78+
assert.are.equal(0, mid.r)
79+
assert.are.equal(255, mid.g)
80+
assert.are.equal(0, mid.b)
81+
end)
82+
83+
it("should return last color at end", function()
84+
local end_color = color.getGradientColor(gradient, 1)
85+
assert.are.equal(0, end_color.r)
86+
assert.are.equal(0, end_color.g)
87+
assert.are.equal(255, end_color.b)
88+
end)
89+
90+
it("should interpolate correctly at quarter point", function()
91+
local quarter = color.getGradientColor(gradient, 0.25)
92+
assert.are.equal(127, quarter.r)
93+
assert.are.equal(127, quarter.g)
94+
assert.are.equal(0, quarter.b)
95+
end)
96+
end)
97+
end)

0 commit comments

Comments
 (0)