mirror of
https://github.com/nushell/nushell.git
synced 2025-05-03 01:24:29 +02:00
82 lines
1.8 KiB
Rust
82 lines
1.8 KiB
Rust
use crate::tests::{fail_test, run_test, TestResult};
|
|
|
|
#[test]
|
|
fn build_string1() -> TestResult {
|
|
run_test("build-string 'nu' 'shell'", "nushell")
|
|
}
|
|
|
|
#[test]
|
|
fn build_string2() -> TestResult {
|
|
run_test("'nu' | each {build-string $it 'shell'}", "nushell")
|
|
}
|
|
|
|
#[test]
|
|
fn build_string3() -> TestResult {
|
|
run_test(
|
|
"build-string 'nu' 'shell' | each {build-string $it ' rocks'}",
|
|
"nushell rocks",
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn build_string4() -> TestResult {
|
|
run_test(
|
|
"['sam','rick','pete'] | each { build-string $it ' is studying'} | get 2",
|
|
"pete is studying",
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn build_string5() -> TestResult {
|
|
run_test(
|
|
"['sam','rick','pete'] | each { |x| build-string $x ' is studying'} | get 1",
|
|
"rick is studying",
|
|
)
|
|
}
|
|
|
|
#[test]
|
|
fn cjk_in_substrings() -> TestResult {
|
|
run_test(
|
|
r#"let s = '[Rust 程序设计语言](title-page.md)'; let start = ($s | str index-of '('); let end = ($s | str index-of ')'); echo ($s | str substring $"($start + 1),($end)")"#,
|
|
"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 {
|
|
fail_test(r#"42 in 'abc'"#, "mismatched for operation")
|
|
}
|
|
|
|
#[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",
|
|
)
|
|
}
|