Skip to content

Commit

Permalink
Move tables module to latest std-rfc
Browse files Browse the repository at this point in the history
  • Loading branch information
NotTheDr01ds committed Jan 27, 2025
1 parent fff77c7 commit d1bd7b6
Show file tree
Hide file tree
Showing 11 changed files with 46 additions and 23 deletions.
File renamed without changes.
File renamed without changes.
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,6 @@ use ./row-indices.nu *
export def "reject ranges" [ ...ranges ] {
enumerate
| flatten
| collect
| reject ...(row-indices ...$ranges)
}
Original file line number Diff line number Diff line change
@@ -1,39 +1,44 @@
use std assert
use ../std-rfc/conversions *

export def "test range-into-list" [] {
#[test]
def 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" [] {
#[test]
def string-into-list [] {
assert equal (
"foo" | into list
) (
[ foo ]
)
}

export def "test range-stride-into-list" [] {
#[test]
def range-stride-into-list [] {
assert equal (
0..2..10 | into list
) (
[ 0 2 4 6 8 10 ]
)
}

export def "test null-into-list" [] {
#[test]
def null-into-list [] {
assert equal (
null | into list | get 0 | describe
) (
"nothing"
)
}

export def "test list-into-list" [] {
#[test]
def list-into-list [] {
assert equal (
[ foo bar baz ] | into list
) (
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std assert
use std/assert
use ../std-rfc/tables *

const test_table = [
Expand Down Expand Up @@ -29,31 +29,35 @@ const enumerated_table = [
[ 9 'a9' 'b9' 'c9' 'd9' 'e9' 'f9' ]
]

export def "test row-indices-range" [] {
#[test]
def row-indices--range [] {
assert equal (
row-indices 0..3 10..11
) (
[ 0 1 2 3 10 11 ]
)
}

export def "test row-indices-index" [] {
#[test]
export def row-indices--index [] {
assert equal (
row-indices 4
) (
[ 4 ]
)
}

export def "test row-indices-complex" [] {
#[test]
def row-indices--complex [] {
assert equal (
row-indices 0..2..6 3 7
) (
[ 0 2 4 6 3 7 ]
)
}

export def "test col-index-ints" [] {
#[test]
def col-index--ints [] {
assert equal (
# Third and Fifth Columns
$test_table | col-indices 2 4
Expand All @@ -62,7 +66,8 @@ export def "test col-index-ints" [] {
)
}

export def "test col-index-complex" [] {
#[test]
def col-index--complex [] {
assert equal (
# Every other column, plus the second
$test_table | col-indices 0..2..10 1
Expand All @@ -71,23 +76,26 @@ export def "test col-index-complex" [] {
)
}

export def "test select-range single-int" [] {
#[test]
def select-range--single_int [] {
assert equal (
$test_table | select ranges 1
) (
$enumerated_table | select 1
)
}

export def "test select-range single-range" [] {
#[test]
def select-range--single_range [] {
assert equal (
$test_table | select ranges 2..4
) (
$enumerated_table | select 2 3 4
)
}

export def "test select-range complex" [] {
#[test]
def select-range--complex [] {
assert equal (
# First and every following third-row + second row
$test_table | select ranges 1 0..3..100
Expand All @@ -96,23 +104,26 @@ export def "test select-range complex" [] {
)
}

export def "test select-range out-of-bounds" [] {
#[test]
def select-range--out_of_bounds [] {
assert equal (
$test_table | select ranges 100
) (
[]
)
}

export def "test reject-range single-index" [] {
#[test]
def reject-range--single_index [] {
assert equal (
$test_table | reject ranges 4
) (
$enumerated_table | reject 4
)
}

export def "test reject-range ranges" [] {
#[test]
def reject-range--ranges [] {
assert equal (
# Reject rows 0-3 and 5-9, leaving only 4
$test_table | reject ranges 0..3 5..9
Expand All @@ -121,45 +132,51 @@ export def "test reject-range ranges" [] {
)
}

export def "test reject-range out-of-bounds" [] {
#[test]
def reject-range--out_of_bounds [] {
assert error {
$test_table | reject ranges 1000
}
}

export def "test select-col index" [] {
#[test]
def select-col--index [] {
assert equal (
$test_table | select column-ranges 2
) (
$test_table | select col-c
)
}

export def "test select-col indices" [] {
#[test]
def 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" [] {
#[test]
def 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" [] {
#[test]
def 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" [] {
#[test]
def reject-col--out_of_bounds [] {
assert equal (
$test_table | reject column-ranges 1_000
) (
Expand Down

0 comments on commit d1bd7b6

Please sign in to comment.