2021-12-12 19:59:43 +00:00
|
|
|
use mps_interpreter::tokens::{MpsToken, MpsTokenizer, ParseError};
|
2022-03-16 20:27:08 +00:00
|
|
|
use mps_interpreter::MpsError;
|
2021-12-12 19:59:43 +00:00
|
|
|
use mps_interpreter::*;
|
|
|
|
use std::collections::VecDeque;
|
|
|
|
use std::io::Cursor;
|
2021-12-03 21:13:19 +00:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn parse_line() -> Result<(), ParseError> {
|
|
|
|
let cursor = Cursor::new("sql(`SELECT * FROM songs;`)");
|
|
|
|
let correct_tokens: Vec<MpsToken> = vec![
|
2021-12-29 17:12:58 +00:00
|
|
|
MpsToken::Name("sql".into()),
|
2021-12-03 21:13:19 +00:00
|
|
|
MpsToken::OpenBracket,
|
|
|
|
MpsToken::Literal("SELECT * FROM songs;".into()),
|
|
|
|
MpsToken::CloseBracket,
|
|
|
|
];
|
|
|
|
|
|
|
|
let mut tokenizer = MpsTokenizer::new(cursor);
|
|
|
|
let mut buf = VecDeque::<MpsToken>::new();
|
|
|
|
tokenizer.read_line(&mut buf)?; // operation being tested
|
|
|
|
|
|
|
|
// debug output
|
|
|
|
println!("Token buffer:");
|
|
|
|
for i in 0..buf.len() {
|
|
|
|
println!(" Token #{}: {}", i, &buf[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
// validity tests
|
|
|
|
assert_eq!(buf.len(), correct_tokens.len());
|
|
|
|
for i in 0..buf.len() {
|
2022-01-01 00:56:46 +00:00
|
|
|
assert_eq!(
|
|
|
|
buf[i], correct_tokens[i],
|
|
|
|
"Tokens at position {} do not match ()",
|
|
|
|
i
|
|
|
|
);
|
2021-12-03 21:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
tokenizer.read_line(&mut buf)?; // this should immediately return
|
|
|
|
Ok(())
|
|
|
|
}
|
|
|
|
|
2021-12-29 17:12:58 +00:00
|
|
|
#[inline(always)]
|
2022-01-01 00:56:46 +00:00
|
|
|
fn execute_single_line(
|
|
|
|
line: &str,
|
|
|
|
should_be_emtpy: bool,
|
|
|
|
should_complete: bool,
|
2022-03-04 20:51:04 +00:00
|
|
|
) -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
if line.contains('\n') {
|
2022-02-23 16:33:45 +00:00
|
|
|
println!(
|
|
|
|
"--- Executing MPS code ---\n{}\n--- Executing MPS code ---",
|
|
|
|
line
|
|
|
|
);
|
2022-02-20 01:17:31 +00:00
|
|
|
} else {
|
|
|
|
println!("--- Executing MPS code: '{}' ---", line);
|
|
|
|
}
|
2021-12-12 19:59:43 +00:00
|
|
|
let cursor = Cursor::new(line);
|
2021-12-03 21:13:19 +00:00
|
|
|
|
|
|
|
let tokenizer = MpsTokenizer::new(cursor);
|
|
|
|
let interpreter = MpsInterpretor::with_standard_vocab(tokenizer);
|
|
|
|
|
|
|
|
let mut count = 0;
|
|
|
|
for result in interpreter {
|
|
|
|
if let Ok(item) = result {
|
2021-12-12 19:59:43 +00:00
|
|
|
count += 1;
|
|
|
|
if count > 100 {
|
2021-12-29 17:12:58 +00:00
|
|
|
if should_complete {
|
2021-12-30 00:46:53 +00:00
|
|
|
continue; // skip println, but still check for errors
|
2021-12-29 17:12:58 +00:00
|
|
|
} else {
|
|
|
|
println!("Got 100 items, stopping to avoid infinite loop");
|
|
|
|
break;
|
|
|
|
}
|
2021-12-12 19:59:43 +00:00
|
|
|
} // no need to spam the rest of the songs
|
2022-01-24 21:12:29 +00:00
|
|
|
println!(
|
2022-02-20 01:17:31 +00:00
|
|
|
"Got song `{}` (filename: `{}`)",
|
2022-01-24 21:12:29 +00:00
|
|
|
item.field("title")
|
|
|
|
.expect("Expected field `title` to exist")
|
|
|
|
.clone()
|
|
|
|
.to_str()
|
|
|
|
.expect("Expected field `title` to be String"),
|
|
|
|
item.field("filename")
|
|
|
|
.expect("Expected field `filename` to exist")
|
|
|
|
.clone()
|
|
|
|
.to_str()
|
|
|
|
.expect("Expected field `filename` to be String")
|
2022-01-21 00:52:03 +00:00
|
|
|
);
|
2021-12-03 21:13:19 +00:00
|
|
|
} else {
|
2021-12-29 17:12:58 +00:00
|
|
|
println!("!!! Got error while iterating (executing) !!!");
|
2022-01-01 00:56:46 +00:00
|
|
|
eprintln!("{}", result.as_ref().err().unwrap());
|
2021-12-03 21:13:19 +00:00
|
|
|
result?;
|
|
|
|
}
|
|
|
|
}
|
2021-12-12 19:59:43 +00:00
|
|
|
if should_be_emtpy {
|
2022-01-01 00:56:46 +00:00
|
|
|
assert_eq!(
|
|
|
|
count, 0,
|
|
|
|
"{} music items found while iterating over line which should be None",
|
|
|
|
count
|
|
|
|
);
|
2021-12-12 19:59:43 +00:00
|
|
|
} else {
|
2022-01-01 00:56:46 +00:00
|
|
|
println!(
|
|
|
|
"Got {} items, execution complete (no songs were harmed in the making of this test)",
|
|
|
|
count
|
|
|
|
);
|
|
|
|
assert_ne!(
|
|
|
|
count, 0,
|
|
|
|
"0 music items found while iterating over line which should have Some results"
|
|
|
|
); // assumption: database is populated
|
2021-12-12 19:59:43 +00:00
|
|
|
}
|
2021-12-03 21:13:19 +00:00
|
|
|
Ok(())
|
|
|
|
}
|
2021-12-12 19:59:43 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_sql_line() -> Result<(), MpsError> {
|
2021-12-29 17:12:58 +00:00
|
|
|
execute_single_line("sql(`SELECT * FROM songs ORDER BY artist;`)", false, true)
|
2021-12-12 19:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_simple_sql_line() -> Result<(), MpsError> {
|
2021-12-29 17:12:58 +00:00
|
|
|
execute_single_line("song(`lov`)", false, true)
|
2021-12-12 19:59:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_comment_line() -> Result<(), MpsError> {
|
2021-12-29 17:12:58 +00:00
|
|
|
execute_single_line("// this is a comment", true, true)?;
|
|
|
|
execute_single_line("# this is a special comment", true, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_repeat_line() -> Result<(), MpsError> {
|
2022-01-24 21:12:29 +00:00
|
|
|
execute_single_line(
|
|
|
|
"repeat(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
|
|
|
false,
|
|
|
|
false,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"repeat(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), 4)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"repeat(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), 0)",
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
)
|
2021-12-29 17:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_sql_init_line() -> Result<(), MpsError> {
|
2022-01-01 00:56:46 +00:00
|
|
|
execute_single_line(
|
|
|
|
"sql_init(generate = false, folder = `/home/ngnius/Music`)",
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
)
|
2021-12-29 17:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_assign_line() -> Result<(), MpsError> {
|
2022-01-01 00:56:46 +00:00
|
|
|
execute_single_line(
|
|
|
|
"let some_var = repeat(song(`Christmas in L.A.`))",
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
)?;
|
2021-12-29 17:12:58 +00:00
|
|
|
execute_single_line("let some_var2 = 1234", true, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_emptyfilter_line() -> Result<(), MpsError> {
|
2022-01-24 21:12:29 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).().().()",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
2021-12-29 17:12:58 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_fieldfilter_line() -> Result<(), MpsError> {
|
2022-01-11 15:22:05 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year >= 2000)",
|
|
|
|
false,
|
|
|
|
true,
|
2022-01-12 01:45:48 +00:00
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year <= 2020)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year == 2016)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year != 2048)",
|
|
|
|
false,
|
|
|
|
true,
|
2022-01-11 15:22:05 +00:00
|
|
|
)
|
2021-12-12 19:59:43 +00:00
|
|
|
}
|
2022-01-01 00:56:46 +00:00
|
|
|
|
2022-01-12 14:59:30 +00:00
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_fieldfiltermaybe_line() -> Result<(), MpsError> {
|
2022-01-12 14:59:30 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year? >= 2000)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year? <= 2020)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year! == 2016)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year! != `test`)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-01-01 00:56:46 +00:00
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_files_line() -> Result<(), MpsError> {
|
2022-01-01 00:56:46 +00:00
|
|
|
execute_single_line(
|
2022-01-11 15:22:05 +00:00
|
|
|
r"files(folder=`~/Music/MusicFlac/Bruno Mars/24K Magic/`, re=``, recursive=false)",
|
2022-01-01 00:56:46 +00:00
|
|
|
false,
|
|
|
|
true,
|
2022-01-11 15:22:05 +00:00
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
r"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(r"files()", false, true)
|
2022-01-01 00:56:46 +00:00
|
|
|
}
|
2022-01-12 16:06:32 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_indexfilter_line() -> Result<(), MpsError> {
|
2022-01-12 16:06:32 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(2)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(0)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
2022-01-17 21:58:37 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(!0)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
2022-01-12 16:06:32 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(200)",
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
2022-01-12 21:23:56 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_rangefilter_line() -> Result<(), MpsError> {
|
2022-01-12 21:23:56 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(..)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(0..=4)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(..=4)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(0..5)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
2022-01-17 02:00:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_orfilter_line() -> Result<(), MpsError> {
|
2022-01-17 02:00:00 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(4 || 5)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year != 2020 || 5)",
|
|
|
|
false,
|
|
|
|
true,
|
2022-01-17 21:58:37 +00:00
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(year != 2020 || 5 || 4 || 12)",
|
|
|
|
false,
|
|
|
|
true,
|
2022-01-17 02:00:00 +00:00
|
|
|
)
|
|
|
|
}
|
2022-01-18 14:14:05 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_replacefilter_line() -> Result<(), MpsError> {
|
2022-01-18 14:14:05 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(if 4: files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(5))",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(if 4: files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(5) else item.())",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(if 4: item.() else files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(0 || 1).(if 200: files() else repeat(item.(), 2)))",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
2022-01-23 01:44:53 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_emptysort_line() -> Result<(), MpsError> {
|
2022-01-23 01:44:53 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).sort()",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~()",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
2022-01-24 21:12:00 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_likefilter_line() -> Result<(), MpsError> {
|
2022-01-24 21:12:00 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(not_a_field? like `24K Magic`)",
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(not_a_field! like `24K Magic`)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(album like `24K Magic`)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_fieldsort_line() -> Result<(), MpsError> {
|
2022-01-24 21:12:00 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(title)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).sort(not_a_field)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
2022-01-25 05:04:25 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_blissfirstsort_line() -> Result<(), MpsError> {
|
2022-01-25 05:04:25 +00:00
|
|
|
execute_single_line(
|
2022-01-28 00:55:43 +00:00
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(advanced bliss_first)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_blissnextsort_line() -> Result<(), MpsError> {
|
2022-01-28 00:55:43 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(advanced bliss_next)",
|
2022-01-25 05:04:25 +00:00
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
2022-01-27 21:06:32 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_emptyfn_line() -> Result<(), MpsError> {
|
2022-01-31 14:22:36 +00:00
|
|
|
execute_single_line("empty()", true, true)
|
2022-01-27 21:06:32 +00:00
|
|
|
}
|
2022-01-31 02:13:19 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_resetfn_line() -> Result<(), MpsError> {
|
2022-01-31 14:22:36 +00:00
|
|
|
execute_single_line("reset(empty())", true, true)
|
2022-01-31 02:13:19 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_shufflesort_line() -> Result<(), MpsError> {
|
2022-01-31 02:13:19 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(random shuffle)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)~(shuffle)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
2022-01-31 14:22:36 +00:00
|
|
|
execute_single_line("empty()~(shuffle)", true, true)
|
2022-01-31 02:13:19 +00:00
|
|
|
}
|
2022-02-01 22:15:25 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_unionfn_line() -> Result<(), MpsError> {
|
2022-02-01 22:15:25 +00:00
|
|
|
execute_single_line(
|
|
|
|
"union(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"u(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), union(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)))",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"interleave(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
2022-02-02 20:53:57 +00:00
|
|
|
"interlace(empty(), files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
2022-02-01 22:15:25 +00:00
|
|
|
false,
|
2022-02-03 21:56:42 +00:00
|
|
|
true,
|
2022-02-01 22:15:25 +00:00
|
|
|
)
|
|
|
|
}
|
2022-02-02 18:12:56 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_regexfilter_line() -> Result<(), MpsError> {
|
2022-02-02 18:12:56 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(title matches `24K\\\\s+Magic`)", // note: quad-escape not required in scripts
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(artist? matches `Bruno Mars`)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
2022-02-02 20:53:57 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_intersectionfn_line() -> Result<(), MpsError> {
|
2022-02-02 20:53:57 +00:00
|
|
|
execute_single_line(
|
|
|
|
"intersection(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"n(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), n(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`)))",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"intersection(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
|
|
|
false,
|
|
|
|
true
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"n(empty(), files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`))",
|
|
|
|
true,
|
2022-02-03 21:56:42 +00:00
|
|
|
true,
|
2022-02-02 20:53:57 +00:00
|
|
|
)
|
|
|
|
}
|
2022-02-20 01:17:31 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_declareitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{let x = empty()}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_removeitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{remove item.title, remove item}",
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_multiitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
let x = empty(),
|
|
|
|
remove item,
|
|
|
|
remove x
|
|
|
|
}",
|
|
|
|
true,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_fieldassignitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item.potato = empty(),
|
|
|
|
.test = empty()
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_constitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
`str const`,
|
|
|
|
1234,
|
|
|
|
false,
|
|
|
|
item.test_field = 1234,
|
|
|
|
let foo = false
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_retrieveitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item.path = item.filename,
|
|
|
|
item.new_field = 42,
|
|
|
|
item.title = item.path,
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_additemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item.title = `TEST` + item.title,
|
|
|
|
item.test = 1234 + 94,
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_subtractitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item.test = 1234 - 94,
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_negateitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item.test = 1234,
|
|
|
|
item.test = -item.test,
|
|
|
|
item.test = -42,
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_notitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item.test = false,
|
|
|
|
item.test = !item.test,
|
|
|
|
item.test = !true,
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_orlogicalitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item.test = true || true,
|
|
|
|
item.test = !true || false,
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_andlogicalitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item.test = true && true,
|
|
|
|
item.test = !true && false,
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_bracketsitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item.test = true && true && (false || false),
|
|
|
|
item.test = (!true && false || (false || !false)),
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_stringifyitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item.filepath = ~`test out: {test}` item,
|
|
|
|
item.test = true && true && (false || false),
|
|
|
|
item.test = item.test || ((!true && false) || (false || !false)),
|
|
|
|
item.title = ~`test out: {test}` item
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_branchitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
if false {
|
|
|
|
item.title = 42,
|
|
|
|
item.title = `THIS IS WRONG ` + item.title
|
|
|
|
} else {
|
|
|
|
item.title = `OK `+ item.title,
|
|
|
|
if true {item.filename = `RIGHT`},
|
|
|
|
if true {} else {item.filename = `WRONG`},
|
|
|
|
}
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_compareitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
if 42 != 42 {
|
|
|
|
item.title = `THIS IS WRONG ` + item.title
|
|
|
|
} else {
|
|
|
|
item.title = `OK `+ item.title
|
|
|
|
}
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_computeitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
2022-03-04 16:06:37 +00:00
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
2022-02-20 01:17:31 +00:00
|
|
|
let count = 1,
|
|
|
|
item.track = count,
|
|
|
|
item.title = ~`Song #{track}` item,
|
|
|
|
if count > 5 {
|
|
|
|
item.filename = `¯\\\\_(ツ)_/¯`
|
|
|
|
} else {
|
|
|
|
item.filename = `/shrug`,
|
|
|
|
},
|
|
|
|
count = count + 1,
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-03-04 16:06:37 +00:00
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_complexitemop_line() -> Result<(), MpsError> {
|
2022-03-04 16:06:37 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).().{
|
|
|
|
let count = 1,
|
|
|
|
item.track = count,
|
|
|
|
item.title = ~`Song #{track}` item,
|
|
|
|
if count > 5 {
|
|
|
|
item.filename = `¯\\\\_(ツ)_/¯`
|
|
|
|
} else {
|
|
|
|
item.filename = `/shrug`,
|
|
|
|
},
|
|
|
|
count = count + 1,
|
|
|
|
}.()",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-20 01:17:31 +00:00
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_constructitemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
let other_item = Item (),
|
|
|
|
let temp_item = Item (
|
|
|
|
filename= `???`,
|
|
|
|
title= `???`,
|
|
|
|
),
|
|
|
|
other_item = temp_item,
|
|
|
|
temp_item = item,
|
|
|
|
item = other_item,
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2022-02-20 17:04:56 +00:00
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_iteritemop_line() -> Result<(), MpsError> {
|
2022-02-20 01:17:31 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
|
|
|
item = iter empty()
|
|
|
|
}",
|
2022-02-20 17:04:56 +00:00
|
|
|
true,
|
2022-02-20 01:17:31 +00:00
|
|
|
true,
|
|
|
|
)
|
2022-02-20 17:04:56 +00:00
|
|
|
}
|
2022-02-23 21:06:20 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_uniquefieldfilter_line() -> Result<(), MpsError> {
|
2022-02-23 21:06:20 +00:00
|
|
|
execute_single_line(
|
|
|
|
"repeat(files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`), 3).(unique title?)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(unique album!)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(unique album)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_uniquefilter_line() -> Result<(), MpsError> {
|
2022-02-23 21:06:20 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).(unique)",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
2022-03-01 01:25:29 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_fileitemop_line() -> Result<(), MpsError> {
|
2022-03-01 01:25:29 +00:00
|
|
|
execute_single_line(
|
|
|
|
"files(`~/Music/MusicFlac/Bruno Mars/24K Magic/`).{
|
2022-03-02 01:44:46 +00:00
|
|
|
item.title = `something else`,
|
2022-03-01 01:25:29 +00:00
|
|
|
item = file(item.filename),
|
|
|
|
}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)
|
|
|
|
}
|
2022-03-02 01:44:46 +00:00
|
|
|
|
|
|
|
#[test]
|
2022-03-04 20:51:04 +00:00
|
|
|
fn execute_emptiesop_line() -> Result<(), MpsError> {
|
2022-03-02 01:44:46 +00:00
|
|
|
execute_single_line(
|
|
|
|
"empties(1).{let count = 0, item.title = ~`title #{}` count+1, item.filename = ~`filename_{}` count, count = count + 1}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line(
|
|
|
|
"empties(42).{let count = 0, item.title = ~`title #{}` count+1, item.filename = ~`filename_{}` count, count = count + 1}",
|
|
|
|
false,
|
|
|
|
true,
|
|
|
|
)?;
|
|
|
|
execute_single_line("empties(0)", true, true)
|
|
|
|
}
|