map, filter and cat return an iterator
This commit is contained in:
+46
-12
@@ -35,26 +35,60 @@ func TestIteratorParser(t *testing.T) {
|
||||
/* 20 */ {`it=$({1:"one",2:"two",3:"three"}, "default", "value"); it++`, "one", nil},
|
||||
/* 21 */ {`it=$({1:"one",2:"two",3:"three"}, "desc", "key"); it++`, int64(3), nil},
|
||||
/* 22 */ {`it=$({1:"one",2:"two",3:"three"}, "asc", "item"); it++`, kern.NewList([]any{int64(1), "one"}), nil},
|
||||
/* 23 */ {`builtin "os.file"; fileLineIterator("test-file.txt") map ${__}`, kern.NewList([]any{int64(0), int64(1)}), nil},
|
||||
/* 24 */ {`builtin "os.file"; #(fileLineIterator("test-file.txt") filter (#${_} == 2))`, int64(0), nil},
|
||||
/* 25 */ {`builtin "os.file"; #(fileLineIterator("test-file.txt") filter (#${_} == 3))`, int64(2), nil},
|
||||
/* 26 */ {`#($(10) map ${_})`, int64(10), nil},
|
||||
/* 27 */ {`#($(10,0) map ${_})`, int64(10), nil},
|
||||
/* 28 */ {`$(10) digest ${_}`, int64(9), nil},
|
||||
/* 29 */ {`$(10,0) digest ${_}`, int64(1), nil},
|
||||
/* 30 */ {`$(10,0,-2) digest ${_}`, int64(2), nil},
|
||||
/* 31 */ {`[3,4,5] map ${_#}`, kern.NewList([]any{int64(1), int64(2), int64(3)}), nil},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 10)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
func TestCatIterator(t *testing.T) {
|
||||
section := "Iterator"
|
||||
func TestFilterIterator(t *testing.T) {
|
||||
section := "Iterator-Filter"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`([1] cat [2]) map $_`, kern.NewList([]any{int64(1), int64(2)}), nil},
|
||||
/* 1 */ {`$$([1,2,3] filter $_%2==0)`, kern.NewList([]any{int64(2)}), nil},
|
||||
/* 2 */ {`it = [1,2,3] filter $_%2!=1; $$(it)`, kern.NewList([]any{int64(2)}), nil},
|
||||
/* 3 */ {`builtin "os.file"; #$$(fileLineIterator("test-file.txt") filter (#${_} == 2))`, int64(0), nil},
|
||||
/* 4 */ {`builtin "os.file"; #$$(fileLineIterator("test-file.txt") filter (#${_} == 3))`, int64(2), nil},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 2)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
func TestDigestIterator(t *testing.T) {
|
||||
section := "Iterator-Digest"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`$(10) digest ${_}`, int64(9), nil},
|
||||
/* 2 */ {`$(10,0) digest ${_}`, int64(1), nil},
|
||||
/* 3 */ {`$(10,0,-2) digest ${_}`, int64(2), nil},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 2)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
func TestCatIterator(t *testing.T) {
|
||||
section := "Iterator-Cat"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`$$([1] cat [])`, kern.NewList([]any{int64(1)}), nil},
|
||||
/* 2 */ {`$$([1] cat [2])`, kern.NewList([]any{int64(1), int64(2)}), nil},
|
||||
/* 3 */ {`$$([1] cat nil)`, kern.NewList([]any{int64(1)}), nil},
|
||||
/* 4 */ {`$$(nil cat [2])`, kern.NewList([]any{int64(2)}), nil},
|
||||
/* 5 */ {`$$(nil cat nil)`, kern.NewList([]any{}), nil},
|
||||
/* 6 */ {`$$(["a","b"] cat ["x"-true])`, nil, `[1:23] left operand 'x' [string] and right operand 'true' [bool] are not compatible with operator "-"`},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 6)
|
||||
runTestSuite(t, section, inputs)
|
||||
}
|
||||
|
||||
func TestMapIterator(t *testing.T) {
|
||||
section := "Iterator-Map"
|
||||
inputs := []inputType{
|
||||
/* 1 */ {`$$([3,4,5] map ${_#})`, kern.NewList([]any{int64(1), int64(2), int64(3)}), nil},
|
||||
/* 2 */ {`#$$($(10) map ${_})`, int64(10), nil},
|
||||
/* 3 */ {`#$$($(10,0) map ${_})`, int64(10), nil},
|
||||
/* 4 */ {`builtin "os.file"; $$(fileLineIterator("test-file.txt") map ${__})`, kern.NewList([]any{int64(0), int64(1)}), nil},
|
||||
/* 5 */ {`$$(["1", "2", "3"] map int())`, nil, `int(): too few params -- expected 1, got 0`},
|
||||
}
|
||||
|
||||
// runTestSuiteSpec(t, section, inputs, 2)
|
||||
|
||||
Reference in New Issue
Block a user