-
Notifications
You must be signed in to change notification settings - Fork 17
/
time_test.go
133 lines (102 loc) · 3.36 KB
/
time_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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
package compiler
import (
"bytes"
"testing"
//"github.com/gijit/gi/pkg/verb"
cv "github.com/glycerine/goconvey/convey"
)
func Test921TimeImports(t *testing.T) {
cv.Convey(`import "time"; now := time.Now() should work`+
` to read the time.`, t, func() {
code := `import "time"`
code2 := `now := time.Now()`
vm, err := NewLuaVmWithPrelude(nil)
panicOn(err)
defer vm.Close()
inc := NewIncrState(vm, nil)
translation := inc.trMust([]byte(code))
LuaRunAndReport(vm, string(translation))
translation2 := inc.trMust([]byte(code2))
LuaRunAndReport(vm, string(translation2))
LuaRunAndReport(vm, "nowNil = (now == nil)")
LuaMustBool(vm, "nowNil", false)
cv.So(true, cv.ShouldBeTrue)
})
}
func Test923TimeStruct(t *testing.T) {
cv.Convey(`import "time"; var tm time.Time; should work to instantiate a time struct value.`, t, func() {
code := `import "time"`
code2 := `var tm time.Time`
code3 := `tm = time.Now()`
code4 := `type S struct { tm time.Time };`
code5 := `var s S;`
code6 := `s.tm = time.Now();`
code7 := `u := s.tm.UnixNano()`
// a:=time.Now(); b:=time.Now(); d:= b.Sub(a)
vm, err := NewLuaVmWithPrelude(nil)
panicOn(err)
defer vm.Close()
inc := NewIncrState(vm, nil)
translation := inc.trMust([]byte(code))
LuaRunAndReport(vm, string(translation))
//vv("------------ starting translation2 -----")
translation2 := inc.trMust([]byte(code2))
LuaRunAndReport(vm, string(translation2))
cv.So(string(translation2), matchesLuaSrc, `tm = __type__.time.Time();`)
//vv("------------ starting translation3 -----")
translation3 := inc.trMust([]byte(code3))
LuaRunAndReport(vm, string(translation3))
cv.So(string(translation3), matchesLuaSrc, `tm = time.Now();`)
//vv("------------ starting translation4 -----")
translation4 := inc.trMust([]byte(code4))
LuaRunAndReport(vm, string(translation4))
//vv("------------ starting translation5 -----")
translation5 := inc.trMust([]byte(code5))
LuaRunAndReport(vm, string(translation5))
// get the second statement
cv.So(string(bytes.Split(translation5, []byte("\n\n"))[1]), matchesLuaSrc, `s = __type__.S.ptrToNewlyConstructed(__type__.time.Time());`)
//vv("------------ starting translation6 -----")
translation6 := inc.trMust([]byte(code6))
LuaRunAndReport(vm, string(translation6))
//vv("------------ starting translation7 -----")
translation7 := inc.trMust([]byte(code7))
LuaRunAndReport(vm, string(translation7))
obsU := LuaToInt64(vm, "u")
cv.So(obsU, cv.ShouldBeGreaterThan, 0)
cv.So(true, cv.ShouldBeTrue)
})
}
/* work in progress
func Test922TimeoutsInSelect(t *testing.T) {
cv.Convey(`channel timeouts in a select statement`, t, func() {
code := `import "time"`
code2 := `
ch := make(chan int)
toCount:= 0
go func() {
for {
select {
case <-time.After(time.Millisecond*100):
if toCount < 3 {
toCount++
}
println("timeout! toCount is now ", toCount)
}
}
}()
time.Sleep(5 * time.Millisecond*100)
`
// toCount should be 3
vm, err := NewLuaVmWithPrelude(nil)
panicOn(err)
defer vm.Close()
inc := NewIncrState(vm, nil)
translation := inc.trMust([]byte(code))
LuaRunAndReport(vm, string(translation))
translation2 := inc.trMust([]byte(code2))
LuaRunAndReport(vm, string(translation2))
LuaMustInt(vm, "toCount", 3)
cv.So(true, cv.ShouldBeTrue)
})
}
*/