summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--rust/theBook/chapter-11-writing-automated-tests/adder/Cargo.toml8
-rw-r--r--rust/theBook/chapter-11-writing-automated-tests/adder/src/lib.rs51
-rw-r--r--rust/theBook/chapter-12-command-line-project/minigrep/Cargo.toml8
-rw-r--r--rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs6
4 files changed, 73 insertions, 0 deletions
diff --git a/rust/theBook/chapter-11-writing-automated-tests/adder/Cargo.toml b/rust/theBook/chapter-11-writing-automated-tests/adder/Cargo.toml
new file mode 100644
index 0000000..b7d36d4
--- /dev/null
+++ b/rust/theBook/chapter-11-writing-automated-tests/adder/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "adder"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/rust/theBook/chapter-11-writing-automated-tests/adder/src/lib.rs b/rust/theBook/chapter-11-writing-automated-tests/adder/src/lib.rs
new file mode 100644
index 0000000..55c024c
--- /dev/null
+++ b/rust/theBook/chapter-11-writing-automated-tests/adder/src/lib.rs
@@ -0,0 +1,51 @@
+#[derive(Debug)]
+struct Rectangle {
+ width: u32,
+ height: u32,
+}
+
+impl Rectangle {
+ fn can_hold(&self, other: &Rectangle) -> bool {
+ self.width >= other.width && self.height >= other.height
+ }
+}
+
+pub fn greeting(name: &str) -> String {
+ format!("hello {}!", name)
+}
+
+#[cfg(test)]
+mod tests {
+ use super::*;
+
+ #[test]
+ fn exception() {
+ let result = 2+2;
+ assert_eq!(result, 4);
+ }
+ #[test]
+ fn another() {
+ println!("this one will fail");
+ }
+
+ #[test]
+ fn hold() {
+ let larger = Rectangle {
+ width: 7,
+ height: 8,
+ };
+
+ let smaller = Rectangle {
+ width: 5,
+ height: 4,
+ };
+
+ assert!(larger.can_hold(&smaller));
+ }
+
+ #[test]
+ fn greeting_contain_names() {
+ let result = greeting("caol");
+ assert!(result.contains("carol"), "gretting did not contain name, the value is {}", result);
+ }
+}
diff --git a/rust/theBook/chapter-12-command-line-project/minigrep/Cargo.toml b/rust/theBook/chapter-12-command-line-project/minigrep/Cargo.toml
new file mode 100644
index 0000000..a256566
--- /dev/null
+++ b/rust/theBook/chapter-12-command-line-project/minigrep/Cargo.toml
@@ -0,0 +1,8 @@
+[package]
+name = "minigrep"
+version = "0.1.0"
+edition = "2021"
+
+# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
+
+[dependencies]
diff --git a/rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs b/rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs
new file mode 100644
index 0000000..ae7def5
--- /dev/null
+++ b/rust/theBook/chapter-12-command-line-project/minigrep/src/main.rs
@@ -0,0 +1,6 @@
+use std::env;
+
+fn main() {
+ let args: Vec<String> = env::args().collect();
+ dbg!(args);
+}