[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]

[augeas-devel] augeas: master - Tests for recursive (context free) lenses



Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=49a72159b81a3787d1939ab89de583cb86b8e7cd
Commit:        49a72159b81a3787d1939ab89de583cb86b8e7cd
Parent:        9b44eb7452d95bab287d6be69240d611dfbe833c
Author:        David Lutterkort <lutter redhat com>
AuthorDate:    Fri Dec 18 16:53:54 2009 -0800
Committer:     David Lutterkort <lutter redhat com>
CommitterDate: Thu Jan 14 14:48:38 2010 -0800

Tests for recursive (context free) lenses

---
 tests/modules/fail_cf_two_nullable.aug      |    4 ++
 tests/modules/fail_recursion_multi_keys.aug |    4 ++
 tests/modules/pass_nested_sections.aug      |   54 +++++++++++++++++++++++++++
 tests/modules/pass_simple_recursion.aug     |   53 ++++++++++++++++++++++++++
 4 files changed, 115 insertions(+), 0 deletions(-)

diff --git a/tests/modules/fail_cf_two_nullable.aug b/tests/modules/fail_cf_two_nullable.aug
new file mode 100644
index 0000000..3376803
--- /dev/null
+++ b/tests/modules/fail_cf_two_nullable.aug
@@ -0,0 +1,4 @@
+module Fail_cf_two_nullable =
+
+(* Both branches of the union are nullable, making SPC ambiguous *)
+let rec spc = [ spc . label "x" ] | del /s*/ "s"
diff --git a/tests/modules/fail_recursion_multi_keys.aug b/tests/modules/fail_recursion_multi_keys.aug
new file mode 100644
index 0000000..f6d0c3c
--- /dev/null
+++ b/tests/modules/fail_recursion_multi_keys.aug
@@ -0,0 +1,4 @@
+module Fail_recursion_multi_keys =
+
+(* This is the same as (key "a")* . store "x" *)
+let rec l = key "a" . l | store "x"
diff --git a/tests/modules/pass_nested_sections.aug b/tests/modules/pass_nested_sections.aug
new file mode 100644
index 0000000..7b51bc2
--- /dev/null
+++ b/tests/modules/pass_nested_sections.aug
@@ -0,0 +1,54 @@
+module Pass_nested_sections =
+
+let word = /[a-zA-Z0-9]+/
+let ws = /[ \t]*/
+let nl = /\n/
+
+let eol = del (ws . nl) "\n"
+let eq = del (ws . "=" . ws) "="
+let lbr = del (ws . "{" . ws . nl) " {\n"
+let rbr = del (ws . "}" . ws . nl) "}\n"
+let indent = del ws ""
+
+let entry = [ indent . key word . eq . store word . eol ]
+
+let rec lns =
+  let sec = [ indent . key word . lbr . lns . rbr ] in
+  (sec | entry)+
+
+
+test lns get "key = value\n" = { "key" = "value" }
+
+test lns get "section {
+  key1 = v1
+  key2 = v2
+  section {
+    section {
+      key4 = v4
+    }
+  }
+  section {
+    key5 = v5
+  }
+}\n" =
+  { "section"
+    { "key1" = "v1" }
+    { "key2" = "v2" }
+    { "section" { "section" { "key4" = "v4" } } }
+    { "section" { "key5" = "v5" } } }
+
+
+test lns get "section {
+  section {
+    key2 = v2
+  }
+}
+section {
+  key3 = v3
+}
+" =
+  { "section"
+    { "section"
+      { "key2" = "v2" } } }
+  { "section"
+    { "key3" = "v3" } }
diff --git a/tests/modules/pass_simple_recursion.aug b/tests/modules/pass_simple_recursion.aug
new file mode 100644
index 0000000..849c861
--- /dev/null
+++ b/tests/modules/pass_simple_recursion.aug
@@ -0,0 +1,53 @@
+module Pass_simple_recursion =
+
+let rec lns =
+  let lbr = del "<" "<" in
+  let rbr = del ">" ">" in
+  let k   = [ key /[a-z]+/ ] in
+  let node = [ label "S" . lbr . lns . rbr ] in
+  let b = node | k in
+  b*
+
+(* let rec lns = [ key "a" . lns ] | [ key "a" ] *)
+test lns get "<x>" = { "S" { "x" } }
+
+test lns put "<x>" after rm "nothing" = "<x>"
+
+test lns put "<<x>>" after rm "nothing" = "<<x>>"
+
+test lns put "<x><x>" after rm "/S[2]" = "<x>"
+
+test lns put "<x>" after clear "/S/S/S/x" = "<x<<x>>>"
+
+
+(* Start with { "S" { "x" } } and modify to { "S" { "S" { "x" } } } *)
+test lns put "<x>" after
+  insa "S" "/S";
+  clear "/S[2]/S/x";
+  rm "/S[1]" = "<<x>>"
+
+test lns get "<<<x><x>><x>><x>" =
+  { "S"
+    { "S"
+      { "S" { "x" } }
+      { "S" { "x" } } }
+    { "S" { "x" } } }
+  { "S" { "x" } }
+
+test lns put "<<<x><x>><x>><x>" after rm "/S[1]/S[1]/S[1]" =
+  "<<<x>><x>><x>"
+
+
+test lns get "<<yo>><zulu>" =
+  { "S" { "S" { "yo" } } }
+  { "S" { "zulu" } }
+
+(* Some pathological tests for nullable lenses *)
+
+let rec prim_nullable = [ prim_nullable . key /x/ ] | del /s*/ ""
+test prim_nullable get "sx" = { "x" }
+test prim_nullable get "x" = { "x" }
+
+let rec ambig = [ ambig . label "x" ] | del /s+/ "s"
+test ambig get "" = *
+test ambig get "s" = *



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]