mirror of
https://github.com/nushell/nushell
synced 2024-12-28 14:03:09 +00:00
8e1112c1dd
# Description Purely for consistency, various remaining instances of `$nothing` (almost all of which were in test code) have been changed to `null`. Now, the only place that refers to `$nothing` is the parser code which implements it. # User-Facing Changes The default config.nu now uses `null` in certain places where it used `$nothing`. # Tests + Formatting Don't forget to add tests that cover your changes. Make sure you've run and fixed any issues with these commands: - `cargo fmt --all -- --check` to check standard code formatting (`cargo fmt --all` applies these changes) - `cargo clippy --workspace -- -D warnings -D clippy::unwrap_used -A clippy::needless_collect` to check that you're using the standard code style - `cargo test --workspace` to check that all tests pass # After Submitting If your PR had any user-facing changes, update [the documentation](https://github.com/nushell/nushell.github.io) after the PR is merged, if necessary. This will help us keep the docs up to date.
257 lines
4.8 KiB
Rust
257 lines
4.8 KiB
Rust
use nu_test_support::fs::Stub::FileWithContentToBeTrimmed;
|
|
use nu_test_support::playground::Playground;
|
|
use nu_test_support::{nu, pipeline};
|
|
|
|
#[test]
|
|
fn from_range() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo 1..5 | into string | to json -r
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "[\"1\",\"2\",\"3\",\"4\",\"5\"]");
|
|
}
|
|
|
|
#[test]
|
|
fn from_number() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo 5 | into string
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "5");
|
|
}
|
|
|
|
#[test]
|
|
fn from_decimal() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo 1.5 | into string
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "1.5");
|
|
}
|
|
|
|
#[test]
|
|
fn from_boolean() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo true | into string
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "true");
|
|
}
|
|
|
|
#[test]
|
|
fn from_string() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo "one" | into string
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "one");
|
|
}
|
|
|
|
#[test]
|
|
fn from_filename() {
|
|
Playground::setup("from_filename", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
"sample.toml",
|
|
r#"
|
|
[dependency]
|
|
name = "nu"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
"ls sample.toml | get name | into string | get 0"
|
|
);
|
|
|
|
assert_eq!(actual.out, "sample.toml");
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn from_filesize() {
|
|
Playground::setup("from_filesize", |dirs, sandbox| {
|
|
sandbox.with_files(vec![FileWithContentToBeTrimmed(
|
|
"sample.toml",
|
|
r#"
|
|
[dependency]
|
|
name = "nu"
|
|
"#,
|
|
)]);
|
|
|
|
let actual = nu!(
|
|
cwd: dirs.test(),
|
|
"ls sample.toml | get size | into string | get 0"
|
|
);
|
|
|
|
let expected = if cfg!(windows) { "27 B" } else { "25 B" };
|
|
|
|
assert_eq!(actual.out, expected);
|
|
})
|
|
}
|
|
|
|
#[test]
|
|
fn from_decimal_correct_trailing_zeros() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
1.23000 | into string -d 3
|
|
"#
|
|
));
|
|
|
|
assert!(actual.out.contains("1.230"));
|
|
}
|
|
|
|
#[test]
|
|
fn from_int_decimal_correct_trailing_zeros() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
1.00000 | into string -d 3
|
|
"#
|
|
));
|
|
|
|
assert!(actual.out.contains("1.000"));
|
|
}
|
|
|
|
#[test]
|
|
fn from_int_decimal_trim_trailing_zeros() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
1.00000 | into string | $"($in) flat"
|
|
"#
|
|
));
|
|
|
|
assert!(actual.out.contains("1 flat")); // "1" would match "1.0"
|
|
}
|
|
|
|
#[test]
|
|
fn from_table() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
echo '[{"name": "foo", "weight": 32.377}, {"name": "bar", "weight": 15.2}]'
|
|
| from json
|
|
| into string weight -d 2
|
|
"#
|
|
));
|
|
|
|
assert!(actual.out.contains("32.38"));
|
|
assert!(actual.out.contains("15.20"));
|
|
}
|
|
|
|
#[test]
|
|
fn from_nothing() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
null | into string
|
|
"#
|
|
));
|
|
|
|
assert_eq!(actual.out, "");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string() {
|
|
let actual = nu!(
|
|
cwd: ".", pipeline(
|
|
r#"
|
|
10 | into string
|
|
"#
|
|
));
|
|
|
|
assert_eq!(actual.out, "10");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string_decimals_0() {
|
|
let actual = nu!(
|
|
locale: "en_US.UTF-8",
|
|
pipeline(
|
|
r#"
|
|
10 | into string --decimals 0
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "10");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string_decimals_1() {
|
|
let actual = nu!(
|
|
locale: "en_US.UTF-8",
|
|
pipeline(
|
|
r#"
|
|
10 | into string --decimals 1
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "10.0");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string_decimals_10() {
|
|
let actual = nu!(
|
|
locale: "en_US.UTF-8",
|
|
pipeline(
|
|
r#"
|
|
10 | into string --decimals 10
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "10.0000000000");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string_decimals_respects_system_locale_de() {
|
|
// Set locale to `de_DE`, which uses `,` (comma) as decimal separator
|
|
let actual = nu!(
|
|
locale: "de_DE.UTF-8",
|
|
pipeline(
|
|
r#"
|
|
10 | into string --decimals 1
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "10,0");
|
|
}
|
|
|
|
#[test]
|
|
fn int_into_string_decimals_respects_system_locale_en() {
|
|
// Set locale to `en_US`, which uses `.` (period) as decimal separator
|
|
let actual = nu!(
|
|
locale: "en_US.UTF-8",
|
|
pipeline(
|
|
r#"
|
|
10 | into string --decimals 1
|
|
"#
|
|
)
|
|
);
|
|
|
|
assert_eq!(actual.out, "10.0");
|
|
}
|