Skip to content

Commit 1c7e3d1

Browse files
committed
Add tests demonstrating occurrences on punned expressions
1 parent 052eb68 commit 1c7e3d1

File tree

5 files changed

+118
-0
lines changed

5 files changed

+118
-0
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
let a = Some 1
2+
3+
type t = { value : string }
4+
let value = "hello"
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
Test project-wide occurrences in the presence of punning (both let and record punning)
2+
3+
Compile project, create index file, and configure Merlin to use index file
4+
$ $OCAMLC -bin-annot -bin-annot-occurrences -c definitions.ml usages.ml
5+
$ ocaml-index aggregate definitions.cmt usages.cmt
6+
$ cat > .merlin << EOF
7+
> INDEX project.ocaml-index
8+
> EOF
9+
10+
Convenience function for querying occurrences
11+
$ occurrences () {
12+
> file="$1"
13+
> location="$2"
14+
> $MERLIN single occurrences -scope project -identifier-at "$location" -filename "$file" < "$file" | \
15+
> jq -r '.value[] | "\(.file) \(.start.line):\(.start.col)-\(.end.col)"'
16+
> }
17+
18+
Get occurrences of an identifier that is used as the expression part of a punned let
19+
expression
20+
FIXME: this should also include the occurrence on line 6 of usages.ml
21+
$ occurrences definitions.ml 1:4
22+
$TESTCASE_ROOT/definitions.ml 1:4-5
23+
24+
Get occurrences, with the cursor pointing at the identifier in a punned let.
25+
Merlin returns the occurrences of the new variable bound in that let, rather than the
26+
expression being assigned to the variable.
27+
$ occurrences usages.ml 6:7
28+
$TESTCASE_ROOT/usages.ml 6:7-8
29+
$TESTCASE_ROOT/usages.ml 7:7-8
30+
31+
Get occurrences of a record field, where there is an instance of punning that field while
32+
creating a record
33+
$ occurrences definitions.ml 3:13
34+
$TESTCASE_ROOT/definitions.ml 3:11-16
35+
$TESTCASE_ROOT/usages.ml 10:10-15
36+
37+
Get occurrences of a variable that is used as the value being placed into a record in a
38+
punned record field expression
39+
$ occurrences definitions.ml 4:6
40+
$TESTCASE_ROOT/definitions.ml 4:4-9
41+
$TESTCASE_ROOT/usages.ml 10:10-15
42+
43+
Get occurrences, with the cursor pointing at a punned record field expression.
44+
Merlin finds occurrences of the value being placed into the record rather than the record
45+
field
46+
$ occurrences usages.ml 10:12
47+
$TESTCASE_ROOT/definitions.ml 4:4-9
48+
$TESTCASE_ROOT/usages.ml 10:10-15
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
include Definitions
2+
3+
(* Let punning *)
4+
let _ =
5+
let (let*) = Option.bind in
6+
let* a in
7+
Some a
8+
9+
(* Record field punning *)
10+
let _ = { value }
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
Test occurrences in the presence of punning (both let and record punning)
2+
3+
Convenience function for querying occurrences
4+
$ occurrences () {
5+
> location="$1"
6+
> $MERLIN single occurrences -identifier-at "$location" -filename test.ml < test.ml | \
7+
> jq -r '.value[] | "\(.start.line):\(.start.col)-\(.end.col)"'
8+
> }
9+
10+
Get occurrences of an identifier that is used as the expression part of a punned let
11+
expression
12+
FIXME: this should also include the occurrence on line 5
13+
$ occurrences 4:6
14+
4:6-7
15+
16+
Get occurrences, with the cursor pointing at the identifier in a punned let.
17+
Merlin returns the occurrences of the new variable bound in that let, rather than the
18+
expression being assigned to the variable.
19+
$ occurrences 5:7
20+
5:7-8
21+
6:7-8
22+
23+
Get occurrences of an identifier that was defined in a punned let expression
24+
$ occurrences 5:7
25+
5:7-8
26+
6:7-8
27+
28+
Get occurrences of a record field, where there is an instance of punning that field while
29+
creating a record
30+
$ occurrences 9:13
31+
9:11-16
32+
11:10-15
33+
34+
Get occurrences of a variable that is used as the value being placed into a record in a
35+
punned record field expression
36+
$ occurrences 10:4
37+
10:4-9
38+
11:10-15
39+
40+
Get occurrences, with the cursor pointing at a punned record field expression.
41+
Merlin finds occurrences of the value being placed into the record rather than the record
42+
field
43+
$ occurrences 10:4
44+
10:4-9
45+
11:10-15
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
(* Let punning *)
2+
let _ =
3+
let (let*) = Option.bind in
4+
let a = Some 1 in
5+
let* a in
6+
Some a
7+
8+
(* Record field punning *)
9+
type t = { value : string }
10+
let value = "hello"
11+
let _ = { value }

0 commit comments

Comments
 (0)