summaryrefslogtreecommitdiff
path: root/testsuite/tests/parsing/change_start_loc.ml
blob: 2e5604ce78a3d9f8adccbd664bb13fe393b58c76 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(* TEST
flags = "-I ${ocamlsrcdir}/parsing -I ${ocamlsrcdir}/toplevel"
include ocamlcommon
*)
let position = Lexing.{ (* This corresponds to File "file.ml", line 100, character 10 *)
    pos_fname = "------should not appear------";
    pos_lnum = 100;
    pos_bol = 1000;
    pos_cnum = 1010;
}

(* We need to show, that just changing lex_curr_p is not enough.
   See wrong columns in output for 'Incomplete version'. *)
let set_position_incomplete lexbuf position =
  let open Lexing in
  lexbuf.lex_curr_p  <- {position with pos_fname = lexbuf.lex_curr_p.pos_fname}

(* "Testing framework" *)
let print_error_in_parse set_position_variant =
    try
        let _ =
            let lexbuf = Lexing.from_string ")f x" in (* contains error in chars 0-1, line 0 *)
            set_position_variant lexbuf position;
            Lexing.set_filename lexbuf "file.ml"; (* also testing set_filename *)
            Parse.expression lexbuf in ()
    with e -> Location.report_exception Format.std_formatter e

let _ =
    print_string "Incomplete version:\n";
    print_error_in_parse set_position_incomplete;
    print_string "Good version:\n";
    print_error_in_parse Lexing.set_position