-
Notifications
You must be signed in to change notification settings - Fork 21
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
Showing
6 changed files
with
82 additions
and
3 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,7 @@ | ||
[package] | ||
name = "constants" | ||
version = "0.1.0" | ||
edition = "2021" | ||
|
||
[dev-dependencies] | ||
syntest = { path = "../../crates/syntest" } |
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 @@ | ||
const MAX_SIZE: i32 = 100; | ||
|
||
pub fn main() -> i32 { | ||
MAX_SIZE | ||
} |
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 @@ | ||
// Define a constant MAX_SIZE with a value of 100. | ||
// Your code here | ||
|
||
pub fn main() -> i32 { | ||
MAX_SIZE | ||
} |
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,42 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use constants::*; | ||
use syntest::Syntest; | ||
|
||
#[test] | ||
fn compiles() { | ||
assert_eq!(main(), 100, "Expected main() to return 100"); | ||
} | ||
|
||
#[test] | ||
fn test_constants() { | ||
let syntest = Syntest::from("./src/lib.rs"); | ||
|
||
let const_to_exist = ["MAX_SIZE"]; | ||
let constants = syntest.constant.constants(); | ||
|
||
let mut success = false; | ||
for const_name in const_to_exist.iter() { | ||
constants.iter().for_each(|con| { | ||
if con.ident.to_string() != *const_name { | ||
return; | ||
} | ||
|
||
assert_eq!( | ||
con.ty, | ||
syntest::parse_quote! { i32 }, | ||
"Expected type i32 for constant MAX_SIZE" | ||
); | ||
assert_eq!( | ||
con.expr, | ||
syntest::parse_quote! { 100 }, | ||
"Expected value 100 for constant MAX_SIZE" | ||
); | ||
|
||
success = true; | ||
}) | ||
} | ||
|
||
assert!(success, "Expected constant MAX_SIZE to exist"); | ||
} | ||
} |