1
0

Correct tests

This commit is contained in:
Jeff 2023-08-23 19:00:11 -04:00
parent d54527413d
commit 8728bf5e46
5 changed files with 40 additions and 17 deletions

View File

@ -10,7 +10,7 @@ impl Macro for Transform {
identifier: "transform", identifier: "transform",
description: "Alter a collection by calling a function on each value.", description: "Alter a collection by calling a function on each value.",
group: "collections", group: "collections",
inputs: vec![ValueType::ListOf(vec![ inputs: vec![ValueType::ListExact(vec![
ValueType::List, ValueType::List,
ValueType::Function, ValueType::Function,
])], ])],
@ -119,7 +119,7 @@ impl Macro for CreateTable {
identifier: "create_table", identifier: "create_table",
description: "Define a new table with a list of column names and list of rows.", description: "Define a new table with a list of column names and list of rows.",
group: "collections", 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.", description: "Retrieve a value from a collection.",
group: "collections", group: "collections",
inputs: vec![ inputs: vec![
ValueType::ListOf(vec![ValueType::List, ValueType::Integer]), ValueType::ListExact(vec![ValueType::List, ValueType::Integer]),
ValueType::ListOf(vec![ValueType::Map, ValueType::String]), ValueType::ListExact(vec![ValueType::Map, ValueType::String]),
], ],
} }
} }
@ -242,7 +242,10 @@ impl Macro for Select {
identifier: "select", identifier: "select",
description: "Extract one or more values based on their key.", description: "Extract one or more values based on their key.",
group: "collections", group: "collections",
inputs: vec![ValueType::Table, ValueType::String], inputs: vec![ValueType::ListExact(vec![
ValueType::Table,
ValueType::ListOf(Box::new(ValueType::String)),
])],
} }
} }

View File

@ -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) TableBuilder::new(ui)
.resizable(true) .resizable(true)
.striped(true) .striped(true)

View File

@ -36,7 +36,7 @@ impl Macro for AssertEqual {
identifier: "assert_equal", identifier: "assert_equal",
description: "Panic if two values do not match.", description: "Panic if two values do not match.",
group: "test", 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.", description: "Evaluates the first argument. If true, it does the second argument.",
group: "logic", group: "logic",
inputs: vec![ inputs: vec![
ValueType::ListOf(vec![ ValueType::ListExact(vec![
ValueType::Boolean, ValueType::Boolean,
ValueType::Any, ValueType::Any,
]), ]),
ValueType::ListOf(vec![ ValueType::ListExact(vec![
ValueType::Function, ValueType::Function,
ValueType::Any, 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", description: "Evaluates the first argument. If true, it does the second argument. If false, it does the third argument",
group: "logic", group: "logic",
inputs: vec![ inputs: vec![
ValueType::ListOf(vec![ ValueType::ListExact(vec![
ValueType::Boolean, ValueType::Boolean,
ValueType::Any, ValueType::Any,
ValueType::Any, ValueType::Any,
]), ]),
ValueType::ListOf(vec![ ValueType::ListExact(vec![
ValueType::Function, ValueType::Function,
ValueType::Any, ValueType::Any,
ValueType::Any, ValueType::Any,

View File

@ -11,7 +11,8 @@ pub enum ValueType {
Integer, Integer,
Boolean, Boolean,
List, List,
ListOf(Vec<ValueType>), ListOf(Box<ValueType>),
ListExact(Vec<ValueType>),
Empty, Empty,
Map, Map,
Table, Table,
@ -30,9 +31,23 @@ impl PartialEq for ValueType {
(ValueType::Float, ValueType::Float) => true, (ValueType::Float, ValueType::Float) => true,
(ValueType::Integer, ValueType::Integer) => true, (ValueType::Integer, ValueType::Integer) => true,
(ValueType::Boolean, ValueType::Boolean) => 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::ListOf(_), ValueType::List) => true,
(ValueType::List, ValueType::ListOf(_)) => 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::List, ValueType::List) => true,
(ValueType::Empty, ValueType::Empty) => true, (ValueType::Empty, ValueType::Empty) => true,
(ValueType::Map, ValueType::Map) => true, (ValueType::Map, ValueType::Map) => true,
@ -53,8 +68,11 @@ impl Display for ValueType {
ValueType::Integer => write!(f, "integer"), ValueType::Integer => write!(f, "integer"),
ValueType::Boolean => write!(f, "boolean"), ValueType::Boolean => write!(f, "boolean"),
ValueType::List => write!(f, "list"), ValueType::List => write!(f, "list"),
ValueType::ListOf(items) => { ValueType::ListOf(value_type) => {
let items = items write!(f, "list of {value_type}")
}
ValueType::ListExact(list) => {
let items = list
.iter() .iter()
.map(|value_type| value_type.to_string() + " ") .map(|value_type| value_type.to_string() + " ")
.collect::<String>(); .collect::<String>();
@ -78,7 +96,9 @@ impl From<&Value> for ValueType {
Value::Integer(_) => ValueType::Integer, Value::Integer(_) => ValueType::Integer,
Value::Boolean(_) => ValueType::Boolean, Value::Boolean(_) => ValueType::Boolean,
Value::List(list) => { 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::Empty => ValueType::Empty,
Value::Map(_) => ValueType::Map, Value::Map(_) => ValueType::Map,

View File

@ -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( test_table = create_table(
("text", "number", "bool"), ("text", "number", "bool"),