summaryrefslogtreecommitdiff
path: root/viewport/viewport_test.go
blob: 9da4c3c3e3a58a0e7bcc4dbe50d713d0c32eb597 (plain)
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
//go:build test

package viewport

import (
	"github.com/stretchr/testify/assert"
	"strings"
	"testing"
)

func TestCrop(t *testing.T) {
	input := `0000
AAAA
` + Caret + `BBB
CCC`
	expected := `AAAA
` + Caret + `BBB`
	result, _, _ := Crop(input, strings.Split(input, "\n"), 2)
	assert.Equal(t, expected, result)
}

func TestCrop_Under(t *testing.T) {
	input := `0000
AAAA
` + Caret + `BBB`
	expected := `AAAA
` + Caret + `BBB`
	result, _, _ := Crop(input, strings.Split(input, "\n"), 2)
	assert.Equal(t, expected, result)
}

func TestCrop_Unnecessary(t *testing.T) {
	input := `AAAA
` + Caret + `BBB
CCC
DDDD`
	expected := input
	result, _, _ := Crop(input, strings.Split(input, "\n"), 8)
	assert.Equal(t, expected, result)
}

func TestNeedsViewport(t *testing.T) {
	amount := 3
	input := strings.Repeat("\n", amount)
	output := NeedsViewport(input, 4)
	assert.Equal(t, false, output)
}

func TestNeedsViewport_Negative(t *testing.T) {
	amount := 8
	input := strings.Repeat("\n", amount)
	output := NeedsViewport(input, 4)
	assert.Equal(t, true, output)
}