~ubuntu-branches/ubuntu/natty/augeas/natty

« back to all changes in this revision

Viewing changes to tests/modules/pass_square.aug

  • Committer: Bazaar Package Importer
  • Author(s): Raphaël Pinson
  • Date: 2011-02-24 09:32:22 UTC
  • mfrom: (1.2.15 upstream)
  • Revision ID: james.westby@ubuntu.com-20110224093222-bfd4fkm6envek6ys
Tags: 0.8.0-0ubuntu1
* New upstream release.
* Remove obsolete ruby Build-Depend.
* Build PDF docs and add them to augeas-doc.
* Build-Depend on texlive-latex-base to build PDF docs.
* Install txt doc files in augeas-doc.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
module Pass_square =
 
2
 
 
3
(*  Utilities lens *)
 
4
let dels (s:string) = del s s
 
5
 
 
6
(************************************************************************
 
7
 *                           Regular square lens
 
8
 *************************************************************************)
 
9
 
 
10
(* Simplest square lens *)
 
11
let s = store /[yz]/
 
12
let sqr0 = [ square "x" s ] *
 
13
test sqr0 get "xyxxyxxyx" = { "x" = "y" }{ "x" = "y" }{ "x" = "y" }
 
14
test sqr0 put "xyx" after set "/x[3]" "z" = "xyxxzx"
 
15
 
 
16
(* test mismatch tag *)
 
17
test sqr0 get "xya" = *
 
18
 
 
19
(* Test regular expression matching with multiple groups *)
 
20
let body = del /([f]+)([f]+)/ "ff" . del /([g]+)([g]+)/ "gg"
 
21
let sqr1 = [ square /([a-b]*)([a-b]*)([a-b]*)/ body . del /([x]+)([x]+)/ "xx" ] *
 
22
 
 
23
test sqr1 get "aaffggaaxxbbffggbbxx" = { "aa" }{ "bb" }
 
24
test sqr1 get "affggaxx" = { "a" }
 
25
test sqr1 put "affggaxx" after clear "/b" = "affggaxxbffggbxx"
 
26
 
 
27
(* Test XML like elements up to depth 2 *)
 
28
let b = del ">" ">" . del /[a-z ]*/ "" . del "</" "</"
 
29
let xml = [ del "<" "<" . square /[a-z]+/ b . del ">" ">" ] *
 
30
 
 
31
let b2 = del ">" ">" . xml . del "</" "</"
 
32
let xml2 = [ del "<" "<" . square /[a-z]+/ b2 . del ">" ">" ] *
 
33
 
 
34
test xml get "<a></a><b></b>" = { "a" }{ "b" }
 
35
 
 
36
(* test error on mismatch tag *)
 
37
test xml get "<a></a><b></c>" = *
 
38
 
 
39
(* test get nested tags of depth 2 *)
 
40
test xml2 get "<a><b></b><c></c></a>" =
 
41
  { "a"
 
42
    { "b" }
 
43
    { "c" }
 
44
  }
 
45
 
 
46
(* test nested put of depth 2 *)
 
47
test xml2 put "<a></a>" after clear "/x/y" = "<a></a><x><y></y></x>"
 
48
 
 
49
(* test nested put of depth 3 : should fail *)
 
50
test xml2 put "<a></a>" after clear "/x/y/z" = *
 
51
 
 
52
(************************************************************************
 
53
 *                        Recursive square lens
 
54
 *************************************************************************)
 
55
 
 
56
(* Basic element *)
 
57
let xml_element (body:lens) =
 
58
    let g = del ">" ">" . body . del "</" "</" in
 
59
        [ del "<" "<" . square /[a-z]+/ g . del ">" ">" ] *
 
60
 
 
61
let rec xml_rec = xml_element xml_rec
 
62
 
 
63
test xml_rec get "<a><b><c><d><e></e></d></c></b></a>" =
 
64
  { "a"
 
65
    { "b"
 
66
      { "c"
 
67
        { "d"
 
68
          { "e" }
 
69
        }
 
70
      }
 
71
    }
 
72
  }
 
73
 
 
74
test xml_rec get "<a><b></b><c></c><d></d><e></e></a>" =
 
75
  { "a"
 
76
    { "b" }
 
77
    { "c" }
 
78
    { "d" }
 
79
    { "e" }
 
80
  }
 
81
 
 
82
test xml_rec put "<a></a><b><c></c></b>" after clear "/x/y/z" = "<a></a><b><c></c></b><x><y><z></z></y></x>"
 
83
 
 
84
(* mismatch tag *)
 
85
test xml_rec get "<a></c>" = *
 
86
test xml_rec get "<a><b></b></c>" = *
 
87
test xml_rec get "<a><b></c></a>" = *
 
88
 
 
89
(* test ctype_nullable and typecheck *)
 
90
let rec z = [ square "ab" z? ]
 
91
test z get "abab" = { "ab" }
 
92
 
 
93
(* test tip handling when using store inside body *)
 
94
let c (body:lens) =
 
95
    let sto = store "c" . body* in
 
96
        [ square "ab" sto ]
 
97
 
 
98
let rec cc = c cc
 
99
 
 
100
test cc get "abcabcabab" =
 
101
  { "ab" = "c"
 
102
    { "ab" = "c" }
 
103
  }
 
104
 
 
105
(* test correct put behavior *)
 
106
let input3 = "aaxyxbbaaaxyxbb"
 
107
let b3 = dels "y"
 
108
let sqr3 = [ del /[a]*/ "a" . square /[x]/ b3 . del /[b]*/ "b" ]*
 
109
test sqr3 get input3 = { "x" }{ "x" }
 
110
test sqr3 put input3 after clear "/x[1]" = input3
 
111
 
 
112
let b4 = del "x" "x"
 
113
let rec sqr4 = [ del /[a]+/ "a" . square /[b]|[c]/ (b4|sqr4) ]
 
114
test sqr4 put "aabaaacxcb" after rm "x" = "aabaaacxcb"