summary refs log tree commit diff stats
path: root/tests/objects
diff options
context:
space:
mode:
authorAudun Wilhelmsen <skyfex@gmail.com>2014-03-18 21:11:57 +0100
committerAudun Wilhelmsen <skyfex@gmail.com>2014-03-18 21:11:57 +0100
commit1e45bb79ab4beb7a027b403bd78e879975b09963 (patch)
tree909f3eec08e3ffc255d2cbaf067df38e5d6fec17 /tests/objects
parent261a6ca0179c98559d62d2f56be15cedaffeda0a (diff)
downloadNim-1e45bb79ab4beb7a027b403bd78e879975b09963.tar.gz
Added support for {.packed.} pragma on objects
Added tests for packed and union pragmas
Diffstat (limited to 'tests/objects')
-rw-r--r--tests/objects/tobjpragma.nim49
1 files changed, 49 insertions, 0 deletions
diff --git a/tests/objects/tobjpragma.nim b/tests/objects/tobjpragma.nim
new file mode 100644
index 000000000..f9fbd5e40
--- /dev/null
+++ b/tests/objects/tobjpragma.nim
@@ -0,0 +1,49 @@
+discard """
+  file: "tobjpragma.nim"
+  output: '''2
+3
+9
+257
+1
+2
+3'''
+"""
+
+# Test 
+
+type
+  Foo {.packed.} = object
+    a: int8
+    b: int8
+
+  Bar {.packed.} = object
+    a: int8
+    b: int16   
+    
+  Daz {.packed.} = object
+    a: int32
+    b: int8 
+    c: int32  
+
+
+var f = Foo(a: 1, b: 1)
+var b: Bar
+var d: Daz
+
+echo sizeof(f)
+echo sizeof(b)
+echo sizeof(d)
+echo (cast[ptr int16](f.addr)[])
+
+type
+  Union {.union.} = object
+    a: int8
+    b: int8
+
+var u: Union
+u.a = 1
+echo u.b
+u.a = 2
+echo u.b
+u.b = 3
+echo u.a