mirror of
https://github.com/nushell/nushell.git
synced 2024-12-25 08:29:07 +01:00
ba6d8ad261
related to - https://github.com/nushell/nushell/issues/10233 - https://github.com/nushell/nushell/pull/10293 - https://github.com/nushell/nushell/pull/10292 inspired by @kubouch # Description this PR adds a `repeat` command to the standard library # User-Facing Changes a new `repeat` command in `std` ```nushell repeat anything a bunch of times, yielding a list of *n* times the input # Examples repeat a string > "foo" | std repeat 3 | str join "foofoofoo" Usage: > repeat <n> Flags: -h, --help - Display the help message for this command Parameters: n <int>: the number of repetitions, must be positive Input/output types: ╭───┬───────┬───────────╮ │ # │ input │ output │ ├───┼───────┼───────────┤ │ 0 │ any │ list<any> │ ╰───┴───────┴───────────╯ ``` # Tests + Formatting a new test called `repeat_things` in `test_std.nu` # After Submitting
58 lines
1.3 KiB
Plaintext
58 lines
1.3 KiB
Plaintext
use std
|
|
|
|
#[test]
|
|
def path_add [] {
|
|
use std assert
|
|
|
|
let path_name = if "PATH" in $env { "PATH" } else { "Path" }
|
|
|
|
with-env [$path_name []] {
|
|
def get_path [] { $env | get $path_name }
|
|
|
|
assert equal (get_path) []
|
|
|
|
std path add "/foo/"
|
|
assert equal (get_path) ["/foo/"]
|
|
|
|
std path add "/bar/" "/baz/"
|
|
assert equal (get_path) ["/bar/", "/baz/", "/foo/"]
|
|
|
|
load-env {$path_name: []}
|
|
|
|
std path add "foo"
|
|
std path add "bar" "baz" --append
|
|
assert equal (get_path) ["foo", "bar", "baz"]
|
|
|
|
assert equal (std path add "fooooo" --ret) ["fooooo", "foo", "bar", "baz"]
|
|
assert equal (get_path) ["fooooo", "foo", "bar", "baz"]
|
|
|
|
load-env {$path_name: []}
|
|
|
|
let target_paths = {
|
|
linux: "foo",
|
|
windows: "bar",
|
|
macos: "baz",
|
|
android: "quux",
|
|
}
|
|
|
|
std path add $target_paths
|
|
assert equal (get_path) [($target_paths | get $nu.os-info.name)]
|
|
}
|
|
}
|
|
|
|
#[test]
|
|
def banner [] {
|
|
std assert ((std banner | lines | length) == 15)
|
|
}
|
|
|
|
#[test]
|
|
def repeat_things [] {
|
|
std assert error { "foo" | std repeat -1 }
|
|
|
|
for x in ["foo", [1 2], {a: 1}] {
|
|
std assert equal ($x | std repeat 0) []
|
|
std assert equal ($x | std repeat 1) [$x]
|
|
std assert equal ($x | std repeat 2) [$x $x]
|
|
}
|
|
}
|