Skip to content

Commit 59ed00e

Browse files
committed
Add string literal regression coverage
Signed-off-by: Christoph Knittel <ck@cca.io>
1 parent 59372ec commit 59ed00e

34 files changed

Lines changed: 509 additions & 36 deletions

tests/analysis_tests/tests/src/DocumentSymbol.res

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,5 +30,6 @@ module O = {
3030
}
3131

3232
let zzz = 11
33+
let templateString = `hello ${zzz->Int.toString}`
3334

3435
//^doc

tests/analysis_tests/tests/src/expected/DocumentSymbol.res.txt

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,17 @@
11
DocumentSymbol src/DocumentSymbol.res
22
[
3+
{
4+
"kind": 13,
5+
"name": "templateString",
6+
"range": {
7+
"end": { "character": 49, "line": 32 },
8+
"start": { "character": 0, "line": 32 }
9+
},
10+
"selectionRange": {
11+
"end": { "character": 49, "line": 32 },
12+
"start": { "character": 0, "line": 32 }
13+
}
14+
},
315
{
416
"kind": 16,
517
"name": "zzz",
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
2+
Warning number 110
3+
/.../fixtures/json_literal_todo_payload.res:3:13-32
4+
5+
1 │ /* Known bug: json literals are only meaningful in external attributes,
6+
│ but
7+
2 │ this is currently treated as a regular todo payload. */
8+
3 │ let value = %todo(json`message`)
9+
4 │
10+
11+
Todo found: message
12+
13+
This code is not implemented yet and will crash at runtime. Make sure you implement this before running the code.
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/* Known bug: json literals are only meaningful in external attributes, but
2+
this is currently treated as a regular todo payload. */
3+
let value = %todo(json`message`)

tests/gentype_tests/typescript-react-example/src/EscapedNames.gen.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
import * as EscapedNamesJS from './EscapedNames.res.js';
77

8-
export type variant = "Illegal\"Name";
8+
export type variant = "Illegal\"Name" | "café\npath\\name";
99

1010
export type UppercaseVariant = "Illegal\"Name";
1111

tests/gentype_tests/typescript-react-example/src/EscapedNames.res

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@genType
2-
type variant = | @as("Illegal\"Name") IllegalName
2+
type variant =
3+
| @as("Illegal\"Name") IllegalName
4+
| @as("café\npath\\name") Utf8
35

46
@genType
57
type \"UppercaseVariant" = | @as("Illegal\"Name") IllegalName

tests/gentype_tests/typescript-react-example/src/ImportJsValue.gen.tsx

Lines changed: 18 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
/* eslint-disable */
44
/* tslint:disable */
55

6-
import {round as roundNotChecked} from './MyMath';
6+
import {round as roundNotChecked} from './MyM\x61th';
77

88
import {round2 as round2NotChecked} from './MyMath';
99

@@ -13,6 +13,10 @@ import {returnMixedArray as returnMixedArrayNotChecked} from './MyMath';
1313

1414
import {useColor as useColorNotChecked} from './MyMath';
1515

16+
import {useEscapedInlineVariant as useEscapedInlineVariantNotChecked} from './MyMath';
17+
18+
import {useUtf8InlineVariant as useUtf8InlineVariantNotChecked} from './MyMath';
19+
1620
import {higherOrder as higherOrderNotChecked} from './MyMath';
1721

1822
import {convertVariant as convertVariantNotChecked} from './MyMath';
@@ -21,7 +25,7 @@ import {polymorphic as polymorphicNotChecked} from './MyMath';
2125

2226
import {default as defaultNotChecked} from './MyMath';
2327

24-
// In case of type error, check the type of 'round' in 'ImportJsValue.res' and './MyMath'.
28+
// In case of type error, check the type of 'round' in 'ImportJsValue.res' and './MyM\x61th'.
2529
export const roundTypeChecked: (_1:number) => number = roundNotChecked as any;
2630

2731
// Export 'round' early to allow circular import from the '.bs.js' file.
@@ -51,6 +55,18 @@ export const useColorTypeChecked: (_1:color) => number = useColorNotChecked as a
5155
// Export 'useColor' early to allow circular import from the '.bs.js' file.
5256
export const useColor: unknown = useColorTypeChecked as (_1:color) => number as any;
5357

58+
// In case of type error, check the type of 'useEscapedInlineVariant' in 'ImportJsValue.res' and './MyMath'.
59+
export const useEscapedInlineVariantTypeChecked: (_1:"Illegal\"Name") => number = useEscapedInlineVariantNotChecked as any;
60+
61+
// Export 'useEscapedInlineVariant' early to allow circular import from the '.bs.js' file.
62+
export const useEscapedInlineVariant: unknown = useEscapedInlineVariantTypeChecked as (_1:"Illegal\"Name") => number as any;
63+
64+
// In case of type error, check the type of 'useUtf8InlineVariant' in 'ImportJsValue.res' and './MyMath'.
65+
export const useUtf8InlineVariantTypeChecked: (_1:"café\npath\\name") => number = useUtf8InlineVariantNotChecked as any;
66+
67+
// Export 'useUtf8InlineVariant' early to allow circular import from the '.bs.js' file.
68+
export const useUtf8InlineVariant: unknown = useUtf8InlineVariantTypeChecked as (_1:"café\npath\\name") => number as any;
69+
5470
// In case of type error, check the type of 'higherOrder' in 'ImportJsValue.res' and './MyMath'.
5571
export const higherOrderTypeChecked: (_1:((_1:number, _2:number) => number)) => number = higherOrderNotChecked as any;
5672

tests/gentype_tests/typescript-react-example/src/ImportJsValue.res

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@ocaml.doc("
22
* Wrap JS values to be used from Reason
33
")
4-
@genType.import("./MyMath")
4+
@genType.import(`./MyM\x61th`)
55
external /* This is the module to import from. */
66
/* Name and type of the JS value to bind to. */
77
round: float => float = "round"
@@ -57,6 +57,14 @@ type stringFunction
5757

5858
@genType.import("./MyMath") external useColor: color => int = "useColor"
5959

60+
@genType.import("./MyMath")
61+
external useEscapedInlineVariant: @string [@as("Illegal\"Name") #illegalName] => int =
62+
"useEscapedInlineVariant"
63+
64+
@genType.import("./MyMath")
65+
external useUtf8InlineVariant: @string [@as("café\npath\\name") #utf8] => int =
66+
"useUtf8InlineVariant"
67+
6068
@genType.import("./MyMath") external higherOrder: ((int, int) => int) => int = "higherOrder"
6169

6270
@genType let returnedFromHigherOrder = higherOrder(\"+")

tests/gentype_tests/typescript-react-example/src/ImportJsValue.res.js

Lines changed: 20 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

tests/gentype_tests/typescript-react-example/src/MyMath.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ export type stringFunction = (_: string) => string;
2323

2424
export const useColor = (_x: "tomato" | "gray"): number => 0;
2525

26+
export const useEscapedInlineVariant = (_x: 'Illegal"Name'): number => 0;
27+
28+
export const useUtf8InlineVariant = (_x: "café\npath\\name"): number => 0;
29+
2630
export const higherOrder = (foo: (_1: number, _2: number) => number) =>
2731
foo(3, 4);
2832

0 commit comments

Comments
 (0)