File: test.ml

package info (click to toggle)
ppxlib 0.37.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 4,804 kB
  • sloc: ml: 66,587; sh: 103; makefile: 40; python: 36
file content (84 lines) | stat: -rw-r--r-- 2,294 bytes parent folder | download
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
open Ppxlib

let test_is_recursive stri =
  match stri.pstr_desc with
  | Pstr_type (rf, tds) -> really_recursive rf tds
  | _ -> assert false

[%%expect{|
val test_is_recursive : structure_item -> rec_flag = <fun>
|}]

let loc = Location.none

[%%expect_in <= 5.3 {|
val loc : location =
  {Ppxlib.Location.loc_start =
    {Lexing.pos_fname = "_none_"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1};
   loc_end =
    {Lexing.pos_fname = "_none_"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1};
   loc_ghost = true}
|}]
[%%expect_in >= 5.4 {|
val loc : location =
  {Location.loc_start =
    {Lexing.pos_fname = "_none_"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1};
   loc_end =
    {Lexing.pos_fname = "_none_"; pos_lnum = 0; pos_bol = 0; pos_cnum = -1};
   loc_ghost = true}
|}]

(* Should be Nonrecursive *)
let base_type = test_is_recursive [%stri type t = int]

[%%expect{|
val base_type : rec_flag = Ppxlib__.Import.Nonrecursive
|}]

(* Should be Nonrecursive *)
let looks_recursive_but_is_not = test_is_recursive [%stri type nonrec t = t]

[%%expect{|
val looks_recursive_but_is_not : rec_flag = Ppxlib__.Import.Nonrecursive
|}]

(* Should be Nonrecursive *)
let variant_non_rec = test_is_recursive [%stri type t = A of int | B of string]

[%%expect{|
val variant_non_rec : rec_flag = Ppxlib__.Import.Nonrecursive
|}]

(* Should be Nonrecursive *)
let record_non_rec = test_is_recursive [%stri type t = {a: int; b: string}]

[%%expect{|
val record_non_rec : rec_flag = Ppxlib__.Import.Nonrecursive
|}]

(* Should be Recursive *)
let actually_recursive = test_is_recursive [%stri type t = A of int | T of t]

[%%expect{|
val actually_recursive : rec_flag = Ppxlib__.Import.Recursive
|}]

(* Should be Nonrecursive *)
let ignore_attributes = test_is_recursive [%stri type t = int [@attr: t]]

[%%expect{|
val ignore_attributes : rec_flag = Ppxlib__.Import.Nonrecursive
|}]

(* Should be Recursive
   
   This is subject to debate. @ceastlund's intuition is that we should
   traverse extensions so we'll stick to this for now.

   It's less of a problem as it is likely that when [really_recursive] is called
   those will have been expanded anyway. *)
let extension_points = test_is_recursive [%stri type t = [%ext: t]]

[%%expect{|
val extension_points : rec_flag = Ppxlib__.Import.Recursive
|}]