-
Notifications
You must be signed in to change notification settings - Fork 24
/
internal_function_test.go
61 lines (54 loc) · 1.05 KB
/
internal_function_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
package gscript
import (
"fmt"
"testing"
)
func TestFunction(t *testing.T) {
script := `
int a(){
return 10;
}
println(a());
if (1<a()){
println("1<a()");
}
`
NewCompiler().Compiler(script)
}
func TestPrint(t *testing.T) {
args := []interface{}{
"1", "2",
}
fmt.Printf("hello %s %s\n", args...)
fmt.Println(fmt.Sprintf("abc %d", 123))
}
func TestPrintf(t *testing.T) {
script := `
printf("hello %s ","123");
printf("hello-%s-%s ","123","abc");
printf("hello-%s-%d ","123",123);
string format = "this is %s ";
printf(format, "gscript");
string s = sprintf("nice to meet %s", "you");
println(s);
assertEqual(s,"nice to meet you");
`
NewCompiler().Compiler(script)
}
func TestPrint2(t *testing.T) {
script := `
print("123" + " ");
print("456" + " ");
`
compiler := NewCompiler().Compiler(script)
fmt.Println(compiler)
}
func TestDate2(t *testing.T) {
script := `
DateTime d = DateTime();
string local = d.getCurrentTime("Asia/Shanghai","2006-01-02 15:04:05");
printf("local:%s", local);
`
compiler := NewCompiler().Compiler(script)
fmt.Println(compiler)
}