Skip to content

Commit 52c4496

Browse files
committed
Add tests
1 parent 2483188 commit 52c4496

File tree

1 file changed

+59
-2
lines changed
  • tests/test-dirs/syntax-document/language-extensions.t

1 file changed

+59
-2
lines changed

tests/test-dirs/syntax-document/language-extensions.t/run.t

Lines changed: 59 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -273,18 +273,27 @@ on (module S : Set.S with type elt = s)
273273
> -filename ./first-class-modules.ml < ./first-class-modules.ml | jq '.value.name'
274274
"First class module"
275275

276-
$ syn_doc_name () {
276+
$ call_syntax_doc_and_extract_field () {
277277
> file="$1"
278278
> line="$2"
279279
> col="$3"
280+
> field="$4"
280281
>
281282
> # Print the line, with a ^ underneath pointing at the character
282283
> sed -n "${line}p" "$file"
283284
> printf "%*s^\n" "$col" ""
284285
>
285286
> # Call merlin on the position
286287
> "$MERLIN" single syntax-document -position "$line:$col" -filename "$file" < "$file" \
287-
> | jq 'if (.value | type) == "string" then .value else .value.name end' -r
288+
> | jq "if (.value | type) == \"string\" then .value else .value.$field end" -r
289+
> }
290+
291+
$ syn_doc_name () {
292+
> call_syntax_doc_and_extract_field "$1" "$2" "$3" name
293+
> }
294+
295+
$ syn_doc_desc () {
296+
> call_syntax_doc_and_extract_field "$1" "$2" "$3" description
288297
> }
289298

290299
Convenience function to ensure we haven't made any syntax errors.
@@ -367,6 +376,11 @@ Convenience function to ensure we haven't made any syntax errors.
367376
^
368377
No documentation found
369378

379+
$ syn_doc_desc modes.ml 5 17
380+
let x : int @ local = 10
381+
^
382+
No documentation found
383+
370384
// Modalities
371385
# CR-someday: Add raw modalities (and @@?) to typedtree so this information can be recovered
372386

@@ -420,6 +434,11 @@ Convenience function to ensure we haven't made any syntax errors.
420434
^
421435
Record Type
422436

437+
$ syn_doc_desc modalities.ml 5 28
438+
type t = { foo : int @@ contended }
439+
^
440+
Defines variants with a fixed set of fields
441+
423442
// Kinds
424443

425444
$ cat > kinds.ml << EOF
@@ -509,6 +528,21 @@ Convenience function to ensure we haven't made any syntax errors.
509528
^
510529
Mod-bound
511530

531+
$ syn_doc_desc kinds.ml 7 13
532+
type t : float64 mod everything
533+
^
534+
The layout of types represented by a 64-bit machine float.
535+
536+
$ syn_doc_desc kinds.ml 7 28
537+
type t : float64 mod everything
538+
^
539+
Synonym for "global aliased many contended portable unyielding immutable stateless external_", convenient for describing immediates.
540+
541+
$ syn_doc_desc kinds.ml 1 40
542+
type ('a : immediate) t : value mod portable with 'a @@ global
543+
^
544+
Values of this type can cross to `portable` from weaker modes.
545+
512546
// include functor
513547

514548
$ cat > include_functor.ml << EOF
@@ -840,3 +874,26 @@ Convenience function to ensure we haven't made any syntax errors.
840874
module type S = S with M
841875
^
842876
No documentation found
877+
878+
Validate that docstrings, URLs, and levels are being created correctly
879+
880+
$ cat > validate.ml << EOF
881+
> let rec name1 = 1 :: name2 and name2 = 2 :: name1
882+
> type t : value
883+
> EOF
884+
885+
$ $MERLIN single syntax-document -position 1:6 -filename validate.ml < validate.ml | jq .value
886+
{
887+
"name": "Recursive value definition",
888+
"description": "Supports a certain class of recursive definitions of non-functional values.",
889+
"url": "https://ocaml.org/manual/5.2/letrecvalues.html",
890+
"level": "simple"
891+
}
892+
893+
$ $MERLIN single syntax-document -position 2:11 -filename validate.ml < validate.ml | jq .value
894+
{
895+
"name": "Kind abbreviation",
896+
"description": "The kind of ordinary OCaml types",
897+
"url": "https://oxcaml.org/documentation/kinds/syntax/",
898+
"level": "advanced"
899+
}

0 commit comments

Comments
 (0)