Skip to content

Commit b74903e

Browse files
committed
refactor: new spec for testing, and ci action
1 parent cb1cc5b commit b74903e

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

.github/workflows/ci.yml

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
pull_request:
6+
branches: [master]
7+
tags-ignore:
8+
- '*'
9+
jobs:
10+
build:
11+
runs-on: ubuntu-latest
12+
steps:
13+
- name: Download source
14+
uses: actions/checkout@v2
15+
- name: Install Crystal
16+
uses: crystal-lang/install-crystal@v1
17+
- name: Run tests
18+
run: crystal spec

spec/gradientty_spec.cr

Lines changed: 23 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -2,28 +2,33 @@ require "spec"
22
require "../src/gradientty"
33

44
describe "Gradientty" do
5-
it "prints predefined gradients correctly" do
6-
custom = Gradientty.gradient(["#ff5f6d", "#ffc371"])
5+
it "generates ANSI-colored strings for predefined gradients" do
6+
test_str = "Gradient Test"
7+
8+
gradients = {
9+
"rainbow" => Gradientty.rainbow(test_str),
10+
"crystal" => Gradientty.crystal(test_str),
11+
"pastel" => Gradientty.pastel(test_str),
12+
"vice" => Gradientty.vice(test_str),
13+
}
714

8-
output_0 = Gradientty.rainbow("A test for testing string with gradient.")
9-
output_1 = Gradientty.crystal("A test for testing string with gradient.")
10-
output_2 = Gradientty.pastel("A test for testing string with gradient.")
11-
output_3 = Gradientty.vice("A test for testing string with gradient.")
12-
output_4 = custom.call("CUSTOM")
13-
output_5 = custom.multiline("LINE1\nLINE2")
15+
gradients.each do |name, output|
16+
output.should_not eq ""
17+
# Check that ANSI escape codes exist
18+
output.should match(/\e\[38;2;\d+;\d+;\d+m/)
19+
end
20+
end
21+
22+
it "generates ANSI-colored strings for custom gradients" do
23+
custom = Gradientty.gradient(["#ff5f6d", "#ffc371"])
24+
output_1 = custom.call("CUSTOM")
25+
output_2 = custom.multiline("LINE1\nLINE2", true)
1426

15-
output_0.should_not eq ""
1627
output_1.should_not eq ""
1728
output_2.should_not eq ""
18-
output_3.should_not eq ""
19-
output_4.should_not eq ""
20-
output_5.should_not eq ""
2129

22-
puts output_0
23-
puts output_1
24-
puts output_2
25-
puts output_3
26-
puts output_4
27-
puts output_5
30+
# Check that ANSI escape codes exist
31+
output_1.should match(/\e\[38;2;\d+;\d+;\d+m/)
32+
output_2.should match(/\e\[38;2;\d+;\d+;\d+m/)
2833
end
2934
end

0 commit comments

Comments
 (0)