Bump to 1.14.1
[platform/upstream/augeas.git] / tests / modules / pass_simple_recursion.aug
1 module Pass_simple_recursion =
2
3 let rec lns =
4   let lbr = del "<" "<" in
5   let rbr = del ">" ">" in
6   let k   = [ key /[a-z]+/ ] in
7   let node = [ label "S" . lbr . lns . rbr ] in
8   let b = node | k in
9   b*
10
11 (* let rec lns = [ key "a" . lns ] | [ key "a" ] *)
12 test lns get "<x>" = { "S" { "x" } }
13
14 test lns put "<x>" after rm "nothing" = "<x>"
15
16 test lns put "<<x>>" after rm "nothing" = "<<x>>"
17
18 test lns put "<x><x>" after rm "/S[2]" = "<x>"
19
20 test lns put "<x>" after clear "/S/S/S/x" = "<x<<x>>>"
21
22
23 (* Start with { "S" { "x" } } and modify to { "S" { "S" { "x" } } } *)
24 test lns put "<x>" after
25   insa "S" "/S";
26   clear "/S[2]/S/x";
27   rm "/S[1]" = "<<x>>"
28
29 test lns get "<<<x><x>><x>><x>" =
30   { "S"
31     { "S"
32       { "S" { "x" } }
33       { "S" { "x" } } }
34     { "S" { "x" } } }
35   { "S" { "x" } }
36
37 test lns put "<<<x><x>><x>><x>" after rm "/S[1]/S[1]/S[1]" =
38   "<<<x>><x>><x>"
39
40
41 test lns get "<<yo>><zulu>" =
42   { "S" { "S" { "yo" } } }
43   { "S" { "zulu" } }
44
45 (* Some pathological tests for nullable lenses *)
46
47 let rec prim_nullable = [ prim_nullable . key /x/ ] | del /s*/ ""
48 test prim_nullable get "sx" = { "x" }
49 test prim_nullable get "x" = { "x" }
50
51 let rec ambig = [ ambig . label "x" ] | del /s+/ "s"
52 test ambig get "" = *
53 test ambig get "s" = *
54
55 (* Test link filtering. These tests cause seemingly ambiguous parses, which
56  * need to be disambiguated by filtering links in the Earley graph. See
57  * section 5.3 in the paper *)
58 let rec unamb1 = [ label "x" . unamb1 . store /y/ ] | [ key "z" ]
59 test unamb1 get "zyy" = { "x" = "y" { "x" = "y" { "z" } } }
60
61
62 let rec unamb2 = del /u*/ "" . [ unamb2 . key /x/ ] | del /s*/ ""
63 test unamb2 get "sx" = { "x" }
64 test unamb2 get "x" = { "x" }
65
66 (* Test proper handling of '?'; bug #119 *)
67 let rec maybe = [ del "a" "a" . maybe . del "b" "b" ]?
68 test maybe get "aabb" = { { } }
69
70 (* Test proper handling of '?'; bug #180 *)
71 let rec maybe2 = [ del "a" "a" . maybe2 ]?
72 test maybe2 get "aa" = { { } }
73
74 let rec maybe3 = [ maybe3 . del "a" "a" ]?
75 test maybe3 get "aa" = { { } }
76
77 let rec maybe4 = [ del "a" "a" ] . maybe4?
78 test maybe4 get "aa" = { } { }
79
80 let rec maybe5 = maybe5? . [ del "a" "a" ]
81 test maybe5 get "aa" = { } { }
82
83 (* Test that parses ending with a SCAN are accepted; bug #126 *)
84 let dels (s:string) = del s s
85 let d2 = del /b*/ ""
86 let sec (body:lens) = [ key /a*/ . dels "{" . body . dels "}"]*
87 let rec sec_complete = sec sec_complete
88 let lns2 = sec_complete . d2
89 test lns2 get "a{}b" = { "a" }
90
91 (* Test stack handling with both parsing direction; bug #136 *)
92 let idr = [ key /[0-9]+/ . del /z+/ "z" . store /[0-9]+/ . del /a+/ "a" ]
93 let rec idr_left = idr_left? . idr
94 let rec idr_right = idr . idr_right?
95 let input = "1zz2aa33zzz44aaa555zzzz666aaaa"
96 test idr_left get input = { "1" = "2" }{ "33" = "44" }{ "555" = "666" }
97 test idr_right get input = { "1" = "2" }{ "33" = "44" }{ "555" = "666" }