Another batch of command tests (#4496)

* Add a batch of command tests

* More tests
This commit is contained in:
JT
2022-02-16 07:38:02 -05:00
committed by GitHub
parent 644435bfe3
commit c4e1559f89
13 changed files with 43 additions and 70 deletions

View File

@ -24,7 +24,7 @@ impl Command for WithEnv {
)
.required(
"block",
SyntaxShape::Block(Some(vec![SyntaxShape::Any])),
SyntaxShape::Block(Some(vec![])),
"the block to run once the variable is set",
)
.category(Category::Env)

View File

@ -164,7 +164,7 @@ fn get_cellpath_columns(keep_cols: Vec<String>, span: Span) -> Vec<CellPath> {
fn get_keep_columns(mut input: Vec<String>, rejects: Vec<String>) -> Vec<String> {
for reject in rejects {
if let Some(index) = input.iter().position(|value| *value == reject) {
input.swap_remove(index);
input.remove(index);
}
}
input
@ -173,8 +173,8 @@ fn get_keep_columns(mut input: Vec<String>, rejects: Vec<String>) -> Vec<String>
fn reject_record_columns(cols: &mut Vec<String>, vals: &mut Vec<Value>, rejects: &[String]) {
for reject in rejects {
if let Some(index) = cols.iter().position(|value| value == reject) {
cols.swap_remove(index);
vals.swap_remove(index);
cols.remove(index);
vals.remove(index);
}
}
}

View File

@ -70,7 +70,13 @@ fn decimal(
let range: Option<Range> = call.opt(engine_state, stack, 0)?;
let (min, max) = if let Some(r) = range {
(r.from.as_float()?, r.to.as_float()?)
if r.is_end_inclusive() {
(r.from.as_float()?, r.to.as_float()?)
} else if r.to.as_float()? >= 1.0 {
(r.from.as_float()?, r.to.as_float()? - 1.0)
} else {
(0.0, 0.0)
}
} else {
(0.0, 1.0)
};

View File

@ -70,7 +70,13 @@ fn integer(
let range: Option<Range> = call.opt(engine_state, stack, 0)?;
let (min, max) = if let Some(r) = range {
(r.from.as_integer()?, r.to.as_integer()?)
if r.is_end_inclusive() {
(r.from.as_integer()?, r.to.as_integer()?)
} else if r.to.as_integer()? > 0 {
(r.from.as_integer()?, r.to.as_integer()? - 1)
} else {
(0, 0)
}
} else {
(0, i64::MAX)
};