[augeas-devel] [PATCH 5/6] * tests/modules/pass_strip_quotes.aug: test quote stripping

David Lutterkort lutter at redhat.com
Mon Aug 31 22:09:43 UTC 2009


The tests strips optional quotes and puts them back (or creates them) as
needed, only depending on the value of the tree node.
---
 tests/modules/pass_strip_quotes.aug |   26 ++++++++++++++++++++++++++
 1 files changed, 26 insertions(+), 0 deletions(-)
 create mode 100644 tests/modules/pass_strip_quotes.aug

diff --git a/tests/modules/pass_strip_quotes.aug b/tests/modules/pass_strip_quotes.aug
new file mode 100644
index 0000000..7e24b31
--- /dev/null
+++ b/tests/modules/pass_strip_quotes.aug
@@ -0,0 +1,26 @@
+(* Demonstrate how quotes can be stripped from values.            *)
+(* Values can be enclosed in single or double quotes, if they     *)
+(* contain spaces they _have_ to be enclosed in quotes. Since     *)
+(* everything's regular, we can't actually match a closing quote  *)
+(* to the opening quote, so "hello' will be accepted, too.        *)
+
+module Pass_strip_quotes =
+
+  let nuttin = del /(""|'')?/ "''"
+  let bare = del /["']?/ "" . store /[a-zA-Z0-9]+/ . del /["']?/ ""
+  let quoted = del /["']/ "'" . store /.*[ \t].*/ . del /["']/ "'"
+
+  let lns = [ label "foo" . bare ]
+    | [ label "foo" . quoted ]
+    | [ label "foo" . nuttin ]
+
+  test lns get "'hello'" = { "foo" = "hello" }
+  test lns get "'hello world'" = { "foo" = "hello world" }
+
+  let hw = "'hello world'"
+  let set_hw = set "/foo" "hello world"
+  test lns put "hello" after set_hw = hw
+  test lns put "'hello world'" after set "/foo" "hello" = "'hello'"
+
+  test lns put "" after set_hw = hw
+  test lns put "\"\"" after set_hw = hw
-- 
1.6.2.5




More information about the augeas-devel mailing list