Skip to content

Commit b819a75

Browse files
committed
Add unit tests
1 parent d49eed5 commit b819a75

30 files changed

+1577
-0
lines changed
Lines changed: 131 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,131 @@
1+
// === findAllReferences ===
2+
// === /a.js ===
3+
// --- (line: 3) skipped ---
4+
// class Collection {}
5+
//
6+
// /**
7+
// * <|@typedef {object} [|{| isWriteAccess: true, isDefinition: true |}U/*FIND ALL REFS*/serData|]
8+
// * @property {string} id
9+
// * @property {string} name
10+
// |>*/
11+
//
12+
// /** @specialize <[|UserData|]> */
13+
// const users = new Collection('users');
14+
15+
// === Definitions ===
16+
// === /a.js ===
17+
// --- (line: 3) skipped ---
18+
// class Collection {}
19+
//
20+
// /**
21+
// * <|@typedef {object} [|U/*FIND ALL REFS*/serData|]
22+
// * @property {string} id
23+
// * @property {string} name
24+
// |>*/
25+
//
26+
// /** @specialize <UserData> */
27+
// const users = new Collection('users');
28+
29+
// === Details ===
30+
[
31+
{
32+
"containerKind": "",
33+
"containerName": "",
34+
"kind": "type",
35+
"name": "type UserData = {\n id: string;\n name: string;\n}",
36+
"displayParts": [
37+
{
38+
"text": "type",
39+
"kind": "keyword"
40+
},
41+
{
42+
"text": " ",
43+
"kind": "space"
44+
},
45+
{
46+
"text": "UserData",
47+
"kind": "aliasName"
48+
},
49+
{
50+
"text": " ",
51+
"kind": "space"
52+
},
53+
{
54+
"text": "=",
55+
"kind": "operator"
56+
},
57+
{
58+
"text": " ",
59+
"kind": "space"
60+
},
61+
{
62+
"text": "{",
63+
"kind": "punctuation"
64+
},
65+
{
66+
"text": "\n",
67+
"kind": "lineBreak"
68+
},
69+
{
70+
"text": " ",
71+
"kind": "space"
72+
},
73+
{
74+
"text": "id",
75+
"kind": "propertyName"
76+
},
77+
{
78+
"text": ":",
79+
"kind": "punctuation"
80+
},
81+
{
82+
"text": " ",
83+
"kind": "space"
84+
},
85+
{
86+
"text": "string",
87+
"kind": "keyword"
88+
},
89+
{
90+
"text": ";",
91+
"kind": "punctuation"
92+
},
93+
{
94+
"text": "\n",
95+
"kind": "lineBreak"
96+
},
97+
{
98+
"text": " ",
99+
"kind": "space"
100+
},
101+
{
102+
"text": "name",
103+
"kind": "propertyName"
104+
},
105+
{
106+
"text": ":",
107+
"kind": "punctuation"
108+
},
109+
{
110+
"text": " ",
111+
"kind": "space"
112+
},
113+
{
114+
"text": "string",
115+
"kind": "keyword"
116+
},
117+
{
118+
"text": ";",
119+
"kind": "punctuation"
120+
},
121+
{
122+
"text": "\n",
123+
"kind": "lineBreak"
124+
},
125+
{
126+
"text": "}",
127+
"kind": "punctuation"
128+
}
129+
]
130+
}
131+
]
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
//// [tests/cases/conformance/jsdoc/specializeTag1.ts] ////
2+
3+
//// [specializeTag1.js]
4+
/**
5+
* @template T
6+
* @param {object} _jsonSchema
7+
* @returns {(x: unknown) => x is T}
8+
*/
9+
function createValidator(_jsonSchema) {
10+
/**
11+
* @param {unknown} _x
12+
* @returns {_x is T}
13+
*/
14+
return (_x) => true;
15+
}
16+
17+
/** @specialize <number> */
18+
const isNumber = createValidator({ type: 'number' });
19+
20+
const isString = /** @specialize <string> */(createValidator({ type: 'string' }));
21+
22+
23+
//// [specializeTag1.js]
24+
/**
25+
* @template T
26+
* @param {object} _jsonSchema
27+
* @returns {(x: unknown) => x is T}
28+
*/
29+
function createValidator(_jsonSchema) {
30+
/**
31+
* @param {unknown} _x
32+
* @returns {_x is T}
33+
*/
34+
return function (_x) { return true; };
35+
}
36+
/** @specialize <number> */
37+
var isNumber = createValidator({ type: 'number' });
38+
var isString = /** @specialize <string> */ (createValidator({ type: 'string' }));
39+
40+
41+
//// [specializeTag1.d.ts]
42+
/**
43+
* @template T
44+
* @param {object} _jsonSchema
45+
* @returns {(x: unknown) => x is T}
46+
*/
47+
declare function createValidator<T>(_jsonSchema: object): (x: unknown) => x is T;
48+
/** @specialize <number> */
49+
declare const isNumber: (x: unknown) => x is number;
50+
declare const isString: (x: unknown) => x is string;
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
//// [tests/cases/conformance/jsdoc/specializeTag1.ts] ////
2+
3+
=== specializeTag1.js ===
4+
/**
5+
* @template T
6+
* @param {object} _jsonSchema
7+
* @returns {(x: unknown) => x is T}
8+
*/
9+
function createValidator(_jsonSchema) {
10+
>createValidator : Symbol(createValidator, Decl(specializeTag1.js, 0, 0))
11+
>_jsonSchema : Symbol(_jsonSchema, Decl(specializeTag1.js, 5, 25))
12+
13+
/**
14+
* @param {unknown} _x
15+
* @returns {_x is T}
16+
*/
17+
return (_x) => true;
18+
>_x : Symbol(_x, Decl(specializeTag1.js, 10, 12))
19+
}
20+
21+
/** @specialize <number> */
22+
const isNumber = createValidator({ type: 'number' });
23+
>isNumber : Symbol(isNumber, Decl(specializeTag1.js, 14, 5))
24+
>createValidator : Symbol(createValidator, Decl(specializeTag1.js, 0, 0))
25+
>type : Symbol(type, Decl(specializeTag1.js, 14, 34))
26+
27+
const isString = /** @specialize <string> */(createValidator({ type: 'string' }));
28+
>isString : Symbol(isString, Decl(specializeTag1.js, 16, 5))
29+
>createValidator : Symbol(createValidator, Decl(specializeTag1.js, 0, 0))
30+
>type : Symbol(type, Decl(specializeTag1.js, 16, 62))
31+
Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
//// [tests/cases/conformance/jsdoc/specializeTag1.ts] ////
2+
3+
=== specializeTag1.js ===
4+
/**
5+
* @template T
6+
* @param {object} _jsonSchema
7+
* @returns {(x: unknown) => x is T}
8+
*/
9+
function createValidator(_jsonSchema) {
10+
>createValidator : <T>(_jsonSchema: object) => (x: unknown) => x is T
11+
> : ^ ^^ ^^ ^^^^^
12+
>_jsonSchema : any
13+
14+
/**
15+
* @param {unknown} _x
16+
* @returns {_x is T}
17+
*/
18+
return (_x) => true;
19+
>(_x) => true : (_x: unknown) => _x is T
20+
> : ^ ^^ ^^^^^
21+
>_x : unknown
22+
> : ^^^^^^^
23+
>true : true
24+
> : ^^^^
25+
}
26+
27+
/** @specialize <number> */
28+
const isNumber = createValidator({ type: 'number' });
29+
>isNumber : (x: unknown) => x is number
30+
> : ^ ^^ ^^^^^ ^^^^^^
31+
>createValidator({ type: 'number' }) : (x: unknown) => x is number
32+
> : ^ ^^ ^^^^^ ^^^^^^
33+
>createValidator : <T>(_jsonSchema: object) => (x: unknown) => x is T
34+
> : ^ ^^ ^^ ^^^^^
35+
>{ type: 'number' } : { type: string; }
36+
> : ^^^^^^^^^^^^^^^^^
37+
>type : string
38+
> : ^^^^^^
39+
>'number' : "number"
40+
> : ^^^^^^^^
41+
42+
const isString = /** @specialize <string> */(createValidator({ type: 'string' }));
43+
>isString : (x: unknown) => x is string
44+
> : ^ ^^ ^^^^^ ^^^^^^
45+
>(createValidator({ type: 'string' })) : (x: unknown) => x is string
46+
> : ^ ^^ ^^^^^ ^^^^^^
47+
>createValidator({ type: 'string' }) : (x: unknown) => x is string
48+
> : ^ ^^ ^^^^^ ^^^^^^
49+
>createValidator : <T>(_jsonSchema: object) => (x: unknown) => x is T
50+
> : ^ ^^ ^^ ^^^^^
51+
>{ type: 'string' } : { type: string; }
52+
> : ^^^^^^^^^^^^^^^^^
53+
>type : string
54+
> : ^^^^^^
55+
>'string' : "string"
56+
> : ^^^^^^^^
57+
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
specializeTag2.js(19,15): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
2+
specializeTag2.js(23,26): error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
3+
4+
5+
==== specializeTag2.js (2 errors) ====
6+
/**
7+
* @template T
8+
* @param {TemplateStringsArray} strings
9+
* @param {...T} values
10+
* @returns {Record<string, T>}
11+
*/
12+
function parse(strings, ...values) {
13+
/** @type {Record<string, T>} */
14+
const result = {};
15+
strings.forEach((key, i) => {
16+
if (i < values.length) {
17+
result[key] = values[i];
18+
}
19+
})
20+
return result;
21+
}
22+
23+
const query1 = /** @specialize {string} */(
24+
parse`a=${1}b=${2}`
25+
~
26+
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
27+
)
28+
29+
/** @specialize {string} */
30+
const query2 = parse`a=${1}b=${2}`; // Type error
31+
~
32+
!!! error TS2345: Argument of type 'number' is not assignable to parameter of type 'string'.
33+
34+
/** @specialize <`${number}`> */
35+
const query3 = parse`a=${"1"}b=${"2"}`;
36+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
//// [tests/cases/conformance/jsdoc/specializeTag2.ts] ////
2+
3+
//// [specializeTag2.js]
4+
/**
5+
* @template T
6+
* @param {TemplateStringsArray} strings
7+
* @param {...T} values
8+
* @returns {Record<string, T>}
9+
*/
10+
function parse(strings, ...values) {
11+
/** @type {Record<string, T>} */
12+
const result = {};
13+
strings.forEach((key, i) => {
14+
if (i < values.length) {
15+
result[key] = values[i];
16+
}
17+
})
18+
return result;
19+
}
20+
21+
const query1 = /** @specialize {string} */(
22+
parse`a=${1}b=${2}`
23+
)
24+
25+
/** @specialize {string} */
26+
const query2 = parse`a=${1}b=${2}`; // Type error
27+
28+
/** @specialize <`${number}`> */
29+
const query3 = parse`a=${"1"}b=${"2"}`;
30+
31+
32+
//// [specializeTag2.js]
33+
var __makeTemplateObject = (this && this.__makeTemplateObject) || function (cooked, raw) {
34+
if (Object.defineProperty) { Object.defineProperty(cooked, "raw", { value: raw }); } else { cooked.raw = raw; }
35+
return cooked;
36+
};
37+
/**
38+
* @template T
39+
* @param {TemplateStringsArray} strings
40+
* @param {...T} values
41+
* @returns {Record<string, T>}
42+
*/
43+
function parse(strings) {
44+
var values = [];
45+
for (var _i = 1; _i < arguments.length; _i++) {
46+
values[_i - 1] = arguments[_i];
47+
}
48+
/** @type {Record<string, T>} */
49+
var result = {};
50+
strings.forEach(function (key, i) {
51+
if (i < values.length) {
52+
result[key] = values[i];
53+
}
54+
});
55+
return result;
56+
}
57+
var query1 = /** @specialize {string} */ (parse(__makeTemplateObject(["a=", "b=", ""], ["a=", "b=", ""]), 1, 2));
58+
/** @specialize {string} */
59+
var query2 = parse(__makeTemplateObject(["a=", "b=", ""], ["a=", "b=", ""]), 1, 2); // Type error
60+
/** @specialize <`${number}`> */
61+
var query3 = parse(__makeTemplateObject(["a=", "b=", ""], ["a=", "b=", ""]), "1", "2");
62+
63+
64+
//// [specializeTag2.d.ts]
65+
/**
66+
* @template T
67+
* @param {TemplateStringsArray} strings
68+
* @param {...T} values
69+
* @returns {Record<string, T>}
70+
*/
71+
declare function parse<T>(strings: TemplateStringsArray, ...values: T[]): Record<string, T>;
72+
declare const query1: Record<string, string>;
73+
/** @specialize {string} */
74+
declare const query2: Record<string, string>;
75+
/** @specialize <`${number}`> */
76+
declare const query3: Record<string, `${number}`>;

0 commit comments

Comments
 (0)