-
Notifications
You must be signed in to change notification settings - Fork 10
/
flash_test.go
80 lines (70 loc) · 2.07 KB
/
flash_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
package kocha_test
import (
"reflect"
"testing"
"github.com/naoina/kocha"
)
func TestFlash(t *testing.T) {
f := kocha.Flash{}
key := "test_key"
var actual interface{} = f.Get(key)
var expected interface{} = ""
if !reflect.DeepEqual(actual, expected) {
t.Errorf(`Flash.Get(%#v) => %#v; want %#v`, key, actual, expected)
}
actual = f.Len()
expected = 0
if !reflect.DeepEqual(actual, expected) {
t.Errorf(`Flash.Len() => %#v; want %#v`, actual, expected)
}
value := "test_value"
f.Set(key, value)
actual = f.Len()
expected = 1
if !reflect.DeepEqual(actual, expected) {
t.Errorf(`Flash.Set(%#v, %#v); Flash.Len() => %#v; want %#v`, key, value, actual, expected)
}
actual = f.Get(key)
expected = value
if !reflect.DeepEqual(actual, expected) {
t.Errorf(`Flash.Set(%#v, %#v); Flash.Get(%#v) => %#v; want %#v`, key, value, key, actual, expected)
}
key2 := "test_key2"
value2 := "test_value2"
f.Set(key2, value2)
actual = f.Len()
expected = 2
if !reflect.DeepEqual(actual, expected) {
t.Errorf(`Flash.Set(%#v, %#v); Flash.Set(%#v, %#v); Flash.Len() => %#v; want %#v`, key, value, key2, value2, actual, expected)
}
actual = f.Get(key2)
expected = value2
if !reflect.DeepEqual(actual, expected) {
t.Errorf(`Flash.Set(%#v, %#v); Flash.Set(%#v, %#v); Flash.Get(%#v) => %#v; want %#v`, key, value, key2, value2, key2, actual, expected)
}
}
func TestFlash_Get_withNil(t *testing.T) {
f := kocha.Flash(nil)
key := "test_key"
var actual interface{} = f.Get(key)
var expected interface{} = ""
if !reflect.DeepEqual(actual, expected) {
t.Errorf(`Flash.Get(%#v) => %#v; want %#v`, key, actual, expected)
}
actual = f.Len()
expected = 0
if !reflect.DeepEqual(actual, expected) {
t.Errorf(`Flash.Get(%#v); Flash.Len() => %#v; want %#v`, key, actual, expected)
}
}
func TestFlash_Set_withNil(t *testing.T) {
f := kocha.Flash(nil)
key := "test_key"
value := "test_value"
f.Set(key, value)
actual := f.Len()
expected := 0
if !reflect.DeepEqual(actual, expected) {
t.Errorf(`Flash.Set(%#v, %#v); Flash.Len() => %#v; want %#v`, key, value, actual, expected)
}
}