Commits

camlspotter  committed 76df415

testbed

  • Participants
  • Parent commits 2b8918d

Comments (0)

Files changed (25)

 ^.*\.(cm.*|o|sp.t|annot|opt|run|out|omc)$
 .*~$
+tests_out/.*\.ml
 
 
     location
     pos
     parser
-    token
     lexer
     reader
     filter
 
 clean:
 	rm -f *.cm* *.o *output *.sp?t
+
+.PHONY: test
+
+
+TESTS=$(glob tests/test_*.ml)
+test_out(file) = 
+    return $(addprefix tests_out, $(removeprefix tests, $(file)))
+
+TESTS_OUT=$(test_out $(TESTS))
+
+foreach (file, $(TESTS))
+  $(test_out $(file)): $(file) ./indent
+    ./indent $< > $@
+  export
+
+result.diff: $(TESTS_OUT)
+    diff -c -r tests tests_out > $@
+
+test: result.diff
   type t = {
     bases : Stack.t;
     orig_indent : int; (* The original indent of the current line *)
-    last_indent : int; (* At line head: the fixed indent of the last line
+    last_indent : int; (* At line head, first pass: the fixed indent of the last line
+                          At line head, snd pass: the fixed indent of the current line
                           Otherwise: the fixed indent of the current line *)
     last_token : Parser.token option;
   } with sexp
         if at_the_head then
           { k = KTry columns; indent = Indent.Set (columns + 2); line } :: bases0
         else
-          { k = KTry (indent + 2); indent = Indent.Set (columns + 2); line } :: bases0
+          { k = KTry indent; indent = Indent.Set (indent + 2); line } :: bases0
 
     | WITH ->
         (* support for typeconv *)
   in
 
   let fixed_region = Region.move_chars (state'.last_indent - state.orig_indent) orig_region in
- 
+
+  let state = { state with last_indent = state'.last_indent } in
 (*
   Format.eprintf "<FIX %d>@."
     (Region.columns fixed_region);
 
     let rec loop last_orig_region state str = match Filter.destr str with
       | None ->
-          (* The last white space is gone *)
-          print_string "\n"
+          ()
+      | Some (({Filter.token = EOF} as i), _) ->
+          let space_between = i.Filter.space in
+          print_string space_between
+          
       | Some (i, str) ->
           let t = i.Filter.token in
           let orig_region = i.Filter.region in

File test1.ml

-let f = function
-  | X -> 1
-  | X | Y -> 2
-  | X -> 1
-  | (X | Y) -> 3
-  | X -> 1
-  | Y -> 
-      1
-  | Y -> 1
-      2
-  | _ -> Z
-  | ( X 
-    | Y
-    | Z ) -> 4
-
-(* comment *)
-      

File test3.ml

-let x = 
-  let y = 1
-    + 2
-    - 3
-  and z = foo
-  in
-  y + z
-
-(* comment *)

File test_comma.ml

-let               (* let: = cur+4 *)
-    x y = 1,
-  2
-
-let x 
-    y = 1,
-  2
-
-let x y
-    = 1,
-  2
-
-let x y =        (* =: = let+2 *)
-  1, 2
-
-let x y = 1
-  , 2            (* geez *)
-
-let x = let      (* let: = cur+4 *)
-    y =          (* =: = let+2 *)
-          2      
-        in       (* in: = let *)
-        1
-
-let f = fun
-  x
--> 2
-
-let f = fun
-    x
--> 2
-
-module X =
-  struct
-  end

File test_expr.ml

-let x = 
-  f 1 2 3
-    4 5 6
-    7 8 9
-  + 1 2 3

File test_expr_binop.ml

-let f x = 
-  1 + 2
-    3 -
-    4
-  * 5
-    6
-;;

File test_let.ml

-let 
-    f 
-      x 
-    = 
-  1
-
-and 
-    g
-      y
-    =
-  2
-
-let 
-    f x =
-  2
-;;
-
-let 
-    g 
-      x =
-  2

File test_let_in.ml

-let x =
-  let y = 10 in
-  x
-;;

File test_match.ml

-let rec lparen_read_ahead lnum str =
-  match Filter.destr str with
-| None -> false
-| Some (i, _) when Region.lnum i.Filter.region <> lnum -> false
-| Some (i, str) ->
-    match i.Filter.token with
-| FUN -> false
-| FUNCTION -> false
-| COMMENT -> lparen_read_ahead lnum str
-| _ -> true

File test_paren.ml

-let x = ( 1,
-          2,
-          3 )
-
-let x = (
-  1,
-  2,
-  3
-)
-
-let x = f (fun x ->
-  1
-)
-
-let x = (f
-           g)
-
-let x = (
-  f g
-)
-
-let x = ( 1
-        , 2
-        , 3
-        )
-
-let x = f (fun x -> y
-  z
-)
-
-let z = let x = 
-          f ( (* com *) 1, 
-              2 )
-

File test_record.ml

-type t = {
-  f : int;
-  g : int 
-}

File test_semi.ml

-let x =
-  if true then
-    1;
-  2;
-  3
-;;
-

File tests/test_cases.ml

+let f = function
+  | X -> 1
+  | X | Y -> 2
+  | X -> 1
+  | (X | Y) -> 3
+  | X -> 1
+  | Y -> 
+      1
+  | Y -> 1
+           2
+  | _ -> Z
+  | ( X 
+    | Y
+    | Z ) -> 4
+

File tests/test_comma.ml

+let x y =
+  1, 2
+
+let x y =
+  1, 
+  2
+
+let x y = 1
+          , 2 
+
+let x y = 1,
+          2 

File tests/test_expr.ml

+let x = 
+  f 1 2 3
+    4 5 6
+    7 8 9
+  + 1 2 3

File tests/test_expr_binop.ml

+let f x = 
+  1 + 2
+    3 -
+    4
+  * 5
+    6
+;;

File tests/test_let.ml

+let f x 
+  = 1
+
+let
+  f 
+    x 
+  = 
+  1
+
+and 
+  g
+    y
+  =
+  2

File tests/test_let_in.ml

+let x =
+  let y = 10 in
+  x
+;;

File tests/test_match.ml

+let rec lparen_read_ahead lnum str =
+  match Filter.destr str with
+  | None -> false
+  | Some (i, _) when Region.lnum i.Filter.region <> lnum -> false
+  | Some (i, str) ->
+      match i.Filter.token with
+      | FUN -> false
+      | FUNCTION -> false
+      | COMMENT -> lparen_read_ahead lnum str
+      | _ -> true

File tests/test_ops.ml

+let x = 
+  let y = 1
+          + 2
+          - 3
+  and z = foo
+  in
+  y + z

File tests/test_paren.ml

+let x = ( 1,
+          2,
+          3 )
+
+let x = (
+  1,
+  2,
+  3
+)
+
+let x = f (fun x ->
+  1
+)
+
+let x = (f
+           g)
+
+let x = (
+  f g
+)
+
+let x = ( 1
+        , 2
+        , 3
+        )
+
+let x = f (fun x -> y
+  z
+)
+
+let z = let x = 
+          f ( (* com *) 1, 
+              2 )
+

File tests/test_record.ml

+type t = {
+  f : int;
+  g : int 
+}

File tests/test_semi.ml

+let x =
+  if true then
+    1;
+  2;
+  3
+;;
+