summary refs log tree commit diff stats
diff options
context:
space:
mode:
authorMatt Sullivan <mattsullivan14916@gmail.com>2015-10-31 13:30:07 -0500
committerMatt Sullivan <mattsullivan14916@gmail.com>2015-10-31 13:30:07 -0500
commit8671656e6f6d8cca67054a925dfdcb8246a97bef (patch)
treecc53b0186fc522d43b9feff7b5517ceeabdf09be
parent097c508897ccb53137916c431836689ba0fc0186 (diff)
downloadNim-8671656e6f6d8cca67054a925dfdcb8246a97bef.tar.gz
Add a test to xmlparser
-rw-r--r--lib/pure/xmlparser.nim31
-rw-r--r--tests/testdata/doc1.xml1
2 files changed, 20 insertions, 12 deletions
diff --git a/lib/pure/xmlparser.nim b/lib/pure/xmlparser.nim
index b1c6acace..2a2c3e1dd 100644
--- a/lib/pure/xmlparser.nim
+++ b/lib/pure/xmlparser.nim
@@ -143,17 +143,24 @@ proc loadXml*(path: string): XmlNode =
   result = loadXml(path, errors)
   if errors.len > 0: raiseInvalidXml(errors)
 
-when not defined(testing) and isMainModule:
-  import os
-
-  var errors: seq[string] = @[]
-  var x = loadXml(paramStr(1), errors)
-  for e in items(errors): echo e
-
-  var f: File
-  if open(f, "xmltest.txt", fmWrite):
-    f.write($x)
-    f.close()
+when isMainModule:
+  when not defined(testing):
+    import os
+
+    var errors: seq[string] = @[]
+    var x = loadXml(paramStr(1), errors)
+    for e in items(errors): echo e
+
+    var f: File
+    if open(f, "xmltest.txt", fmWrite):
+      f.write($x)
+      f.close()
+    else:
+      quit("cannot write test.txt")
   else:
-    quit("cannot write test.txt")
+    block: # correctly parse ../../tests/testdata/doc1.xml
+      let filePath = "tests/testdata/doc1.xml"
+      var errors: seq[string] = @[]
+      var xml = loadXml(filePath, errors)
+      assert(errors.len == 0, "The file tests/testdata/doc1.xml should be parsed without errors.")
 
diff --git a/tests/testdata/doc1.xml b/tests/testdata/doc1.xml
index 4e77481aa..07cbceeb7 100644
--- a/tests/testdata/doc1.xml
+++ b/tests/testdata/doc1.xml
@@ -5,6 +5,7 @@
     <test2>
       bla ah absy hsh
       hsh
+      &woohoo;
       sjj
     </test2>
     <test><teh>bla</teh></test>