-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add starting real goto definition tests
These tests are very incomplete, but they serve as a good basis for future work. commit-id:2d88cb6c
- Loading branch information
Showing
8 changed files
with
421 additions
and
27 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
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
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,28 @@ | ||
//! > Test goto definition of an enum variant. | ||
|
||
//! > test_runner_name | ||
test_goto_definition | ||
|
||
//! > cairo_code | ||
enum Foo { | ||
Bar, | ||
Baz, | ||
} | ||
|
||
fn main() { | ||
let foo = Foo::Ba<caret>r; | ||
match foo { | ||
Foo::Ba<caret>r => {} | ||
_ => {} | ||
} | ||
} | ||
|
||
//! > Goto definition #0 | ||
let foo = Foo::Ba<caret>r; | ||
--- | ||
<sel>Bar</sel>, | ||
|
||
//! > Goto definition #1 | ||
Foo::Ba<caret>r => {} | ||
--- | ||
<sel>Bar</sel>, |
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,17 @@ | ||
//! > Test goto definition on inline macro. | ||
|
||
//! > test_runner_name | ||
test_goto_definition | ||
|
||
//! > cairo_code | ||
// FIXME(#116): This is wrong. | ||
fn main() { | ||
prin<caret>t!("Hello, world!"); | ||
} | ||
|
||
//! > Goto definition #0 | ||
prin<caret>t!("Hello, world!"); | ||
--- | ||
<sel>fn main() { | ||
print!("Hello, world!"); | ||
}</sel> |
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,185 @@ | ||
//! > Test goto definition of a function. | ||
|
||
//! > test_runner_name | ||
test_goto_definition | ||
|
||
//! > cairo_code | ||
fn main() { | ||
fo<caret>o(); | ||
} | ||
|
||
fn foo() {} // good | ||
|
||
mod bar { | ||
fn foo() {} // bad | ||
} | ||
|
||
//! > Goto definition #0 | ||
fo<caret>o(); | ||
--- | ||
<sel>fn foo() {}</sel> // good | ||
|
||
//! > ========================================================================== | ||
|
||
//! > Test goto definition of a struct. | ||
|
||
//! > test_runner_name | ||
test_goto_definition | ||
|
||
//! > cairo_code | ||
struct Foo { | ||
field: felt252, | ||
} | ||
|
||
fn main() { | ||
let foo = Fo<caret>o { field: 0 }; | ||
} | ||
|
||
fn calc(foo: Fo<caret>o) {} | ||
|
||
//! > Goto definition #0 | ||
let foo = Fo<caret>o { field: 0 }; | ||
--- | ||
<sel>struct Foo { | ||
field: felt252, | ||
}</sel> | ||
|
||
//! > Goto definition #1 | ||
fn calc(foo: Fo<caret>o) {} | ||
--- | ||
<sel>struct Foo { | ||
field: felt252, | ||
}</sel> | ||
|
||
//! > ========================================================================== | ||
|
||
//! > Test goto definition of an enum. | ||
|
||
//! > test_runner_name | ||
test_goto_definition | ||
|
||
//! > cairo_code | ||
enum Foo { | ||
Bar, | ||
Baz, | ||
} | ||
|
||
fn main() { | ||
let foo = Fo<caret>o::Bar; | ||
} | ||
|
||
fn calc(foo: Fo<caret>o) {} | ||
|
||
//! > Goto definition #0 | ||
let foo = Fo<caret>o::Bar; | ||
--- | ||
<sel>enum Foo { | ||
Bar, | ||
Baz, | ||
}</sel> | ||
|
||
//! > Goto definition #1 | ||
fn calc(foo: Fo<caret>o) {} | ||
--- | ||
<sel>enum Foo { | ||
Bar, | ||
Baz, | ||
}</sel> | ||
|
||
//! > ========================================================================== | ||
|
||
//! > Test goto definition with traits. | ||
|
||
//! > test_runner_name | ||
test_goto_definition | ||
|
||
//! > cairo_code | ||
pub trait ShapeGeometry<T> { | ||
fn boundary(self: T) -> u64; | ||
fn area(self: T) -> u64; | ||
} | ||
|
||
mod rectangle { | ||
use super::Sha<caret>peGeometry; | ||
|
||
#[derive(Copy, Drop)] | ||
pub struct Rectangle { | ||
pub height: u64, | ||
pub width: u64, | ||
} | ||
|
||
impl RectangleGeometry of ShapeGe<caret>ometry<Recta<caret>ngle> { | ||
fn boun<caret>dary(self: Recta<caret>ngle) -> u64 { | ||
2 * (self.height + self.width) | ||
} | ||
fn area(self: Rectangle) -> u64 { | ||
self.height * self.width | ||
} | ||
} | ||
} | ||
|
||
use rectangle::Rectangle; | ||
|
||
fn main() { | ||
let rect = Rectangle { height: 5, width: 7 }; | ||
let area = ShapeGeo<caret>metry::ar<caret>ea(rect); | ||
} | ||
|
||
//! > Goto definition #0 | ||
use super::Sha<caret>peGeometry; | ||
--- | ||
<sel>pub trait ShapeGeometry<T> { | ||
fn boundary(self: T) -> u64; | ||
fn area(self: T) -> u64; | ||
}</sel> | ||
|
||
//! > Goto definition #1 | ||
impl RectangleGeometry of ShapeGe<caret>ometry<Rectangle> { | ||
--- | ||
<sel>pub trait ShapeGeometry<T> { | ||
fn boundary(self: T) -> u64; | ||
fn area(self: T) -> u64; | ||
}</sel> | ||
|
||
//! > Goto definition #2 | ||
impl RectangleGeometry of ShapeGeometry<Recta<caret>ngle> { | ||
--- | ||
<sel>#[derive(Copy, Drop)] | ||
pub struct Rectangle { | ||
pub height: u64, | ||
pub width: u64, | ||
}</sel> | ||
|
||
//! > Goto definition #3 | ||
fn boun<caret>dary(self: Rectangle) -> u64 { | ||
--- | ||
<sel>impl RectangleGeometry of ShapeGeometry<Rectangle> { | ||
fn boundary(self: Rectangle) -> u64 { | ||
2 * (self.height + self.width) | ||
} | ||
fn area(self: Rectangle) -> u64 { | ||
self.height * self.width | ||
} | ||
}</sel> | ||
|
||
//! > Goto definition #4 | ||
fn boundary(self: Recta<caret>ngle) -> u64 { | ||
--- | ||
<sel>#[derive(Copy, Drop)] | ||
pub struct Rectangle { | ||
pub height: u64, | ||
pub width: u64, | ||
}</sel> | ||
|
||
//! > Goto definition #5 | ||
let area = ShapeGeo<caret>metry::area(rect); | ||
--- | ||
<sel>pub trait ShapeGeometry<T> { | ||
fn boundary(self: T) -> u64; | ||
fn area(self: T) -> u64; | ||
}</sel> | ||
|
||
//! > Goto definition #6 | ||
let area = ShapeGeometry::ar<caret>ea(rect); | ||
--- | ||
<sel>fn area(self: T) -> u64;</sel> |
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,64 @@ | ||
//! > Test goto definition of a module. | ||
|
||
//! > test_runner_name | ||
test_goto_definition | ||
|
||
//! > cairo_code | ||
fn main() { | ||
modu<caret>le::ba<caret>r::foo(); | ||
} | ||
|
||
mod module { | ||
// good | ||
mod module { | ||
// bad | ||
} | ||
|
||
mod bar { // good | ||
fn foo() {} | ||
} | ||
} | ||
|
||
//! > Goto definition #0 | ||
modu<caret>le::bar::foo(); | ||
--- | ||
mod module <sel>{ | ||
// good | ||
mod module { | ||
// bad | ||
} | ||
|
||
mod bar { // good | ||
fn foo() {} | ||
} | ||
}</sel> | ||
|
||
//! > Goto definition #1 | ||
module::ba<caret>r::foo(); | ||
--- | ||
mod bar <sel>{ // good | ||
fn foo() {} | ||
}</sel> | ||
|
||
//! > ========================================================================== | ||
|
||
//! > Test goto definition of a function in a submodule. | ||
|
||
//! > test_runner_name | ||
test_goto_definition | ||
|
||
//! > cairo_code | ||
fn main() { | ||
module::fo<caret>o(); | ||
} | ||
|
||
fn foo() {} // bad | ||
|
||
mod module { | ||
fn foo() {} // good | ||
} | ||
|
||
//! > Goto definition #0 | ||
module::fo<caret>o(); | ||
--- | ||
<sel>fn foo() {}</sel> // good |
Oops, something went wrong.