1 # json_write.test - Copyright (C) 2009 Andreas Kupries <andreas_kupries@sourceforge.net>
3 # Tests for the Tcllib json::write package
5 # -------------------------------------------------------------------------
6 # See the file "license.terms" for information on usage and redistribution
7 # of this file, and for a DISCLAIMER OF ALL WARRANTIES.
8 # -------------------------------------------------------------------------
9 # RCS: @(#) $Id: json_write.test,v 1.1 2009/11/25 04:41:01 andreas_kupries Exp $
11 # -------------------------------------------------------------------------
14 [file dirname [file dirname [file join [pwd] [info script]]]] \
15 devtools testutilities.tcl]
21 useLocal json_write.tcl json::write
24 # -------------------------------------------------------------------------
28 A {is {/ {t +} {t -}} mode value}
29 D {is {/ {t 0} {t 1} } mode value}
30 E {is {/ {x {t (} {n E} {t )}} {x {n F} {* {x {n M} {n F}}}}} mode value}
31 F {is {x {n T} {* {x {n A} {n T}}}} mode value}
32 M {is {/ {t *} {t /}} mode value}
33 N {is {x {? {n S}} {+ {n D}}} mode value}
34 S {is {/ {t +} {t -}} mode value}
35 T {is {n N} mode value}
42 array set g $g(grammar)
45 # Assemble the rules ...
47 foreach {symbol def} $g(rules) {
48 lassign $def _ is _ mode
49 lappend rules $symbol \
51 is [json::write string $is] \
52 mode [json::write string $mode]]
55 # Assemble the final result ...
56 return [json::write object grammar \
58 rules [json::write object {*}$rules] \
59 start [json::write string $g(start)]]]
62 # -------------------------------------------------------------------------
64 # -------------------------------------------------------------------------
66 test json-write-1.0 {default configuration} -body {
67 list [json::write indented] [json::write aligned]
70 test json-write-1.1 {implied configurations} -body {
71 json::write indented 0
72 list [json::write indented] [json::write aligned]
75 test json-write-1.2 {implied configurations} -body {
76 json::write indented 0
79 list [json::write indented] [json::write aligned]
82 # -------------------------------------------------------------------------
84 test json-write-2.0 {argument errors} -body {
85 json::write indented X Y
86 } -returnCodes 1 -result {wrong # args: should be "json::write indented ?bool?"}
88 test json-write-2.1 {argument errors} -body {
89 json::write aligned X Y
90 } -returnCodes 1 -result {wrong # args: should be "json::write aligned ?bool?"}
92 test json-write-2.2 {argument errors} -body {
94 } -returnCodes 1 -result {wrong # args: should be "json::write string s"}
96 test json-write-2.3 {argument errors} -body {
97 json::write string A B
98 } -returnCodes 1 -result {wrong # args: should be "json::write string s"}
100 test json-write-2.4 {argument errors} -body {
102 } -returnCodes 1 -result {wrong # args, expected an even number of arguments}
104 # -------------------------------------------------------------------------
106 test json-write-3.0 {indented, aligned} -body {
107 json::write indented 1
108 json::write aligned 1
114 "is" : "\/ {t +} {t -}",
118 "is" : "\/ {t 0} {t 1} ",
122 "is" : "\/ {x {t (} {n E} {t )}} {x {n F} {* {x {n M} {n F}}}}",
126 "is" : "x {n T} {* {x {n A} {n T}}}",
130 "is" : "\/ {t *} {t \/}",
134 "is" : "x {? {n S}} {+ {n D}}",
138 "is" : "\/ {t +} {t -}",
146 "start" : "n Expression"
150 test json-write-3.1 {indented, !aligned} -body {
151 json::write indented 1
152 json::write aligned 0
158 "is" : "\/ {t +} {t -}",
162 "is" : "\/ {t 0} {t 1} ",
166 "is" : "\/ {x {t (} {n E} {t )}} {x {n F} {* {x {n M} {n F}}}}",
170 "is" : "x {n T} {* {x {n A} {n T}}}",
174 "is" : "\/ {t *} {t \/}",
178 "is" : "x {? {n S}} {+ {n D}}",
182 "is" : "\/ {t +} {t -}",
190 "start" : "n Expression"
194 test json-write-3.1 {!indented, !aligned} -body {
195 json::write indented 0
196 json::write aligned 0
198 } -result {{"grammar":{"rules":{"A":{"is":"\/ {t +} {t -}","mode":"value"},"D":{"is":"\/ {t 0} {t 1} ","mode":"value"},"E":{"is":"\/ {x {t (} {n E} {t )}} {x {n F} {* {x {n M} {n F}}}}","mode":"value"},"F":{"is":"x {n T} {* {x {n A} {n T}}}","mode":"value"},"M":{"is":"\/ {t *} {t \/}","mode":"value"},"N":{"is":"x {? {n S}} {+ {n D}}","mode":"value"},"S":{"is":"\/ {t +} {t -}","mode":"value"},"T":{"is":"n N","mode":"value"}},"start":"n Expression"}}}
200 # -------------------------------------------------------------------------
207 # indent-tabs-mode: nil