-
Notifications
You must be signed in to change notification settings - Fork 431
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
07cd528
commit 1f002a4
Showing
4 changed files
with
125 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 |
---|---|---|
@@ -0,0 +1,54 @@ | ||
load( | ||
"//rust:rust.bzl", | ||
"rust_doc_test", | ||
"rust_library", | ||
"rust_test", | ||
) | ||
|
||
rust_library( | ||
name = "mod1", | ||
srcs = ["mod1.rs"], | ||
) | ||
|
||
rust_library( | ||
name = "mod2", | ||
srcs = ["mod2.rs"], | ||
deps = [":mod1"], | ||
) | ||
|
||
rust_library( | ||
name = "mod3", | ||
srcs = ["mod3.rs"], | ||
aliases = { | ||
":mod1": "alias_a", | ||
":mod2": "alias_b", | ||
}, | ||
deps = [ | ||
":mod1", | ||
":mod2", | ||
], | ||
) | ||
|
||
rust_test( | ||
name = "mod1_test", | ||
crate = ":mod1", | ||
) | ||
|
||
rust_test( | ||
name = "mod2_test", | ||
crate = ":mod2", | ||
) | ||
|
||
rust_test( | ||
name = "mod3_test", | ||
crate = ":mod3", | ||
aliases = { | ||
":mod1": "alias_a", | ||
":mod2": "alias_b", | ||
}, | ||
) | ||
|
||
rust_doc_test( | ||
name = "mod3_doc_test", | ||
dep = ":mod3", | ||
) |
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 @@ | ||
pub fn world() -> String { | ||
"world".to_owned() | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
#[test] | ||
fn test_world() { | ||
assert_eq!(super::world(), "world"); | ||
} | ||
} |
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,22 @@ | ||
extern crate mod1; | ||
|
||
pub fn greeter(name: &str) -> String { | ||
format!("Hello, {}!", name) | ||
} | ||
|
||
pub fn default_greeter() -> String { | ||
greeter(&mod1::world()) | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
#[test] | ||
fn test_greeter() { | ||
assert_eq!(super::greeter("Bob"), "Hello, Bob!"); | ||
} | ||
|
||
#[test] | ||
fn test_default_greeter() { | ||
assert_eq!(super::default_greeter(), "Hello, world!"); | ||
} | ||
} |
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,38 @@ | ||
// This crate depends on 2 crates with one of them depending on the other one. | ||
// If the crates are not set correctly in the dependency chain, this crate won't | ||
// compile. The order of the `extern crate` is important to trigger that bug. | ||
extern crate alias_a; | ||
extern crate alias_b; | ||
|
||
pub fn greet(name: &str) { | ||
println!("{}", alias_b::greeter(name)) | ||
} | ||
|
||
pub fn greet_default() { | ||
println!("{}", alias_b::default_greeter()) | ||
} | ||
|
||
/// This is a documentation. | ||
/// | ||
/// # Examples | ||
/// | ||
/// ```rust | ||
/// assert!( | ||
/// mod3::am_i_the_world("world") == true | ||
/// ); | ||
/// assert!( | ||
/// mod3::am_i_the_world("myself") == false | ||
/// ); | ||
/// ``` | ||
pub fn am_i_the_world(me: &str) -> bool { | ||
return me == alias_a::world(); | ||
} | ||
|
||
#[cfg(test)] | ||
mod test { | ||
#[test] | ||
fn test_am_i_the_world() { | ||
assert!(super::am_i_the_world("world")); | ||
assert!(!super::am_i_the_world("bob")); | ||
} | ||
} |