File: list_test.go

package info (click to toggle)
golang-code.rocketnine-tslocum-cview 1.5.4-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 3,396 kB
  • sloc: makefile: 40
file content (75 lines) | stat: -rw-r--r-- 2,018 bytes parent folder | download
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
package cview

import (
	"testing"
)

const (
	listTextA = "Hello, world!"
	listTextB = "Goodnight, moon!"
	listTextC = "Hello, Dolly!"
)

func TestList(t *testing.T) {
	t.Parallel()

	// Initialize

	l := NewList()
	if l.GetItemCount() != 0 {
		t.Errorf("failed to initialize List: expected item count 0, got %d", l.GetItemCount())
	} else if l.GetCurrentItemIndex() != 0 {
		t.Errorf("failed to initialize List: expected current item 0, got %d", l.GetCurrentItemIndex())
	}

	// Add item 0

	itemA := NewListItem(listTextA)
	itemA.SetSecondaryText(listTextB)
	itemA.SetShortcut('a')
	l.AddItem(itemA)
	if l.GetItemCount() != 1 {
		t.Errorf("failed to update List: expected item count 1, got %d", l.GetItemCount())
	} else if l.GetCurrentItemIndex() != 0 {
		t.Errorf("failed to update List: expected current item 0, got %d", l.GetCurrentItemIndex())
	}

	// Get item 0 text

	mainText, secondaryText := l.GetItemText(0)
	if mainText != listTextA {
		t.Errorf("failed to update List: expected main text %s, got %s", listTextA, mainText)
	} else if secondaryText != listTextB {
		t.Errorf("failed to update List: expected secondary text %s, got %s", listTextB, secondaryText)
	}

	// Add item 1

	itemB := NewListItem(listTextB)
	itemB.SetSecondaryText(listTextC)
	itemB.SetShortcut('a')
	l.AddItem(itemB)
	if l.GetItemCount() != 2 {
		t.Errorf("failed to update List: expected item count 1, got %v", l.GetItemCount())
	} else if l.GetCurrentItemIndex() != 0 {
		t.Errorf("failed to update List: expected current item 0, got %v", l.GetCurrentItemIndex())
	}

	// Get item 1 text

	mainText, secondaryText = l.GetItemText(1)
	if mainText != listTextB {
		t.Errorf("failed to update List: expected main text %s, got %s", listTextB, mainText)
	} else if secondaryText != listTextC {
		t.Errorf("failed to update List: expected secondary text %s, got %s", listTextC, secondaryText)
	}

	// Draw

	app, err := newTestApp(l)
	if err != nil {
		t.Errorf("failed to initialize Application: %s", err)
	}

	l.Draw(app.screen)
}