Implement length tool
This commit is contained in:
parent
e95aa1e437
commit
f07e20c403
@ -14,6 +14,8 @@ pub enum Tool {
|
||||
Read,
|
||||
Help,
|
||||
|
||||
Length,
|
||||
|
||||
Raw,
|
||||
Sh,
|
||||
Bash,
|
||||
@ -38,6 +40,8 @@ impl Tool {
|
||||
"assert_equal" => Tool::AssertEqual,
|
||||
"output" => Tool::Output,
|
||||
|
||||
"length" => Tool::Length,
|
||||
|
||||
"raw" => Tool::Raw,
|
||||
"sh" => Tool::Sh,
|
||||
"bash" => Tool::Bash,
|
||||
@ -118,6 +122,29 @@ impl Tool {
|
||||
|
||||
Value::Empty
|
||||
}
|
||||
Tool::Length => {
|
||||
if values.len() != 1 {
|
||||
return Err(Error::ExpectedToolArgumentAmount {
|
||||
tool_name: "len",
|
||||
expected: 1,
|
||||
actual: values.len(),
|
||||
});
|
||||
}
|
||||
|
||||
let length = if let Ok(list) = values[0].as_list() {
|
||||
list.len()
|
||||
} else if let Ok(map) = values[0].as_map() {
|
||||
map.len()
|
||||
} else if let Ok(table) = values[0].as_table() {
|
||||
table.len()
|
||||
} else if let Ok(string) = values[0].as_string() {
|
||||
string.chars().count()
|
||||
} else {
|
||||
1
|
||||
};
|
||||
|
||||
Value::Integer(length as i64)
|
||||
}
|
||||
Tool::Read => {
|
||||
if values.len() != 1 {
|
||||
return Err(Error::ExpectedToolArgumentAmount {
|
||||
|
@ -1 +1 @@
|
||||
Subproject commit cf22950b7ee6f40c7840b6af4d7b2dda69f4965b
|
||||
Subproject commit 9ec43a98418f395a668c59a79b0832e563d9f0e4
|
Loading…
Reference in New Issue
Block a user