Skip to content

Commit 7dc4b86

Browse files
committed
fix doc tests
1 parent ce8576d commit 7dc4b86

14 files changed

+117
-157
lines changed

.gitignore

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,10 +14,8 @@ index_data/*.json
1414
_tempFile.cmi
1515
_tempFile.cmj
1616
_tempFile.cmt
17-
18-
# these docs are checked in, but we consider them frozen.
19-
# pages/docs/manual/v8.0.0/
20-
# pages/docs/manual/v9.0.0/
17+
_tempFile.res
18+
temp
2119

2220
.bsb.lock
2321
.merlin

docs/manual/async-await.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ let fetchData = async () => {
215215
Console.log("user 2 mail: " ++ user2Mail)
216216
}
217217
218-
| exception JsError(err) => Console.log2("Some error occurred", err)
218+
| exception JsExn(err) => Console.log2("Some error occurred", err)
219219
}
220220
}
221221
```

docs/manual/exception.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ You can directly match on exceptions _while_ getting another return value from a
9797
<CodeTab labels={["ReScript", "JS Output"]}>
9898

9999
```res prelude
100-
switch list{1, 2, 3}->List.getExn(4) {
100+
switch list{1, 2, 3}->List.getOrThrow(4) {
101101
| item => Console.log(item)
102102
| exception Not_found => Console.log("No such item found!")
103103
}

docs/manual/function.mdx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ let somethingThatMightThrow = async () => throw(SomeReScriptException)
474474
let someAsyncFn = async () => {
475475
switch await somethingThatMightThrow() {
476476
| data => Some(data)
477-
| exception JsError(_) => None
477+
| exception JsExn(_) => None
478478
| exception SomeReScriptException => None
479479
}
480480
}

docs/manual/generalized-algebraic-data-types.mdx

Lines changed: 18 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ type timezone =
3333

3434
Using this variant type, we will end up having functions like this:
3535

36-
```res example
36+
{/* TODO: fix this example, it has an error because it doesn't have access to the previous snippet */}
37+
```res
3738
let convertToDaylight = tz => {
3839
switch tz {
3940
| EST => EDT
@@ -47,15 +48,17 @@ This function is only valid for a subset of our variant type's constructors but
4748

4849
Let's see if we can find a way for the compiler to help us with normal variants. We could define another variant type to distinguish the two kinds of timezone.
4950

50-
```res example
51+
{/* TODO: fix this example, it has an error because it doesn't have access to the previous snippet */}
52+
```res
5153
type daylightOrStandard =
5254
| Daylight(timezone)
5355
| Standard(timezone)
5456
```
5557

5658
This has a lot of problems. For one, it's cumbersome and redundant. We would now have to pattern-match twice whenever we deal with a timezone that's wrapped up here. The compiler will force us to check whether we are dealing with daylight or standard time, but notice that there's nothing stopping us from providing invalid timezones to these constructors:
5759

58-
```res example
60+
{/* TODO: fix this example, it has an error because it doesn't have access to the previous snippet */}
61+
```res
5962
let invalidTz1 = Daylight(EST)
6063
let invalidTz2 = Standard(EDT)
6164
```
@@ -78,7 +81,8 @@ type rec timezone<_> =
7881
We define our type with a type parameter. We manually annotate each constructor, providing it with the correct type parameter indicating whether it is standard or daylight. Each constructor is a `timezone`,
7982
but we've added another level of specificity using a type parameter. Constructors are now understood to be `standard` or `daylight` at the _type_ level. Now we can fix our function like this:
8083

81-
```res example
84+
{/* TODO: fix this example, it has an error because it doesn't have access to the previous snippet */}
85+
```res
8286
let convertToDaylight = tz => {
8387
switch tz {
8488
| EST => EDT
@@ -92,7 +96,8 @@ The compiler can infer correctly that this function should only take `timezone<s
9296
we try to return a standard timezone from this function. Actually, this seems like it could be a problem,
9397
we still want to be able to match on all cases of the variant sometimes, and a naive attempt at this will not pass the type checker. A naive example will fail:
9498

95-
```res example
99+
{/* TODO: fix this example, it has an error because it doesn't have access to the previous snippet */}
100+
```res
96101
let convertToDaylight = tz =>
97102
switch tz {
98103
| EST => EDT
@@ -104,7 +109,8 @@ let convertToDaylight = tz =>
104109

105110
This will complain that `daylight` and `standard` are incompatible. To fix this, we need to explicitly annotate to tell the compiler to accept both:
106111

107-
```res example
112+
{/* TODO: fix this example, it has an error because it doesn't have access to the previous snippet */}
113+
```res
108114
let convertToDaylight : type a. timezone<a> => timezone<daylight> = // ...
109115
```
110116

@@ -117,7 +123,8 @@ Sometimes, a function should have a different return type based on what you give
117123

118124
[^1]: In ReScript v12, the built-in operators are already generic, but we use them in this example for simplicity.
119125

120-
```res example
126+
{/* this example purposefully has an error so it is not marked as an example */}
127+
```res
121128
type rec number<_> = Int(int): number<int> | Float(float): number<float>
122129
123130
let add = (type a, x: number<a>, y: number<a>): a =>
@@ -204,7 +211,8 @@ This API has a method for binding event handlers, `on`. This takes an event and
204211
depending on which event we are binding to. A naive implementation might look similar to this, defining a
205212
separate method for each stream event to wrap the unsafe version of `on`.
206213

207-
```res example
214+
{/* TODO: fix this example, it has an error */}
215+
```res
208216
module Stream = {
209217
type t
210218
@@ -233,7 +241,8 @@ The real magic happens in the signature of `on`. Read it carefully, and then loo
233241
follow how the type variables are getting filled in, write it out on paper what each type variable is equal
234242
to if you need and it will soon become clear.
235243

236-
```res example
244+
{/* TODO: fix this example, it has an error */}
245+
```res
237246
238247
module Stream = {
239248
type t<'a>

docs/manual/module-functions.mdx

Lines changed: 14 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -36,32 +36,33 @@ module Next = {
3636
}
3737
3838
module Component: {
39-
@react.component
40-
let make: unit => Jsx.element
39+
@react.component
40+
let make: unit => Jsx.element
4141
} = {
4242
// Create a module that matches the module type expected by Next.MakeParams
4343
module P = {
44-
type t = {
45-
tag: string,
46-
item: string,
47-
}
44+
type t = {
45+
tag: string,
46+
item: string,
47+
}
4848
}
4949
5050
// Create a new module using the Params module we created and the Next.MakeParams module function
5151
module Params = Next.MakeParams(P)
5252
5353
@react.component
5454
let make = () => {
55+
5556
// Use the functions, values, or types created by the module function
5657
let params = Params.useParams()
5758
58-
<div>
59-
<p>
60-
{React.string("Tag: " ++ params.tag /_ params is fully typed! _/)}
61-
</p>
62-
<p> {React.string("Item: " ++ params.item)} </p>
63-
</div>
64-
}
59+
<div>
60+
<p>
61+
{React.string("Tag: " ++ params.tag /* params is fully typed! */)}
62+
</p>
63+
<p> {React.string("Item: " ++ params.item)} </p>
64+
</div>
65+
}
6566
}
6667
6768
````

docs/manual/record.mdx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ You can also nest definitions of records.
3636

3737
<CodeTab labels={["ReScript", "JS Output"]}>
3838

39-
```res prelude
39+
```res example
4040
type person = {
4141
age: int,
4242
name: string,
@@ -81,7 +81,7 @@ So if we in the example above ended up needing to refer to `person.notificationS
8181

8282
<CodeTab labels={["ReScript", "JS Output"]}>
8383

84-
```res prelude
84+
```res example
8585
type personNotificationSettings = {
8686
sendEmails: bool,
8787
allowPasswordLogin: bool,

docs/react/hooks-context.mdx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ module ThemedButton = {
4949
| "light" | _ => ("#000000", "#eeeeee")
5050
}
5151
52-
let style = ReactDOMStyle.make(~color, ~backgroundColor, ())
53-
54-
<button style> {React.string("I am a styled button!")} </button>
52+
<button style={{color, backgroundColor}}>
53+
{React.string("I am a styled button!")}
54+
</button>
5555
}
5656
}
5757

docs/react/hooks-custom.mdx

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,8 @@ Let's go back to a previous example from our [React.useEffect section](./hooks-e
2222

2323
<CodeTab labels={["ReScript", "JS Output"]}>
2424

25-
```res example {16-31}
25+
{/* TODO: fix this example */}
26+
```res {16-31}
2627
// FriendStatus.res
2728
2829
module ChatAPI = {
@@ -153,7 +154,7 @@ let make = (~friend: friend) => {
153154
| Loading => "grey"
154155
}
155156
156-
<li style={ReactDOMStyle.make(~color,())}>
157+
<li style={{ color }}>
157158
{React.string(friend.name)}
158159
</li>
159160
}
@@ -371,7 +372,7 @@ let make = (~friend: friend) => {
371372
| Loading => "grey"
372373
}
373374
374-
<li style={ReactDOMStyle.make(~color,())}>
375+
<li style={{ color }}>
375376
{React.string(friend.name)}
376377
</li>
377378
}

docs/react/hooks-effect.mdx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,8 @@ type state = Offline | Loading | Online
184184

185185
<CodeTab labels={["ReScript", "JS Output"]}>
186186

187-
```res example
187+
{/* TODO: fix this example */}
188+
```res
188189
// FriendStatus.res
189190
@react.component
190191
let make = (~friendId: string) => {
@@ -281,7 +282,8 @@ When we render with count updated to 6, React will compare the items in the `[5]
281282

282283
This also works for effects that have a cleanup phase:
283284

284-
```res example
285+
{/* TODO fix this example */}
286+
```res
285287
@react.component
286288
let make = (~friendId: string) => {
287289
let (state, setState) = React.useState(_ => Offline)

0 commit comments

Comments
 (0)