mirror of
https://github.com/nushell/nushell.git
synced 2024-12-26 00:50:03 +01:00
c59f860b48
* Changed time units as outlined in issue #2353. Also applied changes to to_str for Unit - not sure if that was what was wanted. * Forgot the tests! * Updated primitive.rs to match changes. * Updated where example to match changes. * And the html test!
92 lines
8.0 KiB
Rust
92 lines
8.0 KiB
Rust
use nu_test_support::{nu, pipeline};
|
|
|
|
#[test]
|
|
fn out_html_simple() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo 3 | to html
|
|
"#
|
|
));
|
|
|
|
assert_eq!(
|
|
actual.out,
|
|
r"<html><style>body { background-color:white;color:black; }</style><body>3</body></html>"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn out_html_partial() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo 3 | to html -p
|
|
"#
|
|
));
|
|
|
|
assert_eq!(
|
|
actual.out,
|
|
"<div style=\"background-color:white;color:black;\">3</div>"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn out_html_table() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo '{"name": "darren"}' | from json | to html
|
|
"#
|
|
));
|
|
|
|
assert_eq!(
|
|
actual.out,
|
|
r"<html><style>body { background-color:white;color:black; }</style><body><table><tr><th>name</th></tr><tr><td>darren</td></tr></table></body></html>"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_cd_html_color_flag_dark_false() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
cd --help | to html --html_color
|
|
"#
|
|
)
|
|
);
|
|
assert_eq!(
|
|
actual.out,
|
|
r"<html><style>body { background-color:white;color:black; }</style><body>Change to a new path.<br><br>Usage:<br> > cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called 'dirname'<br> > <span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>dirname<span style='color:black;font-weight:normal;'><br><br> Change to your home directory<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'><br><br> Change to your home directory (alternate version)<br> > </span></span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>~<span style='color:black;font-weight:normal;'><br><br> Change to the previous directory<br> > </span><span style='color:#037979;font-weight:bold;'>cd<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#037979;'>-<span style='color:black;font-weight:normal;'><br><br></body></html></span></span></span>"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_no_color_flag() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
cd --help | to html --no_color
|
|
"#
|
|
)
|
|
);
|
|
assert_eq!(
|
|
actual.out,
|
|
r"<html><style>body { background-color:white;color:black; }</style><body>Change to a new path.<br><br>Usage:<br> > cd (directory) {flags} <br><br>Parameters:<br> (directory) the directory to change to<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> Change to a new directory called 'dirname'<br> > cd dirname<br><br> Change to your home directory<br> > cd<br><br> Change to your home directory (alternate version)<br> > cd ~<br><br> Change to the previous directory<br> > cd -<br><br></body></html>"
|
|
);
|
|
}
|
|
|
|
#[test]
|
|
fn test_html_color_where_flag_dark_false() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
where --help | to html --html_color
|
|
"#
|
|
)
|
|
);
|
|
assert_eq!(
|
|
actual.out,
|
|
r"<html><style>body { background-color:white;color:black; }</style><body>Filter table to match the condition.<br><br>Usage:<br> > where <condition> {flags} <br><br>Parameters:<br> <condition> the condition that must match<br><br>Flags:<br> -h, --help: Display this help message<br><br>Examples:<br> List all files in the current directory with sizes greater than 2kb<br> > <span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>size<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>><span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#c800c8;font-weight:bold;'>2<span style='color:black;font-weight:normal;'></span></span><span style='color:#037979;font-weight:bold;'>kb<span style='color:black;font-weight:normal;'><br><br> List only the files in the current directory<br> > </span></span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>type<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>==<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:green;'>File<span style='color:black;font-weight:normal;'><br><br> List all files with names that contain "Car"<br> > </span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>name<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'>=~<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:green;'>"Car"<span style='color:black;font-weight:normal;'><br><br> List all files that were modified in the last two months<br> > </span><span style='color:#037979;font-weight:bold;'>ls<span style='color:black;font-weight:normal;'></span></span></span></span><span style='color:black;'> | <span style='color:black;font-weight:normal;'></span><span style='color:#037979;font-weight:bold;'>where<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;font-weight:bold;'>modified<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#717100;'><=<span style='color:black;font-weight:normal;'></span></span></span><span style='color:black;'> <span style='color:black;font-weight:normal;'></span><span style='color:#c800c8;font-weight:bold;'>2<span style='color:black;font-weight:normal;'></span></span><span style='color:#037979;font-weight:bold;'>mon<span style='color:black;font-weight:normal;'><br><br></body></html></span></span></span>"
|
|
);
|
|
}
|