-
Notifications
You must be signed in to change notification settings - Fork 18
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
7 changed files
with
132 additions
and
2 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 = "mutable-variables" | ||
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,9 @@ | ||
pub fn manipulate_variables() -> i32 { | ||
let mut x = 5; | ||
let mut y = 10; | ||
|
||
x += 10; | ||
y *= 2; | ||
|
||
x + y | ||
} |
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,14 @@ | ||
pub fn manipulate_variables() -> i32 { | ||
// Steps: | ||
// 1. Declare x as a mutable variable and assign it the value 5 | ||
|
||
// 2. Declare y as a mutable variable and assign it the value 10 | ||
|
||
// 3. Increment x by 10 | ||
|
||
// 4. Multiply y by 2 | ||
|
||
// 5. Calculate the sum of x and y | ||
|
||
// 6. Return the calculated sum | ||
} |
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,60 @@ | ||
#[cfg(test)] | ||
mod tests { | ||
use mutable_variables::*; | ||
use syntest::{LocalVariable, Mutation, Syntest, Value}; | ||
|
||
#[test] | ||
fn test_compiles() { | ||
manipulate_variables(); | ||
} | ||
|
||
#[test] | ||
fn test_variables() { | ||
let syntest = Syntest::from("./src/lib.rs"); | ||
|
||
// Expect the 2 variables to exist | ||
syntest | ||
.variables("manipulate_variables") | ||
.iter() | ||
.for_each(|var| match var { | ||
LocalVariable::Int { .. } => match var.name() { | ||
"x" => { | ||
assert_eq!( | ||
var.value(), | ||
Value::Int(15), | ||
"Expected x to be 15, got {}", | ||
var.value() | ||
); | ||
assert!(var.is_used(), "Expected x to be used"); | ||
assert!(var.is_mutable(), "Expected x to be mutable"); | ||
assert_eq!( | ||
var.mutations(), | ||
&vec![Mutation::new(Value::Int(5), Value::Int(15))], | ||
"Expected variable x to have a mutation from 5 to 15.", | ||
); | ||
} | ||
"y" => { | ||
assert_eq!( | ||
var.value(), | ||
Value::Int(20), | ||
"Expected y to be 20, got {}", | ||
var.value() | ||
); | ||
assert!(var.is_used(), "Expected y to be used"); | ||
assert!(var.is_mutable(), "Expected y to be mutable"); | ||
assert_eq!( | ||
var.mutations(), | ||
&vec![Mutation::new(Value::Int(10), Value::Int(20))], | ||
"Expected variable y to have a mutation from 10 to 20." | ||
); | ||
} | ||
_ => { | ||
panic!("Unexpected variable {}", var.name()) | ||
} | ||
}, | ||
_ => { | ||
panic!("Expected type to be an integer.") | ||
} | ||
}) | ||
} | ||
} |
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