forked from tokio-rs/prost
-
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.
- Loading branch information
1 parent
7c04d97
commit 4bd5337
Showing
12 changed files
with
198 additions
and
1 deletion.
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,61 @@ | ||
use self::proto::image::Image; | ||
use self::proto::post::content::post_content_fragment; | ||
use self::proto::post::content::PostContentFragment; | ||
use self::proto::post::Post; | ||
use self::proto::user::User; | ||
use self::proto::Timestamp; | ||
|
||
mod proto { | ||
include!(concat!(env!("OUT_DIR"), "/complex_package_structure/__.rs")); | ||
} | ||
|
||
#[test] | ||
fn it_works() { | ||
let user = User { | ||
id: "69a4cd96-b956-4fb1-9a97-b222eac33b8a".to_string(), | ||
name: "Test User".to_string(), | ||
created_at: Some(Timestamp { | ||
seconds: 1710366135, | ||
nanos: 0, | ||
}), | ||
..User::default() | ||
}; | ||
let posts = vec![ | ||
Post::default(), | ||
Post { | ||
id: "aa1e751f-e287-4c6e-aa0f-f838f96a1a60".to_string(), | ||
author: Some(user), | ||
content: vec![ | ||
PostContentFragment { | ||
content: Some(post_content_fragment::Content::Text( | ||
"Hello, world!".to_string(), | ||
)), | ||
}, | ||
PostContentFragment { | ||
content: Some(post_content_fragment::Content::Image(Image { | ||
name: "doggo.jpg".to_string(), | ||
description: Some("A dog".to_string()), | ||
data: vec![0, 1, 2, 3], | ||
})), | ||
}, | ||
PostContentFragment { | ||
content: Some(post_content_fragment::Content::Link( | ||
"https://example.com".to_string(), | ||
)), | ||
}, | ||
], | ||
..Post::default() | ||
}, | ||
Post::default(), | ||
]; | ||
assert_eq!(posts.len(), 3); | ||
assert_eq!(posts[1].content.len(), 3); | ||
if let PostContentFragment { | ||
content: Some(post_content_fragment::Content::Image(Image { name, .. })), | ||
} = &posts[1].content[1] | ||
{ | ||
assert_eq!(name, "doggo.jpg"); | ||
} else { | ||
assert!(false, "Expected an image") | ||
} | ||
} |
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,3 @@ | ||
[*] | ||
ij_protobuf_keep_blank_lines_in_code = 0 | ||
insert_final_newline = true |
13 changes: 13 additions & 0 deletions
13
tests/src/complex_package_structure/proto/post/content.proto
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,13 @@ | ||
syntax = "proto3"; | ||
|
||
package post.content; | ||
|
||
import "wrong/image.proto"; | ||
|
||
message PostContentFragment { | ||
oneof content { | ||
string text = 1; | ||
image.Image image = 2; | ||
string link = 3; | ||
} | ||
} |
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 @@ | ||
syntax = "proto3"; | ||
|
||
package post; | ||
|
||
import "std/time.proto"; | ||
import "user/user.proto"; | ||
import "post/content.proto"; | ||
|
||
message Post { | ||
string id = 1; | ||
string title = 2; | ||
reserved 3; | ||
user.User author = 4; | ||
Timestamp created_at = 5; | ||
Timestamp updated_at = 6; | ||
repeated content.PostContentFragment content = 7; | ||
} |
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,6 @@ | ||
syntax = "proto3"; | ||
|
||
message Timestamp { | ||
int64 seconds = 1; | ||
int32 nanos = 2; | ||
} |
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,13 @@ | ||
syntax = "proto3"; | ||
|
||
package user; | ||
|
||
import "std/time.proto"; | ||
|
||
message User { | ||
string id = 1; | ||
Timestamp created_at = 2; | ||
Timestamp updated_at = 3; | ||
string name = 4; | ||
string email = 5; | ||
} |
12 changes: 12 additions & 0 deletions
12
tests/src/complex_package_structure/proto/wrong/image.proto
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,12 @@ | ||
// This file makes sure that the file path of the proto file has nothing to do with the package name, | ||
// therefore testing the validity of write_includes. | ||
|
||
syntax = "proto3"; | ||
|
||
package image; | ||
|
||
message Image { | ||
string name = 1; | ||
optional string description = 2; | ||
bytes data = 3; | ||
} |
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,5 @@ | ||
syntax = "proto3"; | ||
|
||
message NoPackageWithMessageExampleMsg { | ||
string some_field = 1; | ||
} |
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,11 @@ | ||
mod proto { | ||
include!(concat!(env!("OUT_DIR"), "/no_package/_includes.rs")); | ||
} | ||
|
||
#[test] | ||
fn it_works() { | ||
assert_eq!( | ||
proto::NoPackageWithMessageExampleMsg::default(), | ||
proto::NoPackageWithMessageExampleMsg::default() | ||
); | ||
} |