~ubuntu-branches/ubuntu/trusty/sexplib310/trusty

« back to all changes in this revision

Viewing changes to lib_test_ounit/test_sexp_with_layout.ml

  • Committer: Package Import Robot
  • Author(s): Stéphane Glondu
  • Date: 2013-12-03 21:36:45 UTC
  • mfrom: (11.1.1 experimental)
  • Revision ID: package-import@ubuntu.com-20131203213645-h1if1c6hxual8p11
Tags: 109.20.00-2
* Team upload
* Upload to unstable

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
(* packaging of annotated sexp functions *)
 
2
 
 
3
open Sexplib
 
4
 
 
5
module M = Sexp.With_layout
 
6
 
 
7
TEST_MODULE "forget" = struct
 
8
 
 
9
  (* dummies *)
 
10
  let dumb_pos = {M.row = 0; col = 0}
 
11
  let dumb_comment = M.Plain_comment (dumb_pos, "comment")
 
12
 
 
13
  let atom x = M.Sexp (M.Atom (dumb_pos, x, None))
 
14
  let list ts = M.Sexp (M.List (dumb_pos, ts, dumb_pos))
 
15
  let comment = M.Comment dumb_comment
 
16
 
 
17
  let a1 = comment
 
18
  let a2 = atom "hello"
 
19
  let a3 = list [comment; atom "yo"; comment; atom "yo"; comment; atom "ma"; comment]
 
20
  let a4 = list [comment; a1; comment; a2; comment; a3; comment; a3]
 
21
  let a5 = list [comment; a1; comment; a2; comment; a3; comment; a4]
 
22
 
 
23
  let b2 = Sexp.Atom "hello"
 
24
  let b3 = Sexp.List [Sexp.Atom "yo"; Sexp.Atom "yo"; Sexp.Atom "ma"]
 
25
  let b4 = Sexp.List [b2; b3; b3]
 
26
  let b5 = Sexp.List [b2; b3; b4]
 
27
 
 
28
  TEST = M.Forget.t_or_comment a1 = None
 
29
  TEST = M.Forget.t_or_comment a2 = Some b2
 
30
  TEST = M.Forget.t_or_comment a3 = Some b3
 
31
  TEST = M.Forget.t_or_comment a4 = Some b4
 
32
  TEST = M.Forget.t_or_comment a5 = Some b5
 
33
 
 
34
  module Simple_forget = struct
 
35
    let rec t = function
 
36
      | M.Atom (_, x, _) -> Sexp.Atom x
 
37
      | M.List (_, ts, _) -> Sexp.List (t_or_comments ts)
 
38
    and t_or_comments = function
 
39
      | [] -> []
 
40
      | t :: ts ->
 
41
        match t_or_comment t with
 
42
        | None -> t_or_comments ts
 
43
        | Some s -> s :: t_or_comments ts
 
44
    and t_or_comment = function
 
45
      | M.Sexp x -> Some (t x)
 
46
      | M.Comment _ -> None
 
47
  end
 
48
 
 
49
  let same_as_simple x = M.Forget.t_or_comment x = Simple_forget.t_or_comment x
 
50
 
 
51
  TEST = same_as_simple a1
 
52
  TEST = same_as_simple a2
 
53
  TEST = same_as_simple a3
 
54
  TEST = same_as_simple a4
 
55
  TEST = same_as_simple a5
 
56
 
 
57
end
 
58