summary refs log tree commit diff stats
path: root/rust/semi-structured-logs/tests
diff options
context:
space:
mode:
authorAndinus <andinus@nand.sh>2021-09-29 09:43:51 +0530
committerAndinus <andinus@nand.sh>2021-09-29 09:43:51 +0530
commitd8a4756b35ce3576bc5027e166903610558cfeab (patch)
tree5b49c90e6428fe6914f2e9505d73faa1c80dd978 /rust/semi-structured-logs/tests
parent45fab565a31a535324a335fa96df8f010d855b5c (diff)
downloadexercism-d8a4756b35ce3576bc5027e166903610558cfeab.tar.gz
Rust: Semi Structured Logs: Add Solution
Diffstat (limited to 'rust/semi-structured-logs/tests')
-rw-r--r--rust/semi-structured-logs/tests/semi-structured-logs.rs47
1 files changed, 47 insertions, 0 deletions
diff --git a/rust/semi-structured-logs/tests/semi-structured-logs.rs b/rust/semi-structured-logs/tests/semi-structured-logs.rs
new file mode 100644
index 0000000..fc45208
--- /dev/null
+++ b/rust/semi-structured-logs/tests/semi-structured-logs.rs
@@ -0,0 +1,47 @@
+use semi_structured_logs::{error, info, log, warn, LogLevel};
+
+#[test]
+fn emits_info() {
+    assert_eq!(info("Timezone changed"), "[INFO]: Timezone changed");
+}
+
+#[test]
+fn emits_warning() {
+    assert_eq!(warn("Timezone not set"), "[WARNING]: Timezone not set");
+}
+
+#[test]
+fn emits_error() {
+    assert_eq!(error("Disk full"), "[ERROR]: Disk full");
+}
+
+#[test]
+fn log_emits_info() {
+    assert_eq!(
+        log(LogLevel::Info, "Timezone changed"),
+        "[INFO]: Timezone changed"
+    );
+}
+
+#[test]
+fn log_emits_warning() {
+    assert_eq!(
+        log(LogLevel::Warning, "Timezone not set"),
+        "[WARNING]: Timezone not set"
+    );
+}
+
+#[test]
+fn log_emits_error() {
+    assert_eq!(log(LogLevel::Error, "Disk full"), "[ERROR]: Disk full");
+}
+
+#[test]
+#[cfg(feature = "add-a-variant")]
+fn add_a_variant() {
+    // this test won't even compile until the enum is complete, which is why it is feature-gated.
+    assert_eq!(
+        log(LogLevel::Debug, "reached line 123"),
+        "[DEBUG]: reached line 123",
+    );
+}