forked from extern/nushell
@ -24,7 +24,7 @@ pub fn convert_toml_value_to_nu_value(v: &toml::Value, tag: impl Into<Tag>) -> V
|
||||
match v {
|
||||
toml::Value::Boolean(b) => UntaggedValue::boolean(*b).into_value(tag),
|
||||
toml::Value::Integer(n) => UntaggedValue::int(*n).into_value(tag),
|
||||
toml::Value::Float(n) => UntaggedValue::decimal(*n).into_value(tag),
|
||||
toml::Value::Float(n) => UntaggedValue::decimal_from_float(*n, tag.span).into_value(tag),
|
||||
toml::Value::String(s) => {
|
||||
UntaggedValue::Primitive(Primitive::String(String::from(s))).into_value(tag)
|
||||
}
|
||||
|
@ -253,7 +253,7 @@ pub fn percentages(
|
||||
&split
|
||||
.table_entries()
|
||||
.filter_map(|s| {
|
||||
let hundred = UntaggedValue::decimal(100);
|
||||
let hundred = UntaggedValue::decimal_from_float(100.0, tag.span);
|
||||
|
||||
match compute_values(Operator::Divide, &hundred, &maxima) {
|
||||
Ok(v) => match compute_values(Operator::Multiply, &s, &v) {
|
||||
|
@ -103,7 +103,7 @@ pub mod helpers {
|
||||
use indexmap::indexmap;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{UntaggedValue, Value};
|
||||
use nu_source::{Tag, TaggedItem};
|
||||
use nu_source::{Span, Tag, TaggedItem};
|
||||
use nu_value_ext::ValueExt;
|
||||
use num_bigint::BigInt;
|
||||
|
||||
@ -117,6 +117,10 @@ pub mod helpers {
|
||||
UntaggedValue::decimal(f.into()).into_untagged_value()
|
||||
}
|
||||
|
||||
pub fn decimal_from_float(f: f64, span: Span) -> Value {
|
||||
UntaggedValue::decimal_from_float(f, span).into_untagged_value()
|
||||
}
|
||||
|
||||
pub fn string(input: impl Into<String>) -> Value {
|
||||
UntaggedValue::string(input.into()).into_untagged_value()
|
||||
}
|
||||
@ -228,12 +232,13 @@ pub mod helpers {
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::helpers::{
|
||||
assert_without_checking_percentages, committers, date_formatter, decimal, int, table,
|
||||
assert_without_checking_percentages, committers, date_formatter, decimal,
|
||||
decimal_from_float, int, table,
|
||||
};
|
||||
use super::{report, Labels, Model, Operation, Range};
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::Value;
|
||||
use nu_source::{Tag, TaggedItem};
|
||||
use nu_source::{Span, Tag, TaggedItem};
|
||||
use nu_value_ext::ValueExt;
|
||||
#[test]
|
||||
fn prepares_report_using_accumulating_value() {
|
||||
@ -299,9 +304,21 @@ mod tests {
|
||||
table(&[int(2), int(6), int(12)]),
|
||||
]),
|
||||
percentages: table(&[
|
||||
table(&[decimal(16.66), decimal(50), decimal(100)]),
|
||||
table(&[decimal(8.33), decimal(25), decimal(50)]),
|
||||
table(&[decimal(3.33), decimal(10), decimal(20)]),
|
||||
table(&[
|
||||
decimal_from_float(16.66, Span::unknown()),
|
||||
decimal(50),
|
||||
decimal(100),
|
||||
]),
|
||||
table(&[
|
||||
decimal_from_float(8.33, Span::unknown()),
|
||||
decimal(25),
|
||||
decimal(50),
|
||||
]),
|
||||
table(&[
|
||||
decimal_from_float(3.33, Span::unknown()),
|
||||
decimal(10),
|
||||
decimal(20),
|
||||
]),
|
||||
]),
|
||||
},
|
||||
);
|
||||
|
Reference in New Issue
Block a user