mirror of
https://github.com/c-cube/ocaml-containers.git
synced 2025-12-06 11:15:31 -05:00
CCSexp: Escape empty atoms
Otherwise (`List [ `Atom "" ]) would be formatted as "()", which is (`List []).
This commit is contained in:
parent
a5b8a0aa18
commit
203723d350
1 changed files with 12 additions and 6 deletions
|
|
@ -61,6 +61,9 @@ module Make(Sexp : SEXP) = struct
|
||||||
false
|
false
|
||||||
with Exit -> true
|
with Exit -> true
|
||||||
|
|
||||||
|
(* empty atoms must be escaped *)
|
||||||
|
let _must_escape s = String.length s = 0 || _must_escape s
|
||||||
|
|
||||||
let rec to_buf b t =
|
let rec to_buf b t =
|
||||||
Sexp.match_ t
|
Sexp.match_ t
|
||||||
~atom:(fun s ->
|
~atom:(fun s ->
|
||||||
|
|
@ -358,6 +361,14 @@ include (Make(struct
|
||||||
*)
|
*)
|
||||||
|
|
||||||
|
|
||||||
|
(*$inject
|
||||||
|
let sexp_bijective s = to_string s |> parse_string = Ok s
|
||||||
|
*)
|
||||||
|
|
||||||
|
(*$T
|
||||||
|
sexp_bijective (`List [`Atom ""])
|
||||||
|
*)
|
||||||
|
|
||||||
(*$inject
|
(*$inject
|
||||||
let sexp_gen =
|
let sexp_gen =
|
||||||
let mkatom a = `Atom a and mklist l = `List l in
|
let mkatom a = `Atom a and mklist l = `List l in
|
||||||
|
|
@ -384,15 +395,10 @@ include (Make(struct
|
||||||
| `List l -> Q.Iter.map mklist (Q.Shrink.list ~shrink l)
|
| `List l -> Q.Iter.map mklist (Q.Shrink.list ~shrink l)
|
||||||
in
|
in
|
||||||
Q.make ~print ~small ~shrink gen
|
Q.make ~print ~small ~shrink gen
|
||||||
|
|
||||||
let rec sexp_valid = function
|
|
||||||
| `Atom "" -> false
|
|
||||||
| `Atom _ -> true
|
|
||||||
| `List l -> List.for_all sexp_valid l
|
|
||||||
*)
|
*)
|
||||||
|
|
||||||
(*$Q & ~count:100
|
(*$Q & ~count:100
|
||||||
sexp_gen (fun s -> sexp_valid s ==> (to_string s |> parse_string = Ok s))
|
sexp_gen sexp_bijective
|
||||||
*)
|
*)
|
||||||
|
|
||||||
let atom s : t = `Atom s
|
let atom s : t = `Atom s
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue