Skip to content

Commit

Permalink
Add impl tests for self as a function argument and function return …
Browse files Browse the repository at this point in the history
…type

#617

PiperOrigin-RevId: 705138801
  • Loading branch information
erinzmoore authored and copybara-github committed Dec 11, 2024
1 parent 851ec27 commit 5f4e5e7
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions xls/dslx/tests/impl.x
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ struct Point { x: u32, y: u32 }

impl Point {
const MY_CONST = u32:5;

fn zero() -> Self { Point { x: u32:0, y: u32:0 } }

fn area(self: Self) -> u32 { self.x * self.y }
}

fn main() -> u32 { Point::MY_CONST }
Expand All @@ -25,3 +29,15 @@ fn use_impl_const() {
type PointAlias = Point;
assert_eq(PointAlias::MY_CONST, u32:5);
}

#[test]
fn test_area() {
let p = Point { x: u32:2, y: u32:4 };
assert_eq(p.area(), u32:8);
}

#[test]
fn test_zero() {
let p = Point::zero();
assert_eq(p.x, u32:0);
}

0 comments on commit 5f4e5e7

Please sign in to comment.