-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpath_test.go
54 lines (40 loc) · 1.16 KB
/
path_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
package valley
import (
"testing"
"github.com/stretchr/testify/assert"
)
func TestNewPath(t *testing.T) {
t.Run("should not return ni", func(t *testing.T) {
assert.NotNil(t, NewPath())
})
}
func TestPath_Write(t *testing.T) {
t.Run("should return the number of bytes written", func(t *testing.T) {
path := NewPath()
input := "this is a test"
expected := len(input)
actual := path.Write(input)
assert.Equal(t, expected, actual)
})
t.Run("should append the given input to the path", func(t *testing.T) {
path := NewPath()
assert.Equal(t, "", path.String())
path.Write("this is a")
assert.Equal(t, "this is a", path.String())
path.Write(" test")
assert.Equal(t, "this is a test", path.String())
})
}
func TestPath_TruncateRight(t *testing.T) {
t.Run("should remove n bytes from the path", func(t *testing.T) {
path := NewPath()
input := "this is a test"
_ = path.Write(input)
path.TruncateRight(5)
assert.Equal(t, "this is a", path.String())
path.TruncateRight(9)
assert.Equal(t, "", path.String())
})
}
// NOTE: Path.String() is already well tested enough from the above. Out expectations cover what it
// should be returning.