mod support;
use predicates::prelude::*;
use std::fs;
use support::lx_no_colour;
use tempfile::tempdir;
#[test]
fn time_style_default() {
lx_no_colour()
.args(["-l", "--time-style=default", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::contains("Cargo.toml"));
}
#[test]
fn time_style_iso() {
lx_no_colour()
.args(["-l", "--time-style=iso", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::contains("Cargo.toml"));
}
#[test]
fn time_style_long_iso() {
lx_no_colour()
.args(["-l", "--time-style=long-iso", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::is_match(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}").unwrap());
}
#[test]
fn time_style_full_iso() {
lx_no_colour()
.args(["-l", "--time-style=full-iso", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::is_match(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}:\d{2}").unwrap());
}
#[test]
fn time_style_from_env() {
lx_no_colour()
.args(["-l", "Cargo.toml"])
.env("TIME_STYLE", "long-iso")
.assert()
.success()
.stdout(predicate::str::is_match(r"\d{4}-\d{2}-\d{2} \d{2}:\d{2}").unwrap());
}
#[test]
fn time_style_flag_overrides_env() {
lx_no_colour()
.args(["-l", "--time-style=iso", "Cargo.toml"])
.env("TIME_STYLE", "full-iso")
.assert()
.success()
.stdout(predicate::str::contains("Cargo.toml"));
}
#[test]
fn time_modified_flag() {
lx_no_colour()
.args(["-lm", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::contains("Cargo.toml"));
}
#[test]
fn time_accessed_flag() {
lx_no_colour()
.args(["-l", "--accessed", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::contains("Cargo.toml"));
}
#[test]
fn time_created_flag() {
lx_no_colour()
.args(["-l", "--created", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::contains("Cargo.toml"));
}
#[test]
fn time_tier_1() {
lx_no_colour()
.args(["-lt", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::contains("Cargo.toml"));
}
#[test]
fn time_tier_2() {
lx_no_colour()
.args(["-ltt", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::contains("Cargo.toml"));
}
#[test]
fn time_tier_3() {
lx_no_colour()
.args(["-lttt", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::contains("Cargo.toml"));
}
#[test]
fn no_time_suppresses_date() {
let dir = tempdir().expect("failed to create tempdir");
fs::write(dir.path().join("file.txt"), "content").unwrap();
lx_no_colour()
.args(["-l", "--no-time", "--time-style=long-iso"])
.arg(dir.path().join("file.txt"))
.assert()
.success()
.stdout(
predicate::str::is_match(r"\d{4}-\d{2}-\d{2}")
.unwrap()
.not(),
);
}
#[test]
fn no_modified_suppresses_only_modified() {
let dir = tempdir().expect("failed to create tempdir");
fs::write(dir.path().join("file.txt"), "content").unwrap();
lx_no_colour()
.args(["-lll", "--no-modified", "--time-style=long-iso"])
.arg(dir.path().join("file.txt"))
.assert()
.success()
.stdout(predicate::str::is_match(r"\d{4}-\d{2}-\d{2}").unwrap());
}
#[test]
fn multiple_time_flags_combine() {
lx_no_colour()
.args(["-lm", "--accessed", "Cargo.toml"])
.assert()
.success()
.stdout(predicate::str::contains("Cargo.toml"));
}