mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
miller/types/mlrval_functions_test.go iterate
This commit is contained in:
parent
12fa4f63a1
commit
a0658b45ae
6 changed files with 87 additions and 45 deletions
|
|
@ -1,2 +1,3 @@
|
|||
map \d :w<C-m>:!clear;echo Building ...; echo; build-go<C-m>
|
||||
map \f :w<C-m>:!clear;echo Building ...; echo; build<C-m>
|
||||
map \t :w<C-m>:!clear;echo; tester<C-m>
|
||||
|
|
|
|||
1
go/build
1
go/build
|
|
@ -9,4 +9,5 @@ fi
|
|||
set -euo pipefail
|
||||
|
||||
./build-go
|
||||
tester
|
||||
check $verbose
|
||||
|
|
|
|||
15
go/check
15
go/check
|
|
@ -1,5 +1,9 @@
|
|||
#!/bin/bash
|
||||
|
||||
# ================================================================
|
||||
# COMMAND-LINE TESTS
|
||||
# ================================================================
|
||||
|
||||
runner="bash"
|
||||
if [ "$1" = "-v" ]; then
|
||||
set -x
|
||||
|
|
@ -8,17 +12,6 @@ fi
|
|||
|
||||
set -euo pipefail
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# GO-SOURCE TESTS
|
||||
|
||||
# go test -v ./... doesn't work since it triggers unready things in
|
||||
# src/github.com/goccmack
|
||||
|
||||
export GOPATH=$(pwd)
|
||||
go test miller/types
|
||||
|
||||
# ----------------------------------------------------------------
|
||||
# COMMAND-LINE TESTS
|
||||
$runner u/try-io > u/try-io.out
|
||||
$runner u/try-chain > u/try-chain.out
|
||||
$runner u/try-verbs > u/try-verbs.out
|
||||
|
|
|
|||
|
|
@ -7,33 +7,15 @@ package types
|
|||
|
||||
import (
|
||||
"testing"
|
||||
//"types"
|
||||
)
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
func TestLexicalAscendingComparator(t *testing.T) {
|
||||
var a = MlrvalFromInt64(10)
|
||||
var b = MlrvalFromInt64(2)
|
||||
if LexicalAscendingComparator(&a, &b) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
a = MlrvalFromString("abc")
|
||||
b = MlrvalFromString("def")
|
||||
if LexicalAscendingComparator(&a, &b) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
a = MlrvalFromInt64(3)
|
||||
b = MlrvalFromBool(true)
|
||||
if LexicalAscendingComparator(&a, &b) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
||||
// ----------------------------------------------------------------
|
||||
// SORTING
|
||||
// Sort rules (same for min, max, and comparator):
|
||||
//
|
||||
// Lexical compare is just string-sort on stringify of mlrvals:
|
||||
// e.g. "hello" < "true".
|
||||
//
|
||||
// Numerical sort rules (same for min, max, and comparator):
|
||||
// * NUMERICS < BOOL < STRINGS < ERROR < ABSENT
|
||||
// * error == error (singleton type)
|
||||
// * absent == absent (singleton type)
|
||||
|
|
@ -41,7 +23,8 @@ func TestLexicalAscendingComparator(t *testing.T) {
|
|||
// * numeric compares on numbers
|
||||
// * false < true
|
||||
|
||||
func TestNumericAscendingComparator(t *testing.T) {
|
||||
func TestComparactors(t *testing.T) {
|
||||
|
||||
i10 := MlrvalFromInt64(10)
|
||||
i2 := MlrvalFromInt64(2)
|
||||
|
||||
|
|
@ -56,7 +39,28 @@ func TestNumericAscendingComparator(t *testing.T) {
|
|||
a := MlrvalFromAbsent()
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Within-type comparisons
|
||||
// Within-type lexical comparisons
|
||||
if LexicalAscendingComparator(&i10, &i2) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
if LexicalAscendingComparator(&bfalse, &bfalse) != 0 {
|
||||
t.Fatal()
|
||||
}
|
||||
if LexicalAscendingComparator(&bfalse, &btrue) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
if LexicalAscendingComparator(&sabc, &sdef) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
if LexicalAscendingComparator(&e, &e) != 0 {
|
||||
t.Fatal()
|
||||
}
|
||||
if LexicalAscendingComparator(&a, &a) != 0 {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Within-type numeric comparisons
|
||||
if NumericAscendingComparator(&i10, &i2) != 1 {
|
||||
t.Fatal()
|
||||
}
|
||||
|
|
@ -77,17 +81,54 @@ func TestNumericAscendingComparator(t *testing.T) {
|
|||
if NumericAscendingComparator(&a, &a) != 0 {
|
||||
t.Fatal()
|
||||
}
|
||||
// xxx more
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Across-type comparisons
|
||||
// Across-type lexical comparisons
|
||||
|
||||
if LexicalAscendingComparator(&i10, &btrue) != -1 { // "10" < "true"
|
||||
t.Fatal()
|
||||
}
|
||||
if LexicalAscendingComparator(&i10, &sabc) != -1 { // "10" < "abc"
|
||||
t.Fatal()
|
||||
}
|
||||
if LexicalAscendingComparator(&i10, &e) != 1 { // "10" > "(error)"
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
if LexicalAscendingComparator(&bfalse, &sabc) != 1 { // "false" > "abc"
|
||||
t.Fatal()
|
||||
}
|
||||
if LexicalAscendingComparator(&bfalse, &e) != 1 { // "false" > "(error)"
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
|
||||
// Across-type numeric comparisons
|
||||
|
||||
if NumericAscendingComparator(&i10, &btrue) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
if NumericAscendingComparator(&e, &a) != -1 {
|
||||
if NumericAscendingComparator(&i10, &sabc) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
if NumericAscendingComparator(&i10, &e) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
if NumericAscendingComparator(&i10, &a) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
// xxx more
|
||||
if NumericAscendingComparator(&bfalse, &sabc) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
if NumericAscendingComparator(&bfalse, &e) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
if NumericAscendingComparator(&bfalse, &a) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
|
||||
if NumericAscendingComparator(&e, &a) != -1 {
|
||||
t.Fatal()
|
||||
}
|
||||
}
|
||||
|
|
|
|||
11
go/tester
Executable file
11
go/tester
Executable file
|
|
@ -0,0 +1,11 @@
|
|||
#!/bin/bash
|
||||
|
||||
# ================================================================
|
||||
# GO-SOURCE TESTS
|
||||
# ================================================================
|
||||
|
||||
# go test -v ./... doesn't work since it triggers unready things in
|
||||
# src/github.com/goccmack
|
||||
|
||||
export GOPATH=$(pwd)
|
||||
go test miller/types
|
||||
|
|
@ -2,14 +2,9 @@
|
|||
TOP OF LIST:
|
||||
|
||||
* go-try:
|
||||
|
||||
o rename: bulk-edit for b,i,x vs x,i,b cases
|
||||
|
||||
! sort
|
||||
- UT per se for 'NUMERICS < BOOL < STRINGS < ERROR < ABSENT'
|
||||
! filter
|
||||
! emit; print/dump
|
||||
|
||||
! quoted NIDX
|
||||
- how with whitespace regex -- ?
|
||||
! quoted DKVP
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue