-
Notifications
You must be signed in to change notification settings - Fork 199
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore: add some tests for type aliases
- Loading branch information
1 parent
ec75e8e
commit 600ffeb
Showing
2 changed files
with
53 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,6 @@ | ||
#![cfg(test)] | ||
|
||
mod aliases; | ||
mod bound_checks; | ||
mod imports; | ||
mod metaprogramming; | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
use super::assert_no_errors; | ||
|
||
#[test] | ||
fn allows_usage_of_type_alias_as_argument_type() { | ||
let src = r#" | ||
type Foo = Field; | ||
fn accepts_a_foo(x: Foo) { | ||
assert_eq(x, 42); | ||
} | ||
fn main() { | ||
accepts_a_foo(42); | ||
} | ||
"#; | ||
assert_no_errors(src); | ||
} | ||
|
||
#[test] | ||
fn allows_usage_of_type_alias_as_return_type() { | ||
let src = r#" | ||
type Foo = Field; | ||
fn returns_a_foo() -> Foo { | ||
42 | ||
} | ||
fn main() { | ||
let _ = returns_a_foo(); | ||
} | ||
"#; | ||
assert_no_errors(src); | ||
} | ||
|
||
// This is a regression test for https://github.com/noir-lang/noir/issues/6347 | ||
#[test] | ||
#[should_panic = r#"ResolverError(Expected { span: Span(Span { start: ByteIndex(95), end: ByteIndex(98) }), expected: "type", got: "type alias" }"#] | ||
fn allows_destructuring_a_type_alias_of_a_struct() { | ||
let src = r#" | ||
struct Foo { | ||
inner: Field | ||
} | ||
type Bar = Foo; | ||
fn main() { | ||
let Bar { inner } = Foo { inner: 42 }; | ||
assert_eq(inner, 42); | ||
} | ||
"#; | ||
assert_no_errors(src); | ||
} |