|
| 1 | +// Copyright Quad4 2026 |
| 2 | +// SPDX-License-Identifier: 0BSD |
| 3 | + |
| 4 | +package micron |
| 5 | + |
| 6 | +import ( |
| 7 | + "strings" |
| 8 | + "testing" |
| 9 | +) |
| 10 | + |
| 11 | +func TestAccessibilityHeadingRole(t *testing.T) { |
| 12 | + p := Parser{DarkTheme: true, ForceMonospace: true, Accessibility: true} |
| 13 | + out := p.ConvertMicronToHTML("> Title\n") |
| 14 | + if !strings.Contains(out, `role="heading"`) { |
| 15 | + t.Fatalf("expected role=heading, got: %s", out) |
| 16 | + } |
| 17 | + if !strings.Contains(out, `aria-level="1"`) { |
| 18 | + t.Fatalf("expected aria-level=1, got: %s", out) |
| 19 | + } |
| 20 | + if strings.Count(out, `role="heading"`) != 1 { |
| 21 | + t.Fatalf("expected exactly one heading role, got: %s", out) |
| 22 | + } |
| 23 | +} |
| 24 | + |
| 25 | +func TestAccessibilityHeadingLevel(t *testing.T) { |
| 26 | + p := Parser{DarkTheme: true, ForceMonospace: true, Accessibility: true} |
| 27 | + out := p.ConvertMicronToHTML(">>> Deep\n") |
| 28 | + if !strings.Contains(out, `aria-level="3"`) { |
| 29 | + t.Fatalf("expected aria-level=3, got: %s", out) |
| 30 | + } |
| 31 | +} |
| 32 | + |
| 33 | +func TestAccessibilityOffByDefault(t *testing.T) { |
| 34 | + p := Parser{DarkTheme: true, ForceMonospace: true} |
| 35 | + out := p.ConvertMicronToHTML("> Title\n-=\nx\n") |
| 36 | + for _, frag := range []string{`role="heading"`, `aria-level`, `role="separator"`, `Mu-sr`, `aria-live`} { |
| 37 | + if strings.Contains(out, frag) { |
| 38 | + t.Fatalf("expected no %q without Accessibility, got: %s", frag, out) |
| 39 | + } |
| 40 | + } |
| 41 | +} |
| 42 | + |
| 43 | +func TestAccessibilityDividerSeparator(t *testing.T) { |
| 44 | + p := Parser{DarkTheme: true, ForceMonospace: true, Accessibility: true} |
| 45 | + out := p.ConvertMicronToHTML("-=\n") |
| 46 | + if !strings.Contains(out, `role="separator"`) { |
| 47 | + t.Fatalf("expected role=separator on divider, got: %s", out) |
| 48 | + } |
| 49 | +} |
| 50 | + |
| 51 | +func TestAccessibilityFoldGlyphHidden(t *testing.T) { |
| 52 | + p := Parser{DarkTheme: true, ForceMonospace: true, Accessibility: true} |
| 53 | + out := p.ConvertMicronToHTML("`+> Fold\nbody\n`-\n") |
| 54 | + if !strings.Contains(out, `class="Mu-fold-glyph" aria-hidden="true"`) { |
| 55 | + t.Fatalf("expected aria-hidden fold glyph, got: %s", out) |
| 56 | + } |
| 57 | +} |
| 58 | + |
| 59 | +func TestAccessibilityPartialStatus(t *testing.T) { |
| 60 | + p := Parser{DarkTheme: true, ForceMonospace: true, Accessibility: true} |
| 61 | + out := p.ConvertMicronToHTML("`{file.mu`30`a=b}\n") |
| 62 | + if !strings.Contains(out, `role="status"`) { |
| 63 | + t.Fatalf("expected role=status on partial, got: %s", out) |
| 64 | + } |
| 65 | + if !strings.Contains(out, `aria-live="polite"`) { |
| 66 | + t.Fatalf("expected aria-live=polite on partial, got: %s", out) |
| 67 | + } |
| 68 | +} |
| 69 | + |
| 70 | +func TestAccessibilityReadableText(t *testing.T) { |
| 71 | + p := Parser{DarkTheme: true, ForceMonospace: true, Accessibility: true} |
| 72 | + out := p.ConvertMicronToHTML("hello world\n") |
| 73 | + if !strings.Contains(out, `class="Mu-sr"`) { |
| 74 | + t.Fatalf("expected Mu-sr readable span, got: %s", out) |
| 75 | + } |
| 76 | + if !strings.Contains(out, `aria-hidden="true"`) { |
| 77 | + t.Fatalf("expected aria-hidden visual span, got: %s", out) |
| 78 | + } |
| 79 | +} |
| 80 | + |
| 81 | +func TestAccessibilityFieldLabel(t *testing.T) { |
| 82 | + p := Parser{DarkTheme: true, ForceMonospace: true, Accessibility: true} |
| 83 | + out := p.ConvertMicronToHTML("`<24|username`alice>\n") |
| 84 | + if !strings.Contains(out, `aria-label="username"`) { |
| 85 | + t.Fatalf("expected aria-label on field, got: %s", out) |
| 86 | + } |
| 87 | + if !strings.Contains(out, `name="username"`) { |
| 88 | + t.Fatalf("expected name attribute preserved, got: %s", out) |
| 89 | + } |
| 90 | +} |
| 91 | + |
| 92 | +func TestFieldWidthAndRows(t *testing.T) { |
| 93 | + p := Parser{DarkTheme: true, ForceMonospace: true} |
| 94 | + out := p.ConvertMicronToHTML("`<40|name`bob>\n") |
| 95 | + if !strings.Contains(out, `size="40"`) { |
| 96 | + t.Fatalf("expected size=40 on input, got: %s", out) |
| 97 | + } |
| 98 | + if !strings.Contains(out, "<input") { |
| 99 | + t.Fatalf("expected input element, got: %s", out) |
| 100 | + } |
| 101 | +} |
| 102 | + |
| 103 | +func TestFieldRowsTextarea(t *testing.T) { |
| 104 | + p := Parser{DarkTheme: true, ForceMonospace: true} |
| 105 | + out := p.ConvertMicronToHTML("`<20x3|bio`hello>\n") |
| 106 | + if !strings.Contains(out, "<textarea") { |
| 107 | + t.Fatalf("expected textarea for WxR field, got: %s", out) |
| 108 | + } |
| 109 | + if !strings.Contains(out, `rows="3"`) { |
| 110 | + t.Fatalf("expected rows=3, got: %s", out) |
| 111 | + } |
| 112 | + if !strings.Contains(out, `cols="20"`) { |
| 113 | + t.Fatalf("expected cols=20, got: %s", out) |
| 114 | + } |
| 115 | + if !strings.Contains(out, `name="bio"`) { |
| 116 | + t.Fatalf("expected name=bio, got: %s", out) |
| 117 | + } |
| 118 | +} |
| 119 | + |
| 120 | +func TestHeadingAnchorSlug(t *testing.T) { |
| 121 | + p := Parser{DarkTheme: true, ForceMonospace: true} |
| 122 | + out := p.ConvertMicronToHTML("> My Section!\n") |
| 123 | + if !strings.Contains(out, `id="my-section"`) { |
| 124 | + t.Fatalf("expected slug anchor id=my-section, got: %s", out) |
| 125 | + } |
| 126 | + if !strings.Contains(out, `micron-header-anchor`) { |
| 127 | + t.Fatalf("expected micron-header-anchor class, got: %s", out) |
| 128 | + } |
| 129 | +} |
| 130 | + |
| 131 | +func TestExplicitAnchor(t *testing.T) { |
| 132 | + p := Parser{DarkTheme: true, ForceMonospace: true} |
| 133 | + out := p.ConvertMicronToHTML("text `:target` more\n") |
| 134 | + if !strings.Contains(out, `id="target"`) { |
| 135 | + t.Fatalf("expected explicit anchor id=target, got: %s", out) |
| 136 | + } |
| 137 | + if !strings.Contains(out, `class="micron-anchor"`) { |
| 138 | + t.Fatalf("expected micron-anchor class, got: %s", out) |
| 139 | + } |
| 140 | +} |
| 141 | + |
| 142 | +func TestEmptyAnchorResolvesToNextHeading(t *testing.T) { |
| 143 | + p := Parser{DarkTheme: true, ForceMonospace: true} |
| 144 | + out := p.ConvertMicronToHTML("`[next`#]\n> Second\n") |
| 145 | + if !strings.Contains(out, `href="#second"`) { |
| 146 | + t.Fatalf("expected href resolved to #second, got: %s", out) |
| 147 | + } |
| 148 | + if strings.Contains(out, `href="#"`) { |
| 149 | + t.Fatalf("expected no unresolved empty anchor, got: %s", out) |
| 150 | + } |
| 151 | +} |
| 152 | + |
| 153 | +func TestEmptyAnchorUnmatchedStays(t *testing.T) { |
| 154 | + p := Parser{DarkTheme: true, ForceMonospace: true} |
| 155 | + out := p.ConvertMicronToHTML("> First\n`[next`#]\n") |
| 156 | + if !strings.Contains(out, `href="#"`) { |
| 157 | + t.Fatalf("expected unresolved empty anchor to stay href=#, got: %s", out) |
| 158 | + } |
| 159 | +} |
| 160 | + |
| 161 | +func TestSerifRootClass(t *testing.T) { |
| 162 | + p := Parser{DarkTheme: true, ForceMonospace: true, Serif: true} |
| 163 | + out := p.ConvertMicronToHTML("body\n") |
| 164 | + if !strings.Contains(out, `Mu-serif`) { |
| 165 | + t.Fatalf("expected Mu-serif root class, got: %s", out) |
| 166 | + } |
| 167 | +} |
| 168 | + |
| 169 | +func TestSerifOffByDefault(t *testing.T) { |
| 170 | + p := Parser{DarkTheme: true, ForceMonospace: true} |
| 171 | + out := p.ConvertMicronToHTML("body\n") |
| 172 | + if strings.Contains(out, `Mu-serif`) { |
| 173 | + t.Fatalf("expected no Mu-serif without Serif, got: %s", out) |
| 174 | + } |
| 175 | +} |
| 176 | + |
| 177 | +func TestCRLFNormalization(t *testing.T) { |
| 178 | + p := Parser{DarkTheme: true, ForceMonospace: true} |
| 179 | + crlf := p.ConvertMicronToHTML("> Title\r\nbody\r\n") |
| 180 | + lf := p.ConvertMicronToHTML("> Title\nbody\n") |
| 181 | + if crlf != lf { |
| 182 | + t.Fatalf("CRLF and LF input must render identically.\nCRLF: %s\nLF: %s", crlf, lf) |
| 183 | + } |
| 184 | +} |
| 185 | + |
| 186 | +func TestHashLinkNotNomadWrapped(t *testing.T) { |
| 187 | + p := Parser{DarkTheme: true, ForceMonospace: true} |
| 188 | + out := p.ConvertMicronToHTML("> Target\n`[back`#]\n") |
| 189 | + if strings.Contains(out, `href="nomadnetwork://#"`) { |
| 190 | + t.Fatalf("expected bare # href, got nomadnetwork-wrapped: %s", out) |
| 191 | + } |
| 192 | +} |
0 commit comments