Skip to content

Commit fb3ceea

Browse files
committed
Added tests for CSS color module
1 parent 05bd26a commit fb3ceea

File tree

9 files changed

+196
-368
lines changed

9 files changed

+196
-368
lines changed

.typstignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,3 +14,4 @@ Justfile
1414
# PDF manuals should be included so that they can be linked, but not their sources
1515
docs/*
1616
!docs/*.pdf
17+
.DS_Store

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,3 +66,5 @@ A more in-depth description of usage. Any template arguments? A complicated exam
6666
* Confluence link:
6767
* Asana board:
6868
* etc...
69+
70+
# Needed to install just, rust and tytanic

docs/manual.pdf

-14.6 KB
Binary file not shown.

docs/manual.typ

Lines changed: 180 additions & 315 deletions
Large diffs are not rendered by default.

scripts/generate_css_colors.py

Lines changed: 3 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -19,33 +19,16 @@
1919
# generate_css_colors.py
2020

2121
import os
22-
import platform
23-
import shutil
24-
import sys
2522

26-
CSS_COLORS_MODULE_NAME = "css-colors"
27-
CSS_COLORS_MODULE_VERSION = "0.1.0"
2823
CSS_COLORS_MODULE = os.path.abspath("../src/css-colors.typ")
2924
HTML_COLORS_TABLE = os.path.abspath("../docs/css-colors-table.html")
3025
INPUT_FILE = os.path.abspath("css-hex.txt")
3126

32-
PREVIEW_DIR = os.path.join("preview", CSS_COLORS_MODULE_NAME, CSS_COLORS_MODULE_VERSION)
33-
PACKAGE_DIR = {
34-
"Linux": os.path.join(
35-
os.path.expanduser("~/.local/share/typst/packages"), PREVIEW_DIR
36-
),
37-
"Darwin": os.path.join(
38-
os.path.expanduser("~/Library/Application Support/typst/packages"),
39-
PREVIEW_DIR,
40-
),
41-
}
42-
4327

4428
def main():
4529
"""Generate css-colors module and HTML colors table."""
4630
color_map = get_css_color_map()
47-
pkg_dir = create_preview_pkg_dir()
48-
generate_css_colors_module(color_map, pkg_dir)
31+
generate_css_colors_module(color_map)
4932
generate_html_colors_table(color_map)
5033

5134

@@ -61,24 +44,7 @@ def get_css_color_map():
6144
color_map[name.lower()] = hexval.lower()
6245
return color_map
6346

64-
65-
def create_preview_pkg_dir():
66-
"""Create the preview package directory."""
67-
pkg_dir = None
68-
try:
69-
pkg_dir = PACKAGE_DIR[platform.system()]
70-
except KeyError:
71-
print(f"❌ Unsupported platform: {platform.system()}")
72-
sys.exit(1)
73-
74-
os.makedirs(pkg_dir, exist_ok=True)
75-
os.makedirs(os.path.join(pkg_dir, "src"), exist_ok=True)
76-
77-
print(f"✅ Created preview package directory: {pkg_dir}")
78-
return pkg_dir
79-
80-
81-
def generate_css_colors_module(color_map, pkg_dir):
47+
def generate_css_colors_module(color_map):
8248
"""Generate the css-colors module."""
8349
with open(CSS_COLORS_MODULE, "w", encoding="utf-8") as out:
8450
# CSS color map
@@ -89,22 +55,9 @@ def generate_css_colors_module(color_map, pkg_dir):
8955

9056
# Function to get GB function from the color map given a color name
9157
out.write("#let css(color-name) = {\n")
92-
out.write(
93-
".".join(
94-
[
95-
" css-colors.at(lower(str(color-name))",
96-
'replace(" ", "")',
97-
'replace("_", "")',
98-
'replace("-", ""))\n',
99-
]
100-
)
101-
)
58+
out.write(' css-colors.at(lower(str(color-name)), default: rgb("#000000"))\n')
10259
out.write("}\n")
10360

104-
# Copy the module and TOML to the preview package directory
105-
shutil.copytree("../src", os.path.join(pkg_dir, "src"), dirs_exist_ok=True)
106-
shutil.copy("../typst.toml", os.path.join(pkg_dir, "typst.toml"))
107-
10861
print("✅ Generated css-colors module:")
10962
print(f"- {CSS_COLORS_MODULE}")
11063

src/css-colors.typ

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

151151
#let css(color-name) = {
152-
css-colors.at(lower(str(color-name)).replace(" ", "").replace("_", "").replace("-", ""))
152+
css-colors.at(lower(str(color-name)), default: rgb("#000000"))
153153
}

tests/test1/ref/1.png

-50.1 KB
Loading

tests/test1/test.typ

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
#import "@preview/css-colors:0.1.0": *
22

3-
Hello World
3+
#assert.eq(
4+
css("aliceblue"), rgb("#f0f8ff"), message: "The color name aliceblue should be the same as the hex value #f0f8ff.",
5+
)
6+
#assert.eq(
7+
css("AliceBlue"), rgb("#f0f8ff"), message: "The color name AliceBlue should be the same as the hex value #f0f8ff.",
8+
)
9+
#assert.eq(css("color"), rgb("#000000"), message: "The color name color should default to black.",
10+
)

tests/unit1/test.typ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
#import #import "@preview/css-colors:0.1.0": *
1+
#import "@preview/css-colors:0.1.0": *
22

33
// TODO real tests
44
#assert(true)

0 commit comments

Comments
 (0)