diff --git a/stdlib-candidate/std-rfc/fs.nu b/stdlib-candidate/std-rfc/fs.nu index 7390dd845..e2fce5210 100644 --- a/stdlib-candidate/std-rfc/fs.nu +++ b/stdlib-candidate/std-rfc/fs.nu @@ -20,8 +20,8 @@ export def "file bulk-rename" [ stem_update: closure, # the code to run on the stem of the files: should start with parsing the format and end with reconstructing the same format --verbose, # be verbose when moving the files around ]: nothing -> nothing { - ls --full-paths $directory | insert new { - get name | path parse | update stem $stem_update | path join + ls --full-paths $directory | insert new {|row| + $row.name | path parse | update stem $stem_update | path join } | each { if $verbose { diff --git a/stdlib-candidate/tests/fs.nu b/stdlib-candidate/tests/fs.nu index 469ad3847..b1af35327 100644 --- a/stdlib-candidate/tests/fs.nu +++ b/stdlib-candidate/tests/fs.nu @@ -1,7 +1,9 @@ -#[test] -def test [] { - use std assert +use std assert +use ../std-rfc "file bulk-rename" +alias rename = file bulk-rename + +export def "file bulk-rename" [] { let test_dir = $nu.temp-path | path join (random uuid) mkdir $test_dir @@ -22,7 +24,7 @@ def test [] { let actual = glob $"($test_dir)/*" | str replace $test_dir "" | str trim --left --char "/" assert equal ($actual | sort) $expected - file bulk-rename $test_dir { + rename $test_dir { parse "some_{i}_format" | get 0 | update i { fill --alignment r --character 0 --width 3 } diff --git a/stdlib-candidate/tests/mod.nu b/stdlib-candidate/tests/mod.nu new file mode 100644 index 000000000..8f03760ec --- /dev/null +++ b/stdlib-candidate/tests/mod.nu @@ -0,0 +1,3 @@ +export module fs.nu +export module record.nu +export module str.nu diff --git a/stdlib-candidate/tests/record.nu b/stdlib-candidate/tests/record.nu index 0867a2731..fb71f61e2 100644 --- a/stdlib-candidate/tests/record.nu +++ b/stdlib-candidate/tests/record.nu @@ -1,22 +1,20 @@ -#[test] -def test_record_list_merge [] { - use std assert - assert equal ([{a:1} {b:2} {c:3} {d:4}] | list merge) {a:1 b:2 c:3 d:4} +use std assert +use ../std-rfc record + +export def "list_merge" [] { + assert equal ([{a:1} {b:2} {c:3} {d:4}] | record list merge) {a:1 b:2 c:3 d:4} } -#[test] -def test_record_filtername_predicate [] { - use std assert - assert equal ({aa:1 ab:2 ba:3 bb:4 ca:5 cb:6} | filter-name predicate {$in | str contains a}) {aa:1 ab:2 ba:3 ca:5} + +export def "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} } -#[test] -def test_record_filtername_text [] { - use std assert - assert equal ({aa:1 ab:2 ba:3 bb:4 ca:5 cb:6} | 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} | filter-name text -r ^a) {aa:1 ab:2} - assert equal ({aa:1 ab:2 ba:3 bb:4 ca:5 cb:6} | filter-name text -r ^A) {} + +export def "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) {} } -#[test] -def test_record_filtervalue_predicate [] { - use std assert - assert equal ({aa:1 ab:2 ba:3 bb:4 ca:5 cb:6} | filter-value predicate { $in mod 2 == 0 }) {ab:2 bb:4 cb:6} + +export def "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} } diff --git a/stdlib-candidate/tests/str.nu b/stdlib-candidate/tests/str.nu index af388b783..dbd6b6d61 100644 --- a/stdlib-candidate/tests/str.nu +++ b/stdlib-candidate/tests/str.nu @@ -1,15 +1,12 @@ -#[test] -def test_append [] { - use std assert - assert equal ("foo" | append "/") "foo/" - assert equal (["foo", "bar", "baz"] | append "/") ["foo/", "bar/", "baz/"] +use std assert +use ../std-rfc str +export def append [] { + 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" | prepend "/") "/foo" - assert equal (["foo", "bar", "baz"] | prepend "/") ["/foo", "/bar", "/baz"] - +export def prepend [] { + assert equal ("foo" | str prepend "/") "/foo" + assert equal (["foo", "bar", "baz"] | str prepend "/") ["/foo", "/bar", "/baz"] }