summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorBillingsly Wetherfordshire <phowl.mouth@gmail.com>2014-05-03 16:49:41 -0500
committerBillingsly Wetherfordshire <phowl.mouth@gmail.com>2014-05-03 16:49:41 -0500
commit4099abc8675ca37e713098c211bfe73aabd34259 (patch)
tree6361745d725808cb936227cdf881676a474d4508
parent24babdedf135a85569251b47c03a294623016fc8 (diff)
downloadNim-4099abc8675ca37e713098c211bfe73aabd34259.tar.gz
added `==` for PJsonNode
-rw-r--r--lib/pure/json.nim19
1 files changed, 19 insertions, 0 deletions
diff --git a/lib/pure/json.nim b/lib/pure/json.nim
index 4250847e5..b325c2905 100644
--- a/lib/pure/json.nim
+++ b/lib/pure/json.nim
@@ -619,6 +619,25 @@ proc `%`*(elements: openArray[PJsonNode]): PJsonNode =
   newSeq(result.elems, elements.len)
   for i, p in pairs(elements): result.elems[i] = p
 
+proc `==`* (a,b: PJsonNode): bool =
+  if a.kind != b.kind: false
+  else:
+    case a.kind
+    of JString:
+      a.str == b.str
+    of JInt:
+      a.num == b.num
+    of JFloat:
+      a.fnum == b.fnum
+    of JBool:
+      a.bval == b.bval
+    of JNull:
+      true
+    of JArray:
+      a.elems == b.elems
+    of JObject:
+      a.fields == b.fields
+
 proc len*(n: PJsonNode): int = 
   ## If `n` is a `JArray`, it returns the number of elements.
   ## If `n` is a `JObject`, it returns the number of pairs.