Skip to content

Commit

Permalink
Add failing (on C backend) test for deep struct equality.
Browse files Browse the repository at this point in the history
  • Loading branch information
cpressey committed Feb 8, 2022
1 parent ded3519 commit 3f847d5
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
15 changes: 15 additions & 0 deletions eg/equality.castile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
struct name { first: string; last: string }
struct person { age: integer; name: name }

fun main() {
a = 40 as string|integer
b = 40 as string|integer
if a == b {
print("these union-type values are equal")
}
j = make person(age: 23, name:make name(first:"Bamber", last:"Smith"));
k = make person(age: 23, name:make name(first:"Bamber", last:"Smith"));
if j == k {
print("these deep struct-type values are equal")
}
}
7 changes: 0 additions & 7 deletions eg/struct-equality.castile

This file was deleted.

20 changes: 20 additions & 0 deletions tests/Castile.md
Original file line number Diff line number Diff line change
Expand Up @@ -807,6 +807,26 @@ Structs of two different types cannot be tested for equality.
| }
? mismatch

Deeply nested structs can be tested for equality.

| struct name { first: string; last: string }
| struct person { age: integer; name: name }
| main = fun() {
| j = make person(age: 23, name:make name(first:"Bamber", last:"Smith"));
| k = make person(age: 23, name:make name(first:"Bamber", last:"Smith"));
| j == k
| }
= True

| struct name { first: string; last: string }
| struct person { age: integer; name: name }
| main = fun() {
| j = make person(age: 23, name:make name(first:"Bamber", last:"Smith"));
| k = make person(age: 23, name:make name(first:"Amber", last:"Smith"));
| j != k
| }
= True

Structs cannot be compared for ordering.

| struct person { age: integer; name: string }
Expand Down

0 comments on commit 3f847d5

Please sign in to comment.