Add type checks
This commit is contained in:
parent
8d04e0bb04
commit
8721ad41b1
@ -1,4 +1,6 @@
|
||||
//! Macros for collection values: strings, lists, maps and tables.
|
||||
//!
|
||||
//! Tests for this module are written in Dust and can be found at tests/collections.ds.
|
||||
|
||||
use crate::{Error, Result, Table, Tool, ToolInfo, Value, ValueType, VariableMap};
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
use std::process::Command;
|
||||
|
||||
use crate::{Result, Tool, ToolInfo, Value};
|
||||
use crate::{Result, Tool, ToolInfo, Value, ValueType};
|
||||
|
||||
pub struct Sh;
|
||||
|
||||
@ -10,7 +10,7 @@ impl Tool for Sh {
|
||||
identifier: "sh",
|
||||
description: "Pass input to the Bourne Shell.",
|
||||
group: "command",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::String],
|
||||
}
|
||||
}
|
||||
|
||||
@ -31,7 +31,7 @@ impl Tool for Bash {
|
||||
identifier: "bash",
|
||||
description: "Pass input to the Bourne Again Shell.",
|
||||
group: "command",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::String],
|
||||
}
|
||||
}
|
||||
|
||||
@ -55,7 +55,7 @@ impl Tool for Fish {
|
||||
identifier: "fish",
|
||||
description: "Pass input to the fish shell.",
|
||||
group: "command",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::String],
|
||||
}
|
||||
}
|
||||
|
||||
@ -80,7 +80,7 @@ impl Tool for Zsh {
|
||||
identifier: "zsh",
|
||||
description: "Pass input to the Z shell.",
|
||||
group: "command",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::String],
|
||||
}
|
||||
}
|
||||
|
||||
@ -105,7 +105,7 @@ impl Tool for Raw {
|
||||
identifier: "raw",
|
||||
description: "Run input as a command without a shell",
|
||||
group: "command",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::String],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -30,7 +30,7 @@ impl Tool for ToJson {
|
||||
identifier: "to_json",
|
||||
description: "Create a JSON string from a whale value.",
|
||||
group: "data",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::Any],
|
||||
}
|
||||
}
|
||||
|
||||
@ -96,7 +96,7 @@ impl Tool for ToCsv {
|
||||
identifier: "to_csv",
|
||||
description: "Convert a value to a string of comma-separated values.",
|
||||
group: "data",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::Any],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -2,7 +2,7 @@ use std::process::Command;
|
||||
|
||||
use sysinfo::{DiskExt, System, SystemExt};
|
||||
|
||||
use crate::{Result, Table, Tool, ToolInfo, Value};
|
||||
use crate::{Result, Table, Tool, ToolInfo, Value, ValueType};
|
||||
|
||||
pub struct ListDisks;
|
||||
|
||||
@ -12,7 +12,7 @@ impl Tool for ListDisks {
|
||||
identifier: "list_disks",
|
||||
description: "List all block devices.",
|
||||
group: "disks",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::Empty],
|
||||
}
|
||||
}
|
||||
|
||||
@ -66,7 +66,7 @@ impl Tool for Partition {
|
||||
identifier: "partition",
|
||||
description: "Partition a disk, clearing its content.",
|
||||
group: "disks",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::Map],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,8 +1,8 @@
|
||||
use std::{fs, thread::sleep, time::Duration};
|
||||
use std::{thread::sleep, time::Duration};
|
||||
|
||||
use rayon::prelude::{IntoParallelRefIterator, ParallelIterator};
|
||||
|
||||
use crate::{Function, Result, Tool, ToolInfo, Value};
|
||||
use crate::{Result, Tool, ToolInfo, Value, ValueType};
|
||||
|
||||
pub struct Output;
|
||||
|
||||
@ -12,7 +12,7 @@ impl Tool for Output {
|
||||
identifier: "output",
|
||||
description: "Print a value.",
|
||||
group: "general",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::Any],
|
||||
}
|
||||
}
|
||||
|
||||
@ -30,7 +30,10 @@ impl Tool for Repeat {
|
||||
identifier: "repeat",
|
||||
description: "Run a function the given number of times.",
|
||||
group: "general",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::ListExact(vec![
|
||||
ValueType::Function,
|
||||
ValueType::Integer,
|
||||
])],
|
||||
}
|
||||
}
|
||||
|
||||
@ -50,35 +53,15 @@ impl Tool for Repeat {
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Run;
|
||||
|
||||
impl Tool for Run {
|
||||
fn info(&self) -> ToolInfo<'static> {
|
||||
ToolInfo {
|
||||
identifier: "run",
|
||||
description: "Run a whale file.",
|
||||
group: "general",
|
||||
inputs: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
fn run(&self, argument: &Value) -> Result<Value> {
|
||||
let path = argument.as_string()?;
|
||||
let file_contents = fs::read_to_string(path)?;
|
||||
|
||||
Function::new(&file_contents).run()
|
||||
}
|
||||
}
|
||||
|
||||
pub struct Async;
|
||||
|
||||
impl Tool for Async {
|
||||
fn info(&self) -> ToolInfo<'static> {
|
||||
ToolInfo {
|
||||
identifier: "async",
|
||||
identifier: "run",
|
||||
description: "Run functions in parallel.",
|
||||
group: "general",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::ListOf(Box::new(ValueType::Function))],
|
||||
}
|
||||
}
|
||||
|
||||
@ -112,7 +95,7 @@ impl Tool for Wait {
|
||||
identifier: "wait",
|
||||
description: "Wait for the given number of milliseconds.",
|
||||
group: "general",
|
||||
inputs: vec![],
|
||||
inputs: vec![ValueType::Integer],
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -51,7 +51,7 @@ pub mod time;
|
||||
/// Master list of all tools.
|
||||
///
|
||||
/// This list is used to match identifiers with tools and to provide info to the shell.
|
||||
pub const TOOL_LIST: [&'static dyn Tool; 56] = [
|
||||
pub const TOOL_LIST: [&'static dyn Tool; 55] = [
|
||||
&collections::Count,
|
||||
&collections::CreateTable,
|
||||
&collections::Insert,
|
||||
@ -84,7 +84,6 @@ pub const TOOL_LIST: [&'static dyn Tool; 56] = [
|
||||
&general::Async,
|
||||
&general::Output,
|
||||
&general::Repeat,
|
||||
&general::Run,
|
||||
&general::Wait,
|
||||
&gui::BarGraph,
|
||||
&gui::Plot,
|
||||
@ -385,7 +384,7 @@ mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn macro_formatting() {
|
||||
fn tool_identifier_formatting() {
|
||||
for function in TOOL_LIST {
|
||||
let identifier = function.info().identifier;
|
||||
|
||||
@ -398,4 +397,14 @@ mod tests {
|
||||
assert!(!identifier.contains('-'));
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tool_inputs_exist() {
|
||||
for function in TOOL_LIST {
|
||||
let identifier = function.info().identifier;
|
||||
let input_count = function.info().inputs.len();
|
||||
|
||||
assert!(input_count > 0, "{} has no inputs declared", identifier);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user