Write and pass tests
This commit is contained in:
parent
fabcbdd216
commit
8d04e0bb04
@ -18,11 +18,9 @@ impl Tool for Transform {
|
||||
}
|
||||
|
||||
fn run(&self, argument: &Value) -> Result<Value> {
|
||||
let argument = self.check_type(argument)?;
|
||||
|
||||
if let Value::List(list) = argument {
|
||||
let list = list[0].as_list()?;
|
||||
let function = list[1].as_function()?;
|
||||
let argument = self.check_type(argument)?.as_list()?;
|
||||
let list = argument[0].as_list()?;
|
||||
let function = argument[1].as_function()?;
|
||||
let mut mapped_list = Vec::with_capacity(list.len());
|
||||
|
||||
for value in list {
|
||||
@ -37,9 +35,6 @@ impl Tool for Transform {
|
||||
|
||||
return Ok(Value::List(mapped_list));
|
||||
}
|
||||
|
||||
self.fail(argument)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct String;
|
||||
@ -84,7 +79,12 @@ impl Tool for Count {
|
||||
identifier: "count",
|
||||
description: "Return the number of items in a collection.",
|
||||
group: "collections",
|
||||
inputs: vec![ValueType::Any],
|
||||
inputs: vec![
|
||||
ValueType::String,
|
||||
ValueType::List,
|
||||
ValueType::Map,
|
||||
ValueType::Table,
|
||||
],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,10 +1,11 @@
|
||||
|
||||
# transform
|
||||
|
||||
list = (1, 2, 3);
|
||||
test = transform(list, 'input + 1');
|
||||
assert_equal((2, 3, 4), test);
|
||||
|
||||
# string
|
||||
|
||||
test = string(42);
|
||||
assert_equal("42", test);
|
||||
|
||||
@ -14,9 +15,100 @@ assert_equal("42.42", test);
|
||||
test = string(false);
|
||||
assert_equal("false", test);
|
||||
|
||||
# create_table
|
||||
|
||||
table = create_table(
|
||||
("text", "num"),
|
||||
(
|
||||
("foo", 1),
|
||||
("bar", 2)
|
||||
)
|
||||
);
|
||||
|
||||
# rows
|
||||
|
||||
test = rows(table);
|
||||
assert_equal(
|
||||
(
|
||||
("foo", 1),
|
||||
("bar", 2)
|
||||
),
|
||||
test
|
||||
);
|
||||
|
||||
# insert
|
||||
|
||||
test = insert(
|
||||
table,
|
||||
(
|
||||
("foo", 1),
|
||||
("bar", 2)
|
||||
)
|
||||
);
|
||||
assert_equal(
|
||||
create_table(
|
||||
("text", "num"),
|
||||
(
|
||||
("foo", 1),
|
||||
("bar", 2),
|
||||
("foo", 1),
|
||||
("bar", 2)
|
||||
)
|
||||
),
|
||||
test
|
||||
);
|
||||
|
||||
# select
|
||||
|
||||
table = create_table(
|
||||
("text", "number", "bool"),
|
||||
(
|
||||
("a", 1, true),
|
||||
("b", 2, true),
|
||||
("a", 3, true)
|
||||
)
|
||||
);
|
||||
|
||||
test_table = create_table(
|
||||
("text", "bool"),
|
||||
(
|
||||
("a", true),
|
||||
("b", true),
|
||||
("a", true)
|
||||
)
|
||||
);
|
||||
|
||||
assert_equal(select(table, ("text", "bool")), test_table);
|
||||
|
||||
test_table = create_table(
|
||||
("text", "number", "bool"),
|
||||
(
|
||||
("a", 1, true),
|
||||
("a", 3, true)
|
||||
)
|
||||
);
|
||||
|
||||
assert_equal(where(table, 'text == "a"'), test_table);
|
||||
|
||||
# count
|
||||
|
||||
table = create_table(
|
||||
("text", "number", "bool"),
|
||||
(
|
||||
("a", 1, true),
|
||||
("b", 2, true),
|
||||
("a", 3, true)
|
||||
)
|
||||
);
|
||||
test = count(table);
|
||||
assert_equal(3, test);
|
||||
|
||||
test = count("123");
|
||||
assert_equal(3, test);
|
||||
|
||||
# create_table
|
||||
test = count(1, 2, 3);
|
||||
assert_equal(3, test);
|
||||
|
||||
map.x.z.y = 1;
|
||||
test = count(map);
|
||||
assert_equal(1, test);
|
||||
|
Loading…
Reference in New Issue
Block a user