Changed . token to _dot

This change allows the dotfiles to work with chezmoi (e.g: on windows)
and improves grepability with neovim/telescope
This commit is contained in:
2024-11-07 13:52:17 +00:00
parent 83b02bd753
commit 896af887ca
2351 changed files with 0 additions and 0 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,43 @@
use std assert
use ../std-rfc/conversions *
export def "test range-into-list" [] {
assert equal (
1..10 | into list
) (
[ 1 2 3 4 5 6 7 8 9 10 ]
)
}
export def "test string-into-list" [] {
assert equal (
"foo" | into list
) (
[ foo ]
)
}
export def "test range-stride-into-list" [] {
assert equal (
0..2..10 | into list
) (
[ 0 2 4 6 8 10 ]
)
}
export def "test null-into-list" [] {
assert equal (
null | into list | get 0 | describe
) (
"nothing"
)
}
export def "test list-into-list" [] {
assert equal (
[ foo bar baz ] | into list
) (
[ foo bar baz ]
)
}

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"]
}

View File

@@ -0,0 +1,168 @@
use std assert
use ../std-rfc/tables *
const test_table = [
[ col-a col-b col-c col-d col-e col-f ];
[ 'a0' 'b0' 'c0' 'd0' 'e0' 'f0' ]
[ 'a1' 'b1' 'c1' 'd1' 'e1' 'f1' ]
[ 'a2' 'b2' 'c2' 'd2' 'e2' 'f2' ]
[ 'a3' 'b3' 'c3' 'd3' 'e3' 'f3' ]
[ 'a4' 'b4' 'c4' 'd4' 'e4' 'f4' ]
[ 'a5' 'b5' 'c5' 'd5' 'e5' 'f5' ]
[ 'a6' 'b6' 'c6' 'd6' 'e6' 'f6' ]
[ 'a7' 'b7' 'c7' 'd7' 'e7' 'f7' ]
[ 'a8' 'b8' 'c8' 'd8' 'e8' 'f8' ]
[ 'a9' 'b9' 'c9' 'd9' 'e9' 'f9' ]
]
const enumerated_table = [
[ index col-a col-b col-c col-d col-e col-f ];
[ 0 'a0' 'b0' 'c0' 'd0' 'e0' 'f0' ]
[ 1 'a1' 'b1' 'c1' 'd1' 'e1' 'f1' ]
[ 2 'a2' 'b2' 'c2' 'd2' 'e2' 'f2' ]
[ 3 'a3' 'b3' 'c3' 'd3' 'e3' 'f3' ]
[ 4 'a4' 'b4' 'c4' 'd4' 'e4' 'f4' ]
[ 5 'a5' 'b5' 'c5' 'd5' 'e5' 'f5' ]
[ 6 'a6' 'b6' 'c6' 'd6' 'e6' 'f6' ]
[ 7 'a7' 'b7' 'c7' 'd7' 'e7' 'f7' ]
[ 8 'a8' 'b8' 'c8' 'd8' 'e8' 'f8' ]
[ 9 'a9' 'b9' 'c9' 'd9' 'e9' 'f9' ]
]
export def "test row-indices-range" [] {
assert equal (
row-indices 0..3 10..11
) (
[ 0 1 2 3 10 11 ]
)
}
export def "test row-indices-index" [] {
assert equal (
row-indices 4
) (
[ 4 ]
)
}
export def "test row-indices-complex" [] {
assert equal (
row-indices 0..2..6 3 7
) (
[ 0 2 4 6 3 7 ]
)
}
export def "test col-index-ints" [] {
assert equal (
# Third and Fifth Columns
$test_table | col-indices 2 4
) (
[ 'col-c', 'col-e' ]
)
}
export def "test col-index-complex" [] {
assert equal (
# Every other column, plus the second
$test_table | col-indices 0..2..10 1
) (
[ 'col-a', 'col-b', 'col-c', 'col-e' ]
)
}
export def "test select-range single-int" [] {
assert equal (
$test_table | select ranges 1
) (
$enumerated_table | select 1
)
}
export def "test select-range single-range" [] {
assert equal (
$test_table | select ranges 2..4
) (
$enumerated_table | select 2 3 4
)
}
export def "test select-range complex" [] {
assert equal (
# First and every following third-row + second row
$test_table | select ranges 1 0..3..100
) (
$enumerated_table | select 0 1 3 6 9
)
}
export def "test select-range out-of-bounds" [] {
assert equal (
$test_table | select ranges 100
) (
[]
)
}
export def "test reject-range single-index" [] {
assert equal (
$test_table | reject ranges 4
) (
$enumerated_table | reject 4
)
}
export def "test reject-range ranges" [] {
assert equal (
# Reject rows 0-3 and 5-9, leaving only 4
$test_table | reject ranges 0..3 5..9
) (
$enumerated_table | select 4
)
}
export def "test reject-range out-of-bounds" [] {
assert error {
$test_table | reject ranges 1000
}
}
export def "test select-col index" [] {
assert equal (
$test_table | select column-ranges 2
) (
$test_table | select col-c
)
}
export def "test select-col indices" [] {
assert equal (
$test_table | select column-ranges 2 4
) (
$test_table | select col-c col-e
)
}
export def "test select-col ranges-and-index" [] {
assert equal (
$test_table | select column-ranges 0..2..5 1
) (
$test_table | select col-a col-c col-e col-b
)
}
export def "test reject-col ranges-and-index" [] {
assert equal (
$test_table | reject column-ranges 0..2..5 1
) (
$enumerated_table | select col-d col-f
)
}
export def "test reject-col out-of-bounds" [] {
assert equal (
$test_table | reject column-ranges 1_000
) (
$test_table
)
}