summaryrefslogtreecommitdiffstats
path: root/CLI/rust
diff options
context:
space:
mode:
authora14m <[email protected]>2021-04-05 23:00:42 +0200
committera14m <[email protected]>2021-04-05 23:00:42 +0200
commitacb43997d5581b9c72d4a27db28f11406b86ed7a (patch)
tree9843cfd8ddbf12f3c1f26720cb8b2106e94babc0 /CLI/rust
parentef2287c2de5be59d20da679443353abedf01fb1c (diff)
DRY testing with opts configurable object
Diffstat (limited to 'CLI/rust')
-rw-r--r--CLI/rust/src/game_of_life/generators/input.rs26
1 files changed, 10 insertions, 16 deletions
diff --git a/CLI/rust/src/game_of_life/generators/input.rs b/CLI/rust/src/game_of_life/generators/input.rs
index ee41de5..07ab43a 100644
--- a/CLI/rust/src/game_of_life/generators/input.rs
+++ b/CLI/rust/src/game_of_life/generators/input.rs
@@ -34,18 +34,21 @@ mod new {
}
}
- #[test]
- fn with_url() {
- let opts = Opts {
- seed: 1337,
- input: Some(String::from("https://example.com")),
+ fn opts(input: Option<String>) -> Opts {
+ Opts {
+ input,
width: 13,
height: 13,
+ seed: 1337,
live_cell: 'L',
dead_cell: 'D',
delay: 13,
- };
+ }
+ }
+ #[test]
+ fn with_url() {
+ let opts = opts(Some(String::from("https://example.com")));
generate_file_data.mock_safe(|_| panic!());
generate_url_data.mock_safe(|opts| MockResult::Return(Ok(universe_mock(opts))));
let universe = new(opts.clone()).unwrap();
@@ -54,16 +57,7 @@ mod new {
#[test]
fn with_file() {
- let opts = Opts {
- seed: 1337,
- input: Some(String::from("./example.txt")),
- width: 13,
- height: 13,
- live_cell: 'L',
- dead_cell: 'D',
- delay: 13,
- };
-
+ let opts = opts(Some(String::from("./example.txt")));
generate_file_data.mock_safe(|opts| MockResult::Return(Ok(universe_mock(opts))));
generate_url_data.mock_safe(|_| panic!());
let universe = new(opts.clone()).unwrap();