Skip to content

Commit 08c3ea7

Browse files
committed
Added unit tests for the CSS color module
1 parent fb3ceea commit 08c3ea7

File tree

18 files changed

+238
-97
lines changed

18 files changed

+238
-97
lines changed

docs/manual.pdf

15 Bytes
Binary file not shown.

docs/manual.typ

Lines changed: 169 additions & 80 deletions
Large diffs are not rendered by default.

scripts/generate_css_colors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ def generate_css_colors_module(color_map):
5555

5656
# Function to get GB function from the color map given a color name
5757
out.write("#let css(color-name) = {\n")
58-
out.write(' css-colors.at(lower(str(color-name)), default: rgb("#000000"))\n')
58+
out.write(' css-colors.at(lower(str(color-name)))\n')
5959
out.write("}\n")
6060

6161
print("✅ Generated css-colors module:")

src/css-colors.typ

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,5 +149,9 @@
149149
)
150150

151151
#let css(color-name) = {
152-
css-colors.at(lower(str(color-name)), default: rgb("#000000"))
152+
if lower(str(color-name)) in css-colors {
153+
css-colors.at(lower(str(color-name)))
154+
} else {
155+
panic("error: invalid CSS color name: " + str(color-name))
156+
}
153157
}
File renamed without changes.
File renamed without changes.

tests/case-insensitivity/test.typ

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
#import "/src/css-colors.typ": *
2+
3+
#assert.eq(
4+
css("AliceBlue"),
5+
rgb("#f0f8ff"),
6+
message: "The color name AliceBlue does not have the hex value #f0f8ff."
7+
)
8+
9+
#assert.eq(
10+
css("aliceblue"),
11+
rgb("#f0f8ff"),
12+
message: "The color name AliceBlue does not have the hex value #f0f8ff."
13+
)

tests/unit1/.gitignore renamed to tests/error-cases/.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,3 @@
22

33
diff/**
44
out/**
5-
ref/**

tests/error-cases/ref/1.png

339 Bytes
Loading

tests/error-cases/test.typ

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#import "/src/css-colors.typ": *
2+
3+
#assert.eq(
4+
catch(() => css("invalidcolor")),
5+
"panicked with: \"error: invalid CSS color name: invalidcolor\""
6+
)

0 commit comments

Comments
 (0)