-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstack_test.go
More file actions
61 lines (49 loc) · 1.28 KB
/
Copy pathstack_test.go
File metadata and controls
61 lines (49 loc) · 1.28 KB
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
// Copyright 2021 Mark Mandriota. All right reserved.
// Use of this source code is governed by a MIT-style
// license that can be found in the LICENSE file.
package stack
import (
"reflect"
"testing"
)
var stack *Frame
func init() {
_ = make([]byte, 1<<32-1)
stack = NewStack(0).Ret(1<<14)
}
func TestStack(t *testing.T) {
frameT := reflect.TypeOf(stack).Elem()
t.Logf("FRAME:\tsize:%8X align:%8X", frameT.Size(), frameT.Align())
for i := 0; i < frameT.NumField(); i++ {
fieldT := frameT.Field(i)
t.Logf("field:%d:%s)\toffset:%8X align:%8X size:%8X", i, fieldT.Name, fieldT.Offset, fieldT.Type.FieldAlign(), fieldT.Type.Size())
}
}
func TestStack_Add(t *testing.T) {
stack = stack.Add(42).Add("heh").Add(TestStack_Add)
t.Logf("Current position:\t%d", stack.cp)
}
func TestStack_Sub(t *testing.T) {
var (
fun func(t *testing.T)
str string
num int
)
stack = stack.Sub(&fun).Sub(&str).Sub(&num)
t.Logf("Result: %v %v %v", reflect.ValueOf(fun), str, num)
t.Logf("Current position:\t%d", stack.cp)
}
func BenchmarkStack_Add(b *testing.B) {
src := 1
for i := 0; i < b.N; i++ {
stack = stack.Add(src)
}
}
func BenchmarkStack_Sub(b *testing.B) {
dst := 0
for i := 0; i < b.N; i++ {
if stack = stack.Sub(&dst); stack == nil {
panic("No elements onto a stack")
}
}
}