-
Notifications
You must be signed in to change notification settings - Fork 29
Add tests for transit_model_procmacro #412
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -5,10 +5,22 @@ authors = ["Guillaume Pinot <[email protected]>"] | |
| license = "AGPL-3.0-only" | ||
| description = "A private procmacro crate for the transit_model crate" | ||
| edition = "2018" | ||
| autotests = false | ||
|
|
||
| [lib] | ||
| proc-macro = true | ||
|
|
||
| [dependencies] | ||
| syn = "0.11.11" | ||
| quote = "0.3.15" | ||
|
|
||
| [dev-dependencies] | ||
| pretty_assertions = "0.6" | ||
| trybuild = "1" | ||
| transit_model = { path = "../" } | ||
| transit_model_collection = { path = "../collection" } | ||
| transit_model_relations = { path = "../relations" } | ||
|
|
||
| [[test]] | ||
| name = "tests" | ||
| path = "tests/tests.rs" | ||
This file contains hidden or 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,82 @@ | ||
| use transit_model::objects::*; | ||
| use transit_model_collection::*; | ||
| use transit_model_procmacro::*; | ||
| use transit_model_relations::*; | ||
|
|
||
| #[derive(GetCorresponding)] | ||
| pub struct Model { | ||
| lines_to_routes: OneToMany<Line, Route>, | ||
| routes_to_vehicle_journeys: OneToMany<Route, VehicleJourney>, | ||
| } | ||
|
|
||
| fn main() { | ||
| let line = Line { | ||
| id: String::from("line_id"), | ||
| name: String::from("Line name"), | ||
| ..Default::default() | ||
| }; | ||
| let route1 = Route { | ||
| id: String::from("route_id_1"), | ||
| name: String::from("Route Name 1"), | ||
| line_id: String::from("line_id"), | ||
| ..Default::default() | ||
| }; | ||
| let route2 = Route { | ||
| id: String::from("route_id_2"), | ||
| name: String::from("Route Name 2"), | ||
| line_id: String::from("line_id"), | ||
| ..Default::default() | ||
| }; | ||
| let vehicle_journey_1 = VehicleJourney { | ||
| id: String::from("vehicle_journey_id_1"), | ||
| route_id: String::from("route_id_1"), | ||
| ..Default::default() | ||
| }; | ||
| let vehicle_journey_2 = VehicleJourney { | ||
| id: String::from("vehicle_journey_id_2"), | ||
| route_id: String::from("route_id_1"), | ||
| ..Default::default() | ||
| }; | ||
| let vehicle_journey_3 = VehicleJourney { | ||
| id: String::from("vehicle_journey_id_3"), | ||
| route_id: String::from("route_id_2"), | ||
| ..Default::default() | ||
| }; | ||
| let vehicle_journey_4 = VehicleJourney { | ||
| id: String::from("vehicle_journey_id_4"), | ||
| route_id: String::from("route_id_2"), | ||
| ..Default::default() | ||
| }; | ||
| let lines = CollectionWithId::from(line); | ||
| let routes = CollectionWithId::new(vec![route1, route2]).unwrap(); | ||
| let vehicle_journeys = CollectionWithId::new(vec![ | ||
| vehicle_journey_1, | ||
| vehicle_journey_2, | ||
| vehicle_journey_3, | ||
| vehicle_journey_4, | ||
| ]) | ||
| .unwrap(); | ||
| let model = Model { | ||
| lines_to_routes: OneToMany::new(&lines, &routes, "lines_to_routes").unwrap(), | ||
| routes_to_vehicle_journeys: OneToMany::new( | ||
| &routes, | ||
| &vehicle_journeys, | ||
| "routes_to_vehicle_journeys", | ||
| ) | ||
| .unwrap(), | ||
| }; | ||
|
|
||
| let line_idx = lines.get_idx("line_id").unwrap(); | ||
| let vehicle_journey_indexes = model.get_corresponding_from_idx(line_idx); | ||
| let vehicle_journey_1_idx = vehicle_journeys.get_idx("vehicle_journey_id_1").unwrap(); | ||
| assert!(vehicle_journey_indexes.contains(&vehicle_journey_1_idx)); | ||
| let vehicle_journey_2_idx = vehicle_journeys.get_idx("vehicle_journey_id_2").unwrap(); | ||
| assert!(vehicle_journey_indexes.contains(&vehicle_journey_2_idx)); | ||
| let vehicle_journey_3_idx = vehicle_journeys.get_idx("vehicle_journey_id_3").unwrap(); | ||
| assert!(vehicle_journey_indexes.contains(&vehicle_journey_3_idx)); | ||
| let vehicle_journey_4_idx = vehicle_journeys.get_idx("vehicle_journey_id_4").unwrap(); | ||
| assert!(vehicle_journey_indexes.contains(&vehicle_journey_4_idx)); | ||
|
|
||
| let line_indexes = model.get_corresponding_from_idx(vehicle_journey_1_idx); | ||
| assert!(line_indexes.contains(&line_idx)); | ||
| } |
This file contains hidden or 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,12 @@ | ||
| use transit_model::objects::*; | ||
| use transit_model_collection::*; | ||
| use transit_model_procmacro::*; | ||
| use transit_model_relations::*; | ||
|
|
||
| #[derive(GetCorresponding)] | ||
| pub struct Model { | ||
| #[get_corresponding(weight = "abc")] | ||
| lines_to_routes: OneToMany<Line, Route>, | ||
| } | ||
|
|
||
| fn main() {} |
This file contains hidden or 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,7 @@ | ||
| error: proc-macro derive panicked | ||
| --> $DIR/02-invalid-weight.rs:6:10 | ||
| | | ||
| 6 | #[derive(GetCorresponding)] | ||
| | ^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: message: `weight` attribute must be convertible to f64: ParseFloatError { kind: Invalid } |
12 changes: 12 additions & 0 deletions
12
transit_model_procmacro/tests/03-non-supported-argument.rs
This file contains hidden or 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,12 @@ | ||
| use transit_model::objects::*; | ||
| use transit_model_collection::*; | ||
| use transit_model_procmacro::*; | ||
| use transit_model_relations::*; | ||
|
|
||
| #[derive(GetCorresponding)] | ||
| pub struct Model { | ||
| #[get_corresponding(nonsupportedargument)] | ||
| lines_to_routes: OneToMany<Line, Route>, | ||
| } | ||
|
|
||
| fn main() {} |
7 changes: 7 additions & 0 deletions
7
transit_model_procmacro/tests/03-non-supported-argument.stderr
This file contains hidden or 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,7 @@ | ||
| error: proc-macro derive panicked | ||
| --> $DIR/03-non-supported-argument.rs:6:10 | ||
| | | ||
| 6 | #[derive(GetCorresponding)] | ||
| | ^^^^^^^^^^^^^^^^ | ||
| | | ||
| = help: message: Only `key = "value"` attributes supported. |
This file contains hidden or 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,7 @@ | ||
| #[test] | ||
| fn compile_error() { | ||
| let t = trybuild::TestCases::new(); | ||
| t.pass("tests/01-get-corresponding.rs"); | ||
| t.compile_fail("tests/02-invalid-weight.rs"); | ||
| t.compile_fail("tests/03-non-supported-argument.rs"); | ||
| } |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it's very painfull to release cyclic dependencies
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Even for
dev-dependencies?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
OK, so then, what do we do?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Will this change in
[email protected]help with the problem?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
according to the unit test yes