Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .busted
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
return {
default = {
ROOT = {"spec"},
pattern = "_spec",
verbose = true
}
}
27 changes: 27 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
name: CI

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v4

- name: Install Lua and LuaRocks
run: |
sudo apt-get update
sudo apt-get install -y lua5.3 luarocks

- name: Install busted testing framework
run: |
sudo luarocks install busted

- name: Run tests
run: |
busted
18 changes: 17 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,20 @@ luajit sequence.lua --color1 FF0000 --targetcolor1 00FFFF \
- **Flexible Input**: Accepts hex colors with or without `#` prefix.
- **Defaults**: Black → Gray → White (`000000` → `808080` → `FFFFFF`) if not specified.
- **Error Handling**: Invalid hex values will show a clear error message.
- **Backwards Compatible**: Defaults to grayscale if no color options are provided.
- **Backwards Compatible**: Defaults to grayscale if no color options are provided.

## Development

### Running Tests

The project uses the [busted](https://olivinelabs.com/busted/) testing framework. To run all tests:

```bash
# Install busted (requires luarocks)
sudo luarocks install busted

# Run all tests
busted
```

Tests are located in the `spec/` directory and follow the `*_spec.lua` naming convention.
34 changes: 0 additions & 34 deletions lib/cli-command-tests.lua

This file was deleted.

55 changes: 0 additions & 55 deletions lib/color-tests.lua

This file was deleted.

44 changes: 0 additions & 44 deletions lib/complex-tests.lua

This file was deleted.

54 changes: 54 additions & 0 deletions spec/cli_command_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
local cli = require("lib/cli-command")

describe("CLI command parsing", function()
it("should build command string from arguments", function()
local args = {"arg1", "arg2", "arg3"}
local result = cli.buildCommandString(args)
assert.are.equal("arg1 arg2 arg3", result)
end)

describe("getSwitch", function()
it("should detect switches correctly", function()
assert.is_truthy(cli.getSwitch("-b", "b", "black"))
end)

it("should parse complex command strings correctly", function()
local commandString = "-a -bc --long --typooo"
assert.is_truthy(cli.getSwitch(commandString, "a", "aaa"))
assert.is_truthy(cli.getSwitch(commandString, "b", "bbb"))
assert.is_truthy(cli.getSwitch(commandString, "c", "ccc"))
assert.is_truthy(cli.getSwitch(commandString, "l", "long"))
assert.is_falsy(cli.getSwitch(commandString, "d", "ddd"))
assert.is_falsy(cli.getSwitch(commandString, "t", "typo"))
assert.is_truthy(cli.getSwitch(commandString, "t", "typooo"))
end)
end)

describe("getArgument", function()
local commandString = "-a value -bc -d 1 -e -0.4 --long longvalue --typooo=typovalue -q \"some quoted' value\" -s 'another quoted\" value'"

it("should parse simple arguments", function()
assert.are.equal("value", cli.getArgument(commandString, "a", "aaa"))
assert.are.equal("1", cli.getArgument(commandString, "d", "ddd"))
assert.are.equal("longvalue", cli.getArgument(commandString, "l", "long"))
end)

it("should handle switches without values as true", function()
assert.are.equal(true, cli.getArgument(commandString, "b", "bbb"))
assert.are.equal(true, cli.getArgument(commandString, "c", "ccc"))
end)

it("should handle negative numbers", function()
assert.are.equal("-0.4", cli.getArgument(commandString, "e", "eee"))
end)

it("should handle quoted values", function()
assert.are.equal("some quoted' value", cli.getArgument(commandString, "q", "quoted"))
assert.are.equal("another quoted\" value", cli.getArgument(commandString, "s", "singlequoted"))
end)

it("should return nil for non-existent arguments", function()
assert.is_nil(cli.getArgument(commandString, "t", "typo"))
end)
end)
end)
97 changes: 97 additions & 0 deletions spec/color_spec.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
local color = require("lib/color")

describe("Color operations", function()
describe("parseHex", function()
it("should parse basic color hex values", function()
local red = color.parseHex("FF0000")
assert.are.equal(255, red.r)
assert.are.equal(0, red.g)
assert.are.equal(0, red.b)

local green = color.parseHex("00FF00")
assert.are.equal(0, green.r)
assert.are.equal(255, green.g)
assert.are.equal(0, green.b)

local blue = color.parseHex("0000FF")
assert.are.equal(0, blue.r)
assert.are.equal(0, blue.g)
assert.are.equal(255, blue.b)
end)

it("should handle hex values with # prefix", function()
local white = color.parseHex("#FFFFFF")
assert.are.equal(255, white.r)
assert.are.equal(255, white.g)
assert.are.equal(255, white.b)
end)

it("should parse black correctly", function()
local black = color.parseHex("000000")
assert.are.equal(0, black.r)
assert.are.equal(0, black.g)
assert.are.equal(0, black.b)
end)
end)

describe("interpolate", function()
local red = {r = 255, g = 0, b = 0}
local blue = {r = 0, g = 0, b = 255}

it("should interpolate between colors at midpoint", function()
local mid = color.interpolate(red, blue, 0.5)
assert.are.equal(127, mid.r)
assert.are.equal(0, mid.g)
assert.are.equal(127, mid.b)
end)

it("should return start color at t=0", function()
local start = color.interpolate(red, blue, 0)
assert.are.equal(255, start.r)
assert.are.equal(0, start.g)
assert.are.equal(0, start.b)
end)

it("should return end color at t=1", function()
local end_color = color.interpolate(red, blue, 1)
assert.are.equal(0, end_color.r)
assert.are.equal(0, end_color.g)
assert.are.equal(255, end_color.b)
end)
end)

describe("getGradientColor", function()
local red = {r = 255, g = 0, b = 0}
local green = {r = 0, g = 255, b = 0}
local blue = {r = 0, g = 0, b = 255}
local gradient = {red, green, blue}

it("should return first color at start", function()
local start = color.getGradientColor(gradient, 0)
assert.are.equal(255, start.r)
assert.are.equal(0, start.g)
assert.are.equal(0, start.b)
end)

it("should return middle color at midpoint", function()
local mid = color.getGradientColor(gradient, 0.5)
assert.are.equal(0, mid.r)
assert.are.equal(255, mid.g)
assert.are.equal(0, mid.b)
end)

it("should return last color at end", function()
local end_color = color.getGradientColor(gradient, 1)
assert.are.equal(0, end_color.r)
assert.are.equal(0, end_color.g)
assert.are.equal(255, end_color.b)
end)

it("should interpolate correctly at quarter point", function()
local quarter = color.getGradientColor(gradient, 0.25)
assert.are.equal(127, quarter.r)
assert.are.equal(127, quarter.g)
assert.are.equal(0, quarter.b)
end)
end)
end)
Loading
Loading