2020-05-10 01:05:48 +02:00
|
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
|
2024-06-22 14:41:29 +02:00
|
|
|
// Tests against table/structured data
|
2020-05-11 02:35:24 +02:00
|
|
|
#[test]
|
|
|
|
fn cal_full_year() {
|
2024-06-22 14:41:29 +02:00
|
|
|
let actual = nu!("cal -t -y --full-year 2010 | first | to json -r");
|
2022-02-04 03:01:45 +01:00
|
|
|
|
2024-02-26 15:31:46 +01:00
|
|
|
let first_week_2010_json =
|
2024-03-20 22:14:31 +01:00
|
|
|
r#"{"year":2010,"su":null,"mo":null,"tu":null,"we":null,"th":null,"fr":1,"sa":2}"#;
|
2020-05-11 02:35:24 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.out, first_week_2010_json);
|
|
|
|
}
|
|
|
|
|
2020-05-10 01:05:48 +02:00
|
|
|
#[test]
|
|
|
|
fn cal_february_2020_leap_year() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-05-10 01:05:48 +02:00
|
|
|
r#"
|
2024-06-22 14:41:29 +02:00
|
|
|
cal --as-table -ym --full-year 2020 --month-names | where month == "february" | to json -r
|
2022-02-04 03:01:45 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2024-03-20 22:14:31 +01:00
|
|
|
let cal_february_json = r#"[{"year":2020,"month":"february","su":null,"mo":null,"tu":null,"we":null,"th":null,"fr":null,"sa":1},{"year":2020,"month":"february","su":2,"mo":3,"tu":4,"we":5,"th":6,"fr":7,"sa":8},{"year":2020,"month":"february","su":9,"mo":10,"tu":11,"we":12,"th":13,"fr":14,"sa":15},{"year":2020,"month":"february","su":16,"mo":17,"tu":18,"we":19,"th":20,"fr":21,"sa":22},{"year":2020,"month":"february","su":23,"mo":24,"tu":25,"we":26,"th":27,"fr":28,"sa":29}]"#;
|
2020-05-10 01:05:48 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.out, cal_february_json);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2024-02-26 15:31:46 +01:00
|
|
|
fn cal_fr_the_thirteenths_in_2015() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-05-10 01:05:48 +02:00
|
|
|
r#"
|
2024-06-22 14:41:29 +02:00
|
|
|
cal --as-table --full-year 2015 | default 0 fr | where fr == 13 | length
|
2020-05-10 01:05:48 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2020-05-16 05:18:24 +02:00
|
|
|
assert!(actual.out.contains('3'));
|
2020-05-10 01:05:48 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cal_rows_in_2020() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-05-10 01:05:48 +02:00
|
|
|
r#"
|
2024-06-22 14:41:29 +02:00
|
|
|
cal --as-table --full-year 2020 | length
|
2020-05-10 01:05:48 +02:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert!(actual.out.contains("62"));
|
|
|
|
}
|
2020-05-12 05:58:16 +02:00
|
|
|
|
2020-06-18 19:34:51 +02:00
|
|
|
#[test]
|
2024-02-26 15:31:46 +01:00
|
|
|
fn cal_week_day_start_mo() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-06-18 19:34:51 +02:00
|
|
|
r#"
|
2024-06-22 14:41:29 +02:00
|
|
|
cal --as-table --full-year 2020 -m --month-names --week-start mo | where month == january | to json -r
|
2022-02-04 03:01:45 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2024-03-20 22:14:31 +01:00
|
|
|
let cal_january_json = r#"[{"month":"january","mo":null,"tu":null,"we":1,"th":2,"fr":3,"sa":4,"su":5},{"month":"january","mo":6,"tu":7,"we":8,"th":9,"fr":10,"sa":11,"su":12},{"month":"january","mo":13,"tu":14,"we":15,"th":16,"fr":17,"sa":18,"su":19},{"month":"january","mo":20,"tu":21,"we":22,"th":23,"fr":24,"sa":25,"su":26},{"month":"january","mo":27,"tu":28,"we":29,"th":30,"fr":31,"sa":null,"su":null}]"#;
|
2020-06-18 19:34:51 +02:00
|
|
|
|
|
|
|
assert_eq!(actual.out, cal_january_json);
|
|
|
|
}
|
|
|
|
|
2020-05-12 05:58:16 +02:00
|
|
|
#[test]
|
|
|
|
fn cal_sees_pipeline_year() {
|
2023-04-07 23:09:55 +02:00
|
|
|
let actual = nu!(pipeline(
|
2020-05-12 05:58:16 +02:00
|
|
|
r#"
|
2024-06-22 14:41:29 +02:00
|
|
|
cal --as-table --full-year 1020 | get mo | first 4 | to json -r
|
2022-02-04 03:01:45 +01:00
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
2022-02-04 14:24:36 +01:00
|
|
|
assert_eq!(actual.out, "[null,3,10,17]");
|
2020-05-12 05:58:16 +02:00
|
|
|
}
|
2024-06-22 14:41:29 +02:00
|
|
|
|
|
|
|
// Tests against default string output
|
|
|
|
#[test]
|
|
|
|
fn cal_is_string() {
|
|
|
|
let actual = nu!(pipeline(
|
|
|
|
r#"
|
|
|
|
cal | describe
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "string (stream)");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cal_year_num_lines() {
|
|
|
|
let actual = nu!(pipeline(
|
|
|
|
r#"
|
|
|
|
cal --full-year 2024 | lines | length
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "68");
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cal_week_start_string() {
|
|
|
|
let actual = nu!(pipeline(
|
|
|
|
r#"
|
|
|
|
cal --week-start fr | lines | get 1 | split row '│' | get 2 | ansi strip | str trim
|
|
|
|
"#
|
|
|
|
));
|
|
|
|
|
|
|
|
assert_eq!(actual.out, "sa");
|
|
|
|
}
|