2024-05-13 15:37:53 +02:00
|
|
|
use crate::repl::tests::{fail_test, run_test, TestResult};
|
2021-12-25 20:39:42 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn cjk_in_substrings() -> TestResult {
|
|
|
|
run_test(
|
2024-05-22 19:00:58 +02:00
|
|
|
r#"let s = '[Rust 程序设计语言](title-page.md)'; let start = ($s | str index-of '('); let end = ($s | str index-of ')'); $s | str substring ($start + 1)..<($end)"#,
|
2021-12-25 20:39:42 +01:00
|
|
|
"title-page.md",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn string_not_in_string() -> TestResult {
|
|
|
|
run_test(r#"'d' not-in 'abc'"#, "true")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn string_in_string() -> TestResult {
|
|
|
|
run_test(r#"'z' in 'abc'"#, "false")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn non_string_in_string() -> TestResult {
|
2023-04-07 23:32:44 +02:00
|
|
|
fail_test(r#"42 in 'abc'"#, "is not supported")
|
2021-12-25 20:39:42 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn string_in_record() -> TestResult {
|
|
|
|
run_test(r#""a" in ('{ "a": 13, "b": 14 }' | from json)"#, "true")
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn non_string_in_record() -> TestResult {
|
|
|
|
fail_test(
|
|
|
|
r#"4 in ('{ "a": 13, "b": 14 }' | from json)"#,
|
|
|
|
"mismatch during operation",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn string_in_valuestream() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"
|
|
|
|
'Hello' in ("Hello
|
|
|
|
World" | lines)"#,
|
|
|
|
"true",
|
|
|
|
)
|
|
|
|
}
|
2021-12-25 21:50:02 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn single_tick_interpolation() -> TestResult {
|
|
|
|
run_test(r#"$'(3 + 4)'"#, "7")
|
|
|
|
}
|
2021-12-27 00:11:18 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn detect_newlines() -> TestResult {
|
|
|
|
run_test("'hello\r\nworld' | lines | get 0 | str length", "5")
|
|
|
|
}
|
2022-02-16 17:12:49 +01:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn case_insensitive_sort() -> TestResult {
|
|
|
|
run_test(
|
2022-11-09 23:16:51 +01:00
|
|
|
r#"[a, B, d, C, f] | sort -i | to json --raw"#,
|
2022-02-16 17:12:49 +01:00
|
|
|
"[\"a\",\"B\",\"C\",\"d\",\"f\"]",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn case_insensitive_sort_columns() -> TestResult {
|
|
|
|
run_test(
|
|
|
|
r#"[[version, package]; ["two", "Abc"], ["three", "abc"], ["four", "abc"]] | sort-by -i package version | to json --raw"#,
|
2024-03-20 22:14:31 +01:00
|
|
|
r#"[{"version":"four","package":"abc"},{"version":"three","package":"abc"},{"version":"two","package":"Abc"}]"#,
|
2022-02-16 17:12:49 +01:00
|
|
|
)
|
|
|
|
}
|
2024-05-02 15:36:37 +02:00
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn raw_string() -> TestResult {
|
|
|
|
run_test(r#"r#'abcde""fghi"''''jkl'#"#, r#"abcde""fghi"''''jkl"#)?;
|
|
|
|
run_test(r#"r##'abcde""fghi"''''#jkl'##"#, r#"abcde""fghi"''''#jkl"#)?;
|
|
|
|
run_test(
|
|
|
|
r#"r###'abcde""fghi"'''##'#jkl'###"#,
|
|
|
|
r#"abcde""fghi"'''##'#jkl"#,
|
|
|
|
)?;
|
|
|
|
run_test("r#''#", "")?;
|
|
|
|
run_test(
|
|
|
|
r#"r#'a string with sharp inside # and ends with #'#"#,
|
|
|
|
"a string with sharp inside # and ends with #",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-05-06 22:53:58 +02:00
|
|
|
#[test]
|
|
|
|
fn raw_string_inside_parentheses() -> TestResult {
|
|
|
|
let (left, right) = ('(', ')');
|
|
|
|
run_test(
|
|
|
|
&format!(r#"{left}r#'abcde""fghi"''''jkl'#{right}"#),
|
|
|
|
r#"abcde""fghi"''''jkl"#,
|
|
|
|
)?;
|
|
|
|
run_test(
|
|
|
|
&format!(r#"{left}r##'abcde""fghi"''''#jkl'##{right}"#),
|
|
|
|
r#"abcde""fghi"''''#jkl"#,
|
|
|
|
)?;
|
|
|
|
run_test(
|
|
|
|
&format!(r#"{left}r###'abcde""fghi"'''##'#jkl'###{right}"#),
|
|
|
|
r#"abcde""fghi"'''##'#jkl"#,
|
|
|
|
)?;
|
|
|
|
run_test(&format!("{left}r#''#{right}"), "")?;
|
|
|
|
run_test(
|
|
|
|
&format!(r#"{left}r#'a string with sharp inside # and ends with #'#{right}"#),
|
|
|
|
"a string with sharp inside # and ends with #",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn raw_string_inside_list() -> TestResult {
|
|
|
|
let (left, right) = ('[', ']');
|
|
|
|
run_test(
|
|
|
|
&format!(r#"{left}r#'abcde""fghi"''''jkl'#{right} | get 0"#),
|
|
|
|
r#"abcde""fghi"''''jkl"#,
|
|
|
|
)?;
|
|
|
|
run_test(
|
|
|
|
&format!(r#"{left}r##'abcde""fghi"''''#jkl'##{right} | get 0"#),
|
|
|
|
r#"abcde""fghi"''''#jkl"#,
|
|
|
|
)?;
|
|
|
|
run_test(
|
|
|
|
&format!(r#"{left}r###'abcde""fghi"'''##'#jkl'###{right} | get 0"#),
|
|
|
|
r#"abcde""fghi"'''##'#jkl"#,
|
|
|
|
)?;
|
|
|
|
run_test(&format!("{left}r#''#{right} | get 0"), "")?;
|
|
|
|
run_test(
|
|
|
|
&format!(r#"{left}r#'a string with sharp inside # and ends with #'#{right} | get 0"#),
|
|
|
|
"a string with sharp inside # and ends with #",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn raw_string_inside_closure() -> TestResult {
|
|
|
|
let (left, right) = ('{', '}');
|
|
|
|
run_test(
|
|
|
|
&format!(r#"do {left}r#'abcde""fghi"''''jkl'#{right}"#),
|
|
|
|
r#"abcde""fghi"''''jkl"#,
|
|
|
|
)?;
|
|
|
|
run_test(
|
|
|
|
&format!(r#"do {left}r##'abcde""fghi"''''#jkl'##{right}"#),
|
|
|
|
r#"abcde""fghi"''''#jkl"#,
|
|
|
|
)?;
|
|
|
|
run_test(
|
|
|
|
&format!(r#"do {left}r###'abcde""fghi"'''##'#jkl'###{right}"#),
|
|
|
|
r#"abcde""fghi"'''##'#jkl"#,
|
|
|
|
)?;
|
|
|
|
run_test(&format!("do {left}r#''#{right}"), "")?;
|
|
|
|
run_test(
|
|
|
|
&format!(r#"do {left}r#'a string with sharp inside # and ends with #'#{right}"#),
|
|
|
|
"a string with sharp inside # and ends with #",
|
|
|
|
)
|
|
|
|
}
|
|
|
|
|
2024-05-02 15:36:37 +02:00
|
|
|
#[test]
|
2024-05-15 03:14:11 +02:00
|
|
|
fn incomplete_string() -> TestResult {
|
|
|
|
fail_test("r#abc", "expected '")?;
|
|
|
|
fail_test("r#'bc", "expected closing '#")?;
|
|
|
|
fail_test("'ab\"", "expected closing '")?;
|
|
|
|
fail_test("\"ab'", "expected closing \"")?;
|
|
|
|
fail_test(
|
|
|
|
r#"def func [] {
|
|
|
|
{
|
|
|
|
"A": ""B" # <- the quote is bad
|
|
|
|
}
|
|
|
|
}
|
|
|
|
"#,
|
|
|
|
"expected closing \"",
|
|
|
|
)
|
2024-05-02 15:36:37 +02:00
|
|
|
}
|