Skip to content

Commit 167db9c

Browse files
committed
End-to-end tests for unions
1 parent 69e2014 commit 167db9c

File tree

4 files changed

+28
-3
lines changed

4 files changed

+28
-3
lines changed

tests/samples/Union.c

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "Union.h"
2+
#include <stdlib.h>
3+
4+
union values *getValues() {
5+
union values *myValues = malloc(sizeof(union values));
6+
myValues->a = 10;
7+
return myValues;
8+
}

tests/samples/Union.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
union point {
1+
union values {
22
long a;
33
int b;
44
long long c;
55
};
6+
7+
union values *getValues();

tests/samples/Union.scala

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,14 +6,15 @@ import scala.scalanative.native._
66
@native.link("bindgentests")
77
@native.extern
88
object Union {
9-
type union_point = native.CArray[Byte, native.Nat.Digit[native.Nat._6, native.Nat._4]]
9+
type union_values = native.CArray[Byte, native.Nat.Digit[native.Nat._6, native.Nat._4]]
10+
def getValues(): native.Ptr[union_values] = native.extern
1011
}
1112

1213
import Union._
1314

1415
object UnionHelpers {
1516

16-
implicit class union_point_pos(val p: native.Ptr[union_point]) extends AnyVal {
17+
implicit class union_values_pos(val p: native.Ptr[union_values]) extends AnyVal {
1718
def a: native.Ptr[native.CLong] = p.cast[native.Ptr[native.CLong]]
1819
def a_=(value: native.CLong): Unit = !p.cast[native.Ptr[native.CLong]] = value
1920
def b: native.Ptr[native.CInt] = p.cast[native.Ptr[native.CInt]]
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package org.scalanative.bindgen.samples
2+
3+
import utest._
4+
import scala.scalanative.native._
5+
import org.scalanative.bindgen.samples.UnionHelpers._
6+
7+
object UnionTests extends TestSuite {
8+
val tests = Tests {
9+
'getValues - {
10+
val point = Union.getValues()
11+
assert(point.a == 10)
12+
}
13+
}
14+
}

0 commit comments

Comments
 (0)