Commits

camlspotter  committed 0ca777f

added tests

  • Participants
  • Parent commits a449df9
  • Branches indent-warning

Comments (0)

Files changed (19)

-3.11.2+ocamlspotter-1.2+camlp4-lexer-plugs
+3.11.2+ocamlspotter-1.2+camlp4-lexer-plugs+indent-warning
 
 # The version string is the first line of this file.
 # It must be in the format described in stdlib/sys.mli

File ocamlspot/indent-test/function_bad_first_pattern2.ml

+let _ = function
+  | _ -> 
+      let f x = function
+	| [] -> 0
+  | _ -> 2 
+;;
+

File ocamlspot/indent-test/function_bad_first_pattern2_.ml

+let f x = function
+  | [] -> 0
+| _ -> 2 (* ridiculous but ok, since it is not confusing, because it
+	    is not preceded by another pattern match *)
+;;
+

File ocamlspot/indent-test/function_bad_first_pattern3_.ml

+(* found in OCaml *)
+let _ = 
+  List.map (function [] -> 0
+    | _ -> 1) [] (* safe but reported *)
+

File ocamlspot/indent-test/function_bad_first_pattern_.ml

+(* 2, or 3 examples in OCaml implementation *)
+let f = function
+     [] -> 0
+  | _ -> 2 (* geez, it is ok but ocaml has no info of '|' position *)
+;;
+

File ocamlspot/indent-test/function_function_is_right.ml

+(* Some examples in OCaml implementation *)
+let f = function 
+  | _ -> 
+      function [] -> 0
+    | _ -> 1
+

File ocamlspot/indent-test/function_function_is_right2.ml

+(* Some examples in OCaml implementation *)
+let f = function 
+  | _ -> 
+      function [] -> 0
+   | _ -> 1
+

File ocamlspot/indent-test/function_function_is_right_.ml

+(* Some examples in OCaml implementation *)
+let f = function [] -> 0
+  | _ -> 1 (* safe *)
+

File ocamlspot/indent-test/if.ml

+let _ = 
+  (* if in seq *)
+  if true then 
+    prerr_endline "x"; 
+    prerr_endline "y" (* the following exp is right of if *)
+;;
+

File ocamlspot/indent-test/match_case.ml

+let _ = 
+  prerr_endline "1";
+  (* match inside seq, but actually not *)
+  match true with
+  | _ -> prerr_endline "2";
+  prerr_endline "3"; (* expr left of its pattern *)
+;;
+
+(* Rule B:
+   If the case expression starts right of the pattern, 
+   all the lines of the case expr must appear at the right of the pattern.
+*)
+

File ocamlspot/indent-test/match_case2.ml

+let _ = 
+  prerr_endline "1";
+  (* match inside seq, but actually not *)
+  match true with
+  | _ -> prerr_endline "2";
+   prerr_endline "3"; (* expr left of its pattern *)
+;;
+
+(* Rule B:
+   If the case expression starts right of the pattern, 
+   all the lines of the case expr must appear at the right of the pattern.
+*)
+

File ocamlspot/indent-test/match_first_case_one_line.ml

+(* This is often seen in OCaml implementation *)
+let _ = 
+  match [] with [] -> 0
+ | _x::_xs -> 1 (* ok, since it is at the same level of match *)
+

File ocamlspot/indent-test/match_first_case_one_line_.ml

+(* This is often seen in OCaml implementation *)
+let _ = 
+  match [] with [] -> 0
+  | _x::_xs -> 1 (* ok, since it is at the same level of match *)
+

File ocamlspot/indent-test/match_match.ml

+let _ = 
+  match true with
+  | _ ->
+      (* match inside a match case, but actually not *)
+      match true with
+      | true -> 1
+  | false -> 2 (* the pattern is left of either match or the first pattern *)
+;;
+
+(* Rule A:
+   The second and later pattern must appear at the same or right of
+   the match or the first pattern.
+
+   Note:
+   A is applied if the match is inside an outer case expression
+*)

File ocamlspot/indent-test/match_match2.ml

+let _ = 
+  match true with
+  | _ ->
+      (* match inside a match case, but actually not *)
+      match true with
+      | true -> 1
+    | false -> 2 (* the pattern is left of either match or the first pattern *)
+;;
+
+(* Rule A:
+   The second and later pattern must appear at the same or right of
+   the match or the first pattern.
+
+   Note:
+   A is applied if the match is inside an outer case expression
+*)

File ocamlspot/indent-test/match_match_is_right_.ml

+(* Some people (including me) like the following. *)
+let f x = match fst x with
+  | [] -> 0
+  | _ -> 2 (* ok, since it is at the same level of the first pattern *)
+;;
+

File ocamlspot/indent-test/tab_.ml

+(* visually safe, but actually the second has a TAB! *)
+let _ =
+         begin match None with 
+         | Some () -> ()
+	 | None -> ()
+         end
+;;

File ocamlspot/indent-test/test.sh

+#!/bin/sh
+for i in *.ml
+do
+  mes=`../../ocamlc -c $i 2>&1`
+
+  case $i in
+  *_.ml)
+    if [ "$mes" = "" ]; then
+      echo "$i: OK"
+    else
+      echo "$i: XXX"
+    fi
+  ;;
+  *)
+    if [ "$mes" = "" ]; then
+      echo "$i: XXX"
+    else
+      echo "$i: OK"
+    fi
+  ;;
+  esac
+done

File typing/typecore.ml

       List.iter (fun (pat,_) ->
 	(* CR jfuruse: TAB count failure *)
 	if bol_of_loc pat.ppat_loc < bol_start 
-	  && bol_of_loc pat.ppat_loc < bol_of_loc pexp.pexp_loc
+	  && bol_of_loc pat.ppat_loc - 2 (* = String.length "| " *) < bol_of_loc pexp.pexp_loc
 	then
 	  Location.prerr_warning pat.ppat_loc Warnings.Confusing_indent)
 	pat_a_list