1
0
Fork 0
gilo/internal/gilo/buffer_test.go

63 lines
1.1 KiB
Go
Raw Permalink Normal View History

2021-04-02 15:36:43 -04:00
package gilo
2021-04-01 13:00:58 -04:00
import "testing"
2021-04-02 19:24:20 -04:00
func TestBuffer_AppendRune(t *testing.T) {
2021-04-02 13:11:54 -04:00
b := NewBuffer()
2021-04-01 13:00:58 -04:00
2021-04-02 13:11:54 -04:00
got := b.AppendRune('a')
2021-04-01 13:00:58 -04:00
want := 1
if got != want {
t.Errorf("Wrong length for rune, got %q, expected %q for rune %c", got, want, 'a')
}
}
2021-04-02 19:24:20 -04:00
func TestBuffer_Append(t *testing.T) {
2021-04-02 13:11:54 -04:00
b := NewBuffer()
2021-04-01 13:00:58 -04:00
2021-04-02 13:11:54 -04:00
got := b.Append("123")
2021-04-01 13:00:58 -04:00
want := 3
if got != want {
t.Errorf("Wrong length for string, got %d, expected %d for input '%s'", got, want, "123")
}
}
2021-04-02 19:24:20 -04:00
func TestBuffer_AppendLn(t *testing.T) {
2021-04-02 13:11:54 -04:00
b := NewBuffer()
2021-04-01 13:00:58 -04:00
2021-04-02 13:11:54 -04:00
got := b.AppendLn("123")
2021-04-01 13:00:58 -04:00
// Adds carriage return and line feed
want := 5
if got != want {
t.Errorf("Wrong length for string, got %d, expected %d for input '%s'", got, want, "123")
}
}
2021-04-02 19:24:20 -04:00
func TestBuffer_ToString(t *testing.T) {
2021-04-02 13:11:54 -04:00
b := NewBuffer()
b.Append("foo")
2021-04-01 13:00:58 -04:00
2021-04-02 13:11:54 -04:00
got := b.ToString()
2021-04-01 13:00:58 -04:00
want := "foo"
if got != want {
t.Errorf("Failed to convert to proper string")
}
2021-04-01 16:17:13 -04:00
}
2021-04-02 19:24:20 -04:00
func TestBuffer_Len(t *testing.T) {
b := NewBuffer()
b.Append("foo")
got := b.Len()
want := 3
if got != want {
t.Errorf("Wrong length for string, got %d, expected %d", got, want)
}
}