summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
Diffstat (limited to 'test')
-rw-r--r--test/c/eq_struct.expect1
-rw-r--r--test/c/eq_struct.sail38
2 files changed, 39 insertions, 0 deletions
diff --git a/test/c/eq_struct.expect b/test/c/eq_struct.expect
new file mode 100644
index 00000000..9766475a
--- /dev/null
+++ b/test/c/eq_struct.expect
@@ -0,0 +1 @@
+ok
diff --git a/test/c/eq_struct.sail b/test/c/eq_struct.sail
new file mode 100644
index 00000000..b4258569
--- /dev/null
+++ b/test/c/eq_struct.sail
@@ -0,0 +1,38 @@
+default Order dec
+
+$include <flow.sail>
+$include <exception_basic.sail>
+
+val eq = "eq_anything" : forall ('a : Type). ('a, 'a) -> bool
+
+overload operator == = {eq}
+
+val neq : forall ('a : Type). ('a, 'a) -> bool
+
+overload operator != = {neq}
+
+overload ~ = {not_bool}
+
+function neq(x, y) = ~(eq(x, y))
+
+struct S = {
+ field1: int,
+ field2: vector(8, dec, bit)
+}
+
+val "print" : string -> unit
+
+val main : unit -> unit effect {escape}
+
+function main() = {
+ let s : S = struct {
+ field1 = 4,
+ field2 = 0xFF
+ };
+ assert(s == s, "1");
+ assert(~(s == { s with field2 = 0xAB }), "2");
+ assert(s != { s with field1 = 5}, "3");
+ assert(s == { s with field2 = 0xFF });
+ assert({ s with field1 = 0} == {s with field1 = 0});
+ print("ok\n")
+} \ No newline at end of file