Write tests; Clean up
This commit is contained in:
parent
93e2a24a25
commit
ba0d154962
@ -4,9 +4,7 @@ use enum_iterator::{all, Sequence};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{
|
||||
built_in_functions::{
|
||||
fs::fs_functions, json::json_functions, string::string_functions, Callable,
|
||||
},
|
||||
built_in_functions::{fs::fs_functions, json::json_functions, str::string_functions, Callable},
|
||||
AbstractTree, BuiltInFunction, Format, Function, List, Map, Result, SyntaxNode, Type, Value,
|
||||
};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
pub mod fs;
|
||||
pub mod json;
|
||||
pub mod string;
|
||||
pub mod str;
|
||||
|
||||
use std::fmt::{self, Display, Formatter};
|
||||
|
||||
@ -9,7 +9,7 @@ use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{Error, Format, Map, Result, Type, Value};
|
||||
|
||||
use self::{fs::Fs, json::Json, string::StrFunction};
|
||||
use self::{fs::Fs, json::Json, str::StrFunction};
|
||||
|
||||
pub trait Callable {
|
||||
fn name(&self) -> &'static str;
|
||||
|
@ -13,3 +13,37 @@ fn as_bytes() {
|
||||
])))
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ends_with() {
|
||||
let result = interpret("str:ends_with('abc', 'c')");
|
||||
|
||||
assert_eq!(result, Ok(Value::Boolean(true)));
|
||||
|
||||
let result = interpret("str:ends_with('abc', 'b')");
|
||||
|
||||
assert_eq!(result, Ok(Value::Boolean(false)));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn find() {
|
||||
let result = interpret("str:find('abc', 'a')");
|
||||
|
||||
assert_eq!(result, Ok(Value::Option(Some(Box::new(Value::Integer(0))))));
|
||||
|
||||
let result = interpret("str:find('foobar', 'b')");
|
||||
|
||||
assert_eq!(result, Ok(Value::Option(Some(Box::new(Value::Integer(3))))));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn insert() {
|
||||
assert_eq!(
|
||||
interpret("str:insert('ac', 1, 'b')"),
|
||||
Ok(Value::String("abc".to_string()))
|
||||
);
|
||||
assert_eq!(
|
||||
interpret("str:insert('foo', 3, 'bar')"),
|
||||
Ok(Value::String("foobar".to_string()))
|
||||
);
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user