1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 07:07:46 +00:00

Deprecate the nu_scripts version of stdlib-candidate (#1042)

Deprecates the existing `stdlib-candidate` directories in `nu_scripts`
since `std-rfc` has now transitioned to the main repo. Updates readme
and renamed directories.
This commit is contained in:
Douglas 2025-02-09 15:34:40 -05:00 committed by GitHub
parent a31f8490fb
commit 5869e0b529
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
53 changed files with 18 additions and 40 deletions

View file

@ -0,0 +1,12 @@
use std assert
use ../std-rfc bench
export def "test bench-timings" [] {
let $test = bench {1 + 2} --rounds 3 --timings | get times | length
assert equal $test 3
}
export def "test bench-pretty" [] {
let $test = (bench {1 + 2} --rounds 3 --pretty) =~ '\d.* ± \d'
assert equal $test true
}

View file

@ -0,0 +1,98 @@
use std assert
use ../std-rfc 'bulk-rename'
const fixture = [
.gitignore
Cargo.toml
LICENSE
README.md
src
test.nu
]
export def 'test ls' [] {
let expects = [
.gitignore # hidden by ls
_Cargo.toml
_LICENSE
_README.md
_src
_test.nu
]
test $expects {
ls $in | bulk-rename { '_' + $in }
}
}
export def 'test --no-execute' [] {
test $fixture {
ls $in | bulk-rename --no-execute { '_' + $in }
}
}
export def 'test --verbose' [] {
let expects = [
# .gitignore unchanged
_Cargo.toml
_LICENSE
_README.md
_src
_test.nu
]
let renamed = test $fixture {
# Note: Currently failing due to Nushell core #13267
# Remove the 'sort' once it is fixed
# ls $in | bulk-rename --verbose --no-execute { '_' + $in }
ls $in | bulk-rename --verbose --no-execute { '_' + $in } | sort
}
assert equal ($renamed.new | each { path basename }) $expects
}
export def 'test skip-extensions' [] {
let expects = [
.gitignore
Cargo.toml
LICENSE.txt # changed
README.md
src.txt # changed
test.nu
]
test $expects {
ls $in | bulk-rename { |path|
if $path.input.name ends-with $path.stem {
$path.stem + .txt
}
}
}
}
export def 'test glob' [] {
let expects = [
LICENSE # skipped
_.gitignore
_Cargo.toml
_README.md
_test.nu
src # skipped
]
test $expects {
glob ($in | path join *.*) | bulk-rename { '_' + $in }
}
}
def test [expects: list<string> command: closure] {
let test_dir = $nu.temp-path | path join (random uuid)
def actual-files [] {
ls --all --short-names $test_dir | get name | sort
}
# before
mkdir $test_dir
$fixture | each { |name| touch ($test_dir | path join $name) }
assert equal (actual-files) $fixture
# test
let renamed = $test_dir | do $command
assert equal (actual-files) $expects
# after
rm --recursive --force $test_dir
$renamed
}

View file

@ -0,0 +1,29 @@
use std assert
use ../std-rfc/math
#[test]
export def "test significant-digits-decimals" [] {
assert equal (0.0000012346789 | math significant-digits 2) 0.0000012
assert equal (11 / 3 | math significant-digits 6) 3.66666
assert not equal (0.0000012346789 | math significant-digits 2) 0.00000123
assert equal (1.999999 | math significant-digits 1) 1.0
}
#[test]
export def "test significant-digits-duration" [] {
assert equal (2min / 7 | math significant-digits 3) 17100000000ns
assert equal (1sec | math significant-digits 3) 1000000000ns
}
#[test]
export def "test significant-digits-ints" [] {
assert equal (123456 | math significant-digits 2) 120000
}
export def "test significant-digits-0" [] {
assert equal (0 | math significant-digits 2) 0
}
export def "test significant-digits-negative" [] {
assert equal (-1.23456789 | math significant-digits 5) (-1.2346)
}

View file

@ -0,0 +1,9 @@
export module bulk-rename.nu
export module record.nu
export module str_xpend.nu
export module math.nu
export module bench.nu
export module script-parsing.nu
export module str_dedent.nu
export module conversions.nu
export module tables.nu

View file

@ -0,0 +1,20 @@
use std assert
use ../std-rfc record
export def "test list_merge" [] {
assert equal ([{a:1} {b:2} {c:3} {d:4}] | record list merge) {a:1 b:2 c:3 d:4}
}
export def "test filter-name predicate" [] {
assert equal ({aa:1 ab:2 ba:3 bb:4 ca:5 cb:6} | record filter-name predicate {$in | str contains a}) {aa:1 ab:2 ba:3 ca:5}
}
export def "test filter-name text" [] {
assert equal ({aa:1 ab:2 ba:3 bb:4 ca:5 cb:6} | record filter-name text a) {aa:1 ab:2 ba:3 ca:5}
assert equal ({aa:1 ab:2 ba:3 bb:4 ca:5 cb:6} | record filter-name text -r ^a) {aa:1 ab:2}
assert equal ({aa:1 ab:2 ba:3 bb:4 ca:5 cb:6} | record filter-name text -r ^A) {}
}
export def "test filter-value predicate" [] {
assert equal ({aa:1 ab:2 ba:3 bb:4 ca:5 cb:6} | record filter-value predicate { $in mod 2 == 0 }) {ab:2 bb:4 cb:6}
}

View file

@ -0,0 +1,37 @@
use std assert
use ../std-rfc parse-arg
const SPAN = { start: 0, end: 0 }
export def "test parse-arg ok" [] {
const TEST_CASES = [
[ input, type, expected ];
[ "123", "int", 123 ],
[ "[1, 2, 3]", "list<int>", [1, 2, 3] ],
[ "'spam'", "string", "spam" ],
[
"{ a: 1, b: 'egg', c: false }",
"record<a: int, b: string, c: bool>",
{ a: 1, b: 'egg', c: false },
],
]
for t in $TEST_CASES {
assert equal ($t.input | parse-arg $SPAN $t.type) $t.expected
}
}
export def "test parse-arg err" [] {
const TEST_CASES = [
[ input, type ];
[ "{ invalid NUON", "" ],
[ "[1, 2, 3]", "string" ],
]
for t in $TEST_CASES {
let msg = $"test case: input: '($t.input)', type: ($t.type)"
assert error { $t.input | parse-arg $SPAN $t.type } $msg
}
}

View file

@ -0,0 +1,144 @@
use std assert
use ../std-rfc str
export def "test str dedent" [] {
# Test 1:
# Should start with "Heading" in the first character position
# Should not end with a line-break
# The blank line has no extra spaces
assert equal (
do {
let s = "
Heading
one
two
"
$s | str dedent
}
) "Heading\n\n one\n two"
# Test 2:
# Same as #1, but the blank line has leftover whitespace
# indentation (16 spaces) which is left in the result
assert equal (
do {
let s = "
Heading
one
two
"
$s | str dedent
}
) "Heading\n \n one\n two"
# Test 3:
# Same, but with a single tab character on the "blank" line
assert equal (
do {
let s = "
Heading
\t
one
two
"
$s | str dedent
}
) "Heading\n\t\n one\n two"
# Test 4:
# Ends with line-break
assert equal (
do {
let s = "
Heading
one
two
"
$s | str dedent
}
) "Heading\n\n one\n two\n"
# Test 5:
# Identity - Returns the original string sans first and last empty lines
# No other whitespace should be removed
assert equal (
do {
let s = "\n Identity \n"
$s | str dedent
}
) " Identity "
# Test 6:
# Error - Does not contain an empty first line
assert error {||
let s = "Error"
$s | str dedent
}
# Test 6.1:
# Error - Does not contain an empty first line
assert error {||
let s = "Error\n \nTesting\n"
$s | str dedent
}
# Test 7:
# Error - Does not contain an empty last line
assert error {||
let s = "
Error"
$s | str dedent
}
# Test 7.1:
# Error - Does not contain an empty last line
assert error {||
let s = "
Error"
$s | str dedent
}
# Test 8:
# Error - Line 1 does not have enough indentation
assert error {||
let s = "
Line 1
Line 2
"
$s | str dedent
}
# Test 8:
# Error - Line 2 does not have enough indentation
assert error {||
let s = "
Line 1
Line 2
"
$s | str dedent
}
# Test 9:
# Error - Line does not have enough indentation
assert error {||
let s = "
Line
"
$s | str dedent
}
# Test 10:
# "Hidden" whitespace on the first line is allowed
assert equal (
do {
let s = " \t \n Identity \n"
$s | str dedent
}
) " Identity "
}

View file

@ -0,0 +1,12 @@
use std assert
use ../std-rfc str
export def "test append" [] {
assert equal ("foo" | str append "/") "foo/"
assert equal (["foo", "bar", "baz"] | str append "/") ["foo/", "bar/", "baz/"]
}
export def "test prepend" [] {
assert equal ("foo" | str prepend "/") "/foo"
assert equal (["foo", "bar", "baz"] | str prepend "/") ["/foo", "/bar", "/baz"]
}