Skip to content

Commit

Permalink
tests: new and improved tests
Browse files Browse the repository at this point in the history
  • Loading branch information
voodoos committed Nov 14, 2023
1 parent a68329f commit 097b8d8
Show file tree
Hide file tree
Showing 6 changed files with 225 additions and 11 deletions.
1 change: 1 addition & 0 deletions tests/test-dirs/config/dot-merlin-reader/quoting.t
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@
}
],
"stdlib": null,
"index_file": null,
"reader": [],
"protocol": "json",
"log_file": null,
Expand Down
14 changes: 10 additions & 4 deletions tests/test-dirs/locate/in-implicit-trans-dep.t/run.t
Original file line number Diff line number Diff line change
@@ -1,12 +1,18 @@
$ dune build @check

FIXME: When the deifinition is in one of the implicit transitive dependencies
Merlin does not found the file in the source path provided by Dune. One possible
fix would be for Dune to provide additional source path for "externatl" deps.
When the definition is in one of the implicit transitive dependencies
Merlin does not find the file in the source path provided by Dune. One possible
fix would be for Dune to provide additional source path for "external" deps.
$ $MERLIN single locate -look-for ml -position 1:15 \
> -filename bin/main.ml <bin/main.ml
{
"class": "return",
"value": "'Lib1.t' seems to originate from 'Lib2' whose ML file could not be found",
"value": {
"file": "$TESTCASE_ROOT/src/lib2/lib2.ml",
"pos": {
"line": 1,
"col": 5
}
},
"notifications": []
}
24 changes: 23 additions & 1 deletion tests/test-dirs/locate/locate-constrs-decl-def.t
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,18 @@

$ cat >constr.mli <<EOF
> type t = A of int | B
> type u = { label_a : int }
> EOF

$ cat >constr.ml <<EOF
> type u = C of int
> type u = { label_a : int }
> type t = A of int | B
> let foo : t = A 42
> EOF

$ cat >main.ml <<EOF
> let foo : Constr.t = Constr.A 42
> let bar : Constr.u = { Constr.label_a = 42 }
> EOF

$ $OCAMLC -c -bin-annot -store-usage-index constr.mli constr.ml
Expand All @@ -38,6 +40,26 @@
}
}

$ $MERLIN single locate -look-for mli -position 2:30 \
> -filename ./main.ml < ./main.ml | jq '.value'
{
"file": "$TESTCASE_ROOT/constr.mli",
"pos": {
"line": 2,
"col": 11
}
}

$ $MERLIN single locate -look-for ml -position 2:30 \
> -filename ./main.ml < ./main.ml | jq '.value'
{
"file": "$TESTCASE_ROOT/constr.ml",
"pos": {
"line": 1,
"col": 11
}
}

$ cat >main.ml <<EOF
> module Constr : sig
> type t = A of int | B
Expand Down
189 changes: 189 additions & 0 deletions tests/test-dirs/occurrences/constrs-decl-def.t
Original file line number Diff line number Diff line change
@@ -0,0 +1,189 @@
$ cat >main.ml <<'EOF'
> module M : sig
> type t = A of { label_a : int }
> end = struct
> type t = A of { label_a : int }
> let _ = A { label_a = 1 }
> end
>
> let _ = M.A { label_a = 1 }
>
> open M
>
> let _ = A { label_a = 1 }
> EOF

Constructor declaration:
$ $MERLIN single locate -look-for mli -position 12:8 \
> -filename main.ml <main.ml | jq '.value.pos'
{
"line": 2,
"col": 11
}

Constructor definition:
$ $MERLIN single locate -look-for ml -position 12:8 \
> -filename main.ml <main.ml | jq '.value.pos'
{
"line": 4,
"col": 11
}

Label declaration:
$ $MERLIN single locate -look-for mli -position 12:13 \
> -filename main.ml <main.ml | jq '.value.pos'
{
"line": 2,
"col": 18
}

Label definition:
$ $MERLIN single locate -look-for ml -position 12:13 \
> -filename main.ml <main.ml | jq '.value.pos'
{
"line": 4,
"col": 18
}

Constructor occurrences:
$ $MERLIN single occurrences -identifier-at 12:8 \
> -filename main.ml <main.ml | grep line | uniq
"line": 4,
"line": 5,
"line": 8,
"line": 12,

Label occurrences:
$ $MERLIN single occurrences -identifier-at 12:13 \
> -filename main.ml <main.ml | jq '.value'
[
{
"start": {
"line": 4,
"col": 18
},
"end": {
"line": 4,
"col": 25
}
},
{
"start": {
"line": 5,
"col": 14
},
"end": {
"line": 5,
"col": 21
}
},
{
"start": {
"line": 8,
"col": 14
},
"end": {
"line": 8,
"col": 21
}
},
{
"start": {
"line": 12,
"col": 12
},
"end": {
"line": 12,
"col": 19
}
}
]

$ cat >main.ml <<'EOF'
> type t = { a : int; b : float }
> let _ = { a = 4; b = 2.0 }
> let a = 4
> let r = { a; b = 2.0 }
> let _ = { r with b = 2.0 }
> let { a; b } = r
> EOF

$ $MERLIN single occurrences -identifier-at 6:15 \
> -filename main.ml <main.ml | jq '.value'
[
{
"start": {
"line": 4,
"col": 4
},
"end": {
"line": 4,
"col": 5
}
},
{
"start": {
"line": 5,
"col": 10
},
"end": {
"line": 5,
"col": 11
}
},
{
"start": {
"line": 6,
"col": 15
},
"end": {
"line": 6,
"col": 16
}
}
]

$ $MERLIN single occurrences -identifier-at 2:10 \
> -filename main.ml <main.ml | jq '.value'
[
{
"start": {
"line": 1,
"col": 11
},
"end": {
"line": 1,
"col": 12
}
},
{
"start": {
"line": 2,
"col": 10
},
"end": {
"line": 2,
"col": 11
}
},
{
"start": {
"line": 4,
"col": 10
},
"end": {
"line": 4,
"col": 11
}
},
{
"start": {
"line": 6,
"col": 6
},
"end": {
"line": 6,
"col": 7
}
}
]
4 changes: 2 additions & 2 deletions tests/test-dirs/occurrences/issue1398.t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ Test finding occurrences of let-based binding operator, from reified syntax:
{
"start": {
"line": 3,
"col": 10
"col": 12
},
"end": {
"line": 3,
Expand Down Expand Up @@ -57,7 +57,7 @@ Test finding occurrences of and-based binding operator, from reified syntax:
{
"start": {
"line": 3,
"col": 19
"col": 21
},
"end": {
"line": 3,
Expand Down
4 changes: 0 additions & 4 deletions tests/test-dirs/occurrences/project-wide/simple.t
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,6 @@
> EOF

$ dune build @all
ld: warning: -undefined suppress is deprecated
ld: warning: -undefined suppress is deprecated
ld: warning: -undefined suppress is deprecated
ld: warning: -undefined suppress is deprecated

$ ocaml-index dump _build/default/project.ocaml-index
3 uids:
Expand Down

0 comments on commit 097b8d8

Please sign in to comment.