interplane.Get Omega
Read in your language

omega-mv

Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.

Brought by drakestapleton

branch main Branches Tags History

omega-mv / aienux / crates / allen-design-tokens / design_tokens_test.om

137 lines · 3678 bytes Raw Blame History
1note SPDX-License-Identifier: Apache-2.0
2note aienux/crates/allen-design-tokens/design_tokens_test.om: Behavioral self-test for allen-design-tokens.
3note Compose with: si/directives/om2.om aienux/crates/allen-design-tokens/design_tokens.om aienux/crates/allen-design-tokens/design_tokens_test.om
4
5text adtt_mini "---\nname: T\ncolors:\n primary: \"#ECF0FC\"\n night: \"#060812\"\ncomponents:\n page:\n backgroundColor: \"{colors.night}\"\n---\n\n## Motion\n\n```allen-tokens\nmotion:\n letter: 35ms\n ease-smooth: \"cubic-bezier(0.3333, 0, 0.6667, 1)\"\ncontrast:\n primary-on-night: \"7.0\"\n```\n"
6text adtt_bad_ref "---\ncolors:\n night: \"#060812\"\ncomponents:\n page:\n backgroundColor: \"{colors.nope}\"\n---\n"
7text adtt_dup "---\nmotion:\n letter: 35ms\n letter: 36ms\n---\n"
8text adtt_loop "---\na: \"{b}\"\nb: \"{a}\"\n---\n"
9
10text adtt_p_night "colors.night"
11text adtt_p_bg "components.page.backgroundColor"
12text adtt_p_letter "motion.letter"
13text adtt_p_ease "motion.ease-smooth"
14text adtt_v_night "#060812"
15text adtt_v_letter "35ms"
16text adtt_c_night "#define ALLEN_COLORS_NIGHT 0x060812u\n"
17text adtt_c_letter "#define ALLEN_MOTION_LETTER_MS 35u\n"
18text adtt_c_ease "#define ALLEN_MOTION_EASE_SMOOTH_X1_Q16 21843\n"
19
20fn adtt_raw_eq idx ulong want view uchar * to bool
21if ne get adt_raw_len idx len want
22ret false
23end
24base = mul idx ADT_MAX_RAW
25for i ulong len want bound 64
26if ne get adt_raw add base i get want i
27ret false
28end
29end
30ret true
31end
32
33fn main to int
34note 1. Parse MINI front matter + allen-tokens block + resolve reference
35if ne adt_parse adtt_mini len adtt_mini ADT_OK
36ret 1
37end
38i_night = adt_find_token adtt_p_night len adtt_p_night
39if lt i_night 0
40ret 2
41end
42if not adtt_raw_eq ulong i_night adtt_v_night
43ret 3
44end
45i_bg = adt_find_token adtt_p_bg len adtt_p_bg
46if lt i_bg 0
47ret 4
48end
49if not adtt_raw_eq ulong i_bg adtt_v_night
50ret 5
51end
52i_let = adt_find_token adtt_p_letter len adtt_p_letter
53if lt i_let 0
54ret 6
55end
56if not adtt_raw_eq ulong i_let adtt_v_letter
57ret 7
58end
59
60note 2. Contrast check on primary (#ECF0FC) on night (#060812) passes floor 7.0
61if ne adt_check_contrast ADT_OK
62ret 8
63end
64if ne get adt_cr_cnt 0 1
65ret 9
66end
67if ne get adt_cr_pass 0 1
68ret 10
69end
70if lt get adt_cr_ratio 0 15.0f64
71ret 11
72end
73
74note 3. C export is integer-only and matches exact #define lines
75line = new uchar 128 0
76n1 = adt_emit_c_token ulong i_night line
77if ne n1 long len adtt_c_night
78ret 12
79end
80if not adt_slice_eq part line 0 ulong n1 adtt_c_night
81ret 13
82end
83
84n2 = adt_emit_c_token ulong i_let line
85if ne n2 long len adtt_c_letter
86ret 14
87end
88if not adt_slice_eq part line 0 ulong n2 adtt_c_letter
89ret 15
90end
91
92i_ease = adt_find_token adtt_p_ease len adtt_p_ease
93if lt i_ease 0
94ret 16
95end
96n3 = adt_emit_c_token ulong i_ease line
97if ne n3 long len adtt_c_ease
98ret 17
99end
100if not adt_slice_eq part line 0 ulong n3 adtt_c_ease
101ret 18
102end
103
104note 4. WCAG 2.2 reference contrast values: black on white == 21:1, equal == 1:1
105c_bw = adt_contrast 0 0 0 255 255 255
106if gt fabs sub c_bw 21.0f64 0.000001f64
107ret 19
108end
109c_eq = adt_contrast 6 8 18 6 8 18
110if gt fabs sub c_eq 1.0f64 0.000001f64
111ret 20
112end
113
114note 5. Fixed-point kernel constants (chirp peak Q15=22937, breath depth Q16=1966, heart Q8=50,70,120,80)
115if ne adt_q_fixed 0.7f64 32767.0f64 22937
116ret 21
117end
118if ne adt_q_fixed 0.030f64 65536.0f64 1966
119ret 22
120end
121if ne adt_q_fixed 0.195f64 256.0f64 50
122ret 23
123end
124
125note 6. Error paths: broken reference, duplicate token, reference loop
126if ne adt_parse adtt_bad_ref len adtt_bad_ref ADT_ERR_REF_MISSING
127ret 24
128end
129if ne adt_parse adtt_dup len adtt_dup ADT_ERR_DUPLICATE
130ret 25
131end
132if ne adt_parse adtt_loop len adtt_loop ADT_ERR_REF_LOOP
133ret 26
134end
135
136ret 0
137end