Add helper functions
This commit is contained in:
parent
b131d40702
commit
a7ba99b3a8
|
|
@ -443,10 +443,34 @@ impl OpenFunction {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::{ast::*, types::ValueInner};
|
||||
use crate::{
|
||||
ast::*,
|
||||
types::{Value, ValueInner},
|
||||
};
|
||||
|
||||
use super::build;
|
||||
|
||||
fn get(table: &Value, index: &str) -> Value {
|
||||
let Some(ValueInner::Table(table)) = table else {
|
||||
panic!("a table expected");
|
||||
};
|
||||
table.get(index.into())
|
||||
}
|
||||
|
||||
fn set(table: &Value, index: &str, value: Value) {
|
||||
let Some(ValueInner::Table(table)) = table else {
|
||||
panic!("a table expected");
|
||||
};
|
||||
table.set(index.into(), value);
|
||||
}
|
||||
|
||||
fn call(func: &Value, args: &[Value]) -> Value {
|
||||
let Some(ValueInner::Function(func)) = func else {
|
||||
panic!("a function expected");
|
||||
};
|
||||
func.call(args)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_local() {
|
||||
let testee = Function {
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user