Simplify a few boolean creations (#2543)

This commit is contained in:
Chris Gillespie 2020-09-13 18:15:44 -07:00 committed by GitHub
parent dd79afb503
commit e05e6b42fe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 14 additions and 22 deletions

View File

@ -130,7 +130,7 @@ fn action(
mod tests { mod tests {
use super::{action, SubCommand}; use super::{action, SubCommand};
use nu_plugin::test_helpers::value::string; use nu_plugin::test_helpers::value::string;
use nu_protocol::{Primitive, UntaggedValue}; use nu_protocol::UntaggedValue;
use nu_source::Tag; use nu_source::Tag;
#[test] #[test]
@ -145,8 +145,7 @@ mod tests {
let word = string("Cargo.tomL"); let word = string("Cargo.tomL");
let pattern = ".tomL"; let pattern = ".tomL";
let insensitive = false; let insensitive = false;
let expected = let expected = UntaggedValue::boolean(true).into_untagged_value();
UntaggedValue::Primitive(Primitive::Boolean(true.into())).into_untagged_value();
let actual = action(&word, &pattern, insensitive, Tag::unknown()).unwrap(); let actual = action(&word, &pattern, insensitive, Tag::unknown()).unwrap();
assert_eq!(actual, expected); assert_eq!(actual, expected);
@ -157,8 +156,7 @@ mod tests {
let word = string("Cargo.tomL"); let word = string("Cargo.tomL");
let pattern = "Lomt."; let pattern = "Lomt.";
let insensitive = false; let insensitive = false;
let expected = let expected = UntaggedValue::boolean(false).into_untagged_value();
UntaggedValue::Primitive(Primitive::Boolean(false.into())).into_untagged_value();
let actual = action(&word, &pattern, insensitive, Tag::unknown()).unwrap(); let actual = action(&word, &pattern, insensitive, Tag::unknown()).unwrap();
assert_eq!(actual, expected); assert_eq!(actual, expected);
@ -169,8 +167,7 @@ mod tests {
let word = string("Cargo.ToMl"); let word = string("Cargo.ToMl");
let pattern = ".TOML"; let pattern = ".TOML";
let insensitive = true; let insensitive = true;
let expected = let expected = UntaggedValue::boolean(true).into_untagged_value();
UntaggedValue::Primitive(Primitive::Boolean(true.into())).into_untagged_value();
let actual = action(&word, &pattern, insensitive, Tag::unknown()).unwrap(); let actual = action(&word, &pattern, insensitive, Tag::unknown()).unwrap();
assert_eq!(actual, expected); assert_eq!(actual, expected);
@ -181,8 +178,7 @@ mod tests {
let word = string("Cargo.tOml"); let word = string("Cargo.tOml");
let pattern = "lomt."; let pattern = "lomt.";
let insensitive = true; let insensitive = true;
let expected = let expected = UntaggedValue::boolean(false).into_untagged_value();
UntaggedValue::Primitive(Primitive::Boolean(false.into())).into_untagged_value();
let actual = action(&word, &pattern, insensitive, Tag::unknown()).unwrap(); let actual = action(&word, &pattern, insensitive, Tag::unknown()).unwrap();
assert_eq!(actual, expected); assert_eq!(actual, expected);

View File

@ -104,7 +104,7 @@ fn action(input: &Value, pattern: &str, tag: impl Into<Tag>) -> Result<Value, Sh
mod tests { mod tests {
use super::{action, SubCommand}; use super::{action, SubCommand};
use nu_plugin::test_helpers::value::string; use nu_plugin::test_helpers::value::string;
use nu_protocol::{Primitive, UntaggedValue}; use nu_protocol::UntaggedValue;
use nu_source::Tag; use nu_source::Tag;
#[test] #[test]
@ -118,8 +118,7 @@ mod tests {
fn str_ends_with_pattern() { fn str_ends_with_pattern() {
let word = string("Cargo.toml"); let word = string("Cargo.toml");
let pattern = ".toml"; let pattern = ".toml";
let expected = let expected = UntaggedValue::boolean(true).into_untagged_value();
UntaggedValue::Primitive(Primitive::Boolean(true.into())).into_untagged_value();
let actual = action(&word, &pattern, Tag::unknown()).unwrap(); let actual = action(&word, &pattern, Tag::unknown()).unwrap();
assert_eq!(actual, expected); assert_eq!(actual, expected);
@ -129,8 +128,7 @@ mod tests {
fn str_does_not_end_with_pattern() { fn str_does_not_end_with_pattern() {
let word = string("Cargo.toml"); let word = string("Cargo.toml");
let pattern = "Car"; let pattern = "Car";
let expected = let expected = UntaggedValue::boolean(false).into_untagged_value();
UntaggedValue::Primitive(Primitive::Boolean(false.into())).into_untagged_value();
let actual = action(&word, &pattern, Tag::unknown()).unwrap(); let actual = action(&word, &pattern, Tag::unknown()).unwrap();
assert_eq!(actual, expected); assert_eq!(actual, expected);

View File

@ -104,7 +104,7 @@ fn action(input: &Value, pattern: &str, tag: impl Into<Tag>) -> Result<Value, Sh
mod tests { mod tests {
use super::{action, SubCommand}; use super::{action, SubCommand};
use nu_plugin::test_helpers::value::string; use nu_plugin::test_helpers::value::string;
use nu_protocol::{Primitive, UntaggedValue}; use nu_protocol::UntaggedValue;
use nu_source::Tag; use nu_source::Tag;
#[test] #[test]
@ -118,8 +118,7 @@ mod tests {
fn str_starts_with_pattern() { fn str_starts_with_pattern() {
let word = string("Cargo.toml"); let word = string("Cargo.toml");
let pattern = "Car"; let pattern = "Car";
let expected = let expected = UntaggedValue::boolean(true).into_untagged_value();
UntaggedValue::Primitive(Primitive::Boolean(true.into())).into_untagged_value();
let actual = action(&word, &pattern, Tag::unknown()).unwrap(); let actual = action(&word, &pattern, Tag::unknown()).unwrap();
assert_eq!(actual, expected); assert_eq!(actual, expected);
@ -129,8 +128,7 @@ mod tests {
fn str_does_not_start_with_pattern() { fn str_does_not_start_with_pattern() {
let word = string("Cargo.toml"); let word = string("Cargo.toml");
let pattern = ".toml"; let pattern = ".toml";
let expected = let expected = UntaggedValue::boolean(false).into_untagged_value();
UntaggedValue::Primitive(Primitive::Boolean(false.into())).into_untagged_value();
let actual = action(&word, &pattern, Tag::unknown()).unwrap(); let actual = action(&word, &pattern, Tag::unknown()).unwrap();
assert_eq!(actual, expected); assert_eq!(actual, expected);

View File

@ -42,7 +42,7 @@ fn entry(arg: impl Into<String>, path: Value, builtin: bool, tag: Tag) -> Value
map.insert("path".to_string(), path); map.insert("path".to_string(), path);
map.insert( map.insert(
"builtin".to_string(), "builtin".to_string(),
UntaggedValue::Primitive(Primitive::Boolean(builtin)).into_value(tag.clone()), UntaggedValue::boolean(builtin).into_value(tag.clone()),
); );
UntaggedValue::row(map).into_value(tag) UntaggedValue::row(map).into_value(tag)

View File

@ -207,8 +207,8 @@ impl UntaggedValue {
} }
/// Helper for creating boolean values /// Helper for creating boolean values
pub fn boolean(s: impl Into<bool>) -> UntaggedValue { pub fn boolean(b: impl Into<bool>) -> UntaggedValue {
UntaggedValue::Primitive(Primitive::Boolean(s.into())) UntaggedValue::Primitive(Primitive::Boolean(b.into()))
} }
/// Helper for creating date duration values /// Helper for creating date duration values