Commit 407b72d dengsgo
committed
1 parent e6dc263 commit 407b72d Copy full SHA for 407b72d
File tree 2 files changed +15
-1
lines changed
2 files changed +15
-1
lines changed Original file line number Diff line number Diff line change @@ -106,6 +106,16 @@ func TestParseAndExecTrigonometric(t *testing.T) {
106
106
}
107
107
}
108
108
109
+ func TestRegFunction (t * testing.T ) {
110
+ RegFunction ("double" , 1 , func (expr ... ExprAST ) float64 {
111
+ return ExprASTResult (expr [0 ]) * 2
112
+ })
113
+ r , err := ParseAndExec ("double(6)" )
114
+ if r != 12 {
115
+ t .Error (err , "RegFunction errors when register new funtion" )
116
+ }
117
+ }
118
+
109
119
func TestParseAndExecError (t * testing.T ) {
110
120
exprs := []string {
111
121
"(" ,
Original file line number Diff line number Diff line change @@ -3,10 +3,11 @@ package main
3
3
import (
4
4
"bufio"
5
5
"fmt"
6
- "github.com/dengsgo/math-engine/engine"
7
6
"os"
8
7
"strings"
9
8
"time"
9
+
10
+ "github.com/dengsgo/math-engine/engine"
10
11
)
11
12
12
13
func main () {
@@ -15,6 +16,9 @@ func main() {
15
16
16
17
// input loop
17
18
func loop () {
19
+ engine .RegFunction ("double" , 1 , func (expr ... engine.ExprAST ) float64 {
20
+ return engine .ExprASTResult (expr [0 ]) * 2
21
+ })
18
22
for {
19
23
fmt .Print ("input /> " )
20
24
f := bufio .NewReader (os .Stdin )
You can’t perform that action at this time.
0 commit comments