summary refs log tree commit diff stats
path: root/tests/js/testobjs.nim
diff options
context:
space:
mode:
authorjuxiliary <juxiliary@gmail.com>2014-12-06 21:57:20 +1000
committerjuxiliary <juxiliary@gmail.com>2014-12-06 21:57:20 +1000
commitcd0f17202ee167c0ec0db2bb497d1c4554655abd (patch)
treef2e8b4b7a3c5e3dee91c6d1791d06e7529e735f4 /tests/js/testobjs.nim
parent898501d9d1973a0ac1571a9e34c33f47e36d6c8a (diff)
downloadNim-cd0f17202ee167c0ec0db2bb497d1c4554655abd.tar.gz
Fixing extraneous semicolon in jsgen output
jsgen was producing javascript objects like this
```
{, name:"foo"}
```
causing syntax errors in javascript interpretors.
Diffstat (limited to 'tests/js/testobjs.nim')
-rw-r--r--tests/js/testobjs.nim34
1 files changed, 34 insertions, 0 deletions
diff --git a/tests/js/testobjs.nim b/tests/js/testobjs.nim
new file mode 100644
index 000000000..4fb9a83dc
--- /dev/null
+++ b/tests/js/testobjs.nim
@@ -0,0 +1,34 @@
+## Tests javascript object generation
+
+type
+  Kg = distinct float
+  Price = int
+  Item = object of RootObj
+    weight: Kg
+    price: Price
+    desc: cstring
+  Person = object of RootObj
+    name: cstring
+    age: int
+    item: Item
+  Test = object
+    name: cstring
+  Recurse[T] = object
+    data: T
+    next: ref Recurse[T]
+
+var
+  test = Test(name: "Jorden")
+  sword = Item(desc: "pointy", weight: Kg(10.0),
+                price: Price(50))
+  knight = Person(name: "robert", age: 19, item: sword)
+  recurse4 = (ref Recurse[int])(data: 4, next: nil)
+  recurse3 = (ref Recurse[int])(data: 3, next: recurse4)
+  recurse2 = (ref Recurse[int])(data: 2, next: recurse3)
+  recurse1 = Recurse[int](data: 1, next: recurse2)
+
+
+assert(test.name == "Jorden")
+assert(knight.age == 19)
+assert(knight.item.price == 50)
+assert(recurse1.next.next.data == 3)