|
| 1 | +Test Merlin's behavior around unboxed records |
| 2 | + |
| 3 | +Complete a label |
| 4 | + |
| 5 | + $ cat > test.ml << EOF |
| 6 | + > type t = #{ foo : string } |
| 7 | + > let f (x : t) = x.#fo |
| 8 | + > EOF |
| 9 | + |
| 10 | +TODO (unboxed records): support completion of unboxed record labels |
| 11 | + $ $MERLIN single complete-prefix -position 2:21 -prefix "fo" -filename test.ml < test.ml \ |
| 12 | + > | revert-newlines | jq .value.entries[].name -r |
| 13 | + format_of_string |
| 14 | + format |
| 15 | + format4 |
| 16 | + format6 |
| 17 | + |
| 18 | + |
| 19 | +Get type of a label in an expression |
| 20 | + |
| 21 | + $ cat > test.ml << EOF |
| 22 | + > type t = #{ foo : string } |
| 23 | + > let f (x : t) = x.#foo |
| 24 | + > EOF |
| 25 | + |
| 26 | +TODO (unboxed records): maybe location should include the `#`? |
| 27 | + $ $MERLIN single type-enclosing -position 2:21 -filename test.ml < test.ml | jq .value[:2] |
| 28 | + [ |
| 29 | + { |
| 30 | + "start": { |
| 31 | + "line": 2, |
| 32 | + "col": 19 |
| 33 | + }, |
| 34 | + "end": { |
| 35 | + "line": 2, |
| 36 | + "col": 22 |
| 37 | + }, |
| 38 | + "type": "string", |
| 39 | + "tail": "no" |
| 40 | + }, |
| 41 | + { |
| 42 | + "start": { |
| 43 | + "line": 2, |
| 44 | + "col": 16 |
| 45 | + }, |
| 46 | + "end": { |
| 47 | + "line": 2, |
| 48 | + "col": 22 |
| 49 | + }, |
| 50 | + "type": "string", |
| 51 | + "tail": "no" |
| 52 | + } |
| 53 | + ] |
| 54 | + |
| 55 | +Get type of a label in a pattern |
| 56 | + |
| 57 | + $ cat > test.ml << EOF |
| 58 | + > type t = #{ foo : string } |
| 59 | + > let f #{ foo = _ } = () |
| 60 | + > EOF |
| 61 | + |
| 62 | + $ $MERLIN single type-enclosing -position 2:10 -filename test.ml < test.ml | jq .value[:2] |
| 63 | + [ |
| 64 | + { |
| 65 | + "start": { |
| 66 | + "line": 2, |
| 67 | + "col": 9 |
| 68 | + }, |
| 69 | + "end": { |
| 70 | + "line": 2, |
| 71 | + "col": 12 |
| 72 | + }, |
| 73 | + "type": "string", |
| 74 | + "tail": "no" |
| 75 | + }, |
| 76 | + { |
| 77 | + "start": { |
| 78 | + "line": 2, |
| 79 | + "col": 6 |
| 80 | + }, |
| 81 | + "end": { |
| 82 | + "line": 2, |
| 83 | + "col": 18 |
| 84 | + }, |
| 85 | + "type": "t", |
| 86 | + "tail": "no" |
| 87 | + } |
| 88 | + ] |
| 89 | + |
| 90 | +Go to definition of a label in an expression |
| 91 | + |
| 92 | + $ cat > test.ml << EOF |
| 93 | + > type t = #{ foo : string } |
| 94 | + > let f (x : t) = x.#foo |
| 95 | + > let _ = #{ foo = "hi" } |
| 96 | + > EOF |
| 97 | + |
| 98 | + $ $MERLIN single locate -position 2:21 -filename test.ml < test.ml | jq .value |
| 99 | + { |
| 100 | + "file": "$TESTCASE_ROOT/test.ml", |
| 101 | + "pos": { |
| 102 | + "line": 1, |
| 103 | + "col": 12 |
| 104 | + } |
| 105 | + } |
| 106 | + |
| 107 | + $ $MERLIN single locate -position 3:12 -filename test.ml < test.ml | jq .value |
| 108 | + { |
| 109 | + "file": "$TESTCASE_ROOT/test.ml", |
| 110 | + "pos": { |
| 111 | + "line": 1, |
| 112 | + "col": 12 |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | +Go to definition of a label in a pattern |
| 117 | + |
| 118 | + $ cat > test.ml << EOF |
| 119 | + > type t = #{ foo : string } |
| 120 | + > let f #{ foo = _ } = () |
| 121 | + > EOF |
| 122 | + |
| 123 | + $ $MERLIN single locate -position 2:10 -filename test.ml < test.ml | jq .value |
| 124 | + { |
| 125 | + "file": "$TESTCASE_ROOT/test.ml", |
| 126 | + "pos": { |
| 127 | + "line": 1, |
| 128 | + "col": 12 |
| 129 | + } |
| 130 | + } |
| 131 | + |
| 132 | +Get usages of a label in an unboxed record |
| 133 | + |
| 134 | + $ cat > test.ml << EOF |
| 135 | + > type t = #{ foo : string } |
| 136 | + > let f #{ foo = _ } x = |
| 137 | + > let _ = x.#foo in |
| 138 | + > #{ foo = 10 } |
| 139 | + > EOF |
| 140 | + |
| 141 | + $ $MERLIN single occurrences -identifier-at 2:10 -filename test.ml < test.ml | jq .value |
| 142 | + [ |
| 143 | + { |
| 144 | + "start": { |
| 145 | + "line": 1, |
| 146 | + "col": 12 |
| 147 | + }, |
| 148 | + "end": { |
| 149 | + "line": 1, |
| 150 | + "col": 15 |
| 151 | + } |
| 152 | + }, |
| 153 | + { |
| 154 | + "start": { |
| 155 | + "line": 2, |
| 156 | + "col": 9 |
| 157 | + }, |
| 158 | + "end": { |
| 159 | + "line": 2, |
| 160 | + "col": 12 |
| 161 | + } |
| 162 | + }, |
| 163 | + { |
| 164 | + "start": { |
| 165 | + "line": 3, |
| 166 | + "col": 13 |
| 167 | + }, |
| 168 | + "end": { |
| 169 | + "line": 3, |
| 170 | + "col": 16 |
| 171 | + } |
| 172 | + }, |
| 173 | + { |
| 174 | + "start": { |
| 175 | + "line": 4, |
| 176 | + "col": 5 |
| 177 | + }, |
| 178 | + "end": { |
| 179 | + "line": 4, |
| 180 | + "col": 8 |
| 181 | + } |
| 182 | + } |
| 183 | + ] |
| 184 | + |
| 185 | +Construct a record |
| 186 | + |
| 187 | + $ cat > test.ml << EOF |
| 188 | + > type t = #{ foo : string } |
| 189 | + > let (_ : t) = _ |
| 190 | + > EOF |
| 191 | + |
| 192 | +TODO (unboxed records): the record is missing the # at the start of it |
| 193 | + $ $MERLIN single construct -position 2:14 -filename test.ml < test.ml | jq .value |
| 194 | + [ |
| 195 | + { |
| 196 | + "start": { |
| 197 | + "line": 2, |
| 198 | + "col": 14 |
| 199 | + }, |
| 200 | + "end": { |
| 201 | + "line": 2, |
| 202 | + "col": 15 |
| 203 | + } |
| 204 | + }, |
| 205 | + [ |
| 206 | + "{ foo = _ }" |
| 207 | + ] |
| 208 | + ] |
| 209 | + |
| 210 | +Destruct a record |
| 211 | + |
| 212 | + $ cat > test.ml << EOF |
| 213 | + > type t = #{ foo : string } |
| 214 | + > let (x : t) = x |
| 215 | + > EOF |
| 216 | + |
| 217 | +TODO (unboxed records): allow destruction |
| 218 | + $ $MERLIN single case-analysis -start 2:14 -end 2:15 -filename test.ml < test.ml | jq .value |
| 219 | + "Destruct not allowed on non-destructible type: t" |
0 commit comments