summaryrefslogtreecommitdiffstats
path: root/tests/testsuite/time.rs
diff options
context:
space:
mode:
authorJohn Letey <30328854+johnletey@users.noreply.github.com>2019-09-10 18:54:40 +0100
committerKevin Song <chipbuster@users.noreply.github.com>2019-09-10 12:54:40 -0500
commitf9a45140459c9f155a2be46c2c51d3c186bb3175 (patch)
treeaf2d8a5a21d4261ca10c7ba37efc1b40ee7c2278 /tests/testsuite/time.rs
parent7d02f718c85834eed558d80fdecbebbb7f8513b0 (diff)
feat: Implement the prompt module for time (#138)
Add a module which displays the current time in a format requested by the user. Disabled by default.
Diffstat (limited to 'tests/testsuite/time.rs')
-rw-r--r--tests/testsuite/time.rs62
1 files changed, 62 insertions, 0 deletions
diff --git a/tests/testsuite/time.rs b/tests/testsuite/time.rs
new file mode 100644
index 000000000..c73545b26
--- /dev/null
+++ b/tests/testsuite/time.rs
@@ -0,0 +1,62 @@
+use ansi_term::Color;
+use std::fs;
+use std::io;
+use std::path::Path;
+use tempfile::TempDir;
+
+use crate::common::{self, TestCommand};
+
+/* Note: tests in this crate cannot rely on the actual time displayed by
+the module, since that is dependent on the time inside the test environment,
+which we cannot control.
+
+However, we *can* test certain things here, such as the fact that the module
+should not display when disabled, should display *something* when enabled,
+and should have the correct prefixes and suffixes in a given config */
+
+#[test]
+fn config_enabled() -> io::Result<()> {
+ let output = common::render_module("time")
+ .use_config(toml::toml! {
+ [time]
+ disabled = false
+ })
+ .output()?;
+ let actual = String::from_utf8(output.stdout).unwrap();
+
+ // We can't test what it actually is...but we can assert it's not blank
+ assert!(!actual.is_empty());
+ Ok(())
+}
+
+#[test]
+fn config_blank() -> io::Result<()> {
+ let output = common::render_module("time").output()?;
+ let actual = String::from_utf8(output.stdout).unwrap();
+
+ let expected = "";
+ assert_eq!(expected, actual);
+ Ok(())
+}
+
+#[test]
+fn config_check_prefix_and_suffix() -> io::Result<()> {
+ let output = common::render_module("time")
+ .use_config(toml::toml! {
+ [time]
+ disabled = false
+ format = "[%T]"
+ })
+ .output()?;
+ let actual = String::from_utf8(output.stdout).unwrap();
+
+ // This is the prefix with "at ", the color code, then the prefix char [
+ let col_prefix = format!("at {}{}[", '\u{1b}', "[1;33m");
+
+ // This is the suffix with suffix char ']', then color codes, then a space
+ let col_suffix = format!("]{}{} ", '\u{1b}', "[0m");
+
+ assert!(actual.starts_with(&col_prefix));
+ assert!(actual.ends_with(&col_suffix));
+ Ok(())
+}