From d54527413d4b95141238eea830411a6dfe157909 Mon Sep 17 00:00:00 2001 From: Jeff Date: Wed, 23 Aug 2023 17:28:19 -0400 Subject: [PATCH] Edit README --- README.md | 40 +++++----- src/commands/collections.rs | 149 +----------------------------------- tests/collections.ds | 21 ++++- 3 files changed, 41 insertions(+), 169 deletions(-) diff --git a/README.md b/README.md index a5f7886..374fcf4 100644 --- a/README.md +++ b/README.md @@ -1,21 +1,5 @@ # Dust - -- [Dust](#dust) - - [Features](#features) - - [Usage](#usage) - - [Installation](#installation) - - [The Dust Programming Language](#the-dust-programming-language) - - [Variables and Data Types](#variables-and-data-types) - - [Commands](#commands) - - [Lists](#lists) - - [Maps](#maps) - - [Tables](#tables) - - [The Yield Operator](#the-yield-operator) - - [Functions](#functions) - - [Time](#time) - - Dust is a data-oriented programming language and interactive shell. Dust can be used as a replacement for a traditional command line shell, as a scripting language and as a tool create or manage data. Dust is expression-based, has first-class functions, lexical scope and lightweight syntax. A basic dust program: @@ -43,6 +27,22 @@ read("examples/assets/faithful.csv") -> plot(input) ``` + +- [Dust](#dust) + - [Features](#features) + - [Usage](#usage) + - [Installation](#installation) + - [The Dust Programming Language](#the-dust-programming-language) + - [Variables and Data Types](#variables-and-data-types) + - [Commands](#commands) + - [Lists](#lists) + - [Maps](#maps) + - [Tables](#tables) + - [The Yield Operator](#the-yield-operator) + - [Functions](#functions) + - [Time](#time) + + ## Features - Data visualization: GUI (not TUI) plots, graphs and charts are available from directly within dust. No external tools are needed. @@ -60,11 +60,15 @@ Dust is an experimental project under active development. At this stage, feature You must have the default rust toolchain installed and up-to-date. Clone the repository and run `cargo run` to start the interactive shell. To see other command line options, use `cargo run -- --help`. +## Contributing + +Please submit any thoughts or suggestions for this project. To contribute a new command, see the library documentation. Implementation tests are written in dust and are run by a corresponding rust test so dust tests will be run when `cargo test` is called. + ## The Dust Programming Language Dust is a hard fork of [evalexpr]; a simple expression language. Dust's core language features maintain this simplicity. But it can manage large, complex sets of data and perform complicated tasks through commands. It should not take long for a new user to learn the language, especially with the assistance of the shell. -If your editor supports tree sitter, you can use [tree-sitter-dust] for syntax highlighting and completion support. +If your editor supports tree sitter, you can use [tree-sitter-dust] for syntax highlighting and completion support. Aside from this guide, the best way to learn dust is to read the examples and tests to get a better idea of what dust can do. ### Variables and Data Types @@ -166,7 +170,7 @@ insert( assert_eq(length(animals.all), 6); -animals.by_name = sort_by(animals.all, "name"); +by_name = sort_by(animals, "name"); ``` ### The Yield Operator diff --git a/src/commands/collections.rs b/src/commands/collections.rs index 53b2960..5aa3272 100644 --- a/src/commands/collections.rs +++ b/src/commands/collections.rs @@ -8,7 +8,7 @@ impl Macro for Transform { fn info(&self) -> MacroInfo<'static> { MacroInfo { identifier: "transform", - description: "Change each value with a function.", + description: "Alter a collection by calling a function on each value.", group: "collections", inputs: vec![ValueType::ListOf(vec![ ValueType::List, @@ -418,150 +418,3 @@ impl Macro for Where { todo!() } } - -#[cfg(test)] -mod tests { - use crate::Function; - - use super::*; - - #[test] - fn where_from_non_collections() { - Where - .run(&Value::List(vec![ - Value::Integer(1), - Value::Function(Function::new("input == 1")), - ])) - .unwrap_err(); - Where - .run(&Value::List(vec![ - Value::Float(1.0), - Value::Function(Function::new("input == 1.0")), - ])) - .unwrap_err(); - Where - .run(&Value::List(vec![ - Value::Boolean(true), - Value::Function(Function::new("input == true")), - ])) - .unwrap_err(); - } - - #[test] - fn where_from_list() { - let arguments = Value::List(vec![ - Value::List(vec![Value::Integer(1), Value::Integer(2)]), - Value::Function(Function::new("input == 1")), - ]); - let select = Where.run(&arguments).unwrap(); - - assert_eq!(Value::List(vec![Value::Integer(1)]), select); - } - - #[test] - fn where_from_map() { - let mut map = VariableMap::new(); - - map.set_value("foo", Value::Integer(1)).unwrap(); - map.set_value("bar", Value::Integer(2)).unwrap(); - - let arguments = Value::List(vec![ - Value::Map(map), - Value::Function(Function::new("input == 1")), - ]); - let select = Where.run(&arguments).unwrap(); - - let mut map = VariableMap::new(); - - map.set_value("foo", Value::Integer(1)).unwrap(); - - assert_eq!(Value::Map(map), select); - } - - #[test] - fn where_from_table() { - let mut table = Table::new(vec!["foo".to_string(), "bar".to_string()]); - - table - .insert(vec![Value::Integer(1), Value::Integer(2)]) - .unwrap(); - table - .insert(vec![Value::Integer(3), Value::Integer(4)]) - .unwrap(); - - let arguments = Value::List(vec![ - Value::Table(table), - Value::Function(Function::new("foo == 1")), - ]); - let select = Where.run(&arguments).unwrap(); - let mut table = Table::new(vec!["foo".to_string(), "bar".to_string()]); - - table - .insert(vec![Value::Integer(1), Value::Integer(2)]) - .unwrap(); - - assert_eq!(Value::Table(table), select); - } - - #[test] - fn select_from_non_collections() { - Select - .run(&Value::List(vec![Value::Integer(1), Value::Integer(1)])) - .unwrap_err(); - Select - .run(&Value::List(vec![Value::Float(1.0), Value::Float(1.0)])) - .unwrap_err(); - Select - .run(&Value::List(vec![ - Value::Boolean(true), - Value::Boolean(true), - ])) - .unwrap_err(); - } - - #[test] - fn select_from_list() { - let arguments = Value::List(vec![ - Value::List(vec![Value::Integer(1), Value::Integer(2)]), - Value::Integer(0), - ]); - let select = Select.run(&arguments).unwrap(); - - assert_eq!(Value::List(vec![Value::Integer(1)]), select); - } - - #[test] - fn select_from_map() { - let mut map = VariableMap::new(); - - map.set_value("foo", Value::Integer(1)).unwrap(); - map.set_value("bar", Value::Integer(2)).unwrap(); - - let arguments = Value::List(vec![Value::Map(map), Value::String("foo".to_string())]); - let select = Select.run(&arguments).unwrap(); - - let mut map = VariableMap::new(); - - map.set_value("foo", Value::Integer(1)).unwrap(); - - assert_eq!(Value::Map(map), select); - } - - #[test] - fn select_from_table() { - let mut table = Table::new(vec!["foo".to_string(), "bar".to_string()]); - - table - .insert(vec![Value::Integer(1), Value::Integer(2)]) - .unwrap(); - - let arguments = Value::List(vec![Value::Table(table), Value::String("foo".to_string())]); - let select = Select.run(&arguments).unwrap(); - - let mut table = Table::new(vec!["foo".to_string()]); - - table.insert(vec![Value::Integer(1)]).unwrap(); - - assert_eq!(Value::Table(table), select); - } -} diff --git a/tests/collections.ds b/tests/collections.ds index 8c53ca6..936aaa3 100644 --- a/tests/collections.ds +++ b/tests/collections.ds @@ -1,7 +1,22 @@ -list = (1, 2, 3); +# transform +list = (1, 2, 3); test = transform(list, 'input + 1'); assert_equal((2, 3, 4), test); -test = get(list, 0); -assert_equal(1, test); +# string +test = string(42); +assert_equal("42", test); + +test = string(42.42); +assert_equal("42.42", test); + +test = string(false); +assert_equal("false", test); + +# count + +test = count("123"); +assert_equal(3, test); + +# create_table