Skip to content

Commit

Permalink
Add testcase
Browse files Browse the repository at this point in the history
  • Loading branch information
garritfra committed Dec 10, 2024
1 parent e358cd5 commit e540ea0
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 7 deletions.
27 changes: 20 additions & 7 deletions examples/sandbox.sb
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
fn main() {
let number = 3
struct Point {
x: int
y: int
}

while number != 0 {
println(number)
struct Rectangle {
origin: Point
width: int
height: int
}

number = number - 1
fn test_nested_field_access() {
let rect = new Rectangle {
origin: new Point {
x: 10
y: 20
}
width: 100
height: 50
}

println("LIFTOFF!!!")
assert(rect.origin.x == 10)
rect.origin.x += 5
assert(rect.origin.x == 15)
}
26 changes: 26 additions & 0 deletions tests/structs.sb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ fn structs_main() {
test_method_call()
test_function_call_with_constructor()
test_method_with_self_statement()
test_nested_field_access()
}

struct User {
Expand Down Expand Up @@ -109,3 +110,28 @@ fn test_method_with_self_statement() {
let foo = new Self_test_struct { a: 5 }
foo.bar()
}

struct Point {
x: int
y: int
}

struct Rectangle {
origin: Point
width: int
height: int
}

fn test_nested_field_access() {
let rect = new Rectangle {
origin: new Point {
x: 10
y: 20
}
width: 100
height: 50
}
assert(rect.origin.x == 10)
rect.origin.x += 5
assert(rect.origin.x == 15)
}

0 comments on commit e540ea0

Please sign in to comment.