Write test; Add toml tooling; Fix errors
This commit is contained in:
parent
0b79287132
commit
a5c2e6c49f
@ -1,6 +1,6 @@
|
|||||||
use dust_lib::eval;
|
use dust_lib::{eval, Value};
|
||||||
use iced::widget::{button, column, container, scrollable, text, text_input, Column, Text};
|
use iced::widget::{column, container, text, text_input, Column};
|
||||||
use iced::{executor, Alignment, Application, Command, Element, Sandbox, Settings, Theme};
|
use iced::{executor, Application, Command, Element, Sandbox, Settings, Theme};
|
||||||
use once_cell::sync::Lazy;
|
use once_cell::sync::Lazy;
|
||||||
|
|
||||||
static INPUT_ID: Lazy<text_input::Id> = Lazy::new(text_input::Id::unique);
|
static INPUT_ID: Lazy<text_input::Id> = Lazy::new(text_input::Id::unique);
|
||||||
@ -69,7 +69,7 @@ impl Application for DustGui {
|
|||||||
let mut text_widgets = Vec::new();
|
let mut text_widgets = Vec::new();
|
||||||
|
|
||||||
for result in &self.results {
|
for result in &self.results {
|
||||||
text_widgets.push(text(result).into());
|
// text_widgets.push(text(result).style().into());
|
||||||
}
|
}
|
||||||
|
|
||||||
text_widgets.reverse();
|
text_widgets.reverse();
|
||||||
@ -86,3 +86,7 @@ enum Message {
|
|||||||
TextInput(String),
|
TextInput(String),
|
||||||
Evaluate,
|
Evaluate,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
struct DustOutput {
|
||||||
|
content: dust_lib::Result<Value>,
|
||||||
|
}
|
||||||
|
@ -293,6 +293,12 @@ impl From<trash::Error> for Error {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
impl From<toml::de::Error> for Error {
|
||||||
|
fn from(value: toml::de::Error) -> Self {
|
||||||
|
Error::MacroFailure(value.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
impl Error {
|
impl Error {
|
||||||
pub(crate) fn expect_operator_argument_amount(actual: usize, expected: usize) -> Result<()> {
|
pub(crate) fn expect_operator_argument_amount(actual: usize, expected: usize) -> Result<()> {
|
||||||
if actual == expected {
|
if actual == expected {
|
||||||
|
@ -2,6 +2,26 @@
|
|||||||
|
|
||||||
use crate::{Result, Table, Tool, ToolInfo, Value, ValueType};
|
use crate::{Result, Table, Tool, ToolInfo, Value, ValueType};
|
||||||
|
|
||||||
|
pub struct FromToml;
|
||||||
|
|
||||||
|
impl Tool for FromToml {
|
||||||
|
fn info(&self) -> ToolInfo<'static> {
|
||||||
|
ToolInfo {
|
||||||
|
identifier: "from_toml",
|
||||||
|
description: "Create a value from a TOML string.",
|
||||||
|
group: "data",
|
||||||
|
inputs: vec![ValueType::String],
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fn run(&self, argument: &Value) -> Result<Value> {
|
||||||
|
let argument = argument.as_string()?;
|
||||||
|
let value = toml::from_str(&argument)?;
|
||||||
|
|
||||||
|
Ok(value)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct FromJson;
|
pub struct FromJson;
|
||||||
|
|
||||||
impl Tool for FromJson {
|
impl Tool for FromJson {
|
||||||
|
@ -10,7 +10,7 @@
|
|||||||
|
|
||||||
use std::{
|
use std::{
|
||||||
fmt::{self, Display, Formatter},
|
fmt::{self, Display, Formatter},
|
||||||
time::{Duration, Instant, SystemTime, UNIX_EPOCH},
|
time::{Instant, SystemTime},
|
||||||
};
|
};
|
||||||
|
|
||||||
use chrono::{DateTime, FixedOffset, Local as LocalTime, NaiveDateTime};
|
use chrono::{DateTime, FixedOffset, Local as LocalTime, NaiveDateTime};
|
||||||
|
4
tests/data_formats.ds
Normal file
4
tests/data_formats.ds
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
dob = from_toml("1979-05-27T07:32:00-08:00");
|
||||||
|
toml = to_toml(dob);
|
||||||
|
|
||||||
|
assert_equal(toml, "1979-05-27T07:32:00-08:00");
|
@ -36,3 +36,10 @@ fn scope() {
|
|||||||
|
|
||||||
eval(&file_contents).unwrap();
|
eval(&file_contents).unwrap();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn data_formats() {
|
||||||
|
let file_contents = read_to_string("tests/data_formats.ds").unwrap();
|
||||||
|
|
||||||
|
eval(&file_contents).unwrap();
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user