aboutsummaryrefslogtreecommitdiff
path: root/tests/drivers/lsp_test.js
diff options
context:
space:
mode:
authorGravatar zinc <zinc@downsta.ir> 2026-10-14 09:39:22 +0000
committerGravatar zinc <zinc@downsta.ir> 2026-10-14 09:39:22 +0000
commit6bb3d79cbd853601623095b497a1807489c3ef6e (patch)
tree188bc9ceb6d6db1670427f4355529eb8d46d1494 /tests/drivers/lsp_test.js
parenttodo: record the reverted unchecked trial and what it showed (diff)
add c-style typedef and a built-in string alias
typedef T name; binds name to the type record of T, at the top level or in a function (scoped to its block). string is a built-in alias for char*. A type name straight before , or ) in a parameter list is the parameter's name, so fn f(string) still works. The language server shows typedef T name; on hover and highlights typedef as a keyword.
Diffstat (limited to 'tests/drivers/lsp_test.js')
-rw-r--r--tests/drivers/lsp_test.js18
1 files changed, 18 insertions, 0 deletions
diff --git a/tests/drivers/lsp_test.js b/tests/drivers/lsp_test.js
index 18d8bf7..0f4abe1 100644
--- a/tests/drivers/lsp_test.js
+++ b/tests/drivers/lsp_test.js
@@ -250,5 +250,23 @@ check(hcv && hcv.includes('parameter'), 'hover on a use of a parameter named lik
hcv = hover(scp, 4, at(scp, 4, 'len'));
check(hcv && hcv.includes('the number of items'), 'hover on the built-in still shows its text where no local shadows it', hcv);
+// typedefs: the name shows its declaration, at the declaration, at a use in a declaration, and in a block
+const tdsrc = 'struct node { int v; node* next; };\n// another name for node*\ntypedef node* link;\ntypedef int(int, int) binop;\nlink head(link n) { return n; }\nint use(string s) {\n\ttypedef int cell;\n\tcell c = 1;\n\tbinop f = 0;\n\treturn c;\n}\n';
+hv = hover(tdsrc, 2, at(tdsrc, 2, 'link'));
+check(hv && hv.includes('typedef node* link;') && hv.includes('another name for node*'), 'hover on the name in a typedef shows the typedef and its doc', hv);
+hv = hover(tdsrc, 4, at(tdsrc, 4, 'link'));
+check(hv && hv.includes('typedef node* link;') && hv.includes('a pointer to `node`'), 'hover on a typedef name used as a type shows the typedef and the type', hv);
+hv = hover(tdsrc, 4, at(tdsrc, 4, 'link', 1));
+check(hv && hv.includes('typedef node* link;'), 'hover on a typedef name used as a parameter type shows the typedef', hv);
+hv = hover(tdsrc, 3, at(tdsrc, 3, 'binop'));
+check(hv && hv.includes('typedef int(int, int) binop;'), 'hover on a function type typedef shows the whole typedef', hv);
+hv = hover(tdsrc, 7, at(tdsrc, 7, 'cell'));
+check(hv && hv.includes('typedef int cell;'), 'hover on a typedef made in a block shows the typedef', hv);
+hv = hover(tdsrc, 5, at(tdsrc, 5, 'string'));
+check(hv && hv.includes('char*') && hv.includes('built-in alias'), 'hover on string shows char* and what string is', hv);
+hv = hover(tdsrc, 2, 3);
+check(hv && hv.includes('typedef T name;') && hv.includes('type name = T;'), 'hover on the typedef keyword explains it', hv);
+check(tokens(tdsrc).includes('typedef:keyword'), 'typedef is highlighted as a keyword', tokens(tdsrc));
+
console.log(ok + ' lsp checks passed, ' + bad + ' failed');
process.exit(bad ? 1 : 0);