mte/unikernel/duniverse/ppx_sexp_conv/test/examples.mlt
2025-11-11 02:07:51 +01:00

67 lines
1.2 KiB
Text

module Position_for_polymorphic_variant_errors = struct
type t1 = [ `A ] [@@deriving of_sexp]
type t2 = [ `B ] [@@deriving of_sexp]
type t3 = A of [ t1 | t2 ] [@@deriving of_sexp]
let (_ : t3) = t3_of_sexp (List [ Atom "A"; Atom "C" ])
end
[%%expect
{|
Exception:
(Of_sexp_error
"examples.mlt.Position_for_polymorphic_variant_errors.t3_of_sexp: no matching variant found"
(invalid_sexp C))
|}]
let _ = [%sexp_of: 'a]
[%%expect
{|
Line _, characters _-_:
Error: ppx_sexp_conv: unbound type variable 'a
|}]
let _ = [%of_sexp: 'a]
[%%expect
{|
Line _, characters _-_:
Error: ppx_sexp_conv: unbound type variable 'a
|}]
let _ = [%sexp (() : 'a)]
[%%expect
{|
Line _, characters _-_:
Error: ppx_sexp_conv: unbound type variable 'a
|}]
type 'a t =
| None
| Something_else of { value : 'a }
[@@deriving sexp]
[%%expect {| |}]
module Record_with_defaults = struct
open Sexplib0.Sexp_conv
let a_field = "a_field"
let b_field = "b_field"
type record_with_defaults =
{ a : string [@default a_field]
; b : string [@default b_field]
}
[@@deriving of_sexp]
end
[%%expect {| |}]
module Polymorphic_recursion = struct
type 'a t = T of 'a t t [@@deriving sexp_grammar]
end
[%%expect {| |}]