[augeas-devel] [PATCH 4/5] square lens: correctly process skeletons during put

lutter at redhat.com lutter at redhat.com
Thu Nov 1 23:50:27 UTC 2012


From: David Lutterkort <lutter at redhat.com>

The current code would identify a L_SQUARE skeleton to match even when it
did not, meaning we would not trigger a create in all instances where it
was needed.
---
 src/put.c                     |    3 ++-
 tests/modules/pass_square.aug |   17 +++++++++++++++++
 2 files changed, 19 insertions(+), 1 deletions(-)

diff --git a/src/put.c b/src/put.c
index 5e6212e..6888ef9 100644
--- a/src/put.c
+++ b/src/put.c
@@ -421,7 +421,8 @@ static int skel_instance_of(struct lens *lens, struct skel *skel) {
     case L_REC:
         return skel_instance_of(lens->body, skel);
     case L_SQUARE:
-        return skel->tag == L_SQUARE;
+        return skel->tag == L_SQUARE
+            && skel_instance_of(lens->child, skel->skels);
     default:
         BUG_ON(true, lens->info, "illegal lens tag %d", lens->tag);
         break;
diff --git a/tests/modules/pass_square.aug b/tests/modules/pass_square.aug
index cdb3cbc..9262bc8 100644
--- a/tests/modules/pass_square.aug
+++ b/tests/modules/pass_square.aug
@@ -103,3 +103,20 @@ test entry put "key=value" after
 
 test entry put "key=\"value\"" after
   set "/key" "other" = "key=\"other\""
+
+(* create with square *)
+(* Passing this test successfully requires that the skeleton from the get *)
+(* is correctly detected as not matching the skeleton for the second lens *)
+(* in hte union - the reason for the mismatch is that the quote is        *)
+(* optional in the first branch of the union, and the skeleton therefore  *)
+(* does not have "@" in the right places, triggering a create             *)
+let sq_create =
+  let word = store /[a-z]+/ in
+  let number = store /[0-9]+/ in
+  let quot = dels "@" in
+  let quot_opt = del /@?/ "@" in
+    [ label "t" . square quot_opt word quot_opt ]
+  | [ label "t" . square quot number quot ]
+
+test sq_create put "abc" after
+  set "/t" "42" = "@42@"
-- 
1.7.7.6




More information about the augeas-devel mailing list