Skip to content

Commit d477520

Browse files
committed
docs: give example categories better names
1 parent 79daca0 commit d477520

File tree

2 files changed

+50
-53
lines changed

2 files changed

+50
-53
lines changed

docs/src/examples/README.generated.md

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
# Examples
22

3-
- [Compatibility](#compatibility)
4-
- [Diff](#diff)
5-
- [Validation](#validation)
3+
- [JSON Schema Change Compatibility Checks](#json-schema-change-compatibility-checks)
4+
- [JSON Schema Difference Calculation](#json-schema-difference-calculation)
5+
- [JSON Values Validation](#json-values-validation)
66

77
---
8-
## Compatibility
8+
## JSON Schema Change Compatibility Checks
99
### ⌘ No JSON schema differences
1010
When there is not JSON schema differences, schema change is fully compatible.
1111
#### Input
@@ -178,7 +178,7 @@ forward
178178
```
179179

180180
---
181-
## Diff
181+
## JSON Schema Difference Calculation
182182
### ⌘ Comparing identical schemata
183183
When two identical schemata are compared, no difference should be found.
184184
#### Input
@@ -217,7 +217,7 @@ Any change in expected JSON value type should be accounted as a difference.
217217
```
218218

219219
---
220-
## Validation
220+
## JSON Values Validation
221221
### ⌘ A null value against a schema accepting only null values
222222
A null value conforms to the schema.
223223
#### Input

test/unit/Docs.purs

Lines changed: 44 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Data.FoldableWithIndex
1111
import Data.Map (Map)
1212
import Data.Map as Map
1313
import Data.Maybe (Maybe(..))
14+
import Data.String (Pattern(..), Replacement(..))
1415
import Data.String as String
1516
import Effect (Effect)
1617
import Effect.Aff (launchAff_)
@@ -26,56 +27,44 @@ import Test.Spec.JsonSchema.Diff as Diff
2627
import Test.Spec.JsonSchema.Validation as Validation
2728
import Test.Types (Example)
2829

29-
main Effect Unit
30-
main = do
31-
args ← Process.argv
32-
examples ← selectExamples $ args !! 2
30+
data Category
31+
= Compatibility
32+
| Diff
33+
| Validation
3334

34-
launchAff_
35-
$ FS.writeTextFile UTF8 "docs/src/examples/README.generated.md"
36-
$ printExamples
37-
$ groupExamplesByCategory examples
38-
where
39-
selectExamples Maybe String Effect (Array PrintableExample)
40-
selectExamples = case _ of
41-
Nothing
42-
pure allExamples
43-
Just moduleName →
44-
case moduleName of
45-
"Codec"
46-
pure $ makePrintable "Codec" <$> Codec.examples
47-
"Compatibility"
48-
pure $ makePrintable "Compatibility" <$>
49-
Compatibility.examples
50-
"Diff"
51-
pure $ makePrintable "Diff" <$> Diff.examples
52-
"Parsing"
53-
pure $ makePrintable "Parsing" <$> Parsing.examples
54-
"Printing"
55-
pure $ makePrintable "Printing" <$> Printing.examples
56-
"Validation"
57-
pure $ makePrintable "Validation" <$> Validation.examples
58-
_ →
59-
throw $ "Unknown module name \"" <> moduleName <> "\""
35+
derive instance Eq Category
36+
derive instance Ord Category
37+
38+
renderCategory Category String
39+
renderCategory = case _ of
40+
Compatibility
41+
"JSON Schema Change Compatibility Checks"
42+
Diff
43+
"JSON Schema Difference Calculation"
44+
Validation
45+
"JSON Values Validation"
6046

61-
allExamples Array PrintableExample
62-
allExamples =
63-
(makePrintable "Codec" <$> Codec.examples)
64-
<> (makePrintable "Compatibility" <$> Compatibility.examples)
65-
<> (makePrintable "Diff" <$> Diff.examples)
66-
<> (makePrintable "Parsing" <$> Parsing.examples)
67-
<> (makePrintable "Printing" <$> Printing.examples)
68-
<> (makePrintable "Validation" <$> Validation.examples)
47+
main Effect Unit
48+
main = launchAff_
49+
$ FS.writeTextFile UTF8 "docs/src/examples/README.generated.md"
50+
$ printExamples
51+
$ groupExamplesByCategory examples
52+
where
53+
examples Array PrintableExample
54+
examples =
55+
(makePrintable Compatibility <$> Compatibility.examples)
56+
<> (makePrintable Diff <$> Diff.examples)
57+
<> (makePrintable Validation <$> Validation.examples)
6958

7059
type PrintableExample =
71-
{ category String
60+
{ category Category
7261
, description String
7362
, input String
7463
, output String
7564
, title String
7665
}
7766

78-
makePrintable i o. String Example i o PrintableExample
67+
makePrintable i o. Category Example i o PrintableExample
7968
makePrintable category example =
8069
{ category
8170
, description: example.description
@@ -88,7 +77,7 @@ groupExamplesByCategory
8877
f
8978
. Foldable f
9079
f PrintableExample
91-
Map String (Array PrintableExample)
80+
Map Category (Array PrintableExample)
9281
groupExamplesByCategory = foldl
9382
( \acc example →
9483
Map.insertWith
@@ -101,7 +90,7 @@ groupExamplesByCategory = foldl
10190

10291
printExamples
10392
f
104-
. FoldableWithIndex String f
93+
. FoldableWithIndex Category f
10594
f (Array PrintableExample)
10695
String
10796
printExamples examplesByCategory =
@@ -114,19 +103,23 @@ printExamples examplesByCategory =
114103
)
115104
<> foldMapWithIndex printCategory examplesByCategory
116105
where
117-
printTableOfContents Array String String
106+
printTableOfContents Array Category String
118107
printTableOfContents = (_ <> "\n")
119108
<<< foldMap printTableOfContentsEntry
120109

121-
printTableOfContentsEntry String String
110+
printTableOfContentsEntry Category String
122111
printTableOfContentsEntry category =
123-
"- [" <> category <> "](#" <> String.toLower category <> ")\n"
112+
"- ["
113+
<> renderCategory category
114+
<> "](#"
115+
<> (formatAnchor $ renderCategory category)
116+
<> ")\n"
124117

125-
printCategory String Array PrintableExample String
118+
printCategory Category Array PrintableExample String
126119
printCategory category examples =
127120
"---\n"
128121
<> "## "
129-
<> category
122+
<> renderCategory category
130123
<> "\n"
131124
<> foldMap printExample examples
132125

@@ -141,3 +134,7 @@ printExamples examplesByCategory =
141134
<> "\n#### Output\n"
142135
<> output
143136
<> "\n\n"
137+
138+
formatAnchor String String
139+
formatAnchor = String.replaceAll (Pattern " ") (Replacement "-")
140+
<<< String.toLower

0 commit comments

Comments
 (0)