summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--CLI/rust/Cargo.lock33
-rw-r--r--CLI/rust/Cargo.toml1
-rw-r--r--CLI/rust/src/game_of_life/generators/input.rs67
3 files changed, 101 insertions, 0 deletions
diff --git a/CLI/rust/Cargo.lock b/CLI/rust/Cargo.lock
index 1c71ee6..07cfd26 100644
--- a/CLI/rust/Cargo.lock
+++ b/CLI/rust/Cargo.lock
@@ -1,6 +1,15 @@
# This file is automatically @generated by Cargo.
# It is not intended for manual editing.
[[package]]
+name = "aho-corasick"
+version = "0.7.15"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "7404febffaa47dac81aa44dba71523c9d069b1bdc50a77db41195149e17f68e5"
+dependencies = [
+ "memchr",
+]
+
+[[package]]
name = "atty"
version = "0.2.14"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -69,6 +78,7 @@ dependencies = [
"clap",
"mocktopus",
"rand",
+ "regex",
"terminal_size",
]
@@ -130,6 +140,12 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1482821306169ec4d07f6aca392a4681f66c75c9918aa49641a2595db64053cb"
[[package]]
+name = "memchr"
+version = "2.3.4"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "0ee1c47aaa256ecabcaea351eae4a9b01ef39ed810004e298d2511ed284b1525"
+
+[[package]]
name = "mocktopus"
version = "0.7.10"
source = "registry+https://github.com/rust-lang/crates.io-index"
@@ -244,6 +260,23 @@ dependencies = [
]
[[package]]
+name = "regex"
+version = "1.4.5"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "957056ecddbeba1b26965114e191d2e8589ce74db242b6ea25fc4062427a5c19"
+dependencies = [
+ "aho-corasick",
+ "memchr",
+ "regex-syntax",
+]
+
+[[package]]
+name = "regex-syntax"
+version = "0.6.23"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "24d5f089152e60f62d28b835fbff2cd2e8dc0baf1ac13343bef92ab7eed84548"
+
+[[package]]
name = "strsim"
version = "0.10.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
diff --git a/CLI/rust/Cargo.toml b/CLI/rust/Cargo.toml
index a741a3d..752c526 100644
--- a/CLI/rust/Cargo.toml
+++ b/CLI/rust/Cargo.toml
@@ -7,6 +7,7 @@ edition = "2018"
[dependencies]
clap = { version = "3.0.0-beta.2", features = ["wrap_help"] }
rand = "0.8.3"
+regex = "1.4.5"
terminal_size = "0.1.16"
[dev-dependencies]
diff --git a/CLI/rust/src/game_of_life/generators/input.rs b/CLI/rust/src/game_of_life/generators/input.rs
index 1f10a22..c2b2bb0 100644
--- a/CLI/rust/src/game_of_life/generators/input.rs
+++ b/CLI/rust/src/game_of_life/generators/input.rs
@@ -1,5 +1,6 @@
use crate::game_of_life::opts::Opts;
use crate::game_of_life::universe::Universe;
+use regex::Regex;
#[cfg(test)]
use mocktopus::macros::mockable;
@@ -12,5 +13,71 @@ use mocktopus::macros::mockable;
/// used as the seeding input
#[cfg_attr(test, mockable)]
pub(crate) fn new(opts: Opts) -> Universe {
+ let input = opts.input.clone().unwrap();
+ match Regex::new("^(ht|f)?tp(s)?://*").unwrap().is_match(&input) {
+ true => generate_url_data(opts),
+ false => generate_file_data(opts),
+ }
+}
+
+#[cfg(test)]
+mod new {
+ use super::*;
+ use mocktopus::mocking::*;
+
+ fn universe_mock(opts: Opts) -> Universe {
+ Universe {
+ opts,
+ current: vec![vec![]],
+ future: vec![vec![]],
+ }
+ }
+
+ #[test]
+ fn with_url() {
+ let opts = Opts {
+ seed: 1337,
+ input: Some(String::from("https://example.com")),
+ width: 13,
+ height: 13,
+ live_cell: 'L',
+ dead_cell: 'D',
+ delay: 13,
+ };
+
+ generate_file_data.mock_safe(|_| panic!());
+ generate_url_data.mock_safe(|opts| MockResult::Return(universe_mock(opts)));
+ assert_eq!(new(opts.clone()), universe_mock(opts.clone()));
+ }
+
+ #[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,
+ };
+
+ generate_file_data.mock_safe(|opts| MockResult::Return(universe_mock(opts)));
+ generate_url_data.mock_safe(|_| panic!());
+ assert_eq!(new(opts.clone()), universe_mock(opts.clone()));
+ }
+}
+
+/// Reads a local file and parses it, converting alpha-numerical chars into living cells
+/// in a newly generated universe simulation
+#[cfg_attr(test, mockable)]
+fn generate_file_data(_opts: Opts) -> Universe {
+ unimplemented!()
+}
+
+/// Reads a URL and parses it, converting alpha-numerical chars into living cells
+/// in a newly generated universe simulation
+#[cfg_attr(test, mockable)]
+fn generate_url_data(_opts: Opts) -> Universe {
unimplemented!()
}