mirror of
https://github.com/johnkerl/miller.git
synced 2026-01-23 02:14:13 +00:00
parent
521215992d
commit
f8fbfeeb0b
4 changed files with 38 additions and 36 deletions
|
|
@ -12,129 +12,129 @@ import (
|
|||
|
||||
func TestFromDeferredType(t *testing.T) {
|
||||
mv := FromDeferredType("123")
|
||||
assert.Equal(t, MVType(MT_PENDING), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_PENDING, mv.mvtype)
|
||||
assert.Equal(t, "123", mv.printrep)
|
||||
assert.True(t, mv.printrepValid)
|
||||
|
||||
mv = FromDeferredType("true")
|
||||
assert.Equal(t, MVType(MT_PENDING), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_PENDING, mv.mvtype)
|
||||
assert.Equal(t, "true", mv.printrep)
|
||||
assert.True(t, mv.printrepValid)
|
||||
|
||||
mv = FromDeferredType("abc")
|
||||
assert.Equal(t, MVType(MT_PENDING), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_PENDING, mv.mvtype)
|
||||
assert.Equal(t, "abc", mv.printrep)
|
||||
assert.True(t, mv.printrepValid)
|
||||
|
||||
mv = FromDeferredType("")
|
||||
assert.Equal(t, MVType(MT_PENDING), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_PENDING, mv.mvtype)
|
||||
assert.Equal(t, "", mv.printrep)
|
||||
assert.True(t, mv.printrepValid)
|
||||
}
|
||||
|
||||
func TestFromInferredType(t *testing.T) {
|
||||
mv := FromInferredType("123")
|
||||
assert.Equal(t, MVType(MT_INT), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_INT, mv.mvtype)
|
||||
assert.Equal(t, "123", mv.printrep)
|
||||
assert.True(t, mv.printrepValid)
|
||||
assert.Equal(t, mv.intval, 123)
|
||||
|
||||
mv = FromInferredType("true")
|
||||
assert.Equal(t, MVType(MT_BOOL), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_BOOL, mv.mvtype)
|
||||
assert.Equal(t, "true", mv.printrep)
|
||||
assert.True(t, mv.printrepValid)
|
||||
assert.Equal(t, mv.boolval, true)
|
||||
|
||||
mv = FromInferredType("abc")
|
||||
assert.Equal(t, MVType(MT_STRING), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_STRING, mv.mvtype)
|
||||
assert.Equal(t, "abc", mv.printrep)
|
||||
assert.True(t, mv.printrepValid)
|
||||
|
||||
mv = FromInferredType("")
|
||||
assert.Equal(t, MVType(MT_VOID), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_VOID, mv.mvtype)
|
||||
assert.Equal(t, "", mv.printrep)
|
||||
assert.True(t, mv.printrepValid)
|
||||
}
|
||||
|
||||
func TestFromString(t *testing.T) {
|
||||
mv := FromString("123")
|
||||
assert.Equal(t, MVType(MT_STRING), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_STRING, mv.mvtype)
|
||||
assert.Equal(t, "123", mv.printrep)
|
||||
assert.True(t, mv.printrepValid)
|
||||
|
||||
mv = FromString("")
|
||||
assert.Equal(t, MVType(MT_VOID), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_VOID, mv.mvtype)
|
||||
assert.Equal(t, "", mv.printrep)
|
||||
assert.True(t, mv.printrepValid)
|
||||
}
|
||||
|
||||
func TestFromInt(t *testing.T) {
|
||||
mv := FromInt(123)
|
||||
assert.Equal(t, MVType(MT_INT), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_INT, mv.mvtype)
|
||||
assert.False(t, mv.printrepValid, "printrep should not be computed yet")
|
||||
}
|
||||
|
||||
func TestTryFromIntString(t *testing.T) {
|
||||
mv := TryFromIntString("123")
|
||||
assert.Equal(t, MVType(MT_INT), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_INT, mv.mvtype)
|
||||
assert.True(t, mv.printrepValid, "printrep should be computed")
|
||||
|
||||
mv = TryFromIntString("[123]")
|
||||
assert.Equal(t, MVType(MT_STRING), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_STRING, mv.mvtype)
|
||||
assert.True(t, mv.printrepValid, "printrep should be computed")
|
||||
}
|
||||
|
||||
func TestFromFloat(t *testing.T) {
|
||||
mv := FromFloat(123.4)
|
||||
assert.Equal(t, MVType(MT_FLOAT), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_FLOAT, mv.mvtype)
|
||||
assert.False(t, mv.printrepValid, "printrep should not be computed yet")
|
||||
}
|
||||
|
||||
func TestTryFromFloatString(t *testing.T) {
|
||||
mv := TryFromFloatString("123.4")
|
||||
assert.Equal(t, MVType(MT_FLOAT), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_FLOAT, mv.mvtype)
|
||||
assert.True(t, mv.printrepValid, "printrep should be computed")
|
||||
|
||||
mv = TryFromIntString("[123.4]")
|
||||
assert.Equal(t, MVType(MT_STRING), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_STRING, mv.mvtype)
|
||||
assert.True(t, mv.printrepValid, "printrep should be computed")
|
||||
}
|
||||
|
||||
func TestFromBool(t *testing.T) {
|
||||
mv := FromBool(true)
|
||||
assert.Equal(t, MVType(MT_BOOL), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_BOOL, mv.mvtype)
|
||||
assert.True(t, mv.printrepValid)
|
||||
|
||||
mv = FromBool(false)
|
||||
assert.Equal(t, MVType(MT_BOOL), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_BOOL, mv.mvtype)
|
||||
assert.True(t, mv.printrepValid)
|
||||
}
|
||||
|
||||
func TestFromBoolString(t *testing.T) {
|
||||
mv := FromBoolString("true")
|
||||
assert.Equal(t, MVType(MT_BOOL), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_BOOL, mv.mvtype)
|
||||
assert.True(t, mv.printrepValid)
|
||||
|
||||
mv = FromBoolString("false")
|
||||
assert.Equal(t, MVType(MT_BOOL), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_BOOL, mv.mvtype)
|
||||
assert.True(t, mv.printrepValid)
|
||||
}
|
||||
|
||||
func TestFromFunction(t *testing.T) {
|
||||
mv := FromFunction("test data", "f001")
|
||||
assert.Equal(t, MVType(MT_FUNC), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_FUNC, mv.mvtype)
|
||||
assert.True(t, mv.printrepValid)
|
||||
assert.Equal(t, "test data", mv.funcval.(string))
|
||||
}
|
||||
|
||||
func TestFromArray(t *testing.T) {
|
||||
mv := FromArray([]*Mlrval{FromInt(10)})
|
||||
assert.Equal(t, MVType(MT_ARRAY), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_ARRAY, mv.mvtype)
|
||||
assert.Equal(t, 1, len(mv.arrayval))
|
||||
}
|
||||
|
||||
func TestFromMap(t *testing.T) {
|
||||
mv := FromMap(NewMlrmap())
|
||||
assert.Equal(t, MVType(MT_MAP), MVType(mv.mvtype))
|
||||
assert.Equal(t, MT_MAP, mv.mvtype)
|
||||
assert.True(t, mv.mapval.IsEmpty())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -102,22 +102,22 @@ const (
|
|||
// optimization.
|
||||
MT_PENDING MVType = -1
|
||||
|
||||
MT_INT = 0
|
||||
MT_INT MVType = 0
|
||||
|
||||
MT_FLOAT = 1
|
||||
MT_FLOAT MVType = 1
|
||||
|
||||
MT_BOOL = 2
|
||||
MT_BOOL MVType = 2
|
||||
|
||||
// Key present in input record with empty value, e.g. input data '$x=,$y=2'
|
||||
MT_VOID = 3
|
||||
MT_VOID MVType = 3
|
||||
|
||||
MT_STRING = 4
|
||||
MT_STRING MVType = 4
|
||||
|
||||
MT_ARRAY = 5
|
||||
MT_ARRAY MVType = 5
|
||||
|
||||
MT_MAP = 6
|
||||
MT_MAP MVType = 6
|
||||
|
||||
MT_FUNC = 7
|
||||
MT_FUNC MVType = 7
|
||||
|
||||
// E.g. error encountered in one eval & it propagates up the AST at
|
||||
// evaluation time. Various runtime errors, such as file-not-found, result
|
||||
|
|
@ -125,22 +125,22 @@ const (
|
|||
// are intended to result in "(error)"-valued output rather than a crash.
|
||||
// This is analogous to the way that IEEE-754 arithmetic carries around
|
||||
// Inf and NaN through computation chains.
|
||||
MT_ERROR = 8
|
||||
MT_ERROR MVType = 8
|
||||
|
||||
// Used only for JSON null, and for 'empty' slots when an array is
|
||||
// auto-extended by assigning to an index having a gap from the last index.
|
||||
// E.g. x=[1,2,3] then x[5]=5; now x[4] is null
|
||||
MT_NULL = 9
|
||||
MT_NULL MVType = 9
|
||||
|
||||
// Key not present in input record, e.g. 'foo = $nosuchkey'
|
||||
MT_ABSENT = 10
|
||||
MT_ABSENT MVType = 10
|
||||
|
||||
// Not a type -- this is a dimension for disposition vectors and
|
||||
// disposition matrices. For example, when we want to add two mlrvals,
|
||||
// instead of if/elsing or switching on the types of both operands, we
|
||||
// instead jump directly to a type-specific function in a matrix of
|
||||
// function pointers which is MT_DIM x MT_DIM.
|
||||
MT_DIM = 11
|
||||
MT_DIM MVType = 11
|
||||
)
|
||||
|
||||
var TYPE_NAMES = [MT_DIM]string{
|
||||
|
|
|
|||
|
|
@ -18,5 +18,5 @@ func TestTypeNames(t *testing.T) {
|
|||
assert.Equal(t, "error", TYPE_NAMES[MT_ERROR])
|
||||
assert.Equal(t, "null", TYPE_NAMES[MT_NULL])
|
||||
assert.Equal(t, "absent", TYPE_NAMES[MT_ABSENT])
|
||||
assert.Equal(t, MT_DIM, len(TYPE_NAMES))
|
||||
assert.Equal(t, int(MT_DIM), len(TYPE_NAMES))
|
||||
}
|
||||
|
|
|
|||
2
todo.txt
2
todo.txt
|
|
@ -208,6 +208,8 @@ PERFORMANCE
|
|||
================================================================
|
||||
CODE-NEATENS / QUALITY
|
||||
|
||||
* go-style assert.Equal(t, actual, expected) in place of R style expect_equal(expected, actual) in .../*_test.go
|
||||
|
||||
! ast namings etc
|
||||
? make a simple NodeFromToken & have all interface{} be *ASTNode, not *token.Token
|
||||
! broad commenting pass / TODO
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue