From f16d0747ba0fa9d2b025c8206fb1f4a2a4c720bd Mon Sep 17 00:00:00 2001 From: Nathan Rebours Date: Mon, 18 Nov 2024 16:33:34 +0100 Subject: [PATCH 1/7] Add versioned expect block to expect test runner Signed-off-by: Nathan Rebours --- test/expect/expect_lexer.mli | 13 +++- test/expect/expect_lexer.mll | 121 +++++++++++++++++++++++++++++++++-- test/expect/expect_test.ml | 91 +++++++++++++++++++++----- 3 files changed, 203 insertions(+), 22 deletions(-) diff --git a/test/expect/expect_lexer.mli b/test/expect/expect_lexer.mli index 4364bda04..3c5b2373a 100644 --- a/test/expect/expect_lexer.mli +++ b/test/expect/expect_lexer.mli @@ -1,2 +1,13 @@ +type version = int * int + +type version_range = + | Up_to of version + | From of version + | Between of version * version + +type versioned_expect = version_range * string + val split_file : - file_contents:string -> Lexing.lexbuf -> (Lexing.position * string) list + file_contents:string -> + Lexing.lexbuf -> + (Lexing.position * string * versioned_expect list) list diff --git a/test/expect/expect_lexer.mll b/test/expect/expect_lexer.mll index 3de8722cb..489447b16 100644 --- a/test/expect/expect_lexer.mll +++ b/test/expect/expect_lexer.mll @@ -1,14 +1,66 @@ { open StdLabels + +type version = int * int + +type version_range = + | Up_to of version + | From of version + | Between of version * version + +type versioned_expect = version_range * string + +let make_version major minor = + let major = int_of_string major in + let minor = int_of_string minor in + (major, minor) + +let extract_chunk txt start lexbuf = + let pos = start.Lexing.pos_cnum in + let len = Lexing.lexeme_start lexbuf - pos in + String.sub txt ~pos ~len } +let digit = ['0'-'9'] + +(* Entrypoint + Parses blocks of code to execute seperated by [%%expect{|...|}] statement. + Code blocks can be separated by a single [%%expect{|...|}] statement or by a + series of [%%expect_in {|...|}]. *) rule code txt start = parse | "[%%expect{|\n" { - let pos = start.Lexing.pos_cnum in - let len = Lexing.lexeme_start lexbuf - pos in - let s = String.sub txt ~pos ~len in + let s = extract_chunk txt start lexbuf in Lexing.new_line lexbuf; - (start, s) :: expectation txt lexbuf + (start, s, []) :: expectation txt lexbuf + } + | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) "+ {|\n" { + let s = extract_chunk txt start lexbuf in + Lexing.new_line lexbuf; + let version = make_version major minor in + let range = From version in + let cstart = lexbuf.lex_curr_p in + versioned_expectation_content txt (start, s) [] (range, cstart) lexbuf + } + | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) "- {|\n" { + let s = extract_chunk txt start lexbuf in + Lexing.new_line lexbuf; + let version = make_version major minor in + let range = Up_to version in + let cstart = lexbuf.lex_curr_p in + versioned_expectation_content txt (start, s) [] (range, cstart) lexbuf + } + | "[%%expect_in " + (digit+ as major1) '.' (digit+ as minor1) + ".." + (digit+ as major2) '.' (digit+ as minor2) + " {|\n" { + let s = extract_chunk txt start lexbuf in + Lexing.new_line lexbuf; + let v1 = make_version major1 minor1 in + let v2 = make_version major2 minor2 in + let range = Between (v1, v2) in + let cstart = lexbuf.lex_curr_p in + versioned_expectation_content txt (start, s) [] (range, cstart) lexbuf } | [^'\n']*'\n' { Lexing.new_line lexbuf; @@ -22,7 +74,7 @@ rule code txt start = parse if String.trim s = "" then [] else - [(start, s)] + [(start, s, [])] end else [] } @@ -37,6 +89,65 @@ and expectation txt = parse expectation txt lexbuf } +(* Parses the content of a [%%expect_in .. {| ... |}] block along with following + blocks in the same group *) +and versioned_expectation_content txt code_chunk vexpects curr = parse + | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) "+ {|\n" { + let range, start = curr in + let s = extract_chunk txt start lexbuf in + Lexing.new_line lexbuf; + Lexing.new_line lexbuf; + let block = range, s in + let version = make_version major minor in + let next_range = From version in + let cstart = lexbuf.lex_curr_p in + versioned_expectation_content txt code_chunk + (block::vexpects) (next_range, cstart) lexbuf + } + | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) "- {|\n" { + let range, start = curr in + let s = extract_chunk txt start lexbuf in + Lexing.new_line lexbuf; + Lexing.new_line lexbuf; + let block = range, s in + let version = make_version major minor in + let next_range = Up_to version in + let cstart = lexbuf.lex_curr_p in + versioned_expectation_content txt code_chunk + (block::vexpects) (next_range, cstart) lexbuf + } + | "|}]\n[%%expect_in " + (digit+ as major1) '.' (digit+ as minor1) + ".." + (digit+ as major2) '.' (digit+ as minor2) + " {|\n" { + let range, start = curr in + let s = extract_chunk txt start lexbuf in + Lexing.new_line lexbuf; + Lexing.new_line lexbuf; + let block = range, s in + let v1 = make_version major1 minor1 in + let v2 = make_version major2 minor2 in + let next_range = Between (v1, v2) in + let cstart = lexbuf.lex_curr_p in + versioned_expectation_content txt code_chunk + (block::vexpects) (next_range, cstart) lexbuf + } + | "|}]\n" { + let range, start = curr in + let pos = start.Lexing.pos_cnum in + let len = Lexing.lexeme_start lexbuf - pos in + let s = String.sub txt ~pos ~len in + Lexing.new_line lexbuf; + let vexpects = List.rev ((range, s)::vexpects) in + let start, s = code_chunk in + (start, s, vexpects) :: code txt lexbuf.lex_curr_p lexbuf + } + | [^'\n']*'\n' { + Lexing.new_line lexbuf; + versioned_expectation_content txt code_chunk vexpects curr lexbuf + } + { let split_file ~file_contents lexbuf = code file_contents lexbuf.Lexing.lex_curr_p lexbuf diff --git a/test/expect/expect_test.ml b/test/expect/expect_test.ml index c70949399..26732d20a 100644 --- a/test/expect/expect_test.ml +++ b/test/expect/expect_test.ml @@ -1,5 +1,20 @@ open StdLabels +let compiler_version = + match String.split_on_char ~sep:'.' Sys.ocaml_version with + | major :: minor :: _ -> (int_of_string major, int_of_string minor) + | _ -> assert false + +let include_compiler_version range = + let cmajor, cminor = compiler_version in + match (range : Expect_lexer.version_range) with + | From (major, minor) -> cmajor > major || (cmajor = major && cminor >= minor) + | Up_to (major, minor) -> cmajor < major || (cmajor = major && cminor <= minor) + | Between ((min_major, min_minor), (max_major, max_minor)) -> + (cmajor > min_major && cmajor < max_major) + || (cmajor = min_major && cminor >= min_minor) + || (cmajor = max_major && cminor <= max_minor) + let read_file file = let ic = open_in_bin file in let len = in_channel_length ic in @@ -10,6 +25,7 @@ let read_file file = let run_expect_test file ~f = let file_contents = read_file file in let lexbuf = Lexing.from_string file_contents in + Lexing.set_filename lexbuf file; lexbuf.lex_curr_p <- { pos_fname = file; pos_cnum = 0; pos_lnum = 1; pos_bol = 0 }; @@ -73,6 +89,61 @@ let execute_phrase ppf phr = in match trimmed with "" -> () | _ -> Format.fprintf ppf "%s\n" trimmed +let pp_version ppf (major, minor) = Format.fprintf ppf "%d.%d" major minor + +let pp_range ppf range = + match (range : Expect_lexer.version_range) with + | From v -> Format.fprintf ppf "%a+" pp_version v + | Up_to v -> Format.fprintf ppf "%a-" pp_version v + | Between (v1, v2) -> Format.fprintf ppf "%a..%a" pp_version v1 pp_version v2 + +let run_code ppf starting_pos code = + let lexbuf = Lexing.from_string code in + lexbuf.lex_curr_p <- { starting_pos with pos_lnum = 1 }; + let phrases = !Toploop.parse_use_file lexbuf in + List.iter phrases ~f:(function + | Parsetree.Ptop_def [] -> () + | phr -> ( + try + let phr = apply_rewriters phr in + if !Clflags.dump_source then + Format.fprintf ppf "%a@?" Ppxlib.Pprintast.top_phrase + (Ppxlib.Selected_ast.Of_ocaml.copy_toplevel_phrase phr); + execute_phrase ppf phr + with exn -> Location.report_exception ppf exn)) + +let handle_regular_expect_block ppf starting_pos code = + Format.fprintf ppf "%s[%%%%expect{|@." code; + run_code ppf starting_pos code; + Format.fprintf ppf "@?|}]@." + +let handle_versioned_expect_blocks ppf starting_pos code vexpect_blocks = + let matched = ref false in + let loc = + { + Location.loc_start = starting_pos; + loc_end = starting_pos; + loc_ghost = false; + } + in + Format.fprintf ppf "%s@?" code; + List.iter vexpect_blocks ~f:(fun (range, content) -> + Format.fprintf ppf "[%%%%expect_in %a {|@." pp_range range; + if include_compiler_version range && not !matched then ( + matched := true; + run_code ppf starting_pos code; + Format.fprintf ppf "@?|}]@.") + else if include_compiler_version range && !matched then + Location.raise_errorf ~loc + "Multiple versioned expect block in a group matched our compiler \ + version %a" + pp_version compiler_version + else Format.fprintf ppf "%s|}]@." content); + if not !matched then + Location.raise_errorf ~loc + "No versioned expect block in a group matched our compiler version %a" + pp_version compiler_version + let main () = let rec map_tree = function | Outcometree.Oval_constr (name, params) -> @@ -119,22 +190,10 @@ let main () = is statically linked in *) Topfind.load_deeply [ "ppxlib" ]; - List.iter chunks ~f:(fun (pos, s) -> - Format.fprintf ppf "%s[%%%%expect{|@." s; - let lexbuf = Lexing.from_string s in - lexbuf.lex_curr_p <- { pos with pos_lnum = 1 }; - let phrases = !Toploop.parse_use_file lexbuf in - List.iter phrases ~f:(function - | Parsetree.Ptop_def [] -> () - | phr -> ( - try - let phr = apply_rewriters phr in - if !Clflags.dump_source then - Format.fprintf ppf "%a@?" Ppxlib.Pprintast.top_phrase - (Ppxlib.Selected_ast.Of_ocaml.copy_toplevel_phrase phr); - execute_phrase ppf phr - with exn -> Location.report_exception ppf exn)); - Format.fprintf ppf "@?|}]@."); + List.iter chunks ~f:(fun (pos, s, vexpects) -> + match vexpects with + | [] -> handle_regular_expect_block ppf pos s + | _ -> handle_versioned_expect_blocks ppf pos s vexpects); Buffer.contents buf) let () = From f5febf3e1adb72d375ce561de040c75350cd201c Mon Sep 17 00:00:00 2001 From: Nathan Rebours Date: Tue, 19 Nov 2024 18:33:16 +0100 Subject: [PATCH 2/7] Make new [%%expect_in syntax compatible with ocamlformat Signed-off-by: Nathan Rebours --- test/expect/expect_lexer.mll | 12 ++++++------ test/expect/expect_test.ml | 7 ++++--- 2 files changed, 10 insertions(+), 9 deletions(-) diff --git a/test/expect/expect_lexer.mll b/test/expect/expect_lexer.mll index 489447b16..44881e8cf 100644 --- a/test/expect/expect_lexer.mll +++ b/test/expect/expect_lexer.mll @@ -33,7 +33,7 @@ rule code txt start = parse Lexing.new_line lexbuf; (start, s, []) :: expectation txt lexbuf } - | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) "+ {|\n" { + | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) " + {|\n" { let s = extract_chunk txt start lexbuf in Lexing.new_line lexbuf; let version = make_version major minor in @@ -41,7 +41,7 @@ rule code txt start = parse let cstart = lexbuf.lex_curr_p in versioned_expectation_content txt (start, s) [] (range, cstart) lexbuf } - | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) "- {|\n" { + | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) " - {|\n" { let s = extract_chunk txt start lexbuf in Lexing.new_line lexbuf; let version = make_version major minor in @@ -51,7 +51,7 @@ rule code txt start = parse } | "[%%expect_in " (digit+ as major1) '.' (digit+ as minor1) - ".." + " >> " (digit+ as major2) '.' (digit+ as minor2) " {|\n" { let s = extract_chunk txt start lexbuf in @@ -92,7 +92,7 @@ and expectation txt = parse (* Parses the content of a [%%expect_in .. {| ... |}] block along with following blocks in the same group *) and versioned_expectation_content txt code_chunk vexpects curr = parse - | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) "+ {|\n" { + | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) " + {|\n" { let range, start = curr in let s = extract_chunk txt start lexbuf in Lexing.new_line lexbuf; @@ -104,7 +104,7 @@ and versioned_expectation_content txt code_chunk vexpects curr = parse versioned_expectation_content txt code_chunk (block::vexpects) (next_range, cstart) lexbuf } - | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) "- {|\n" { + | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) " - {|\n" { let range, start = curr in let s = extract_chunk txt start lexbuf in Lexing.new_line lexbuf; @@ -118,7 +118,7 @@ and versioned_expectation_content txt code_chunk vexpects curr = parse } | "|}]\n[%%expect_in " (digit+ as major1) '.' (digit+ as minor1) - ".." + " >> " (digit+ as major2) '.' (digit+ as minor2) " {|\n" { let range, start = curr in diff --git a/test/expect/expect_test.ml b/test/expect/expect_test.ml index 26732d20a..96a960ef8 100644 --- a/test/expect/expect_test.ml +++ b/test/expect/expect_test.ml @@ -93,9 +93,10 @@ let pp_version ppf (major, minor) = Format.fprintf ppf "%d.%d" major minor let pp_range ppf range = match (range : Expect_lexer.version_range) with - | From v -> Format.fprintf ppf "%a+" pp_version v - | Up_to v -> Format.fprintf ppf "%a-" pp_version v - | Between (v1, v2) -> Format.fprintf ppf "%a..%a" pp_version v1 pp_version v2 + | From v -> Format.fprintf ppf "%a +" pp_version v + | Up_to v -> Format.fprintf ppf "%a -" pp_version v + | Between (v1, v2) -> + Format.fprintf ppf "%a >> %a" pp_version v1 pp_version v2 let run_code ppf starting_pos code = let lexbuf = Lexing.from_string code in From d68e6bfcab8254c49f4c701da04ab796245daa12 Mon Sep 17 00:00:00 2001 From: Nathan Rebours Date: Tue, 19 Nov 2024 18:33:47 +0100 Subject: [PATCH 3/7] Make expect test runner compatible with 5.3+ again Signed-off-by: Nathan Rebours --- test/expect/expect_test.ml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/expect/expect_test.ml b/test/expect/expect_test.ml index 96a960ef8..9ce12a0f5 100644 --- a/test/expect/expect_test.ml +++ b/test/expect/expect_test.ml @@ -122,7 +122,7 @@ let handle_versioned_expect_blocks ppf starting_pos code vexpect_blocks = let matched = ref false in let loc = { - Location.loc_start = starting_pos; + Ppxlib.Location.loc_start = starting_pos; loc_end = starting_pos; loc_ghost = false; } @@ -135,13 +135,13 @@ let handle_versioned_expect_blocks ppf starting_pos code vexpect_blocks = run_code ppf starting_pos code; Format.fprintf ppf "@?|}]@.") else if include_compiler_version range && !matched then - Location.raise_errorf ~loc + Ppxlib.Location.raise_errorf ~loc "Multiple versioned expect block in a group matched our compiler \ version %a" pp_version compiler_version else Format.fprintf ppf "%s|}]@." content); if not !matched then - Location.raise_errorf ~loc + Ppxlib.Location.raise_errorf ~loc "No versioned expect block in a group matched our compiler version %a" pp_version compiler_version From 9cb1df4985c8adb4195570eb2c29d02d13a73096 Mon Sep 17 00:00:00 2001 From: Nathan Rebours Date: Tue, 19 Nov 2024 18:37:05 +0100 Subject: [PATCH 4/7] Use [%%expect_in to make test pass under 5.3 Signed-off-by: Nathan Rebours --- test/code_path/test.ml | 7 +- test/expect/expect_test.ml | 1 - test/metaquot/test.ml | 70 +++++++++++-- test/quoter/test.ml | 209 ++++++++++++++++++++++++++++++++++++- 4 files changed, 274 insertions(+), 13 deletions(-) diff --git a/test/code_path/test.ml b/test/code_path/test.ml index 791c551c7..688e3ba07 100644 --- a/test/code_path/test.ml +++ b/test/code_path/test.ml @@ -89,11 +89,16 @@ module Functor() = struct end end let _ = let module M = Functor() in !M.code_path -[%%expect{| +[%%expect_in 5.2 - {| module Functor : functor () -> sig val code_path : string ref end - : string = "(code_path(main_module_name Test)(submodule_path(Functor _))(enclosing_module First_class)(enclosing_value(x))(value(x))(fully_qualified_path Test.Functor._.x))" |}] +[%%expect_in 5.3 + {| +module Functor : () -> sig val code_path : string ref end +- : string = +"(code_path(main_module_name Test)(submodule_path(Functor _))(enclosing_module First_class)(enclosing_value(x))(value(x))(fully_qualified_path Test.Functor._.x))" +|}] module Actual = struct let code_path = [%code_path] diff --git a/test/expect/expect_test.ml b/test/expect/expect_test.ml index 9ce12a0f5..c5e51765d 100644 --- a/test/expect/expect_test.ml +++ b/test/expect/expect_test.ml @@ -25,7 +25,6 @@ let read_file file = let run_expect_test file ~f = let file_contents = read_file file in let lexbuf = Lexing.from_string file_contents in - Lexing.set_filename lexbuf file; lexbuf.lex_curr_p <- { pos_fname = file; pos_cnum = 0; pos_lnum = 1; pos_bol = 0 }; diff --git a/test/metaquot/test.ml b/test/metaquot/test.ml index 026e8dc2e..d1e4db171 100644 --- a/test/metaquot/test.ml +++ b/test/metaquot/test.ml @@ -532,73 +532,123 @@ let _ = (* mistyped escapes (not producing ASTs at all) *) let _ = [%expr [%e ()]] -[%%expect{| +[%%expect_in 5.2 - {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.expression |}] +[%%expect_in 5.3 + {| +Line _, characters 19-21: +Error: This expression should not be a unit literal, the expected type is + Ppxlib.expression +|}] let _ = [%pat? [%p ()]] -[%%expect{| +[%%expect_in 5.2 - {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.pattern |}] +[%%expect_in 5.3 + {| +Line _, characters 19-21: +Error: This expression should not be a unit literal, the expected type is + Ppxlib.pattern +|}] let _ = [%type: [%t ()]] -[%%expect{| +[%%expect_in 5.2 - {| Line _, characters 20-22: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.core_type |}] +[%%expect_in 5.3 + {| +Line _, characters 20-22: +Error: This expression should not be a unit literal, the expected type is + Ppxlib.core_type +|}] let _ = [%stri [%%i ()]] -[%%expect{| +[%%expect_in 5.2 - {| Line _, characters 20-22: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.structure_item |}] +[%%expect_in 5.3 + {| +Line _, characters 20-22: +Error: This expression should not be a unit literal, the expected type is + Ppxlib.structure_item +|}] let _ = [%sigi: [%%i ()]] -[%%expect{| +[%%expect_in 5.2 - {| Line _, characters 21-23: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.signature_item |}] +[%%expect_in 5.3 + {| +Line _, characters 21-23: +Error: This expression should not be a unit literal, the expected type is + Ppxlib.signature_item +|}] (* mistyped escapes (not producing ASTs at all) with attributes *) let _ = [%expr [%e ()] [@attr]] -[%%expect{| +[%%expect_in 5.2 - {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.expression |}] +[%%expect_in 5.3 + {| +Line _, characters 19-21: +Error: This expression should not be a unit literal, the expected type is + Ppxlib.expression +|}] let _ = [%pat? [%p ()] [@attr]] -[%%expect{| +[%%expect_in 5.2 - {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.pattern |}] +[%%expect_in 5.3 + {| +Line _, characters 19-21: +Error: This expression should not be a unit literal, the expected type is + Ppxlib.pattern +|}] let _ = [%type: [%t ()] [@attr]] -[%%expect{| +[%%expect_in 5.2 - {| Line _, characters 20-22: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.core_type |}] +[%%expect_in 5.3 + {| +Line _, characters 20-22: +Error: This expression should not be a unit literal, the expected type is + Ppxlib.core_type +|}] let _ = [%stri module M = [%m ()] [@attr]] -[%%expect{| +[%%expect_in 5.2 - {| Line _, characters 30-32: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.module_expr |}] +[%%expect_in 5.3 + {| +Line _, characters 30-32: +Error: This expression should not be a unit literal, the expected type is + Ppxlib.module_expr +|}] let _ = [%sigi: module type M = [%m ()] [@attr]] -[%%expect{| +[%%expect_in 5.2 - {| Line _, characters 36-38: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.module_type |}] +[%%expect_in 5.3 + {| +Line _, characters 36-38: +Error: This expression should not be a unit literal, the expected type is + Ppxlib.module_type +|}] diff --git a/test/quoter/test.ml b/test/quoter/test.ml index d028a9c59..88b555333 100644 --- a/test/quoter/test.ml +++ b/test/quoter/test.ml @@ -138,7 +138,7 @@ Pprintast.string_of_expression expr3;; let quoted = let expr = Ast.elist ~loc:Location.none [expr1; expr2; expr3] in Quoter.sanitize quoter expr -[%%expect{| +[%%expect_in 5.2 - {| val quoted : expression = {Ppxlib__.Import.pexp_desc = Ppxlib__.Import.Pexp_let (Ppxlib__.Import.Nonrecursive, @@ -332,6 +332,213 @@ val quoted : expression = ...); pexp_loc = ...; pexp_loc_stack = ...; pexp_attributes = ...} |}] +[%%expect_in 5.3 + {| +val quoted : expression = + {Ppxlib__.Import.pexp_desc = + Ppxlib__.Import.Pexp_let (Ppxlib__.Import.Nonrecursive, + [{Ppxlib__.Import.pvb_pat = + {Ppxlib__.Import.ppat_desc = + Ppxlib__.Import.Ppat_var + {Ppxlib__.Import.txt = "__2"; + loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}}; + ppat_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_ghost = true}; + ppat_loc_stack = []; ppat_attributes = []}; + pvb_expr = + {Ppxlib__.Import.pexp_desc = + Ppxlib__.Import.Pexp_fun (Ppxlib__.Import.Nolabel, None, + {Ppxlib__.Import.ppat_desc = + Ppxlib__.Import.Ppat_construct + ({Ppxlib__.Import.txt = Ppxlib__.Import.Lident "()"; + loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}}, + None); + ppat_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}; + ppat_loc_stack = []; ppat_attributes = []}, + {Ppxlib__.Import.pexp_desc = + Ppxlib__.Import.Pexp_apply + ({Ppxlib__.Import.pexp_desc = + Ppxlib__.Import.Pexp_ident + {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "foo"; + loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}}; + pexp_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}; + pexp_loc_stack = []; pexp_attributes = []}, + [(Ppxlib__.Import.Nolabel, + {Ppxlib__.Import.pexp_desc = + Ppxlib__.Import.Pexp_construct + ({Ppxlib__.Import.txt = Ppxlib__.Import.Lident "()"; + loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}}, + None); + pexp_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}; + pexp_loc_stack = []; pexp_attributes = []})]); + pexp_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}; + pexp_loc_stack = []; pexp_attributes = []}); + pexp_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_ghost = true}; + pexp_loc_stack = []; pexp_attributes = []}; + pvb_attributes = []; + pvb_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_ghost = true}}; + {Ppxlib__.Import.pvb_pat = + {Ppxlib__.Import.ppat_desc = + Ppxlib__.Import.Ppat_var + {Ppxlib__.Import.txt = "__1"; + loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}}; + ppat_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_ghost = true}; + ppat_loc_stack = []; ppat_attributes = []}; + pvb_expr = + {Ppxlib__.Import.pexp_desc = + Ppxlib__.Import.Pexp_ident + {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "bar"; + loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}}; + pexp_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_ghost = true}; + pexp_loc_stack = []; pexp_attributes = []}; + pvb_attributes = []; + pvb_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_ghost = true}}; + {Ppxlib__.Import.pvb_pat = + {Ppxlib__.Import.ppat_desc = + Ppxlib__.Import.Ppat_var + {Ppxlib__.Import.txt = "__0"; + loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = 0; pos_cnum = -1}; + loc_ghost = true}}; + ppat_loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_end = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; + pos_cnum = -1}; + loc_ghost = true}; + ppat_loc_stack = []; ppat_attributes = []}; + pvb_expr = + {Ppxlib__.Import.pexp_desc = + Ppxlib__.Import.Pexp_ident + {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "foo"; + loc = + {Ppxlib__.Import.loc_start = + {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; + pos_bol = ...; pos_cnum = ...}; + loc_end = ...; loc_ghost = ...}}; + pexp_loc = ...; pexp_loc_stack = ...; pexp_attributes = ...}; + pvb_attributes = ...; pvb_loc = ...}; + ...], + ...); + pexp_loc = ...; pexp_loc_stack = ...; pexp_attributes = ...} +|}] Pprintast.string_of_expression quoted;; [%%expect{| From 5444b6e7e91b351bbcf1c0850656ff1817bd060a Mon Sep 17 00:00:00 2001 From: Nathan Rebours Date: Wed, 20 Nov 2024 10:59:06 +0100 Subject: [PATCH 5/7] Add support for single version [%%expect_in] Signed-off-by: Nathan Rebours --- test/expect/expect_lexer.mli | 1 + test/expect/expect_lexer.mll | 27 ++++++++++++++++++++++++--- test/expect/expect_test.ml | 2 ++ 3 files changed, 27 insertions(+), 3 deletions(-) diff --git a/test/expect/expect_lexer.mli b/test/expect/expect_lexer.mli index 3c5b2373a..389c42efb 100644 --- a/test/expect/expect_lexer.mli +++ b/test/expect/expect_lexer.mli @@ -1,6 +1,7 @@ type version = int * int type version_range = + | Only of version | Up_to of version | From of version | Between of version * version diff --git a/test/expect/expect_lexer.mll b/test/expect/expect_lexer.mll index 44881e8cf..36f43fc8e 100644 --- a/test/expect/expect_lexer.mll +++ b/test/expect/expect_lexer.mll @@ -4,9 +4,10 @@ open StdLabels type version = int * int type version_range = - | Up_to of version - | From of version - | Between of version * version + | Only of version (* ex: [%%expect_in 5.3 *) + | Up_to of version (* ex: [%%expect_in 5.3 - *) + | From of version (* ex: [%%expect_in 5.3 + *) + | Between of version * version (* ex: [%%expect_in 5.0 >> 5.3 *) type versioned_expect = version_range * string @@ -33,6 +34,14 @@ rule code txt start = parse Lexing.new_line lexbuf; (start, s, []) :: expectation txt lexbuf } + | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) " {|\n" { + let s = extract_chunk txt start lexbuf in + Lexing.new_line lexbuf; + let version = make_version major minor in + let range = Only version in + let cstart = lexbuf.lex_curr_p in + versioned_expectation_content txt (start, s) [] (range, cstart) lexbuf + } | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) " + {|\n" { let s = extract_chunk txt start lexbuf in Lexing.new_line lexbuf; @@ -92,6 +101,18 @@ and expectation txt = parse (* Parses the content of a [%%expect_in .. {| ... |}] block along with following blocks in the same group *) and versioned_expectation_content txt code_chunk vexpects curr = parse + | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) " {|\n" { + let range, start = curr in + let s = extract_chunk txt start lexbuf in + Lexing.new_line lexbuf; + Lexing.new_line lexbuf; + let block = range, s in + let version = make_version major minor in + let next_range = Only version in + let cstart = lexbuf.lex_curr_p in + versioned_expectation_content txt code_chunk + (block::vexpects) (next_range, cstart) lexbuf + } | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) " + {|\n" { let range, start = curr in let s = extract_chunk txt start lexbuf in diff --git a/test/expect/expect_test.ml b/test/expect/expect_test.ml index c5e51765d..3d2ad925f 100644 --- a/test/expect/expect_test.ml +++ b/test/expect/expect_test.ml @@ -8,6 +8,7 @@ let compiler_version = let include_compiler_version range = let cmajor, cminor = compiler_version in match (range : Expect_lexer.version_range) with + | Only (major, minor) -> cmajor = major && cminor = minor | From (major, minor) -> cmajor > major || (cmajor = major && cminor >= minor) | Up_to (major, minor) -> cmajor < major || (cmajor = major && cminor <= minor) | Between ((min_major, min_minor), (max_major, max_minor)) -> @@ -92,6 +93,7 @@ let pp_version ppf (major, minor) = Format.fprintf ppf "%d.%d" major minor let pp_range ppf range = match (range : Expect_lexer.version_range) with + | Only v -> pp_version ppf v | From v -> Format.fprintf ppf "%a +" pp_version v | Up_to v -> Format.fprintf ppf "%a -" pp_version v | Between (v1, v2) -> From fb3c5bf9aaf46457e90cc021381b467d9e91d82a Mon Sep 17 00:00:00 2001 From: Nathan Rebours Date: Wed, 20 Nov 2024 15:50:08 +0100 Subject: [PATCH 6/7] Add [%%ignore] to expect_test runner and fix quoter tests Signed-off-by: Nathan Rebours --- test/expect/expect_lexer.mli | 17 +- test/expect/expect_lexer.mll | 102 ++++--- test/expect/expect_test.ml | 19 +- test/quoter/test.ml | 508 +---------------------------------- 4 files changed, 96 insertions(+), 550 deletions(-) diff --git a/test/expect/expect_lexer.mli b/test/expect/expect_lexer.mli index 389c42efb..26591d348 100644 --- a/test/expect/expect_lexer.mli +++ b/test/expect/expect_lexer.mli @@ -6,9 +6,16 @@ type version_range = | From of version | Between of version * version -type versioned_expect = version_range * string +(*[[%%ignore]], [[%%expect{|...|}] or [%%expect_in 5.3 {|...|}]*) +type expect_block = + | Ignore + | Regular + | Versioned of (version_range * string) list -val split_file : - file_contents:string -> - Lexing.lexbuf -> - (Lexing.position * string * versioned_expect list) list +type chunk = { + phrases : string; + phrases_start : Lexing.position; + expect : expect_block; +} + +val split_file : file_contents:string -> Lexing.lexbuf -> chunk list diff --git a/test/expect/expect_lexer.mll b/test/expect/expect_lexer.mll index 36f43fc8e..0c9389d1f 100644 --- a/test/expect/expect_lexer.mll +++ b/test/expect/expect_lexer.mll @@ -9,17 +9,27 @@ type version_range = | From of version (* ex: [%%expect_in 5.3 + *) | Between of version * version (* ex: [%%expect_in 5.0 >> 5.3 *) -type versioned_expect = version_range * string +(*[%%ignore], [%%expect] or [%%expect_in]*) +type expect_block = + | Ignore + | Regular + | Versioned of (version_range * string) list + +type chunk = + { phrases : string + ; phrases_start : Lexing.position + ; expect : expect_block + } let make_version major minor = let major = int_of_string major in let minor = int_of_string minor in (major, minor) -let extract_chunk txt start lexbuf = +let extract_string all_file start lexbuf = let pos = start.Lexing.pos_cnum in let len = Lexing.lexeme_start lexbuf - pos in - String.sub txt ~pos ~len + String.sub all_file ~pos ~len } let digit = ['0'-'9'] @@ -28,113 +38,124 @@ let digit = ['0'-'9'] Parses blocks of code to execute seperated by [%%expect{|...|}] statement. Code blocks can be separated by a single [%%expect{|...|}] statement or by a series of [%%expect_in {|...|}]. *) -rule code txt start = parse +rule code all_file phrases_start = parse | "[%%expect{|\n" { - let s = extract_chunk txt start lexbuf in + let phrases = extract_string all_file phrases_start lexbuf in Lexing.new_line lexbuf; - (start, s, []) :: expectation txt lexbuf + let chunk = {phrases; phrases_start; expect = Regular} in + chunk :: expectation all_file lexbuf + } + | "[%%ignore]\n" { + let phrases = extract_string all_file phrases_start lexbuf in + Lexing.new_line lexbuf; + let chunk = {phrases; phrases_start; expect = Ignore} in + chunk :: code all_file lexbuf.lex_curr_p lexbuf } | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) " {|\n" { - let s = extract_chunk txt start lexbuf in + let phrases = extract_string all_file phrases_start lexbuf in Lexing.new_line lexbuf; let version = make_version major minor in let range = Only version in - let cstart = lexbuf.lex_curr_p in - versioned_expectation_content txt (start, s) [] (range, cstart) lexbuf + let start = lexbuf.lex_curr_p in + versioned_expectation_content all_file + (phrases_start, phrases) [] (range, start) lexbuf } | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) " + {|\n" { - let s = extract_chunk txt start lexbuf in + let phrases = extract_string all_file phrases_start lexbuf in Lexing.new_line lexbuf; let version = make_version major minor in let range = From version in - let cstart = lexbuf.lex_curr_p in - versioned_expectation_content txt (start, s) [] (range, cstart) lexbuf + let start = lexbuf.lex_curr_p in + versioned_expectation_content all_file + (phrases_start, phrases) [] (range, start) lexbuf } | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) " - {|\n" { - let s = extract_chunk txt start lexbuf in + let phrases = extract_string all_file phrases_start lexbuf in Lexing.new_line lexbuf; let version = make_version major minor in let range = Up_to version in - let cstart = lexbuf.lex_curr_p in - versioned_expectation_content txt (start, s) [] (range, cstart) lexbuf + let start = lexbuf.lex_curr_p in + versioned_expectation_content all_file + (phrases_start, phrases) [] (range, start) lexbuf } | "[%%expect_in " (digit+ as major1) '.' (digit+ as minor1) " >> " (digit+ as major2) '.' (digit+ as minor2) " {|\n" { - let s = extract_chunk txt start lexbuf in + let phrases = extract_string all_file phrases_start lexbuf in Lexing.new_line lexbuf; let v1 = make_version major1 minor1 in let v2 = make_version major2 minor2 in let range = Between (v1, v2) in - let cstart = lexbuf.lex_curr_p in - versioned_expectation_content txt (start, s) [] (range, cstart) lexbuf + let start = lexbuf.lex_curr_p in + versioned_expectation_content all_file + (phrases_start, phrases) [] (range, start) lexbuf } | [^'\n']*'\n' { Lexing.new_line lexbuf; - code txt start lexbuf + code all_file phrases_start lexbuf } | eof { - let pos = start.Lexing.pos_cnum in - let len = String.length txt - pos in + let pos = phrases_start.Lexing.pos_cnum in + let len = String.length all_file - pos in if pos > 0 then begin - let s = String.sub txt ~pos ~len in - if String.trim s = "" then + let phrases = String.sub all_file ~pos ~len in + if String.trim phrases = "" then [] else - [(start, s, [])] + [{phrases_start; phrases; expect = Regular}] end else [] } -and expectation txt = parse +and expectation all_file = parse | "|}]\n" { Lexing.new_line lexbuf; - code txt lexbuf.lex_curr_p lexbuf + code all_file lexbuf.lex_curr_p lexbuf } | [^'\n']*'\n' { Lexing.new_line lexbuf; - expectation txt lexbuf + expectation all_file lexbuf } (* Parses the content of a [%%expect_in .. {| ... |}] block along with following blocks in the same group *) -and versioned_expectation_content txt code_chunk vexpects curr = parse +and versioned_expectation_content all_file code_chunk vexpects curr = parse | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) " {|\n" { let range, start = curr in - let s = extract_chunk txt start lexbuf in + let s = extract_string all_file start lexbuf in Lexing.new_line lexbuf; Lexing.new_line lexbuf; let block = range, s in let version = make_version major minor in let next_range = Only version in let cstart = lexbuf.lex_curr_p in - versioned_expectation_content txt code_chunk + versioned_expectation_content all_file code_chunk (block::vexpects) (next_range, cstart) lexbuf } | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) " + {|\n" { let range, start = curr in - let s = extract_chunk txt start lexbuf in + let s = extract_string all_file start lexbuf in Lexing.new_line lexbuf; Lexing.new_line lexbuf; let block = range, s in let version = make_version major minor in let next_range = From version in let cstart = lexbuf.lex_curr_p in - versioned_expectation_content txt code_chunk + versioned_expectation_content all_file code_chunk (block::vexpects) (next_range, cstart) lexbuf } | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) " - {|\n" { let range, start = curr in - let s = extract_chunk txt start lexbuf in + let s = extract_string all_file start lexbuf in Lexing.new_line lexbuf; Lexing.new_line lexbuf; let block = range, s in let version = make_version major minor in let next_range = Up_to version in let cstart = lexbuf.lex_curr_p in - versioned_expectation_content txt code_chunk + versioned_expectation_content all_file code_chunk (block::vexpects) (next_range, cstart) lexbuf } | "|}]\n[%%expect_in " @@ -143,7 +164,7 @@ and versioned_expectation_content txt code_chunk vexpects curr = parse (digit+ as major2) '.' (digit+ as minor2) " {|\n" { let range, start = curr in - let s = extract_chunk txt start lexbuf in + let s = extract_string all_file start lexbuf in Lexing.new_line lexbuf; Lexing.new_line lexbuf; let block = range, s in @@ -151,22 +172,23 @@ and versioned_expectation_content txt code_chunk vexpects curr = parse let v2 = make_version major2 minor2 in let next_range = Between (v1, v2) in let cstart = lexbuf.lex_curr_p in - versioned_expectation_content txt code_chunk + versioned_expectation_content all_file code_chunk (block::vexpects) (next_range, cstart) lexbuf } | "|}]\n" { let range, start = curr in let pos = start.Lexing.pos_cnum in let len = Lexing.lexeme_start lexbuf - pos in - let s = String.sub txt ~pos ~len in + let s = String.sub all_file ~pos ~len in Lexing.new_line lexbuf; let vexpects = List.rev ((range, s)::vexpects) in - let start, s = code_chunk in - (start, s, vexpects) :: code txt lexbuf.lex_curr_p lexbuf + let phrases_start, phrases = code_chunk in + let chunk = {phrases; phrases_start; expect = Versioned vexpects} in + chunk :: code all_file lexbuf.lex_curr_p lexbuf } | [^'\n']*'\n' { Lexing.new_line lexbuf; - versioned_expectation_content txt code_chunk vexpects curr lexbuf + versioned_expectation_content all_file code_chunk vexpects curr lexbuf } { diff --git a/test/expect/expect_test.ml b/test/expect/expect_test.ml index 3d2ad925f..5944023f8 100644 --- a/test/expect/expect_test.ml +++ b/test/expect/expect_test.ml @@ -114,6 +114,14 @@ let run_code ppf starting_pos code = execute_phrase ppf phr with exn -> Location.report_exception ppf exn)) +let trash_buffer = Buffer.create 1024 +let trash_ppf = Format.formatter_of_buffer trash_buffer + +let handle_ignore_block ppf starting_pos code = + Format.fprintf ppf "%s[%%%%ignore]@." code; + run_code trash_ppf starting_pos code; + Buffer.clear trash_buffer + let handle_regular_expect_block ppf starting_pos code = Format.fprintf ppf "%s[%%%%expect{|@." code; run_code ppf starting_pos code; @@ -192,10 +200,13 @@ let main () = is statically linked in *) Topfind.load_deeply [ "ppxlib" ]; - List.iter chunks ~f:(fun (pos, s, vexpects) -> - match vexpects with - | [] -> handle_regular_expect_block ppf pos s - | _ -> handle_versioned_expect_blocks ppf pos s vexpects); + List.iter chunks + ~f:(fun { Expect_lexer.phrases; phrases_start; expect } -> + match expect with + | Ignore -> handle_ignore_block ppf phrases_start phrases + | Regular -> handle_regular_expect_block ppf phrases_start phrases + | Versioned vexpects -> + handle_versioned_expect_blocks ppf phrases_start phrases vexpects); Buffer.contents buf) let () = diff --git a/test/quoter/test.ml b/test/quoter/test.ml index 88b555333..6647b53de 100644 --- a/test/quoter/test.ml +++ b/test/quoter/test.ml @@ -14,29 +14,7 @@ val quoter : Quoter.t = let expr1 = Ast.evar "foo" ~loc:Location.none |> Quoter.quote quoter -[%%expect{| -val expr1 : expression = - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_ident - {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "__0"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}}; - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []} -|}] +[%%ignore] Pprintast.string_of_expression expr1;; [%%expect{| @@ -46,89 +24,17 @@ Pprintast.string_of_expression expr1;; let expr2 = Ast_builder.Default.evar ~loc:Location.none "bar" |> Quoter.quote quoter +[%%ignore] + +Pprintast.string_of_expression expr2;; [%%expect{| -val expr2 : expression = - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_ident - {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "__1"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}}; - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []} +- : string = "__1" |}] let expr3 = Ast.eapply ~loc:Location.none (Ast.evar "foo" ~loc:Location.none) [Ast.eunit ~loc:Location.none] |> Quoter.quote quoter -[%%expect{| -val expr3 : expression = - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_apply - ({Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_ident - {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "__2"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []}, - [(Ppxlib__.Import.Nolabel, - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_construct - ({Ppxlib__.Import.txt = Ppxlib__.Import.Lident "()"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}, - None); - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []})]); - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []} -|}] +[%%ignore] Pprintast.string_of_expression expr3;; [%%expect{| @@ -138,407 +44,7 @@ Pprintast.string_of_expression expr3;; let quoted = let expr = Ast.elist ~loc:Location.none [expr1; expr2; expr3] in Quoter.sanitize quoter expr -[%%expect_in 5.2 - {| -val quoted : expression = - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_let (Ppxlib__.Import.Nonrecursive, - [{Ppxlib__.Import.pvb_pat = - {Ppxlib__.Import.ppat_desc = - Ppxlib__.Import.Ppat_var - {Ppxlib__.Import.txt = "__2"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - ppat_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - ppat_loc_stack = []; ppat_attributes = []}; - pvb_expr = - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_fun (Ppxlib__.Import.Nolabel, None, - {Ppxlib__.Import.ppat_desc = - Ppxlib__.Import.Ppat_construct - ({Ppxlib__.Import.txt = Ppxlib__.Import.Lident "()"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}, - None); - ppat_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}; - ppat_loc_stack = []; ppat_attributes = []}, - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_apply - ({Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_ident - {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "foo"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []}, - [(Ppxlib__.Import.Nolabel, - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_construct - ({Ppxlib__.Import.txt = Ppxlib__.Import.Lident "()"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}, - None); - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []})]); - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []}); - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []}; - pvb_attributes = []; - pvb_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}}; - {Ppxlib__.Import.pvb_pat = - {Ppxlib__.Import.ppat_desc = - Ppxlib__.Import.Ppat_var - {Ppxlib__.Import.txt = "__1"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - ppat_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - ppat_loc_stack = []; ppat_attributes = []}; - pvb_expr = - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_ident - {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "bar"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []}; - pvb_attributes = []; - pvb_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}}; - {Ppxlib__.Import.pvb_pat = - {Ppxlib__.Import.ppat_desc = - Ppxlib__.Import.Ppat_var - {Ppxlib__.Import.txt = "__0"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - ppat_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = ...; loc_ghost = ...}; - ppat_loc_stack = ...; ppat_attributes = ...}; - pvb_expr = ...; pvb_attributes = ...; pvb_loc = ...}; - ...], - ...); - pexp_loc = ...; pexp_loc_stack = ...; pexp_attributes = ...} -|}] -[%%expect_in 5.3 + {| -val quoted : expression = - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_let (Ppxlib__.Import.Nonrecursive, - [{Ppxlib__.Import.pvb_pat = - {Ppxlib__.Import.ppat_desc = - Ppxlib__.Import.Ppat_var - {Ppxlib__.Import.txt = "__2"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - ppat_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - ppat_loc_stack = []; ppat_attributes = []}; - pvb_expr = - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_fun (Ppxlib__.Import.Nolabel, None, - {Ppxlib__.Import.ppat_desc = - Ppxlib__.Import.Ppat_construct - ({Ppxlib__.Import.txt = Ppxlib__.Import.Lident "()"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}, - None); - ppat_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}; - ppat_loc_stack = []; ppat_attributes = []}, - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_apply - ({Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_ident - {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "foo"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []}, - [(Ppxlib__.Import.Nolabel, - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_construct - ({Ppxlib__.Import.txt = Ppxlib__.Import.Lident "()"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}, - None); - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []})]); - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []}); - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []}; - pvb_attributes = []; - pvb_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}}; - {Ppxlib__.Import.pvb_pat = - {Ppxlib__.Import.ppat_desc = - Ppxlib__.Import.Ppat_var - {Ppxlib__.Import.txt = "__1"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - ppat_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - ppat_loc_stack = []; ppat_attributes = []}; - pvb_expr = - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_ident - {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "bar"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - pexp_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - pexp_loc_stack = []; pexp_attributes = []}; - pvb_attributes = []; - pvb_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}}; - {Ppxlib__.Import.pvb_pat = - {Ppxlib__.Import.ppat_desc = - Ppxlib__.Import.Ppat_var - {Ppxlib__.Import.txt = "__0"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = 0; pos_cnum = -1}; - loc_ghost = true}}; - ppat_loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_end = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; pos_bol = 0; - pos_cnum = -1}; - loc_ghost = true}; - ppat_loc_stack = []; ppat_attributes = []}; - pvb_expr = - {Ppxlib__.Import.pexp_desc = - Ppxlib__.Import.Pexp_ident - {Ppxlib__.Import.txt = Ppxlib__.Import.Lident "foo"; - loc = - {Ppxlib__.Import.loc_start = - {Ppxlib__.Import.pos_fname = "_none_"; pos_lnum = 1; - pos_bol = ...; pos_cnum = ...}; - loc_end = ...; loc_ghost = ...}}; - pexp_loc = ...; pexp_loc_stack = ...; pexp_attributes = ...}; - pvb_attributes = ...; pvb_loc = ...}; - ...], - ...); - pexp_loc = ...; pexp_loc_stack = ...; pexp_attributes = ...} -|}] +[%%ignore] Pprintast.string_of_expression quoted;; [%%expect{| From cbfb6f39d2b5527e587dec7d06bde8a6608632b5 Mon Sep 17 00:00:00 2001 From: Nathan Rebours Date: Mon, 25 Nov 2024 10:35:59 +0100 Subject: [PATCH 7/7] Bring expect_in version ranges in line with opam notations Signed-off-by: Nathan Rebours --- test/code_path/test.ml | 4 ++-- test/expect/expect_lexer.mll | 18 ++++++++-------- test/expect/expect_test.ml | 6 +++--- test/metaquot/test.ml | 40 ++++++++++++++++++------------------ 4 files changed, 34 insertions(+), 34 deletions(-) diff --git a/test/code_path/test.ml b/test/code_path/test.ml index 688e3ba07..7b3dc73dd 100644 --- a/test/code_path/test.ml +++ b/test/code_path/test.ml @@ -89,12 +89,12 @@ module Functor() = struct end end let _ = let module M = Functor() in !M.code_path -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| module Functor : functor () -> sig val code_path : string ref end - : string = "(code_path(main_module_name Test)(submodule_path(Functor _))(enclosing_module First_class)(enclosing_value(x))(value(x))(fully_qualified_path Test.Functor._.x))" |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| module Functor : () -> sig val code_path : string ref end - : string = "(code_path(main_module_name Test)(submodule_path(Functor _))(enclosing_module First_class)(enclosing_value(x))(value(x))(fully_qualified_path Test.Functor._.x))" diff --git a/test/expect/expect_lexer.mll b/test/expect/expect_lexer.mll index 0c9389d1f..c40aad7a3 100644 --- a/test/expect/expect_lexer.mll +++ b/test/expect/expect_lexer.mll @@ -5,9 +5,9 @@ type version = int * int type version_range = | Only of version (* ex: [%%expect_in 5.3 *) - | Up_to of version (* ex: [%%expect_in 5.3 - *) - | From of version (* ex: [%%expect_in 5.3 + *) - | Between of version * version (* ex: [%%expect_in 5.0 >> 5.3 *) + | Up_to of version (* ex: [%%expect_in <= 5.3 *) + | From of version (* ex: [%%expect_in >= 5.3 *) + | Between of version * version (* ex: [%%expect_in 5.0 <=> 5.3 *) (*[%%ignore], [%%expect] or [%%expect_in]*) type expect_block = @@ -60,7 +60,7 @@ rule code all_file phrases_start = parse versioned_expectation_content all_file (phrases_start, phrases) [] (range, start) lexbuf } - | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) " + {|\n" { + | "[%%expect_in >= " (digit+ as major) '.' (digit+ as minor) " {|\n" { let phrases = extract_string all_file phrases_start lexbuf in Lexing.new_line lexbuf; let version = make_version major minor in @@ -69,7 +69,7 @@ rule code all_file phrases_start = parse versioned_expectation_content all_file (phrases_start, phrases) [] (range, start) lexbuf } - | "[%%expect_in " (digit+ as major) '.' (digit+ as minor) " - {|\n" { + | "[%%expect_in <= " (digit+ as major) '.' (digit+ as minor) " {|\n" { let phrases = extract_string all_file phrases_start lexbuf in Lexing.new_line lexbuf; let version = make_version major minor in @@ -80,7 +80,7 @@ rule code all_file phrases_start = parse } | "[%%expect_in " (digit+ as major1) '.' (digit+ as minor1) - " >> " + " <=> " (digit+ as major2) '.' (digit+ as minor2) " {|\n" { let phrases = extract_string all_file phrases_start lexbuf in @@ -134,7 +134,7 @@ and versioned_expectation_content all_file code_chunk vexpects curr = parse versioned_expectation_content all_file code_chunk (block::vexpects) (next_range, cstart) lexbuf } - | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) " + {|\n" { + | "|}]\n[%%expect_in >= " (digit+ as major) '.' (digit+ as minor) " {|\n" { let range, start = curr in let s = extract_string all_file start lexbuf in Lexing.new_line lexbuf; @@ -146,7 +146,7 @@ and versioned_expectation_content all_file code_chunk vexpects curr = parse versioned_expectation_content all_file code_chunk (block::vexpects) (next_range, cstart) lexbuf } - | "|}]\n[%%expect_in " (digit+ as major) '.' (digit+ as minor) " - {|\n" { + | "|}]\n[%%expect_in <= " (digit+ as major) '.' (digit+ as minor) " {|\n" { let range, start = curr in let s = extract_string all_file start lexbuf in Lexing.new_line lexbuf; @@ -160,7 +160,7 @@ and versioned_expectation_content all_file code_chunk vexpects curr = parse } | "|}]\n[%%expect_in " (digit+ as major1) '.' (digit+ as minor1) - " >> " + " <=> " (digit+ as major2) '.' (digit+ as minor2) " {|\n" { let range, start = curr in diff --git a/test/expect/expect_test.ml b/test/expect/expect_test.ml index 5944023f8..248f956d5 100644 --- a/test/expect/expect_test.ml +++ b/test/expect/expect_test.ml @@ -94,10 +94,10 @@ let pp_version ppf (major, minor) = Format.fprintf ppf "%d.%d" major minor let pp_range ppf range = match (range : Expect_lexer.version_range) with | Only v -> pp_version ppf v - | From v -> Format.fprintf ppf "%a +" pp_version v - | Up_to v -> Format.fprintf ppf "%a -" pp_version v + | From v -> Format.fprintf ppf ">= %a" pp_version v + | Up_to v -> Format.fprintf ppf "<= %a" pp_version v | Between (v1, v2) -> - Format.fprintf ppf "%a >> %a" pp_version v1 pp_version v2 + Format.fprintf ppf "%a <=> %a" pp_version v1 pp_version v2 let run_code ppf starting_pos code = let lexbuf = Lexing.from_string code in diff --git a/test/metaquot/test.ml b/test/metaquot/test.ml index d1e4db171..52a2b2666 100644 --- a/test/metaquot/test.ml +++ b/test/metaquot/test.ml @@ -532,60 +532,60 @@ let _ = (* mistyped escapes (not producing ASTs at all) *) let _ = [%expr [%e ()]] -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.expression |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib.expression |}] let _ = [%pat? [%p ()]] -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.pattern |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib.pattern |}] let _ = [%type: [%t ()]] -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| Line _, characters 20-22: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.core_type |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| Line _, characters 20-22: Error: This expression should not be a unit literal, the expected type is Ppxlib.core_type |}] let _ = [%stri [%%i ()]] -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| Line _, characters 20-22: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.structure_item |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| Line _, characters 20-22: Error: This expression should not be a unit literal, the expected type is Ppxlib.structure_item |}] let _ = [%sigi: [%%i ()]] -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| Line _, characters 21-23: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.signature_item |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| Line _, characters 21-23: Error: This expression should not be a unit literal, the expected type is Ppxlib.signature_item @@ -594,60 +594,60 @@ Error: This expression should not be a unit literal, the expected type is (* mistyped escapes (not producing ASTs at all) with attributes *) let _ = [%expr [%e ()] [@attr]] -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.expression |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib.expression |}] let _ = [%pat? [%p ()] [@attr]] -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.pattern |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| Line _, characters 19-21: Error: This expression should not be a unit literal, the expected type is Ppxlib.pattern |}] let _ = [%type: [%t ()] [@attr]] -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| Line _, characters 20-22: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.core_type |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| Line _, characters 20-22: Error: This expression should not be a unit literal, the expected type is Ppxlib.core_type |}] let _ = [%stri module M = [%m ()] [@attr]] -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| Line _, characters 30-32: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.module_expr |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| Line _, characters 30-32: Error: This expression should not be a unit literal, the expected type is Ppxlib.module_expr |}] let _ = [%sigi: module type M = [%m ()] [@attr]] -[%%expect_in 5.2 - {| +[%%expect_in <= 5.2 {| Line _, characters 36-38: Error: This expression should not be a unit literal, the expected type is Ppxlib_ast.Ast.module_type |}] -[%%expect_in 5.3 + {| +[%%expect_in >= 5.3 {| Line _, characters 36-38: Error: This expression should not be a unit literal, the expected type is Ppxlib.module_type