-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfield_test.go
43 lines (41 loc) · 1.02 KB
/
field_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
package jclass
import (
"testing"
)
func TestJavaFieldConstantValue(t *testing.T) {
cases := []struct {
N string
T string
V interface{}
}{
{"stringValue", "java.lang.String", "hoge"},
{"booleanValue", "boolean", true},
{"byteValue", "byte", int8(127)},
{"charValue", "char", 'H'},
{"shortValue", "short", int16(32767)},
{"intValue", "int", int32(2147483647)},
{"longValue", "long", int64(9223372036854775807)},
{"floatValue", "float", float32(3.4028235E38)},
{"doubleValue", "double", float64(1.7976931348623157E308)},
}
class, _ := NewJavaClassFromFilename("./testdata/Constants.class")
for _, c := range cases {
f := class.DeclaredField(c.N)
if f == nil {
t.Errorf("Field not found for %s", c.N)
continue
}
if f.Type() != c.T {
t.Errorf("Field type mismatch %v, wants %v", f.Type(), c.T)
continue
}
v, ok := f.ConstantValue()
if !ok {
t.Errorf("ConstantValue not found for %s", c.N)
continue
}
if v != c.V {
t.Errorf("ConstantValue mismatch %v, wants %v", c.V, v)
}
}
}