Skip to content

Commit 0078b17

Browse files
authored
chore: factor tests into a different file (#908)
The partial module-ification of nightly is making the combined Html file difficult for me to work with, this conceptually simplifies what I'm doing a little bit.
1 parent b5aa427 commit 0078b17

3 files changed

Lines changed: 78 additions & 73 deletions

File tree

src/tests/Tests/VersoManual.lean

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ import Tests.VersoManual.Html
77
import Tests.VersoManual.Html.SoftHyphenate
88
import Tests.VersoManual.License
99
import Tests.VersoManual.Markdown
10+
import Tests.VersoManual.Sections
1011
import Tests.VersoManual.WordCount

src/tests/Tests/VersoManual/Html.lean

Lines changed: 0 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -113,76 +113,3 @@ Done
113113
break
114114

115115
end
116-
117-
namespace DocstringSectionRegression
118-
119-
open Verso
120-
open Verso.Output
121-
open Verso.Genre.Manual
122-
123-
/-- A fixture for Manual docstring subsection HTML rendering. -/
124-
structure SectionFixture where
125-
/-- Field documentation. -/
126-
field : Nat
127-
128-
/-- A fixture for Manual docstring constructor subsection HTML rendering. -/
129-
inductive ConstructorFixture where
130-
/-- Constructor documentation. -/
131-
| intro : ConstructorFixture
132-
133-
#docs (Manual) doc "Docstring section labels" :=
134-
:::::::
135-
136-
{docstring SectionFixture}
137-
138-
{docstring ConstructorFixture}
139-
140-
:::::::
141-
142-
private def hasSubstring (s sub : String) : Bool :=
143-
s.find? sub |>.isSome
144-
145-
private def compactHtml (s : String) : String :=
146-
s.foldl (init := "") fun out c =>
147-
if c.isWhitespace then out else out.push c
148-
149-
private def renderDoc : IO String := do
150-
let rendered ← IO.mkRef ""
151-
let exitCode ← withLogger fun logger => do
152-
let cfg : RenderConfig := {}
153-
let (part, state) ← (traverseHtmlSingle cfg doc.toPart).run extension_impls% |>.run logger
154-
let ctxt : Manual.TraverseContext := {}
155-
let definitionIds := state.definitionIds ctxt
156-
let remotes : Multi.AllRemotes := {}
157-
let linkTargets := cfg.linkTargets state remotes
158-
let (html, _) ←
159-
(Manual.toHtml (m := ReaderT Multi.AllRemotes (ReaderT ExtensionImpls (BuildLogT IO)))
160-
{} ctxt state definitionIds linkTargets {} part).run {}
161-
|>.run remotes
162-
|>.run extension_impls%
163-
|>.run logger
164-
rendered.set html.asString
165-
unless exitCode == 0 do
166-
throw <| IO.userError "Manual docstring HTML rendering logged errors"
167-
rendered.get
168-
169-
private def assertLabeledSection (compact label : String) : IO Unit := do
170-
let id := s!"docstring-section-{label}"
171-
let group := s!"<divclass=\"docstring-section\"role=\"group\"aria-labelledby=\"{id}\">"
172-
unless hasSubstring compact group do
173-
throw <| IO.userError s!"{label} section should render as a named group"
174-
let labelHtml := s!"<pclass=\"docstring-section-label\"id=\"{id}\">{label}</p>"
175-
unless hasSubstring compact labelHtml do
176-
throw <| IO.userError s!"{label} section should use a paragraph label with the group's ID"
177-
if hasSubstring compact s!"<h1>{label}</h1>" then
178-
throw <| IO.userError s!"{label} section label should not render as h1"
179-
180-
/--
181-
info: docstring section labels render as labeled groups
182-
-/
183-
#guard_msgs in
184-
#eval show IO Unit from do
185-
let compact := compactHtml (← renderDoc)
186-
assertLabeledSection compact "Fields"
187-
assertLabeledSection compact "Constructors"
188-
IO.println "docstring section labels render as labeled groups"
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
/-
2+
Copyright (c) 2024-2025 Lean FRO LLC. All rights reserved.
3+
Released under Apache 2.0 license as described in the file LICENSE.
4+
Author: Emilio J. Gallego Arias
5+
-/
6+
import VersoManual
7+
8+
namespace DocstringSectionRegression
9+
10+
open Verso Output Genre Manual
11+
12+
/-- A fixture for Manual docstring subsection HTML rendering. -/
13+
structure SectionFixture where
14+
/-- Field documentation. -/
15+
field : Nat
16+
17+
/-- A fixture for Manual docstring constructor subsection HTML rendering. -/
18+
inductive ConstructorFixture where
19+
/-- Constructor documentation. -/
20+
| intro : ConstructorFixture
21+
22+
#docs (Manual) doc "Docstring section labels" :=
23+
:::::::
24+
25+
{docstring SectionFixture}
26+
27+
{docstring ConstructorFixture}
28+
29+
:::::::
30+
31+
private def hasSubstring (s sub : String) : Bool :=
32+
s.find? sub |>.isSome
33+
34+
private def compactHtml (s : String) : String :=
35+
s.foldl (init := "") fun out c =>
36+
if c.isWhitespace then out else out.push c
37+
38+
private def renderDoc : IO String := do
39+
let rendered ← IO.mkRef ""
40+
let exitCode ← withLogger fun logger => do
41+
let cfg : RenderConfig := {}
42+
let (part, state) ← (traverseHtmlSingle cfg doc.toPart).run extension_impls% |>.run logger
43+
let ctxt : Manual.TraverseContext := {}
44+
let definitionIds := state.definitionIds ctxt
45+
let remotes : Multi.AllRemotes := {}
46+
let linkTargets := cfg.linkTargets state remotes
47+
let (html, _) ←
48+
(Manual.toHtml (m := ReaderT Multi.AllRemotes (ReaderT ExtensionImpls (BuildLogT IO)))
49+
{} ctxt state definitionIds linkTargets {} part).run {}
50+
|>.run remotes
51+
|>.run extension_impls%
52+
|>.run logger
53+
rendered.set html.asString
54+
unless exitCode == 0 do
55+
throw <| IO.userError "Manual docstring HTML rendering logged errors"
56+
rendered.get
57+
58+
private def assertLabeledSection (compact label : String) : IO Unit := do
59+
let id := s!"docstring-section-{label}"
60+
let group := s!"<divclass=\"docstring-section\"role=\"group\"aria-labelledby=\"{id}\">"
61+
unless hasSubstring compact group do
62+
throw <| IO.userError s!"{label} section should render as a named group"
63+
let labelHtml := s!"<pclass=\"docstring-section-label\"id=\"{id}\">{label}</p>"
64+
unless hasSubstring compact labelHtml do
65+
throw <| IO.userError s!"{label} section should use a paragraph label with the group's ID"
66+
if hasSubstring compact s!"<h1>{label}</h1>" then
67+
throw <| IO.userError s!"{label} section label should not render as h1"
68+
69+
/--
70+
info: docstring section labels render as labeled groups
71+
-/
72+
#guard_msgs in
73+
#eval show IO Unit from do
74+
let compact := compactHtml (← renderDoc)
75+
assertLabeledSection compact "Fields"
76+
assertLabeledSection compact "Constructors"
77+
IO.println "docstring section labels render as labeled groups"

0 commit comments

Comments
 (0)