51 lines
1.6 KiB
Go
51 lines
1.6 KiB
Go
|
// Copyright (c) 2024 Celestino Amoroso (celestino.amoroso@gmail.com).
|
||
|
// All rights reserved.
|
||
|
|
||
|
// t_builtin-iterator.go
|
||
|
package expr
|
||
|
|
||
|
import (
|
||
|
"testing"
|
||
|
)
|
||
|
|
||
|
func TestFuncRun(t *testing.T) {
|
||
|
section := "Builtin-Iterator"
|
||
|
|
||
|
inputs := []inputType{
|
||
|
/* 1 */ {`builtin "iterator"; it=$(1,2,3); run(it)`, nil, nil},
|
||
|
/* 2 */ {`builtin "iterator"; run($(1,2,3), func(index,item){item+10})`, nil, nil},
|
||
|
/* 3 */ {`builtin "iterator"; run($(1,2,3), func(index,item){it_status=it_status+item; true}, {"it_status":0})`, int64(6), nil},
|
||
|
/* 4 */ {`builtin ["iterator", "fmt"]; run($(1,2,3), func(index,item){println(item+10)})`, nil, nil},
|
||
|
/* 5 */ {`builtin "iterator"; run(nil)`, nil, `paramter "iterator" must be an iterator, passed <nil> [nil]`},
|
||
|
/* 6 */ {`builtin "iterator"; run($(1,2,3), nil)`, nil, `paramter "operator" must be a function, passed <nil> [nil]`},
|
||
|
/* 7 */ {`builtin "iterator"; run($(1,2,3), func(){1}, "prrr")`, nil, `paramter "vars" must be a dictionary, passed prrr [string]`},
|
||
|
}
|
||
|
|
||
|
//t.Setenv("EXPR_PATH", ".")
|
||
|
|
||
|
//runTestSuiteSpec(t, section, inputs, 3)
|
||
|
runTestSuite(t, section, inputs)
|
||
|
}
|
||
|
|
||
|
// func TestFmt(t *testing.T) {
|
||
|
// section := "Builtin-Fmt"
|
||
|
|
||
|
// text := "ciao mondo"
|
||
|
// inputs := []inputType{
|
||
|
// /* 1 */ {fmt.Sprintf(`println("%s")`, text), int64(11), nil},
|
||
|
// }
|
||
|
|
||
|
// // t.Setenv("EXPR_PATH", ".")
|
||
|
|
||
|
// var b bytes.Buffer
|
||
|
// ctx := NewSimpleStore()
|
||
|
// currentStdout := SetCtrl(ctx, ControlStdout, &b)
|
||
|
|
||
|
// runCtxTestSuite(t, ctx, section, inputs)
|
||
|
|
||
|
// SetCtrl(ctx, ControlStdout, currentStdout)
|
||
|
// if b.String() != text+"\n" {
|
||
|
// t.Errorf("println(): Got: %q, Want: %q", b.String(), text+"\n")
|
||
|
// }
|
||
|
// }
|