Skip to content

Commit 8a93ebe

Browse files
authored
feat(graindoc): Add test harness (#1767)
* feat: Create `graindoc` test harness * chore: Add Some Initial tests * chore: Apply suggestions from code review
1 parent 543807b commit 8a93ebe

13 files changed

+605
-0
lines changed

compiler/test/TestFramework.re

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,8 @@ let test_snapshots_dir = Fp.At.(test_dir / "__snapshots__");
3232
let test_formatter_in_dir = Fp.At.(test_dir / "formatter_inputs");
3333
let test_formatter_out_dir = Fp.At.(test_dir / "formatter_outputs");
3434

35+
let test_gaindoc_dir = Fp.At.(test_dir / "graindoc");
36+
3537
let clean_grain_output = stdlib_dir =>
3638
Array.iter(
3739
file => {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
---
2+
title: DescriptionGrainDoc
3+
---
4+
5+
## Types
6+
7+
Type declarations included in the DescriptionGrainDoc module.
8+
9+
### DescriptionGrainDoc.**DocAlias**
10+
11+
```grain
12+
type DocAlias = Bool
13+
```
14+
15+
Alias Doc
16+
17+
### DescriptionGrainDoc.**DocRecord**
18+
19+
```grain
20+
record DocRecord {
21+
docField: Bool,
22+
}
23+
```
24+
25+
Record Doc
26+
27+
### DescriptionGrainDoc.**DocEnum**
28+
29+
```grain
30+
enum DocEnum {
31+
DocCase,
32+
}
33+
```
34+
35+
Enum Doc
36+
37+
## Values
38+
39+
Functions and constants included in the DescriptionGrainDoc module.
40+
41+
### DescriptionGrainDoc.**docValue**
42+
43+
```grain
44+
docValue : Number
45+
```
46+
47+
Value Doc
48+
49+
### DescriptionGrainDoc.**docFunction**
50+
51+
```grain
52+
docFunction : (x: Number) -> Number
53+
```
54+
55+
Function Doc
56+
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
module DescriptionGrainDoc
2+
3+
// No Documentation
4+
/**
5+
* No Alias Doc
6+
*/
7+
type NoDocAlias = Bool
8+
/**
9+
* No Record Doc
10+
*/
11+
record NoDocRecord {
12+
noDocField: Bool
13+
}
14+
/**
15+
* No Enum Doc
16+
*/
17+
enum NoDocEnum {
18+
NoDocCase
19+
}
20+
/**
21+
* No Value Doc
22+
*/
23+
let noDocValue = 1
24+
/**
25+
* No Function Doc
26+
*/
27+
let noDocFunction = (x: Number) => x + 1
28+
// Documentation
29+
/**
30+
* Alias Doc
31+
*/
32+
provide type DocAlias = Bool
33+
/**
34+
* Record Doc
35+
*/
36+
provide record DocRecord {
37+
docField: Bool
38+
}
39+
/**
40+
* Enum Doc
41+
*/
42+
provide enum DocEnum {
43+
DocCase
44+
}
45+
/**
46+
* Value Doc
47+
*/
48+
provide let docValue = 1
49+
/**
50+
* Function Doc
51+
*/
52+
provide let docFunction = (x: Number) => x + 1
Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
---
2+
title: ExampleDoc
3+
---
4+
5+
## Values
6+
7+
Functions and constants included in the ExampleDoc module.
8+
9+
### ExampleDoc.**singleLineExample**
10+
11+
```grain
12+
singleLineExample : (index: a, array: b) -> Number
13+
```
14+
15+
SingleLineExample
16+
17+
Examples:
18+
19+
```grain
20+
singleLineExample(1, [1, 2, 3])
21+
```
22+
23+
### ExampleDoc.**multiLineExample**
24+
25+
```grain
26+
multiLineExample : (index: a, array: b) -> Number
27+
```
28+
29+
MultiLineExample
30+
31+
Examples:
32+
33+
```grain
34+
let x = multiLineExample(1, [1, 2, 3])
35+
print(x) // 1
36+
```
37+
38+
### ExampleDoc.**multipleSingleLineExamples**
39+
40+
```grain
41+
multipleSingleLineExamples : (index: a, array: b) -> Number
42+
```
43+
44+
SingleLineExample
45+
46+
Examples:
47+
48+
```grain
49+
singleLineExample(1, [1, 2, 3]) == 1
50+
```
51+
52+
```grain
53+
assert singleLineExample(1, [1, 2, 3]) == 1
54+
```
55+
56+
```grain
57+
print(singleLineExample(1, [1, 2, 3]))
58+
```
59+
60+
### ExampleDoc.**multipleMultiLineExample**
61+
62+
```grain
63+
multipleMultiLineExample : (index: a, array: b) -> Number
64+
```
65+
66+
MultiLineExample
67+
68+
Examples:
69+
70+
```grain
71+
let x = multiLineExample(1, [1, 2, 3])
72+
print(x) // 1
73+
```
74+
75+
```grain
76+
let x = multiLineExample(1, [1, 2, 3])
77+
assert x == 1
78+
```
79+
80+
```grain
81+
let x = multiLineExample(1, [1, 2, 3])
82+
x == 1
83+
```
84+
85+
### ExampleDoc.**mixedLineExample**
86+
87+
```grain
88+
mixedLineExample : (index: a, array: b) -> Number
89+
```
90+
91+
MultiLineExample
92+
93+
Examples:
94+
95+
```grain
96+
let x = multiLineExample(1, [1, 2, 3])
97+
print(x) // 1
98+
```
99+
100+
```grain
101+
let x = multiLineExample(1, [1, 2, 3])
102+
assert x == 1
103+
```
104+
105+
```grain
106+
let x = multiLineExample(1, [1, 2, 3])
107+
x == 1
108+
```
109+
110+
```grain
111+
singleLineExample(1, [1, 2, 3]) == 1
112+
```
113+
114+
```grain
115+
assert singleLineExample(1, [1, 2, 3]) == 1
116+
```
117+
118+
```grain
119+
print(singleLineExample(1, [1, 2, 3]))
120+
```
121+
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
module ExampleDoc
2+
3+
/**
4+
* SingleLineExample
5+
*
6+
* @example singleLineExample(1, [1, 2, 3])
7+
*/
8+
provide let singleLineExample = (index, array) => 1
9+
10+
/**
11+
* MultiLineExample
12+
*
13+
* @example
14+
* let x = multiLineExample(1, [1, 2, 3])
15+
* print(x) // 1
16+
*/
17+
provide let multiLineExample = (index, array) => 1
18+
19+
20+
/**
21+
* SingleLineExample
22+
*
23+
* @example singleLineExample(1, [1, 2, 3]) == 1
24+
* @example assert singleLineExample(1, [1, 2, 3]) == 1
25+
*
26+
* @example print(singleLineExample(1, [1, 2, 3]))
27+
*/
28+
provide let multipleSingleLineExamples = (index, array) => 1
29+
30+
/**
31+
* MultiLineExample
32+
*
33+
* @example
34+
* let x = multiLineExample(1, [1, 2, 3])
35+
* print(x) // 1
36+
* @example
37+
* let x = multiLineExample(1, [1, 2, 3])
38+
* assert x == 1
39+
*
40+
* @example
41+
* let x = multiLineExample(1, [1, 2, 3])
42+
* x == 1
43+
*/
44+
provide let multipleMultiLineExample = (index, array) => 1
45+
46+
47+
/**
48+
* MultiLineExample
49+
*
50+
* @example
51+
* let x = multiLineExample(1, [1, 2, 3])
52+
* print(x) // 1
53+
* @example
54+
* let x = multiLineExample(1, [1, 2, 3])
55+
* assert x == 1
56+
*
57+
* @example
58+
* let x = multiLineExample(1, [1, 2, 3])
59+
* x == 1
60+
*
61+
* @example singleLineExample(1, [1, 2, 3]) == 1
62+
* @example assert singleLineExample(1, [1, 2, 3]) == 1
63+
*
64+
* @example print(singleLineExample(1, [1, 2, 3]))
65+
*/
66+
provide let mixedLineExample = (index, array) => 1
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
---
2+
title: FunctionGrainDoc
3+
---
4+
5+
## Values
6+
7+
Functions and constants included in the FunctionGrainDoc module.
8+
9+
### FunctionGrainDoc.**get**
10+
11+
<details>
12+
<summary>Added in <code>0.1.0</code></summary>
13+
<table>
14+
<thead>
15+
<tr><th>version</th><th>changes</th></tr>
16+
</thead>
17+
<tbody>
18+
<tr><td><code>0.2.0</code></td><td>Argument order changed to data-last</td></tr>
19+
</tbody>
20+
</table>
21+
</details>
22+
23+
```grain
24+
get : (index: Number, array: Array<a>) -> a
25+
```
26+
27+
An alias for normal syntactic array access, i.e. `array[n]`.
28+
29+
Retrieves the element from the array at the specified index.
30+
A negative index is treated as an offset from the end of the array.
31+
32+
Parameters:
33+
34+
|param|type|description|
35+
|-----|----|-----------|
36+
|`index`|`Number`|The index to access|
37+
|`array`|`Array<a>`|The array to access|
38+
39+
Returns:
40+
41+
|type|description|
42+
|----|-----------|
43+
|`a`|The element from the array|
44+
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
module FunctionGrainDoc
2+
/**
3+
* An alias for normal syntactic array access, i.e. `array[n]`.
4+
*
5+
* Retrieves the element from the array at the specified index.
6+
* A negative index is treated as an offset from the end of the array.
7+
*
8+
* @param index: The index to access
9+
* @param array: The array to access
10+
* @returns The element from the array
11+
*
12+
* @since v0.1.0
13+
* @history v0.2.0: Argument order changed to data-last
14+
*/
15+
provide let get = (index, array) => {
16+
array[index]
17+
}

0 commit comments

Comments
 (0)