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