Enumerate error types instead of boxing, make error traits private
This commit is contained in:
parent
6abc3c7783
commit
4581fe8fe9
8 changed files with 119 additions and 68 deletions
|
@ -23,7 +23,7 @@ let interpreter = MpsRunner::with_stream(cursor);
|
||||||
// warning: my library has ~3800 songs, so this outputs too much information to be useful.
|
// warning: my library has ~3800 songs, so this outputs too much information to be useful.
|
||||||
for result in interpreter {
|
for result in interpreter {
|
||||||
match result {
|
match result {
|
||||||
Ok(item) => println!("Got song `{}` (file: `{}`)", item.title, item.filename),
|
Ok(item) => println!("Got song `{}` (file: `{}`)", item.field("title").unwrap(), item.field("filename").unwrap()),
|
||||||
Err(e) => panic!("Got error while executing: {}", e),
|
Err(e) => panic!("Got error while executing: {}", e),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
50
mps-interpreter/src/errors.rs
Normal file
50
mps-interpreter/src/errors.rs
Normal file
|
@ -0,0 +1,50 @@
|
||||||
|
use std::fmt::{Debug, Display, Error, Formatter};
|
||||||
|
use std::convert::From;
|
||||||
|
|
||||||
|
use crate::lang::{SyntaxError, RuntimeError, MpsLanguageError};
|
||||||
|
use crate::tokens::ParseError;
|
||||||
|
|
||||||
|
#[derive(Debug)]
|
||||||
|
pub enum MpsError {
|
||||||
|
Syntax(SyntaxError),
|
||||||
|
Runtime(RuntimeError),
|
||||||
|
Parse(ParseError),
|
||||||
|
}
|
||||||
|
|
||||||
|
impl Display for MpsError {
|
||||||
|
fn fmt(&self, f: &mut Formatter) -> Result<(), Error> {
|
||||||
|
match self {
|
||||||
|
Self::Syntax(e) => (e as &dyn Display).fmt(f),
|
||||||
|
Self::Runtime(e) => (e as &dyn Display).fmt(f),
|
||||||
|
Self::Parse(e) => (e as &dyn Display).fmt(f),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl MpsLanguageError for MpsError {
|
||||||
|
fn set_line(&mut self, line: usize) {
|
||||||
|
match self {
|
||||||
|
Self::Syntax(e) => e.set_line(line),
|
||||||
|
Self::Runtime(e) => e.set_line(line),
|
||||||
|
Self::Parse(e) => e.set_line(line),
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<SyntaxError> for MpsError {
|
||||||
|
fn from(e: SyntaxError) -> Self {
|
||||||
|
Self::Syntax(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<RuntimeError> for MpsError {
|
||||||
|
fn from(e: RuntimeError) -> Self {
|
||||||
|
Self::Runtime(e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
impl From<ParseError> for MpsError {
|
||||||
|
fn from(e: ParseError) -> Self {
|
||||||
|
Self::Parse(e)
|
||||||
|
}
|
||||||
|
}
|
|
@ -7,6 +7,7 @@ use super::lang::{MpsLanguageDictionary, MpsLanguageError, MpsOp};
|
||||||
use super::tokens::MpsToken;
|
use super::tokens::MpsToken;
|
||||||
use super::MpsContext;
|
use super::MpsContext;
|
||||||
use super::MpsItem;
|
use super::MpsItem;
|
||||||
|
use super::MpsError;
|
||||||
|
|
||||||
/// The script interpreter.
|
/// The script interpreter.
|
||||||
/// Use MpsRunner for a better interface.
|
/// Use MpsRunner for a better interface.
|
||||||
|
@ -81,7 +82,7 @@ impl<T> Iterator for MpsInterpretor<T>
|
||||||
where
|
where
|
||||||
T: crate::tokens::MpsTokenReader,
|
T: crate::tokens::MpsTokenReader,
|
||||||
{
|
{
|
||||||
type Item = Result<MpsItem, Box<dyn MpsLanguageError>>;
|
type Item = Result<MpsItem, MpsError>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let mut is_stmt_done = false;
|
let mut is_stmt_done = false;
|
||||||
|
@ -91,7 +92,7 @@ where
|
||||||
is_stmt_done = true;
|
is_stmt_done = true;
|
||||||
}
|
}
|
||||||
next_item
|
next_item
|
||||||
.map(|item| item.map_err(|e| box_error_with_ctx(e, self.tokenizer.current_line())))
|
.map(|item| item.map_err(|e| error_with_ctx(e.into(), self.tokenizer.current_line())))
|
||||||
} else {
|
} else {
|
||||||
/*if self.tokenizer.end_of_file() {
|
/*if self.tokenizer.end_of_file() {
|
||||||
return None;
|
return None;
|
||||||
|
@ -101,7 +102,7 @@ where
|
||||||
let token_result = self
|
let token_result = self
|
||||||
.tokenizer
|
.tokenizer
|
||||||
.next_statement(&mut self.buffer)
|
.next_statement(&mut self.buffer)
|
||||||
.map_err(|e| box_error_with_ctx(e, self.tokenizer.current_line()));
|
.map_err(|e| error_with_ctx(e.into(), self.tokenizer.current_line()));
|
||||||
match token_result {
|
match token_result {
|
||||||
Ok(_) => {}
|
Ok(_) => {}
|
||||||
Err(x) => return Some(Err(x)),
|
Err(x) => return Some(Err(x)),
|
||||||
|
@ -123,11 +124,11 @@ where
|
||||||
is_stmt_done = true;
|
is_stmt_done = true;
|
||||||
}
|
}
|
||||||
next_item.map(|item| {
|
next_item.map(|item| {
|
||||||
item.map_err(|e| box_error_with_ctx(e, self.tokenizer.current_line()))
|
item.map_err(|e| error_with_ctx(e.into(), self.tokenizer.current_line()))
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
Some(Err(e).map_err(|e| box_error_with_ctx(e, self.tokenizer.current_line())))
|
Some(Err(e).map_err(|e| error_with_ctx(e.into(), self.tokenizer.current_line())))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
@ -138,12 +139,9 @@ where
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn box_error_with_ctx<E: MpsLanguageError + 'static>(
|
fn error_with_ctx(mut error: MpsError, line: usize) -> MpsError {
|
||||||
mut error: E,
|
|
||||||
line: usize,
|
|
||||||
) -> Box<dyn MpsLanguageError> {
|
|
||||||
error.set_line(line);
|
error.set_line(line);
|
||||||
Box::new(error) as Box<dyn MpsLanguageError>
|
error
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Builder function to add the standard statements of MPS.
|
/// Builder function to add the standard statements of MPS.
|
||||||
|
|
|
@ -16,7 +16,8 @@ mod type_primitives;
|
||||||
pub(crate) mod utility;
|
pub(crate) mod utility;
|
||||||
|
|
||||||
pub use dictionary::MpsLanguageDictionary;
|
pub use dictionary::MpsLanguageDictionary;
|
||||||
pub use error::{MpsLanguageError, RuntimeError, RuntimeMsg, RuntimeOp, SyntaxError};
|
pub use error::{RuntimeError, RuntimeMsg, RuntimeOp, SyntaxError};
|
||||||
|
pub(crate) use error::MpsLanguageError;
|
||||||
pub use filter::{
|
pub use filter::{
|
||||||
MpsFilterFactory, MpsFilterPredicate, MpsFilterStatement, MpsFilterStatementFactory,
|
MpsFilterFactory, MpsFilterPredicate, MpsFilterStatement, MpsFilterStatementFactory,
|
||||||
};
|
};
|
||||||
|
|
|
@ -21,7 +21,7 @@
|
||||||
//! // warning: my library has ~3800 songs, so this outputs too much information to be useful.
|
//! // warning: my library has ~3800 songs, so this outputs too much information to be useful.
|
||||||
//! for result in interpreter {
|
//! for result in interpreter {
|
||||||
//! match result {
|
//! match result {
|
||||||
//! Ok(item) => println!("Got song `{}` (file: `{}`)", item.title, item.filename),
|
//! Ok(item) => println!("Got song `{}` (file: `{}`)", item.field("title").unwrap(), item.field("filename").unwrap()),
|
||||||
//! Err(e) => panic!("Got error while executing: {}", e),
|
//! Err(e) => panic!("Got error while executing: {}", e),
|
||||||
//! }
|
//! }
|
||||||
//! }
|
//! }
|
||||||
|
@ -240,6 +240,7 @@
|
||||||
//!
|
//!
|
||||||
|
|
||||||
mod context;
|
mod context;
|
||||||
|
mod errors;
|
||||||
mod interpretor;
|
mod interpretor;
|
||||||
mod item;
|
mod item;
|
||||||
pub mod lang;
|
pub mod lang;
|
||||||
|
@ -251,6 +252,7 @@ mod runner;
|
||||||
pub mod tokens;
|
pub mod tokens;
|
||||||
|
|
||||||
pub use context::MpsContext;
|
pub use context::MpsContext;
|
||||||
|
pub use errors::MpsError;
|
||||||
pub use interpretor::{interpretor, MpsInterpretor};
|
pub use interpretor::{interpretor, MpsInterpretor};
|
||||||
pub use item::MpsItem;
|
pub use item::MpsItem;
|
||||||
//pub(crate) use item::MpsItemRuntimeUtil;
|
//pub(crate) use item::MpsItemRuntimeUtil;
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
use std::io::Read;
|
use std::io::Read;
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
|
|
||||||
use super::lang::{MpsLanguageDictionary, MpsLanguageError};
|
use super::lang::MpsLanguageDictionary;
|
||||||
use super::tokens::{MpsTokenReader, MpsTokenizer};
|
use super::tokens::{MpsTokenReader, MpsTokenizer};
|
||||||
use super::{MpsContext, MpsInterpretor, MpsItem};
|
use super::{MpsContext, MpsInterpretor, MpsItem, MpsError};
|
||||||
|
|
||||||
pub struct MpsRunnerSettings<T: MpsTokenReader> {
|
pub struct MpsRunnerSettings<T: MpsTokenReader> {
|
||||||
pub vocabulary: MpsLanguageDictionary,
|
pub vocabulary: MpsLanguageDictionary,
|
||||||
|
@ -57,7 +57,7 @@ impl<R: Read> MpsRunner<MpsTokenizer<R>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
impl<T: MpsTokenReader> Iterator for MpsRunner<T> {
|
impl<T: MpsTokenReader> Iterator for MpsRunner<T> {
|
||||||
type Item = Result<MpsItem, Box<dyn MpsLanguageError>>;
|
type Item = Result<MpsItem, MpsError>;
|
||||||
|
|
||||||
fn next(&mut self) -> Option<Self::Item> {
|
fn next(&mut self) -> Option<Self::Item> {
|
||||||
let mut item = self.interpretor.next();
|
let mut item = self.interpretor.next();
|
||||||
|
|
|
@ -2,6 +2,6 @@ mod error;
|
||||||
mod token_enum;
|
mod token_enum;
|
||||||
mod tokenizer;
|
mod tokenizer;
|
||||||
|
|
||||||
pub use error::{MpsTokenError, ParseError};
|
pub use error::ParseError;
|
||||||
pub use token_enum::MpsToken;
|
pub use token_enum::MpsToken;
|
||||||
pub use tokenizer::{MpsTokenReader, MpsTokenizer};
|
pub use tokenizer::{MpsTokenReader, MpsTokenizer};
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
use mps_interpreter::lang::MpsLanguageError;
|
use mps_interpreter::MpsError;
|
||||||
use mps_interpreter::tokens::{MpsToken, MpsTokenizer, ParseError};
|
use mps_interpreter::tokens::{MpsToken, MpsTokenizer, ParseError};
|
||||||
use mps_interpreter::*;
|
use mps_interpreter::*;
|
||||||
use std::collections::VecDeque;
|
use std::collections::VecDeque;
|
||||||
|
@ -43,7 +43,7 @@ fn execute_single_line(
|
||||||
line: &str,
|
line: &str,
|
||||||
should_be_emtpy: bool,
|
should_be_emtpy: bool,
|
||||||
should_complete: bool,
|
should_complete: bool,
|
||||||
) -> Result<(), Box<dyn MpsLanguageError>> {
|
) -> Result<(), MpsError> {
|
||||||
if line.contains('\n') {
|
if line.contains('\n') {
|
||||||
println!(
|
println!(
|
||||||
"--- Executing MPS code ---\n{}\n--- Executing MPS code ---",
|
"--- Executing MPS code ---\n{}\n--- Executing MPS code ---",
|
||||||
|
@ -108,23 +108,23 @@ fn execute_single_line(
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_sql_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_sql_line() -> Result<(), MpsError> {
|
||||||
execute_single_line("sql(`SELECT * FROM songs ORDER BY artist;`)", false, true)
|
execute_single_line("sql(`SELECT * FROM songs ORDER BY artist;`)", false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_simple_sql_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_simple_sql_line() -> Result<(), MpsError> {
|
||||||
execute_single_line("song(`lov`)", false, true)
|
execute_single_line("song(`lov`)", false, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_comment_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_comment_line() -> Result<(), MpsError> {
|
||||||
execute_single_line("// this is a comment", true, true)?;
|
execute_single_line("// this is a comment", true, true)?;
|
||||||
execute_single_line("# this is a special comment", true, true)
|
execute_single_line("# this is a special comment", true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_repeat_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_repeat_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"repeat(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
"repeat(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
||||||
false,
|
false,
|
||||||
|
@ -143,7 +143,7 @@ fn execute_repeat_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_sql_init_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_sql_init_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"sql_init(generate = false, folder = `/home/ngnius/Music`)",
|
"sql_init(generate = false, folder = `/home/ngnius/Music`)",
|
||||||
true,
|
true,
|
||||||
|
@ -152,7 +152,7 @@ fn execute_sql_init_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_assign_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_assign_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"let some_var = repeat(song(`Christmas in L.A.`))",
|
"let some_var = repeat(song(`Christmas in L.A.`))",
|
||||||
true,
|
true,
|
||||||
|
@ -162,7 +162,7 @@ fn execute_assign_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_emptyfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_emptyfilter_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).().().()",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).().().()",
|
||||||
false,
|
false,
|
||||||
|
@ -171,7 +171,7 @@ fn execute_emptyfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_fieldfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_fieldfilter_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year >= 2000)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year >= 2000)",
|
||||||
false,
|
false,
|
||||||
|
@ -195,7 +195,7 @@ fn execute_fieldfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_fieldfiltermaybe_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_fieldfiltermaybe_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year? >= 2000)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year? >= 2000)",
|
||||||
false,
|
false,
|
||||||
|
@ -219,7 +219,7 @@ fn execute_fieldfiltermaybe_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_files_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_files_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
r"files(folder=`~/Music/MusicFlac/Bruno Mars/24K Magic/`, re=``, recursive=false)",
|
r"files(folder=`~/Music/MusicFlac/Bruno Mars/24K Magic/`, re=``, recursive=false)",
|
||||||
false,
|
false,
|
||||||
|
@ -234,7 +234,7 @@ fn execute_files_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_indexfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_indexfilter_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(2)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(2)",
|
||||||
false,
|
false,
|
||||||
|
@ -258,7 +258,7 @@ fn execute_indexfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_rangefilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_rangefilter_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(..)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(..)",
|
||||||
false,
|
false,
|
||||||
|
@ -282,7 +282,7 @@ fn execute_rangefilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_orfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_orfilter_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(4 || 5)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(4 || 5)",
|
||||||
false,
|
false,
|
||||||
|
@ -301,7 +301,7 @@ fn execute_orfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_replacefilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_replacefilter_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(if 4: files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(5))",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(if 4: files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(5))",
|
||||||
false,
|
false,
|
||||||
|
@ -320,7 +320,7 @@ fn execute_replacefilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_emptysort_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_emptysort_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).sort()",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).sort()",
|
||||||
false,
|
false,
|
||||||
|
@ -334,7 +334,7 @@ fn execute_emptysort_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_likefilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_likefilter_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(not_a_field? like `24K Magic`)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(not_a_field? like `24K Magic`)",
|
||||||
true,
|
true,
|
||||||
|
@ -353,7 +353,7 @@ fn execute_likefilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_fieldsort_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_fieldsort_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(title)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(title)",
|
||||||
false,
|
false,
|
||||||
|
@ -367,7 +367,7 @@ fn execute_fieldsort_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_blissfirstsort_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_blissfirstsort_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(advanced bliss_first)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(advanced bliss_first)",
|
||||||
false,
|
false,
|
||||||
|
@ -376,7 +376,7 @@ fn execute_blissfirstsort_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_blissnextsort_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_blissnextsort_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(advanced bliss_next)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(advanced bliss_next)",
|
||||||
false,
|
false,
|
||||||
|
@ -385,17 +385,17 @@ fn execute_blissnextsort_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_emptyfn_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_emptyfn_line() -> Result<(), MpsError> {
|
||||||
execute_single_line("empty()", true, true)
|
execute_single_line("empty()", true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_resetfn_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_resetfn_line() -> Result<(), MpsError> {
|
||||||
execute_single_line("reset(empty())", true, true)
|
execute_single_line("reset(empty())", true, true)
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_shufflesort_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_shufflesort_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(random shuffle)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(random shuffle)",
|
||||||
false,
|
false,
|
||||||
|
@ -410,7 +410,7 @@ fn execute_shufflesort_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_unionfn_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_unionfn_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"union(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
"union(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
||||||
false,
|
false,
|
||||||
|
@ -434,7 +434,7 @@ fn execute_unionfn_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_regexfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_regexfilter_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(title matches `24K\\\\s+Magic`)", // note: quad-escape not required in scripts
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(title matches `24K\\\\s+Magic`)", // note: quad-escape not required in scripts
|
||||||
false,
|
false,
|
||||||
|
@ -448,7 +448,7 @@ fn execute_regexfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_intersectionfn_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_intersectionfn_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"intersection(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
"intersection(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
||||||
false,
|
false,
|
||||||
|
@ -472,7 +472,7 @@ fn execute_intersectionfn_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_declareitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_declareitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{let x = empty()}",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{let x = empty()}",
|
||||||
false,
|
false,
|
||||||
|
@ -481,7 +481,7 @@ fn execute_declareitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_removeitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_removeitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{remove item.title, remove item}",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{remove item.title, remove item}",
|
||||||
true,
|
true,
|
||||||
|
@ -490,7 +490,7 @@ fn execute_removeitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_multiitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_multiitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
let x = empty(),
|
let x = empty(),
|
||||||
|
@ -503,7 +503,7 @@ fn execute_multiitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_fieldassignitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_fieldassignitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.potato = empty(),
|
item.potato = empty(),
|
||||||
|
@ -515,7 +515,7 @@ fn execute_fieldassignitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_constitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_constitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
`str const`,
|
`str const`,
|
||||||
|
@ -530,7 +530,7 @@ fn execute_constitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_retrieveitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_retrieveitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.path = item.filename,
|
item.path = item.filename,
|
||||||
|
@ -543,7 +543,7 @@ fn execute_retrieveitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_additemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_additemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.title = `TEST` + item.title,
|
item.title = `TEST` + item.title,
|
||||||
|
@ -555,7 +555,7 @@ fn execute_additemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_subtractitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_subtractitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.test = 1234 - 94,
|
item.test = 1234 - 94,
|
||||||
|
@ -566,7 +566,7 @@ fn execute_subtractitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_negateitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_negateitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.test = 1234,
|
item.test = 1234,
|
||||||
|
@ -579,7 +579,7 @@ fn execute_negateitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_notitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_notitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.test = false,
|
item.test = false,
|
||||||
|
@ -592,7 +592,7 @@ fn execute_notitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_orlogicalitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_orlogicalitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.test = true || true,
|
item.test = true || true,
|
||||||
|
@ -604,7 +604,7 @@ fn execute_orlogicalitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_andlogicalitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_andlogicalitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.test = true && true,
|
item.test = true && true,
|
||||||
|
@ -616,7 +616,7 @@ fn execute_andlogicalitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_bracketsitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_bracketsitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.test = true && true && (false || false),
|
item.test = true && true && (false || false),
|
||||||
|
@ -628,7 +628,7 @@ fn execute_bracketsitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_stringifyitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_stringifyitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.filepath = ~`test out: {test}` item,
|
item.filepath = ~`test out: {test}` item,
|
||||||
|
@ -642,7 +642,7 @@ fn execute_stringifyitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_branchitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_branchitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
if false {
|
if false {
|
||||||
|
@ -660,7 +660,7 @@ fn execute_branchitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_compareitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_compareitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
if 42 != 42 {
|
if 42 != 42 {
|
||||||
|
@ -675,7 +675,7 @@ fn execute_compareitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_computeitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_computeitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
let count = 1,
|
let count = 1,
|
||||||
|
@ -694,7 +694,7 @@ fn execute_computeitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_complexitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_complexitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).().{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).().{
|
||||||
let count = 1,
|
let count = 1,
|
||||||
|
@ -713,7 +713,7 @@ fn execute_complexitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_constructitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_constructitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
let other_item = Item (),
|
let other_item = Item (),
|
||||||
|
@ -731,7 +731,7 @@ fn execute_constructitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_iteritemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_iteritemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item = iter empty()
|
item = iter empty()
|
||||||
|
@ -742,7 +742,7 @@ fn execute_iteritemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_uniquefieldfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_uniquefieldfilter_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"repeat(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), 3).(unique title?)",
|
"repeat(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), 3).(unique title?)",
|
||||||
false,
|
false,
|
||||||
|
@ -761,7 +761,7 @@ fn execute_uniquefieldfilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_uniquefilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_uniquefilter_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(unique)",
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(unique)",
|
||||||
false,
|
false,
|
||||||
|
@ -770,7 +770,7 @@ fn execute_uniquefilter_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_fileitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_fileitemop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
||||||
item.title = `something else`,
|
item.title = `something else`,
|
||||||
|
@ -782,7 +782,7 @@ fn execute_fileitemop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn execute_emptiesop_line() -> Result<(), Box<dyn MpsLanguageError>> {
|
fn execute_emptiesop_line() -> Result<(), MpsError> {
|
||||||
execute_single_line(
|
execute_single_line(
|
||||||
"empties(1).{let count = 0, item.title = ~`title #{}` count+1, item.filename = ~`filename_{}` count, count = count + 1}",
|
"empties(1).{let count = 0, item.title = ~`title #{}` count+1, item.filename = ~`filename_{}` count, count = count + 1}",
|
||||||
false,
|
false,
|
||||||
|
|
Loading…
Reference in a new issue