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

[augeas-devel] augeas: master - Json: lens and tests for generic Json files



Gitweb:        http://git.fedorahosted.org/git/augeas.git?p=augeas.git;a=commitdiff;h=b6fe24ac31648b807344b21d08087fe1d09b1b20
Commit:        b6fe24ac31648b807344b21d08087fe1d09b1b20
Parent:        49a72159b81a3787d1939ab89de583cb86b8e7cd
Author:        David Lutterkort <lutter redhat com>
AuthorDate:    Mon Dec 21 16:54:09 2009 -0800
Committer:     David Lutterkort <lutter redhat com>
CommitterDate: Thu Jan 14 14:48:39 2010 -0800

Json: lens and tests for generic Json files

---
 lenses/json.aug            |   52 +++++++
 lenses/tests/test_json.aug |  322 ++++++++++++++++++++++++++++++++++++++++++++
 tests/Makefile.am          |    1 +
 3 files changed, 375 insertions(+), 0 deletions(-)

diff --git a/lenses/json.aug b/lenses/json.aug
new file mode 100644
index 0000000..f8f2924
--- /dev/null
+++ b/lenses/json.aug
@@ -0,0 +1,52 @@
+module Json =
+
+(* A generic lens for Json files                                           *)
+(* Based on the following grammar from http://www.json.org/                *)
+(* Object ::= '{'Members ? '}'                                             *)
+(* Members ::= Pair+                                                       *)
+(* Pair ::= String ':' Value                                               *)
+(* Array ::= '[' Elements ']'                                              *)
+(* Elements ::= Value ( "," Value )*                                       *)
+(* Value ::= String | Number | Object | Array | "true" | "false" | "null"  *)
+(* String ::= "\"" Char* "\""                                              *)
+(* Number ::= /-?[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?/                      *)
+
+let spc = /[ \t\n]*/
+
+let ws = del spc ""
+let eol = del spc "\n"
+let delim (c:string) (d:string) = del (spc . c . spc) d
+let dels (s:string) = del s s
+
+let comma = delim "," ", "
+let colon = delim ":" ": "
+let lbrace = delim "{" "{ "
+let rbrace = delim "}" "} "
+let lbrack = delim "[" "[ "
+let rbrack = delim "]" " ]"
+
+let str_store =
+  let q =  del "\"" "\"" in
+  q . store /[^"]*/ . q             (* " Emacs, relax *)
+
+let number = [ label "number" . store /-?[0-9]+(\.[0-9]+)?([eE][+-]?[0-9]+)?/ ]
+let str = [ label "string" . str_store ]
+
+let const (r:regexp) = [ label "const" . store r ]
+
+let value0 = str | number | const /true|false|null/
+
+let fix_value (value:lens) =
+  let array = [ label "array" . lbrack . Build.opt_list value comma . rbrack ] in
+  let pair = [ label "entry" . str_store . colon . value ] in
+  let obj = [ label "dict" . lbrace . Build.opt_list pair comma . rbrace ] in
+  str | number | obj | array | const /true|false|null/
+
+(* Do shallow typechecks *)
+let value1 = fix_value value0
+(* FIXME: We are very sloppy with whitespace
+let value2 = fix_value value1
+*)
+
+(* Construct the real lens *)
+let rec lns = fix_value lns
diff --git a/lenses/tests/test_json.aug b/lenses/tests/test_json.aug
new file mode 100644
index 0000000..0bcd25d
--- /dev/null
+++ b/lenses/tests/test_json.aug
@@ -0,0 +1,322 @@
+module Test_json =
+
+let lns = Json.lns
+
+test lns get "\"menu\"" = { "string" = "menu" }
+
+test lns get "true" = { "const" = "true" }
+
+test lns get "3.141" = { "number" = "3.141" }
+
+test lns get "[true, 0, \"yo\"]" =
+  { "array" { "const" = "true" } { "number" = "0" } { "string" = "yo" } }
+
+test lns get "{\"a\" : true}" =
+  { "dict" { "entry" = "a" { "const" = "true" } } }
+
+test lns get "{ \"0\":true, \"1\":false }" =
+  { "dict" { "entry" = "0" { "const" = "true" } }
+             { "entry" = "1" { "const" = "false" } } }
+
+
+test lns get "{ \"0\": true, \"1\":false }" =
+  { "dict"
+    { "entry" = "0" { "const" = "true" } }
+    { "entry" = "1" { "const" = "false" } } }
+
+test lns get "{\"menu\": \"entry one\"}" =
+  { "dict" { "entry" = "menu" { "string" = "entry one" } } }
+
+
+let s = "{\"menu\": {
+  \"id\": \"file\",
+  \"value\": \"File\",
+  \"popup\": {
+    \"menuitem\": [
+      {\"value\": \"New\", \"onclick\": \"CreateNewDoc()\"},
+      {\"value\": \"Open\", \"onclick\": \"OpenDoc()\"},
+      {\"value\": \"Close\", \"onclick\": \"CloseDoc()\"}
+    ]
+  }
+}}"
+
+test lns get s =
+  { "dict"
+    { "entry" = "menu"
+      { "dict"
+        { "entry" = "id" { "string" = "file" } }
+        { "entry" = "value" { "string" = "File" } }
+        { "entry" = "popup"
+          { "dict"
+            { "entry" = "menuitem"
+              { "array"
+                { "dict"
+                  { "entry" = "value" { "string" = "New" } }
+                  { "entry" = "onclick"
+                    { "string" = "CreateNewDoc()" } } }
+                { "dict"
+                  { "entry" = "value" { "string" = "Open" } }
+                  { "entry" = "onclick" { "string" = "OpenDoc()" } } }
+                { "dict"
+                  { "entry" = "value" { "string" = "Close" } }
+                  { "entry" = "onclick" { "string" = "CloseDoc()" } }
+                } } } } } } } }
+
+let t = "
+{\"web-app\": {
+  \"servlet\": [
+    {
+      \"servlet-name\": \"cofaxCDS\",
+      \"servlet-class\": \"org.cofax.cds.CDSServlet\",
+      \"init-param\": {
+        \"configGlossary:installationAt\": \"Philadelphia, PA\",
+        \"configGlossary:adminEmail\": \"ksm pobox com\",
+        \"configGlossary:poweredBy\": \"Cofax\",
+        \"configGlossary:poweredByIcon\": \"/images/cofax.gif\",
+        \"configGlossary:staticPath\": \"/content/static\",
+        \"templateProcessorClass\": \"org.cofax.WysiwygTemplate\",
+        \"templateLoaderClass\": \"org.cofax.FilesTemplateLoader\",
+        \"templatePath\": \"templates\",
+        \"templateOverridePath\": \"\",
+        \"defaultListTemplate\": \"listTemplate.htm\",
+        \"defaultFileTemplate\": \"articleTemplate.htm\",
+        \"useJSP\": false,
+        \"jspListTemplate\": \"listTemplate.jsp\",
+        \"jspFileTemplate\": \"articleTemplate.jsp\",
+        \"cachePackageTagsTrack\": 200,
+        \"cachePackageTagsStore\": 200,
+        \"cachePackageTagsRefresh\": 60,
+        \"cacheTemplatesTrack\": 100,
+        \"cacheTemplatesStore\": 50,
+        \"cacheTemplatesRefresh\": 15,
+        \"cachePagesTrack\": 200,
+        \"cachePagesStore\": 100,
+        \"cachePagesRefresh\": 10,
+        \"cachePagesDirtyRead\": 10,
+        \"searchEngineListTemplate\": \"forSearchEnginesList.htm\",
+        \"searchEngineFileTemplate\": \"forSearchEngines.htm\",
+        \"searchEngineRobotsDb\": \"WEB-INF/robots.db\",
+        \"useDataStore\": true,
+        \"dataStoreClass\": \"org.cofax.SqlDataStore\",
+        \"redirectionClass\": \"org.cofax.SqlRedirection\",
+        \"dataStoreName\": \"cofax\",
+        \"dataStoreDriver\": \"com.microsoft.jdbc.sqlserver.SQLServerDriver\",
+        \"dataStoreUrl\": \"jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon\",
+        \"dataStoreUser\": \"sa\",
+        \"dataStorePassword\": \"dataStoreTestQuery\",
+        \"dataStoreTestQuery\": \"SET NOCOUNT ON;select test='test';\",
+        \"dataStoreLogFile\": \"/usr/local/tomcat/logs/datastore.log\",
+        \"dataStoreInitConns\": 10,
+        \"dataStoreMaxConns\": 100,
+        \"dataStoreConnUsageLimit\": 100,
+        \"dataStoreLogLevel\": \"debug\",
+        \"maxUrlLength\": 500}},
+    {
+      \"servlet-name\": \"cofaxEmail\",
+      \"servlet-class\": \"org.cofax.cds.EmailServlet\",
+      \"init-param\": {
+      \"mailHost\": \"mail1\",
+      \"mailHostOverride\": \"mail2\"}},
+    {
+      \"servlet-name\": \"cofaxAdmin\",
+      \"servlet-class\": \"org.cofax.cds.AdminServlet\"},
+
+    {
+      \"servlet-name\": \"fileServlet\",
+      \"servlet-class\": \"org.cofax.cds.FileServlet\"},
+    {
+      \"servlet-name\": \"cofaxTools\",
+      \"servlet-class\": \"org.cofax.cms.CofaxToolsServlet\",
+      \"init-param\": {
+        \"templatePath\": \"toolstemplates/\",
+        \"log\": 1,
+        \"logLocation\": \"/usr/local/tomcat/logs/CofaxTools.log\",
+        \"logMaxSize\": \"\",
+        \"dataLog\": 1,
+        \"dataLogLocation\": \"/usr/local/tomcat/logs/dataLog.log\",
+        \"dataLogMaxSize\": \"\",
+        \"removePageCache\": \"/content/admin/remove?cache=pages&id=\",
+        \"removeTemplateCache\": \"/content/admin/remove?cache=templates&id=\",
+        \"fileTransferFolder\": \"/usr/local/tomcat/webapps/content/fileTransferFolder\",
+        \"lookInContext\": 1,
+        \"adminGroupID\": 4,
+        \"betaServer\": true}}],
+  \"servlet-mapping\": {
+    \"cofaxCDS\": \"/\",
+    \"cofaxEmail\": \"/cofaxutil/aemail/*\",
+    \"cofaxAdmin\": \"/admin/*\",
+    \"fileServlet\": \"/static/*\",
+    \"cofaxTools\": \"/tools/*\"},
+
+  \"taglib\": {
+    \"taglib-uri\": \"cofax.tld\",
+    \"taglib-location\": \"/WEB-INF/tlds/cofax.tld\"}}}"
+
+test lns get t =
+  { "dict"
+    { "entry" = "web-app"
+      { "dict"
+        { "entry" = "servlet"
+          { "array"
+            { "dict"
+              { "entry" = "servlet-name" { "string" = "cofaxCDS" } }
+              { "entry" = "servlet-class"
+                { "string" = "org.cofax.cds.CDSServlet" } }
+              { "entry" = "init-param"
+                { "dict"
+                  { "entry" = "configGlossary:installationAt"
+                    { "string" = "Philadelphia, PA" } }
+                  { "entry" = "configGlossary:adminEmail"
+                    { "string" = "ksm pobox com" } }
+                  { "entry" = "configGlossary:poweredBy"
+                    { "string" = "Cofax" } }
+                  { "entry" = "configGlossary:poweredByIcon"
+                    { "string" = "/images/cofax.gif" } }
+                  { "entry" = "configGlossary:staticPath"
+                    { "string" = "/content/static" } }
+                  { "entry" = "templateProcessorClass"
+                    { "string" = "org.cofax.WysiwygTemplate" } }
+                  { "entry" = "templateLoaderClass"
+                    { "string" = "org.cofax.FilesTemplateLoader" } }
+                  { "entry" = "templatePath"
+                    { "string" = "templates" } }
+                  { "entry" = "templateOverridePath"
+                    { "string" = "" } }
+                  { "entry" = "defaultListTemplate"
+                    { "string" = "listTemplate.htm" } }
+                  { "entry" = "defaultFileTemplate"
+                    { "string" = "articleTemplate.htm" } }
+                  { "entry" = "useJSP"
+                    { "const" = "false" } }
+                  { "entry" = "jspListTemplate"
+                    { "string" = "listTemplate.jsp" } }
+                  { "entry" = "jspFileTemplate"
+                    { "string" = "articleTemplate.jsp" } }
+                  { "entry" = "cachePackageTagsTrack"
+                    { "number" = "200" } }
+                  { "entry" = "cachePackageTagsStore"
+                    { "number" = "200" } }
+                  { "entry" = "cachePackageTagsRefresh"
+                    { "number" = "60" } }
+                  { "entry" = "cacheTemplatesTrack"
+                    { "number" = "100" } }
+                  { "entry" = "cacheTemplatesStore"
+                    { "number" = "50" } }
+                  { "entry" = "cacheTemplatesRefresh"
+                    { "number" = "15" } }
+                  { "entry" = "cachePagesTrack"
+                    { "number" = "200" } }
+                  { "entry" = "cachePagesStore"
+                    { "number" = "100" } }
+                  { "entry" = "cachePagesRefresh"
+                    { "number" = "10" } }
+                  { "entry" = "cachePagesDirtyRead"
+                    { "number" = "10" } }
+                  { "entry" = "searchEngineListTemplate"
+                    { "string" = "forSearchEnginesList.htm" } }
+                  { "entry" = "searchEngineFileTemplate"
+                    { "string" = "forSearchEngines.htm" } }
+                  { "entry" = "searchEngineRobotsDb"
+                    { "string" = "WEB-INF/robots.db" } }
+                  { "entry" = "useDataStore"
+                    { "const" = "true" } }
+                  { "entry" = "dataStoreClass"
+                    { "string" = "org.cofax.SqlDataStore" } }
+                  { "entry" = "redirectionClass"
+                    { "string" = "org.cofax.SqlRedirection" } }
+                  { "entry" = "dataStoreName"
+                    { "string" = "cofax" } }
+                  { "entry" = "dataStoreDriver"
+                    { "string" = "com.microsoft.jdbc.sqlserver.SQLServerDriver" } }
+                  { "entry" = "dataStoreUrl"
+                    { "string" = "jdbc:microsoft:sqlserver://LOCALHOST:1433;DatabaseName=goon" } }
+                  { "entry" = "dataStoreUser"
+                    { "string" = "sa" } }
+                  { "entry" = "dataStorePassword"
+                    { "string" = "dataStoreTestQuery" } }
+                  { "entry" = "dataStoreTestQuery"
+                    { "string" = "SET NOCOUNT ON;select test='test';" } }
+                  { "entry" = "dataStoreLogFile"
+                    { "string" = "/usr/local/tomcat/logs/datastore.log" } }
+                  { "entry" = "dataStoreInitConns"
+                    { "number" = "10" } }
+                  { "entry" = "dataStoreMaxConns"
+                    { "number" = "100" } }
+                  { "entry" = "dataStoreConnUsageLimit"
+                    { "number" = "100" } }
+                  { "entry" = "dataStoreLogLevel"
+                    { "string" = "debug" } }
+                  { "entry" = "maxUrlLength"
+                    { "number" = "500" } } } } }
+            { "dict"
+              { "entry" = "servlet-name"
+                { "string" = "cofaxEmail" } }
+              { "entry" = "servlet-class"
+                { "string" = "org.cofax.cds.EmailServlet" } }
+              { "entry" = "init-param"
+                { "dict"
+                  { "entry" = "mailHost"
+                    { "string" = "mail1" } }
+                  { "entry" = "mailHostOverride"
+                    { "string" = "mail2" } } } } }
+            { "dict"
+              { "entry" = "servlet-name"
+                { "string" = "cofaxAdmin" } }
+              { "entry" = "servlet-class"
+                { "string" = "org.cofax.cds.AdminServlet" } } }
+            { "dict"
+              { "entry" = "servlet-name"
+                { "string" = "fileServlet" } }
+              { "entry" = "servlet-class"
+                { "string" = "org.cofax.cds.FileServlet" } } }
+            { "dict"
+              { "entry" = "servlet-name"
+                { "string" = "cofaxTools" } }
+              { "entry" = "servlet-class"
+                { "string" = "org.cofax.cms.CofaxToolsServlet" } }
+              { "entry" = "init-param"
+                { "dict"
+                  { "entry" = "templatePath"
+                    { "string" = "toolstemplates/" } }
+                  { "entry" = "log"
+                    { "number" = "1" } }
+                  { "entry" = "logLocation"
+                    { "string" = "/usr/local/tomcat/logs/CofaxTools.log" } }
+                  { "entry" = "logMaxSize"
+                    { "string" = "" } }
+                  { "entry" = "dataLog"
+                    { "number" = "1" } }
+                  { "entry" = "dataLogLocation"
+                    { "string" = "/usr/local/tomcat/logs/dataLog.log" } }
+                  { "entry" = "dataLogMaxSize"
+                    { "string" = "" } }
+                  { "entry" = "removePageCache"
+                    { "string" = "/content/admin/remove?cache=pages&id=" } }
+                  { "entry" = "removeTemplateCache"
+                    { "string" = "/content/admin/remove?cache=templates&id=" } }
+                  { "entry" = "fileTransferFolder"
+                    { "string" = "/usr/local/tomcat/webapps/content/fileTransferFolder" } }
+                  { "entry" = "lookInContext"
+                    { "number" = "1" } }
+                  { "entry" = "adminGroupID"
+                    { "number" = "4" } }
+                  { "entry" = "betaServer"
+                    { "const" = "true" } } } } } } }
+        { "entry" = "servlet-mapping"
+          { "dict"
+            { "entry" = "cofaxCDS"
+              { "string" = "/" } }
+            { "entry" = "cofaxEmail"
+              { "string" = "/cofaxutil/aemail/*" } }
+            { "entry" = "cofaxAdmin"
+              { "string" = "/admin/*" } }
+            { "entry" = "fileServlet"
+              { "string" = "/static/*" } }
+            { "entry" = "cofaxTools"
+              { "string" = "/tools/*" } } } }
+        { "entry" = "taglib"
+          { "dict"
+            { "entry" = "taglib-uri"
+              { "string" = "cofax.tld" } }
+            { "entry" = "taglib-location"
+              { "string" = "/WEB-INF/tlds/cofax.tld" } } } } } } }
diff --git a/tests/Makefile.am b/tests/Makefile.am
index 91bf4af..617edc2 100644
--- a/tests/Makefile.am
+++ b/tests/Makefile.am
@@ -27,6 +27,7 @@ lens_tests =			\
   lens-fstab.sh			\
   lens-gdm.sh			\
   lens-group.sh			\
+  lens-json.sh          \
   lens-hosts.sh			\
   lens-inetd.sh         \
   lens-inifile.sh		\



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