-
Notifications
You must be signed in to change notification settings - Fork 0
/
constantRegistry_test.go
62 lines (48 loc) · 1.47 KB
/
constantRegistry_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
package gojacego
import (
"testing"
)
func TestAddAndGetConstant(test *testing.T) {
registryCaseInsensitive := newConstantRegistry(false)
registryCaseSensitive := newConstantRegistry(true)
registryCaseInsensitive.registerConstant("test", 42.0, true)
registryCaseSensitive.registerConstant("test", 42.0, true)
val, _ := registryCaseInsensitive.get("test")
if val != 42.0 {
test.Errorf("exptected: 42.0, got: %f", val)
}
val1, _ := registryCaseInsensitive.get("TesT")
if val1 != 42.0 {
test.Errorf("exptected: 42.0, got: %f", val1)
}
val2, _ := registryCaseSensitive.get("test")
if val != 42.0 {
test.Errorf("exptected: 42.0, got: %f", val2)
}
_, found := registryCaseSensitive.get("TesT")
if found != false {
test.Errorf("exptected: false, got: true")
}
}
func TestOverwritable(test *testing.T) {
registry := newConstantRegistry(false)
registry.registerConstant("test", 42, true)
registry.registerConstant("test", 26.3, true)
val, _ := registry.get("test")
if val != 26.3 {
test.Errorf("exptected: 26.3, got: %f", val)
}
}
// https://gist.github.com/wrunk/4afea3d85cc9feb7fd8fcef5a8a98b5e
func shouldPanic(t *testing.T, f func(), message string) {
defer func() { recover() }()
f()
t.Errorf(message)
}
func TestNotOverwritable(test *testing.T) {
registry := newConstantRegistry(false)
registry.registerConstant("test", 42, false)
shouldPanic(test, func() {
registry.registerConstant("test", 26.3, false)
}, "TestNotOverwritable - Panic expected")
}