Skip to content

Commit

Permalink
Fixed bug with record-with
Browse files Browse the repository at this point in the history
  • Loading branch information
AltGr committed Feb 6, 2013
1 parent 7739009 commit 45a8209
Show file tree
Hide file tree
Showing 6 changed files with 80 additions and 46 deletions.
8 changes: 5 additions & 3 deletions src/indentBlock.ml
Expand Up @@ -347,6 +347,7 @@ let rec update_path config t stream tok =
| KParen | KBracket | KBrace | KBar _ -> 1
| KBracketBar -> 2
| KWith KBrace -> 4
| _ -> assert false
in
let l = paren.t + paren_len + 1 (* usually 1 space *) + pad in
Some ({ h with k; l; t=l; pad = h.t - l } :: p)
Expand Down Expand Up @@ -623,10 +624,11 @@ let rec update_path config t stream tok =
match path with
| {k=KBrace; pad} :: _ ->
(match next with
| Some {newlines = 0} ->
append (KWith KBrace) L ~pad:(t.toff+tok.offset+3) path
| Some {newlines = 0; offset} ->
Path.maptop (fun n -> {n with l=n.t})
(append (KWith KBrace) L ~pad:offset path)
| _ ->
append (KWith KBrace) T ~pad:(pad + config.i_base) path)
append (KWith KBrace) L ~pad:(pad + config.i_with) path)
| {k=KVal|KType|KException as k}::_ -> replace (KWith k) L path
| {k=KTry|KMatch} as m
:: ({k = KBody (KLet|KLetIn) | KArrow(KMatch|KTry)} as l)
Expand Down
12 changes: 6 additions & 6 deletions tests/failing-output/obuild.ml
@@ -1,10 +1,10 @@
type predicate =
Pred_Byte
| Pred_Native
| Pred_Toploop
Pred_Byte
| Pred_Native
| Pred_Toploop

let _ =
{ pkg with
package_version = projFile.version
; package_description = _
; package_requires = [] }
package_version = projFile.version
; package_description = _
; package_requires = [] }
68 changes: 34 additions & 34 deletions tests/failing.html
Expand Up @@ -2,7 +2,7 @@
"http://www.w3.org/TR/REC-html40/loose.dtd">
<html>
<head>
<title>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</title>
<title>Failing tests, ocp-indent version 0.6.2+3 (2013-02-06)</title>
<style>
BODY { font-family: monospace; }
TABLE { border-collapse: collapse; border-spacing: 0px; margin: auto; }
Expand All @@ -22,7 +22,7 @@
</style>
</head>
<body>
<h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
<h1>Failing tests, ocp-indent version 0.6.2+3 (2013-02-06)</h1>
<p>Left is expected result, right shows actual indentation by ocp-indent</p>
<table>
<tr><td width="70%">
Expand Down Expand Up @@ -209,7 +209,7 @@ <h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
</tr>
</table>
<hr/>
<i>Generated by <b>diff2html</b> on 2013-02-06 16:59:51</i>
<i>Generated by <b>diff2html</b> on 2013-02-06 17:03:58</i>
<table>
<tr><td width="70%">
<table>
Expand Down Expand Up @@ -808,7 +808,7 @@ <h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
</tr>
</table>
<hr/>
<i>Generated by <b>diff2html</b> on 2013-02-06 16:59:53</i>
<i>Generated by <b>diff2html</b> on 2013-02-06 17:04:00</i>
<table>
<tr><td width="70%">
<table>
Expand Down Expand Up @@ -1015,7 +1015,7 @@ <h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
</tr>
</table>
<hr/>
<i>Generated by <b>diff2html</b> on 2013-02-06 16:59:54</i>
<i>Generated by <b>diff2html</b> on 2013-02-06 17:04:01</i>
<table>
<tr><td width="70%">
<table>
Expand Down Expand Up @@ -1159,13 +1159,13 @@ <h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
</tr>
</table>
<hr/>
<i>Generated by <b>diff2html</b> on 2013-02-06 16:59:55</i>
<i>Generated by <b>diff2html</b> on 2013-02-06 17:04:02</i>
<table>
<tr><td width="70%">
<table>
<tr>
<td class="modified">Modified line(s):&nbsp;</td>
<td class="modified"><a href='#failing/obuild.ml_2'>2</a>&nbsp; <a href='#failing/obuild.ml_3'>3</a>&nbsp; <a href='#failing/obuild.ml_4'>4</a>&nbsp; <a href='#failing/obuild.ml_7'>7</a>&nbsp; <a href='#failing/obuild.ml_8'>8</a>&nbsp; <a href='#failing/obuild.ml_9'>9</a>&nbsp; <a href='#failing/obuild.ml_10'>10</a>&nbsp; </td>
<td class="modified"><a href='#failing/obuild.ml_7'>7</a>&nbsp; <a href='#failing/obuild.ml_10'>10</a>&nbsp; </td>
</tr>
<tr>
<td class="added">Added line(s):&nbsp;</td>
Expand Down Expand Up @@ -1205,8 +1205,8 @@ <h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
<td width="16">&nbsp;</td>
<td>
10 lines<br/>
209 bytes<br/>
Last modified : 2013-02-06 16:07:06 <br>
191 bytes<br/>
Last modified : 2013-02-06 17:03:57 <br>
<hr/>
</td>
</tr>
Expand All @@ -1217,26 +1217,26 @@ <h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
<td class="linenum">1</td>
<td class="normal">type predicate =</td>
</tr>
<tr>
<td class="linenum"><a name="failing/obuild.ml_2">2</a></td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;Pred_Byte</td>
<tr>
<td class="linenum">2</td>
<td class="normal">&nbsp;&nbsp;&nbsp;&nbsp;Pred_Byte</td>
<td width="16">&nbsp;</td>
<td class="linenum">2</td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;Pred_Byte</td>
<td class="normal">&nbsp;&nbsp;&nbsp;&nbsp;Pred_Byte</td>
</tr>
<tr>
<td class="linenum"><a name="failing/obuild.ml_3">3</a></td>
<td class="modified">&nbsp;&nbsp;| Pred_Native</td>
<tr>
<td class="linenum">3</td>
<td class="normal">&nbsp;&nbsp;| Pred_Native</td>
<td width="16">&nbsp;</td>
<td class="linenum">3</td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;| Pred_Native</td>
<td class="normal">&nbsp;&nbsp;| Pred_Native</td>
</tr>
<tr>
<td class="linenum"><a name="failing/obuild.ml_4">4</a></td>
<td class="modified">&nbsp;&nbsp;| Pred_Toploop</td>
<tr>
<td class="linenum">4</td>
<td class="normal">&nbsp;&nbsp;| Pred_Toploop</td>
<td width="16">&nbsp;</td>
<td class="linenum">4</td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;| Pred_Toploop</td>
<td class="normal">&nbsp;&nbsp;| Pred_Toploop</td>
</tr>
<tr>
<td class="linenum">5</td>
Expand All @@ -1259,30 +1259,30 @@ <h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
<td class="linenum">7</td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;{ pkg with</td>
</tr>
<tr>
<td class="linenum"><a name="failing/obuild.ml_8">8</a></td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;package_version = projFile.version</td>
<tr>
<td class="linenum">8</td>
<td class="normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;package_version = projFile.version</td>
<td width="16">&nbsp;</td>
<td class="linenum">8</td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;package_version = projFile.version</td>
<td class="normal">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;package_version = projFile.version</td>
</tr>
<tr>
<td class="linenum"><a name="failing/obuild.ml_9">9</a></td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;; package_description = _</td>
<tr>
<td class="linenum">9</td>
<td class="normal">&nbsp;&nbsp;&nbsp;&nbsp;; package_description = _</td>
<td width="16">&nbsp;</td>
<td class="linenum">9</td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; package_description = _</td>
<td class="normal">&nbsp;&nbsp;&nbsp;&nbsp;; package_description = _</td>
</tr>
<tr>
<td class="linenum"><a name="failing/obuild.ml_10">10</a></td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;; package_requires = [] }</td>
<td width="16">&nbsp;</td>
<td class="linenum">10</td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; package_requires = [] }</td>
<td class="modified">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;; package_requires = [] }</td>
</tr>
</table>
<hr/>
<i>Generated by <b>diff2html</b> on 2013-02-06 16:59:56</i>
<i>Generated by <b>diff2html</b> on 2013-02-06 17:04:03</i>
<table>
<tr><td width="70%">
<table>
Expand Down Expand Up @@ -2217,7 +2217,7 @@ <h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
</tr>
</table>
<hr/>
<i>Generated by <b>diff2html</b> on 2013-02-06 16:59:58</i>
<i>Generated by <b>diff2html</b> on 2013-02-06 17:04:05</i>
<table>
<tr><td width="70%">
<table>
Expand Down Expand Up @@ -3005,7 +3005,7 @@ <h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
</tr>
</table>
<hr/>
<i>Generated by <b>diff2html</b> on 2013-02-06 17:00:00</i>
<i>Generated by <b>diff2html</b> on 2013-02-06 17:04:07</i>
<table>
<tr><td width="70%">
<table>
Expand Down Expand Up @@ -3870,6 +3870,6 @@ <h1>Failing tests, ocp-indent version 0.6.2 (2013-02-06)</h1>
</tr>
</table>
<hr/>
<i>Generated by <b>diff2html</b> on 2013-02-06 17:00:02</i>
<i>Generated by <b>diff2html</b> on 2013-02-06 17:04:09</i>
</body>
</html>
2 changes: 1 addition & 1 deletion tests/failing/obuild.ml.opts
@@ -1 +1 @@
-c base=4,type=4,match_clause=4
-c base=4,type=2,match_clause=4
4 changes: 2 additions & 2 deletions tests/passing/js-record.ml
@@ -1,7 +1,7 @@
let x =
{ x with
foo = 3
; bar = 5
foo = 3
; bar = 5
}

let x =
Expand Down
32 changes: 32 additions & 0 deletions tests/passing/record-with.ml
@@ -0,0 +1,32 @@
let a =
{
somerecord
with
a = b;
c = d;
}

let a =
{
somerecord
with a = b;
c = d;
}

let z =
{ recofzfzfzrd with a = bli; bzeefe =
k
; efgeg = a
}

let b =
let z =
{ reczfzrd with a = bli;
bzeefe = _;
}

let b =
let z =
{ reczfzrd with a = bli;
bzeefe
}

0 comments on commit 45a8209

Please sign in to comment.