forked from extern/nushell
Add decimals to int when using into string --decimals
(#6085)
* Add decimals to int when using `into string --decimals` * Add tests for `into string` when converting int with `--decimals` * Apply formatting * Merge `into_str` test files * Comment out unused code and add TODOs * Use decimal separator depending on system locale * Add test helper to run closure in different locale * Add tests for int-to-string conversion using different locales * Add utils function to get system locale * Add panic message when locking mutex fails * Catch and resume panic later to prevent Mutex poisoning when test fails * Move test to `nu-test-support` to keep `nu-utils` free of `nu-*` dependencies See https://github.com/nushell/nushell/pull/6085#issuecomment-1193131694 * Rename test support fn `with_fake_locale` to `with_locale_override` * Move `get_system_locale()` to `locale` module * Allow overriding locale with special env variable (when not in release) * Use special env var to override locale during testing * Allow callback to return a value in `with_locale_override()` * Allow multiple options in `nu!` macro * Allow to set locale as `nu!` macro option * Use new `locale` option of `nu!` macro instead of `with_locale_override` Using the `locale` options does not lock the `LOCALE_OVERRIDE_MUTEX` mutex in `nu-test-support::locale_override` but instead calls the `nu` command directly with the `NU_LOCALE_OVERRIDE` environment variable. This allows for parallel test excecution. * Fix: Add option identifier for `cwd` in usage of `nu!` macro * Rely on `Display` trait for formatting `nu!` macro command - Removed the `DisplayPath` trait - Implement `Display` for `AbsolutePath`, `RelativePath` and `AbsoluteFile` * Default to locale `en_US.UTF-8` for tests when using `nu!` macro * Add doc comment to `nu!` macro * Format code using `cargo fmt --all` * Pass function directly instead of wrapping the call in a closure https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure * Pass function to `or_else()` instead of calling it inside `or()` https://rust-lang.github.io/rust-clippy/master/index.html#or_fun_call * Fix: Add option identifier for `cwd` in usage of `nu!` macro
This commit is contained in:
@ -1,3 +1,4 @@
|
||||
use std::fmt::Display;
|
||||
use std::io::Read;
|
||||
use std::ops::Div;
|
||||
use std::path::{Path, PathBuf};
|
||||
@ -113,45 +114,25 @@ impl<T: AsRef<str>> Div<T> for &RelativePath {
|
||||
RelativePath::new(result)
|
||||
}
|
||||
}
|
||||
pub trait DisplayPath {
|
||||
fn display_path(&self) -> String;
|
||||
}
|
||||
|
||||
impl DisplayPath for AbsolutePath {
|
||||
fn display_path(&self) -> String {
|
||||
self.inner.display().to_string()
|
||||
impl Display for AbsoluteFile {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.inner.display())
|
||||
}
|
||||
}
|
||||
|
||||
impl DisplayPath for PathBuf {
|
||||
fn display_path(&self) -> String {
|
||||
self.display().to_string()
|
||||
impl Display for AbsolutePath {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.inner.display())
|
||||
}
|
||||
}
|
||||
|
||||
impl DisplayPath for str {
|
||||
fn display_path(&self) -> String {
|
||||
self.to_string()
|
||||
impl Display for RelativePath {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
write!(f, "{}", self.inner.display())
|
||||
}
|
||||
}
|
||||
|
||||
impl DisplayPath for &str {
|
||||
fn display_path(&self) -> String {
|
||||
(*self).to_string()
|
||||
}
|
||||
}
|
||||
|
||||
impl DisplayPath for String {
|
||||
fn display_path(&self) -> String {
|
||||
self.clone()
|
||||
}
|
||||
}
|
||||
|
||||
impl DisplayPath for &String {
|
||||
fn display_path(&self) -> String {
|
||||
(*self).to_string()
|
||||
}
|
||||
}
|
||||
pub enum Stub<'a> {
|
||||
FileWithContent(&'a str, &'a str),
|
||||
FileWithContentToBeTrimmed(&'a str, &'a str),
|
||||
|
Reference in New Issue
Block a user