Update std-rfc tests for to use @test attributes (#15098)

After #14906, the test runner was updated to use attributes, along with
the existing `std` modules. However, since that PR was started before
`std-rfc` was in main, it didn't include updates to those tests. Once
#14906 was merged, the `std-rfc` tests no longer ran in CI. This PR
updates the tests accordingly.
This commit is contained in:
Douglas 2025-02-12 06:48:41 -05:00 committed by GitHub
parent e74ce72f09
commit 3eae657121
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 106 additions and 75 deletions

View File

@ -8,12 +8,18 @@ def "nu-complete threads" [] {
seq 1 (sys cpu | length) seq 1 (sys cpu | length)
} }
# Here we store the map of annotations internal names and the annotation actually used during test creation # Here we store the map of annotations' internal names along with the annotation actually
# The reason we do that is to allow annotations to be easily renamed without modifying rest of the code # used during test creation. We do this to allow annotations to be easily renamed without
# Functions with no annotations or with annotations not on the list are rejected during module evaluation # modifying rest of the code.
# test and test-skip annotations may be used multiple times throughout the module as the function names are stored in a list # Functions with no annotations or with annotations not on the list are rejected during module evaluation.
# Other annotations should only be used once within a module file #
# If you find yourself in need of multiple before- or after- functions it's a sign your test suite probably needs redesign # `test` and `test-skip` annotations may be used multiple times throughout the module as the function names
# are stored in a list.
#
# Other annotations should only be used once within a module file.
#
# If you find yourself in need of multiple `before-*` or `after-*` functions, it's a sign your test suite
# probably needs redesign.
const valid_annotations = { const valid_annotations = {
"test": "test", "test": "test",
"ignore": "test-skip", "ignore": "test-skip",
@ -23,7 +29,7 @@ const valid_annotations = {
"after-all": "after-all" "after-all": "after-all"
} }
# Returns a table containing the list of function names together with their annotations (comments above the declaration) # Returns a table containing the list of command names along with their attributes.
def get-annotated [ def get-annotated [
file: path file: path
]: nothing -> table<function_name: string, annotation: string> { ]: nothing -> table<function_name: string, annotation: string> {

View File

@ -1,7 +1,8 @@
use std assert use std/assert
use std/testing *
use std-rfc/conversions * use std-rfc/conversions *
#[test] @test
def range-into-list [] { def range-into-list [] {
assert equal ( assert equal (
1..10 | into list 1..10 | into list
@ -10,7 +11,7 @@ def range-into-list [] {
) )
} }
#[test] @test
def string-into-list [] { def string-into-list [] {
assert equal ( assert equal (
"foo" | into list "foo" | into list
@ -19,7 +20,7 @@ def string-into-list [] {
) )
} }
#[test] @test
def range-stride-into-list [] { def range-stride-into-list [] {
assert equal ( assert equal (
0..2..10 | into list 0..2..10 | into list
@ -28,7 +29,7 @@ def range-stride-into-list [] {
) )
} }
#[test] @test
def null-into-list [] { def null-into-list [] {
assert equal ( assert equal (
null | into list | get 0 | describe null | into list | get 0 | describe
@ -37,7 +38,7 @@ def null-into-list [] {
) )
} }
#[test] @test
def list-into-list [] { def list-into-list [] {
assert equal ( assert equal (
[ foo bar baz ] | into list [ foo bar baz ] | into list
@ -47,7 +48,7 @@ def list-into-list [] {
} }
#[test] @test
def table-into-columns--roundtrip [] { def table-into-columns--roundtrip [] {
assert equal ( assert equal (
ls ls
@ -61,7 +62,7 @@ const test_record_of_lists = {
b: [ 4 5 6 ] b: [ 4 5 6 ]
} }
#[test] @test
def record-into-columns--simple [] { def record-into-columns--simple [] {
let actual = ( let actual = (
$test_record_of_lists $test_record_of_lists
@ -74,7 +75,7 @@ def record-into-columns--simple [] {
assert equal $actual $expected assert equal $actual $expected
} }
#[test] @test
def table-into-columns--simple [] { def table-into-columns--simple [] {
let actual = ( let actual = (
ls | table-into-columns | get 1 | columns | get 0 ls | table-into-columns | get 1 | columns | get 0
@ -84,7 +85,7 @@ def table-into-columns--simple [] {
assert equal $actual $expected assert equal $actual $expected
} }
#[test] @test
def name-values--simple [] { def name-values--simple [] {
let actual = ( let actual = (
[ 1 2 3 ] | name-values one two three [ 1 2 3 ] | name-values one two three
@ -96,7 +97,7 @@ def name-values--simple [] {
assert equal $actual $expected assert equal $actual $expected
} }
#[test] @test
def name-values--missing-keyname [] { def name-values--missing-keyname [] {
let actual = ( let actual = (
[ 1 2 3 ] | name-values one two [ 1 2 3 ] | name-values one two

View File

@ -1,12 +1,14 @@
use std/assert
const kv_module = if ("sqlite" in (version).features) { "std-rfc/kv" } else { null } const kv_module = if ("sqlite" in (version).features) { "std-rfc/kv" } else { null }
use $kv_module * use $kv_module *
use std/assert
use std/testing *
# It's important to use random keys and to clean-up # It's important to use random keys and to clean-up
# after since the user running these tests may have # after since the user running these tests may have
# either an existing local stor or universal db. # either an existing local stor or universal db.
#[test] @test
def simple-local-set [] { def simple-local-set [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
@ -20,10 +22,11 @@ def simple-local-set [] {
kv drop $key | ignore kv drop $key | ignore
} }
#[test] @test
def local-pipeline_set_returns_value [] { def local-pipeline_set_returns_value [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
let key = (random uuid) let key = (random uuid)
let actual = (42 | kv set $key) let actual = (42 | kv set $key)
let expected = 42 let expected = 42
@ -36,10 +39,11 @@ def local-pipeline_set_returns_value [] {
kv drop $key | ignore kv drop $key | ignore
} }
#[test] @test
def local-multiple_assignment [] { def local-multiple_assignment [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
let key1 = (random uuid) let key1 = (random uuid)
let key2 = (random uuid) let key2 = (random uuid)
let key3 = (random uuid) let key3 = (random uuid)
@ -56,10 +60,11 @@ def local-multiple_assignment [] {
kv drop $key3 kv drop $key3
} }
#[test] @test
def local-transpose_to_record [] { def local-transpose_to_record [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
let key1 = (random uuid) let key1 = (random uuid)
let key2 = (random uuid) let key2 = (random uuid)
let key3 = (random uuid) let key3 = (random uuid)
@ -77,10 +82,11 @@ def local-transpose_to_record [] {
kv drop $key3 kv drop $key3
} }
#[test] @test
def local-using_closure [] { def local-using_closure [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
let name_key = (random uuid) let name_key = (random uuid)
let size_key = (random uuid) let size_key = (random uuid)
@ -100,10 +106,11 @@ def local-using_closure [] {
kv drop $size_key kv drop $size_key
} }
#[test] @test
def local-return-entire-list [] { def local-return-entire-list [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
let key1 = (random uuid) let key1 = (random uuid)
let key2 = (random uuid) let key2 = (random uuid)
@ -122,10 +129,11 @@ def local-return-entire-list [] {
kv drop $key2 kv drop $key2
} }
#[test] @test
def local-return_value_only [] { def local-return_value_only [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
let key = (random uuid) let key = (random uuid)
let expected = 'VALUE' let expected = 'VALUE'
@ -137,9 +145,11 @@ def local-return_value_only [] {
} }
#[test] @test
def universal-simple_set [] { def universal-simple_set [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
$env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3) $env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3)
let key = (random uuid) let key = (random uuid)
@ -153,9 +163,11 @@ def universal-simple_set [] {
rm $env.NU_UNIVERSAL_KV_PATH rm $env.NU_UNIVERSAL_KV_PATH
} }
#[test] @test
def universal-pipeline_set_returns_value [] { def universal-pipeline_set_returns_value [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
$env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3) $env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3)
let key = (random uuid) let key = (random uuid)
@ -171,9 +183,11 @@ def universal-pipeline_set_returns_value [] {
rm $env.NU_UNIVERSAL_KV_PATH rm $env.NU_UNIVERSAL_KV_PATH
} }
#[test] @test
def universal-multiple_assignment [] { def universal-multiple_assignment [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
$env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3) $env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3)
let key1 = (random uuid) let key1 = (random uuid)
@ -193,9 +207,11 @@ def universal-multiple_assignment [] {
rm $env.NU_UNIVERSAL_KV_PATH rm $env.NU_UNIVERSAL_KV_PATH
} }
#[test] @test
def universal-transpose_to_record [] { def universal-transpose_to_record [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
$env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3) $env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3)
let key1 = (random uuid) let key1 = (random uuid)
@ -216,9 +232,11 @@ def universal-transpose_to_record [] {
rm $env.NU_UNIVERSAL_KV_PATH rm $env.NU_UNIVERSAL_KV_PATH
} }
#[test] @test
def universal-using_closure [] { def universal-using_closure [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
$env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3) $env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3)
let name_key = (random uuid) let name_key = (random uuid)
@ -241,9 +259,11 @@ def universal-using_closure [] {
rm $env.NU_UNIVERSAL_KV_PATH rm $env.NU_UNIVERSAL_KV_PATH
} }
#[test] @test
def universal-return-entire-list [] { def universal-return-entire-list [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
$env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3) $env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3)
let key1 = (random uuid) let key1 = (random uuid)
@ -265,9 +285,11 @@ def universal-return-entire-list [] {
rm $env.NU_UNIVERSAL_KV_PATH rm $env.NU_UNIVERSAL_KV_PATH
} }
#[test] @test
def universal-return_value_only [] { def universal-return_value_only [] {
if ('sqlite' not-in (version).features) { return } if ('sqlite' not-in (version).features) { return }
let key = (random uuid)
$env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3) $env.NU_UNIVERSAL_KV_PATH = (mktemp -t --suffix .sqlite3)
let key = (random uuid) let key = (random uuid)
@ -280,4 +302,3 @@ def universal-return_value_only [] {
kv drop --universal $key kv drop --universal $key
rm $env.NU_UNIVERSAL_KV_PATH rm $env.NU_UNIVERSAL_KV_PATH
} }

View File

@ -1,7 +1,8 @@
use std-rfc/path use std-rfc/path
use std/assert use std/assert
use std/testing *
#[test] @test
def path_with_extension [] { def path_with_extension [] {
let new_path = "ab.txt" | path with-extension "rs" let new_path = "ab.txt" | path with-extension "rs"
assert equal $new_path "ab.rs" assert equal $new_path "ab.rs"
@ -10,7 +11,7 @@ def path_with_extension [] {
assert equal $new_path "ab.rs" assert equal $new_path "ab.rs"
} }
#[test] @test
def path_with_extension_for_list [] { def path_with_extension_for_list [] {
let new_path = ["ab.txt", "cd.exe"] | path with-extension "rs" let new_path = ["ab.txt", "cd.exe"] | path with-extension "rs"
assert equal $new_path ["ab.rs", "cd.rs"] assert equal $new_path ["ab.rs", "cd.rs"]
@ -19,7 +20,7 @@ def path_with_extension_for_list [] {
assert equal $new_path ["ab.rs", "cd.rs"] assert equal $new_path ["ab.rs", "cd.rs"]
} }
#[test] @test
def path_with_stem [] { def path_with_stem [] {
let new_path = $"(char psep)usr(char psep)bin" | path with-stem "share" let new_path = $"(char psep)usr(char psep)bin" | path with-stem "share"
assert equal $new_path $"(char psep)usr(char psep)share" assert equal $new_path $"(char psep)usr(char psep)share"
@ -28,7 +29,7 @@ def path_with_stem [] {
assert equal $new_path [$"(char psep)home(char psep)nushell", $"(char psep)home(char psep)bob(char psep)nushell.txt"] assert equal $new_path [$"(char psep)home(char psep)nushell", $"(char psep)home(char psep)bob(char psep)nushell.txt"]
} }
#[test] @test
def path_with_parent [] { def path_with_parent [] {
let new_path = $"(char psep)etc(char psep)foobar" | path with-parent $"(char psep)usr(char psep)share(char psep)" let new_path = $"(char psep)etc(char psep)foobar" | path with-parent $"(char psep)usr(char psep)share(char psep)"
assert equal $new_path $"(char psep)usr(char psep)share(char psep)foobar" assert equal $new_path $"(char psep)usr(char psep)share(char psep)foobar"

View File

@ -1,7 +1,8 @@
use std/assert use std/assert
use std/testing *
use std-rfc/str use std-rfc/str
#[test] @test
def str-dedent_simple [] { def str-dedent_simple [] {
# Test 1: # Test 1:
@ -21,7 +22,7 @@ def str-dedent_simple [] {
) $"Heading(char lsep)(char lsep) one(char lsep) two" ) $"Heading(char lsep)(char lsep) one(char lsep) two"
} }
#[test] @test
def str-dedent_leave_blankline_whitespace [] { def str-dedent_leave_blankline_whitespace [] {
# Test 2: # Test 2:
# Same as #1, but the blank line has leftover whitespace # Same as #1, but the blank line has leftover whitespace
@ -39,7 +40,7 @@ def str-dedent_leave_blankline_whitespace [] {
) $"Heading(char lsep) (char lsep) one(char lsep) two" ) $"Heading(char lsep) (char lsep) one(char lsep) two"
} }
#[test] @test
def str-dedent_leave_blankline_tab [] { def str-dedent_leave_blankline_tab [] {
# Test 3: # Test 3:
# Same, but with a single tab character on the "blank" line # Same, but with a single tab character on the "blank" line
@ -56,7 +57,7 @@ def str-dedent_leave_blankline_tab [] {
) $"Heading(char lsep)(char tab)(char lsep) one(char lsep) two" ) $"Heading(char lsep)(char tab)(char lsep) one(char lsep) two"
} }
#[test] @test
def str-dedent_ends_with_newline [] { def str-dedent_ends_with_newline [] {
# Test 4: # Test 4:
# Ends with line-break # Ends with line-break
@ -74,7 +75,7 @@ def str-dedent_ends_with_newline [] {
) $"Heading(char lsep)(char lsep) one(char lsep) two(char lsep)" ) $"Heading(char lsep)(char lsep) one(char lsep) two(char lsep)"
} }
#[test] @test
def str-dedent_identity [] { def str-dedent_identity [] {
# Test 5: # Test 5:
# Identity - Returns the original string sans first and last empty lines # Identity - Returns the original string sans first and last empty lines
@ -87,7 +88,7 @@ def str-dedent_identity [] {
) " Identity " ) " Identity "
} }
#[test] @test
def str-dedent_error-no_blank_lines [] { def str-dedent_error-no_blank_lines [] {
# Test 6: # Test 6:
# Error - Does not contain an empty first line # Error - Does not contain an empty first line
@ -104,7 +105,7 @@ def str-dedent_error-no_blank_lines [] {
} }
} }
#[test] @test
def str-dedent_error-no_blank_first_line [] { def str-dedent_error-no_blank_first_line [] {
# Test 7: # Test 7:
# Error - Does not contain an empty last line # Error - Does not contain an empty last line
@ -115,7 +116,7 @@ def str-dedent_error-no_blank_first_line [] {
} }
} }
#[test] @test
def str-dedent_error-missing_last_empty_line [] { def str-dedent_error-missing_last_empty_line [] {
# Test 7.1: # Test 7.1:
# Error - Does not contain an empty last line # Error - Does not contain an empty last line
@ -127,7 +128,7 @@ def str-dedent_error-missing_last_empty_line [] {
} }
} }
#[test] @test
def str-dedent_error-not_enough_indentation [] { def str-dedent_error-not_enough_indentation [] {
# Test 8: # Test 8:
# Error - Line 1 does not have enough indentation # Error - Line 1 does not have enough indentation
@ -140,7 +141,7 @@ def str-dedent_error-not_enough_indentation [] {
} }
} }
#[test] @test
def str-dedent_error-not_enough_indentation2 [] { def str-dedent_error-not_enough_indentation2 [] {
# Test 8.1: # Test 8.1:
# Error - Line 2 does not have enough indentation # Error - Line 2 does not have enough indentation
@ -153,7 +154,7 @@ def str-dedent_error-not_enough_indentation2 [] {
} }
} }
#[test] @test
def str-dedent_error-not_enough_indentation3 [] { def str-dedent_error-not_enough_indentation3 [] {
# Test 8.2: # Test 8.2:
# Error - Line does not have enough indentation # Error - Line does not have enough indentation
@ -165,7 +166,7 @@ def str-dedent_error-not_enough_indentation3 [] {
} }
} }
#[test] @test
def str-dedent_first_line_whitespace_allowed [] { def str-dedent_first_line_whitespace_allowed [] {
# Test 9: # Test 9:
# "Hidden" whitespace on the first line is allowed # "Hidden" whitespace on the first line is allowed
@ -177,7 +178,7 @@ def str-dedent_first_line_whitespace_allowed [] {
) " Identity " ) " Identity "
} }
#[test] @test
def str-dedent_using_tabs [] { def str-dedent_using_tabs [] {
# Test 10: # Test 10:
# If the indentation on the last line uses tabs, then the number of tabs # If the indentation on the last line uses tabs, then the number of tabs
@ -192,7 +193,7 @@ def str-dedent_using_tabs [] {
assert equal $actual $expected assert equal $actual $expected
} }
#[test] @test
def str-unindent_simple [] { def str-unindent_simple [] {
# Test 1: # Test 1:
# Should start with "Heading" in the first character position # Should start with "Heading" in the first character position
@ -213,7 +214,7 @@ def str-unindent_simple [] {
assert equal $actual $expected assert equal $actual $expected
} }
#[test] @test
def str-unindent_ignore_first_and_last_whitespace [] { def str-unindent_ignore_first_and_last_whitespace [] {
# Test 2: # Test 2:
# If the first and/or last line are only whitespace # If the first and/or last line are only whitespace
@ -236,7 +237,7 @@ def str-unindent_ignore_first_and_last_whitespace [] {
assert equal $actual $expected assert equal $actual $expected
} }
#[test] @test
def str-unindent_keep_extra_line [] { def str-unindent_keep_extra_line [] {
# Test 3: # Test 3:
# Keep intentional blank lines at start and/or end # Keep intentional blank lines at start and/or end
@ -252,7 +253,7 @@ def str-unindent_keep_extra_line [] {
assert equal $actual $expected assert equal $actual $expected
} }
#[test] @test
def str-unindent_works_on_single_line [] { def str-unindent_works_on_single_line [] {
# Test 4: # Test 4:
# Works on a single-line string # Works on a single-line string
@ -264,7 +265,7 @@ def str-unindent_works_on_single_line [] {
assert equal $actual $expected assert equal $actual $expected
} }
#[test] @test
def str-unindent_whitespace_only_single_line [] { def str-unindent_whitespace_only_single_line [] {
# Test 4: # Test 4:
# Works on a single-line string with whitespace-only # Works on a single-line string with whitespace-only
@ -276,7 +277,7 @@ def str-unindent_whitespace_only_single_line [] {
assert equal $actual $expected assert equal $actual $expected
} }
#[test] @test
def str-unindent_whitespace_works_with_tabs [] { def str-unindent_whitespace_works_with_tabs [] {
# Test 4: # Test 4:
# Works with tabs for indentation # Works with tabs for indentation

View File

@ -1,4 +1,5 @@
use std/assert use std/assert
use std/testing *
use std-rfc/tables * use std-rfc/tables *
const test_table = [ const test_table = [
@ -29,7 +30,7 @@ const enumerated_table = [
[ 9 'a9' 'b9' 'c9' 'd9' 'e9' 'f9' ] [ 9 'a9' 'b9' 'c9' 'd9' 'e9' 'f9' ]
] ]
#[test] @test
def select-slice--single_int [] { def select-slice--single_int [] {
assert equal ( assert equal (
$test_table | select slices 1 $test_table | select slices 1
@ -38,7 +39,7 @@ def select-slice--single_int [] {
) )
} }
#[test] @test
def select-slice--single_slice [] { def select-slice--single_slice [] {
assert equal ( assert equal (
$test_table | select slices 2..4 $test_table | select slices 2..4
@ -47,7 +48,7 @@ def select-slice--single_slice [] {
) )
} }
#[test] @test
def select-slice--complex [] { def select-slice--complex [] {
assert equal ( assert equal (
# First and every following third-row + second row # First and every following third-row + second row
@ -57,7 +58,7 @@ def select-slice--complex [] {
) )
} }
#[test] @test
def select-slice--out_of_bounds [] { def select-slice--out_of_bounds [] {
assert equal ( assert equal (
$test_table | select slices 100 $test_table | select slices 100
@ -66,7 +67,7 @@ def select-slice--out_of_bounds [] {
) )
} }
#[test] @test
def reject-slice--single_index [] { def reject-slice--single_index [] {
assert equal ( assert equal (
$test_table | reject slices 4 $test_table | reject slices 4
@ -75,7 +76,7 @@ def reject-slice--single_index [] {
) )
} }
#[test] @test
def reject-slice--slices [] { def reject-slice--slices [] {
assert equal ( assert equal (
# Reject rows 0-3 and 5-9, leaving only 4 # Reject rows 0-3 and 5-9, leaving only 4
@ -85,14 +86,14 @@ def reject-slice--slices [] {
) )
} }
#[test] @test
def reject-slice--out_of_bounds [] { def reject-slice--out_of_bounds [] {
assert error { assert error {
$test_table | reject slices 1000 $test_table | reject slices 1000
} }
} }
#[test] @test
def select-col--index [] { def select-col--index [] {
assert equal ( assert equal (
$test_table | select column-slices 2 $test_table | select column-slices 2
@ -101,7 +102,7 @@ def select-col--index [] {
) )
} }
#[test] @test
def select-col--indices [] { def select-col--indices [] {
assert equal ( assert equal (
$test_table | select column-slices 2 4 $test_table | select column-slices 2 4
@ -110,7 +111,7 @@ def select-col--indices [] {
) )
} }
#[test] @test
def select-col--slices_and_index [] { def select-col--slices_and_index [] {
assert equal ( assert equal (
$test_table | select column-slices 0..2..5 1 $test_table | select column-slices 0..2..5 1
@ -119,7 +120,7 @@ def select-col--slices_and_index [] {
) )
} }
#[test] @test
def reject-col--slices_and_index [] { def reject-col--slices_and_index [] {
assert equal ( assert equal (
$test_table | reject column-slices 0..2..5 1 $test_table | reject column-slices 0..2..5 1
@ -128,7 +129,7 @@ def reject-col--slices_and_index [] {
) )
} }
#[test] @test
def reject-col--out_of_bounds [] { def reject-col--out_of_bounds [] {
assert equal ( assert equal (
$test_table | reject column-slices 1_000 $test_table | reject column-slices 1_000
@ -217,7 +218,7 @@ const movies = [
[ "(500) Days of Summer", comedy, Fox, 81, 8.096, 87, 60.72, 2009 ] [ "(500) Days of Summer", comedy, Fox, 81, 8.096, 87, 60.72, 2009 ]
] ]
#[test] @test
def count_movies_by_Lead_Studio [] { def count_movies_by_Lead_Studio [] {
let grouped = $movies | group-by Lead_Studio --to-table let grouped = $movies | group-by Lead_Studio --to-table
let out = $grouped | aggregate let out = $grouped | aggregate
@ -242,7 +243,7 @@ def count_movies_by_Lead_Studio [] {
assert equal $out $expected assert equal $out $expected
} }
#[test] @test
def average_gross_by_Genre [] { def average_gross_by_Genre [] {
let grouped = $movies | group-by Genre --to-table let grouped = $movies | group-by Genre --to-table
let out = $grouped | aggregate --ops {avg: {math avg}} Worldwide_Gross | select Genre Worldwide_Gross_avg let out = $grouped | aggregate --ops {avg: {math avg}} Worldwide_Gross | select Genre Worldwide_Gross_avg
@ -267,7 +268,7 @@ def average_gross_by_Genre [] {
assert equal $out $expected assert equal $out $expected
} }
#[test] @test
def aggregate_default_ops [] { def aggregate_default_ops [] {
let grouped = $movies | group-by Genre --to-table let grouped = $movies | group-by Genre --to-table
let out = $grouped | aggregate Worldwide_Gross let out = $grouped | aggregate Worldwide_Gross
@ -292,7 +293,7 @@ def aggregate_default_ops [] {
assert equal $out $expected assert equal $out $expected
} }
#[test] @test
def throw_error_on_non-table_input [] { def throw_error_on_non-table_input [] {
# without --to-table # without --to-table
let out = try { let out = try {
@ -304,7 +305,7 @@ def throw_error_on_non-table_input [] {
assert equal $out "input must be a table" assert equal $out "input must be a table"
} }
#[test] @test
def throw_error_on_non-existing_column [] { def throw_error_on_non-existing_column [] {
let grouped = $movies | group-by Genre --to-table let grouped = $movies | group-by Genre --to-table
let error = try { let error = try {
@ -316,7 +317,7 @@ def throw_error_on_non-existing_column [] {
assert equal $error.inner.0.msg "Cannot find column '$.items.NotInTheDataSet'" assert equal $error.inner.0.msg "Cannot find column '$.items.NotInTheDataSet'"
} }
#[test] @test
def aggregate_stats_without_grouping [] { def aggregate_stats_without_grouping [] {
let out = $movies | aggregate Year | update cells -c [Year_min Year_avg Year_max Year_sum] {math round -p 2} let out = $movies | aggregate Year | update cells -c [Year_min Year_avg Year_max Year_sum] {math round -p 2}
let expected = [{ let expected = [{