2020-11-23 06:12:26 +01:00
|
|
|
// ██████╗ █████╗ ███████╗███████╗██╗███╗ ██╗ ██████╗
|
|
|
|
// ██╔══██╗██╔══██╗██╔════╝██╔════╝██║████╗ ██║██╔════╝
|
|
|
|
// ██████╔╝███████║███████╗███████╗██║██╔██╗ ██║██║ ███╗
|
|
|
|
// ██╔═══╝ ██╔══██║╚════██║╚════██║██║██║╚██╗██║██║ ██║
|
|
|
|
// ██║ ██║ ██║███████║███████║██║██║ ╚████║╚██████╔╝
|
|
|
|
// ╚═╝ ╚═╝ ╚═╝╚══════╝╚══════╝╚═╝╚═╝ ╚═══╝ ╚═════╝
|
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod passing {
|
|
|
|
use assert_cmd::prelude::*;
|
|
|
|
use std::env;
|
|
|
|
use std::process::Command;
|
|
|
|
|
|
|
|
#[test]
|
2021-03-16 07:10:50 +01:00
|
|
|
fn add_new_when_provided() {
|
|
|
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
2020-11-23 06:12:26 +01:00
|
|
|
let out = cmd
|
|
|
|
.arg("-M")
|
|
|
|
.arg("-b")
|
|
|
|
.arg("http://localhost:8000/")
|
|
|
|
.arg("data:text/html,Hello%2C%20World!")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
// STDERR should be empty
|
|
|
|
assert_eq!(String::from_utf8_lossy(&out.stderr), "");
|
|
|
|
|
2020-11-23 06:12:26 +01:00
|
|
|
// STDOUT should contain newly added base URL
|
|
|
|
assert_eq!(
|
2021-06-08 14:30:15 +02:00
|
|
|
String::from_utf8_lossy(&out.stdout),
|
2020-11-23 06:12:26 +01:00
|
|
|
"<html><head>\
|
|
|
|
<base href=\"http://localhost:8000/\"></base>\
|
|
|
|
</head><body>Hello, World!</body></html>\n"
|
|
|
|
);
|
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
// Exit code should be 0
|
2020-11-23 06:12:26 +01:00
|
|
|
out.assert().code(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-03-16 07:10:50 +01:00
|
|
|
fn keep_existing_when_none_provided() {
|
|
|
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
2020-11-23 06:12:26 +01:00
|
|
|
let out = cmd
|
|
|
|
.arg("-M")
|
|
|
|
.arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
// STDERR should be empty
|
|
|
|
assert_eq!(String::from_utf8_lossy(&out.stderr), "");
|
|
|
|
|
2020-11-23 06:12:26 +01:00
|
|
|
// STDOUT should contain newly added base URL
|
|
|
|
assert_eq!(
|
2021-06-08 14:30:15 +02:00
|
|
|
String::from_utf8_lossy(&out.stdout),
|
2020-11-23 06:12:26 +01:00
|
|
|
"<html><head>\
|
|
|
|
<base href=\"http://localhost:8000/\">\
|
|
|
|
</head><body>Hello, World!</body></html>\n"
|
|
|
|
);
|
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
// Exit code should be 0
|
2020-11-23 06:12:26 +01:00
|
|
|
out.assert().code(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-03-16 07:10:50 +01:00
|
|
|
fn override_existing_when_provided() {
|
|
|
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
2020-11-23 06:12:26 +01:00
|
|
|
let out = cmd
|
|
|
|
.arg("-M")
|
|
|
|
.arg("-b")
|
|
|
|
.arg("http://localhost/")
|
|
|
|
.arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
// STDERR should be empty
|
|
|
|
assert_eq!(String::from_utf8_lossy(&out.stderr), "");
|
|
|
|
|
2020-11-23 06:12:26 +01:00
|
|
|
// STDOUT should contain newly added base URL
|
|
|
|
assert_eq!(
|
2021-06-08 14:30:15 +02:00
|
|
|
String::from_utf8_lossy(&out.stdout),
|
2020-11-23 06:12:26 +01:00
|
|
|
"<html><head>\
|
|
|
|
<base href=\"http://localhost/\">\
|
|
|
|
</head><body>Hello, World!</body></html>\n"
|
|
|
|
);
|
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
// Exit code should be 0
|
2020-11-23 06:12:26 +01:00
|
|
|
out.assert().code(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2021-06-02 15:41:41 +02:00
|
|
|
fn set_existing_to_empty_when_empty_provided() {
|
2021-03-16 07:10:50 +01:00
|
|
|
let mut cmd = Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap();
|
2020-11-23 06:12:26 +01:00
|
|
|
let out = cmd
|
|
|
|
.arg("-M")
|
|
|
|
.arg("-b")
|
|
|
|
.arg("")
|
|
|
|
.arg("data:text/html,<base href=\"http://localhost:8000/\" />Hello%2C%20World!")
|
|
|
|
.output()
|
|
|
|
.unwrap();
|
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
// STDERR should be empty
|
|
|
|
assert_eq!(String::from_utf8_lossy(&out.stderr), "");
|
|
|
|
|
2020-11-23 06:12:26 +01:00
|
|
|
// STDOUT should contain newly added base URL
|
|
|
|
assert_eq!(
|
2021-06-08 14:30:15 +02:00
|
|
|
String::from_utf8_lossy(&out.stdout),
|
2020-11-23 06:12:26 +01:00
|
|
|
"<html><head>\
|
|
|
|
<base href=\"\">\
|
|
|
|
</head><body>Hello, World!</body></html>\n"
|
|
|
|
);
|
|
|
|
|
2021-06-08 14:30:15 +02:00
|
|
|
// Exit code should be 0
|
2020-11-23 06:12:26 +01:00
|
|
|
out.assert().code(0);
|
|
|
|
}
|
|
|
|
}
|