mirror of
https://github.com/nushell/nu_scripts.git
synced 2024-10-26 22:08:03 +03:00
dae6115d4d
As requested by @amtoine 😋
---------
Co-authored-by: Antoine Stevan <44101798+amtoine@users.noreply.github.com>
34 lines
970 B
Plaintext
34 lines
970 B
Plaintext
def "str append" [tail: string]: [string -> string, list<string> -> list<string>] {
|
|
let input = $in
|
|
match ($input | describe | str replace --regex '<.*' '') {
|
|
"string" => { $input ++ $tail },
|
|
"list" => { $input | each {|el| $el ++ $tail} },
|
|
_ => $input
|
|
}
|
|
}
|
|
|
|
def "str prepend" [head: string]: [string -> string, list<string> -> list<string>] {
|
|
let input = $in
|
|
match ($input | describe | str replace --regex '<.*' '') {
|
|
"string" => { $head ++ $input },
|
|
"list" => { $input | each {|el| $head ++ $el } },
|
|
_ => $input
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
def test_append [] {
|
|
use std assert
|
|
assert equal ("foo" | str append "/") "foo/"
|
|
assert equal (["foo", "bar", "baz"] | str append "/") ["foo/", "bar/", "baz/"]
|
|
|
|
}
|
|
|
|
#[test]
|
|
def test_prepend [] {
|
|
use std assert
|
|
assert equal ("foo" | str prepend "/") "/foo"
|
|
assert equal (["foo", "bar", "baz"] | str prepend "/") ["/foo", "/bar", "/baz"]
|
|
|
|
}
|