Correct tests
This commit is contained in:
parent
d54527413d
commit
8728bf5e46
@ -10,7 +10,7 @@ impl Macro for Transform {
|
||||
identifier: "transform",
|
||||
description: "Alter a collection by calling a function on each value.",
|
||||
group: "collections",
|
||||
inputs: vec![ValueType::ListOf(vec![
|
||||
inputs: vec![ValueType::ListExact(vec![
|
||||
ValueType::List,
|
||||
ValueType::Function,
|
||||
])],
|
||||
@ -119,7 +119,7 @@ impl Macro for CreateTable {
|
||||
identifier: "create_table",
|
||||
description: "Define a new table with a list of column names and list of rows.",
|
||||
group: "collections",
|
||||
inputs: vec![ValueType::ListOf(vec![ValueType::List, ValueType::List])],
|
||||
inputs: vec![ValueType::ListExact(vec![ValueType::List, ValueType::List])],
|
||||
}
|
||||
}
|
||||
|
||||
@ -181,8 +181,8 @@ impl Macro for Get {
|
||||
description: "Retrieve a value from a collection.",
|
||||
group: "collections",
|
||||
inputs: vec![
|
||||
ValueType::ListOf(vec![ValueType::List, ValueType::Integer]),
|
||||
ValueType::ListOf(vec![ValueType::Map, ValueType::String]),
|
||||
ValueType::ListExact(vec![ValueType::List, ValueType::Integer]),
|
||||
ValueType::ListExact(vec![ValueType::Map, ValueType::String]),
|
||||
],
|
||||
}
|
||||
}
|
||||
@ -242,7 +242,10 @@ impl Macro for Select {
|
||||
identifier: "select",
|
||||
description: "Extract one or more values based on their key.",
|
||||
group: "collections",
|
||||
inputs: vec![ValueType::Table, ValueType::String],
|
||||
inputs: vec![ValueType::ListExact(vec![
|
||||
ValueType::Table,
|
||||
ValueType::ListOf(Box::new(ValueType::String)),
|
||||
])],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -232,7 +232,7 @@ impl GuiApp {
|
||||
}
|
||||
}
|
||||
|
||||
fn table_ui(&mut self, table: &Table, ui: &mut Ui) {
|
||||
fn _table_ui(&mut self, table: &Table, ui: &mut Ui) {
|
||||
TableBuilder::new(ui)
|
||||
.resizable(true)
|
||||
.striped(true)
|
||||
|
@ -36,7 +36,7 @@ impl Macro for AssertEqual {
|
||||
identifier: "assert_equal",
|
||||
description: "Panic if two values do not match.",
|
||||
group: "test",
|
||||
inputs: vec![ValueType::ListOf(vec![ValueType::Any, ValueType::Any])],
|
||||
inputs: vec![ValueType::ListExact(vec![ValueType::Any, ValueType::Any])],
|
||||
}
|
||||
}
|
||||
|
||||
@ -61,11 +61,11 @@ impl Macro for If {
|
||||
description: "Evaluates the first argument. If true, it does the second argument.",
|
||||
group: "logic",
|
||||
inputs: vec![
|
||||
ValueType::ListOf(vec![
|
||||
ValueType::ListExact(vec![
|
||||
ValueType::Boolean,
|
||||
ValueType::Any,
|
||||
]),
|
||||
ValueType::ListOf(vec![
|
||||
ValueType::ListExact(vec![
|
||||
ValueType::Function,
|
||||
ValueType::Any,
|
||||
])],
|
||||
@ -99,12 +99,12 @@ impl Macro for IfElse {
|
||||
description: "Evaluates the first argument. If true, it does the second argument. If false, it does the third argument",
|
||||
group: "logic",
|
||||
inputs: vec![
|
||||
ValueType::ListOf(vec![
|
||||
ValueType::ListExact(vec![
|
||||
ValueType::Boolean,
|
||||
ValueType::Any,
|
||||
ValueType::Any,
|
||||
]),
|
||||
ValueType::ListOf(vec![
|
||||
ValueType::ListExact(vec![
|
||||
ValueType::Function,
|
||||
ValueType::Any,
|
||||
ValueType::Any,
|
||||
|
@ -11,7 +11,8 @@ pub enum ValueType {
|
||||
Integer,
|
||||
Boolean,
|
||||
List,
|
||||
ListOf(Vec<ValueType>),
|
||||
ListOf(Box<ValueType>),
|
||||
ListExact(Vec<ValueType>),
|
||||
Empty,
|
||||
Map,
|
||||
Table,
|
||||
@ -30,9 +31,23 @@ impl PartialEq for ValueType {
|
||||
(ValueType::Float, ValueType::Float) => true,
|
||||
(ValueType::Integer, ValueType::Integer) => true,
|
||||
(ValueType::Boolean, ValueType::Boolean) => true,
|
||||
(ValueType::ListOf(left), ValueType::ListOf(right)) => left == right,
|
||||
(ValueType::ListExact(left), ValueType::ListExact(right)) => left == right,
|
||||
(ValueType::ListExact(_), ValueType::List) => true,
|
||||
(ValueType::List, ValueType::ListExact(_)) => true,
|
||||
(ValueType::ListOf(_), ValueType::List) => true,
|
||||
(ValueType::List, ValueType::ListOf(_)) => true,
|
||||
(ValueType::ListOf(left), ValueType::ListOf(right)) => left == right,
|
||||
(ValueType::ListOf(value_type), ValueType::ListExact(exact_list))
|
||||
| (ValueType::ListExact(exact_list), ValueType::ListOf(value_type)) => {
|
||||
if exact_list
|
||||
.iter()
|
||||
.all(|exact_type| exact_type == value_type.as_ref())
|
||||
{
|
||||
true
|
||||
} else {
|
||||
false
|
||||
}
|
||||
}
|
||||
(ValueType::List, ValueType::List) => true,
|
||||
(ValueType::Empty, ValueType::Empty) => true,
|
||||
(ValueType::Map, ValueType::Map) => true,
|
||||
@ -53,8 +68,11 @@ impl Display for ValueType {
|
||||
ValueType::Integer => write!(f, "integer"),
|
||||
ValueType::Boolean => write!(f, "boolean"),
|
||||
ValueType::List => write!(f, "list"),
|
||||
ValueType::ListOf(items) => {
|
||||
let items = items
|
||||
ValueType::ListOf(value_type) => {
|
||||
write!(f, "list of {value_type}")
|
||||
}
|
||||
ValueType::ListExact(list) => {
|
||||
let items = list
|
||||
.iter()
|
||||
.map(|value_type| value_type.to_string() + " ")
|
||||
.collect::<String>();
|
||||
@ -78,7 +96,9 @@ impl From<&Value> for ValueType {
|
||||
Value::Integer(_) => ValueType::Integer,
|
||||
Value::Boolean(_) => ValueType::Boolean,
|
||||
Value::List(list) => {
|
||||
ValueType::ListOf(list.iter().map(|value| value.value_type()).collect())
|
||||
let values = list.iter().map(|value| value.value_type()).collect();
|
||||
|
||||
ValueType::ListExact(values)
|
||||
}
|
||||
Value::Empty => ValueType::Empty,
|
||||
Value::Map(_) => ValueType::Map,
|
||||
|
@ -16,7 +16,7 @@ test_table = create_table(
|
||||
)
|
||||
);
|
||||
|
||||
assert_equal(select(table, "text", "bool"), test_table);
|
||||
assert_equal(select(table, ("text", "bool")), test_table);
|
||||
|
||||
test_table = create_table(
|
||||
("text", "number", "bool"),
|
||||
|
Loading…
Reference in New Issue
Block a user