-
Notifications
You must be signed in to change notification settings - Fork 31
/
canvas_test.go
102 lines (89 loc) · 2.18 KB
/
canvas_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
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Copyright 2019-2022 Graham Clark. All rights reserved. Use of this source
// code is governed by the MIT license that can be found in the LICENSE
// file.
package gowid
import (
"io"
"testing"
"github.com/stretchr/testify/assert"
)
func TestInterfaces1(t *testing.T) {
var _ io.Writer = (*Canvas)(nil)
}
func TestInterfaces5(t *testing.T) {
var _ IComposite = (*App)(nil)
}
func TestCanvas19(t *testing.T) {
canvas := NewCanvas()
c := canvas.BoxColumns()
r := canvas.BoxRows()
if c != 0 || r != 0 {
t.Errorf("Failed")
}
r1 := CellsFromString("abc")
r2 := CellsFromString("12")
canvas.AppendLine(r1, false)
canvas.AppendLine(r2, false)
c = canvas.BoxColumns()
r = canvas.BoxRows()
if c != 3 || r != 2 {
t.Errorf("Failed c is %d r is %d", c, r)
}
cs := canvas.String()
if cs != "abc\n12 " {
t.Errorf("Failed cs is %v", cs)
}
canvas.AlignRight()
cs = canvas.String()
if cs != "abc\n12 " {
t.Errorf("Failed")
}
canvas2 := NewCanvas()
r21 := CellsFromString(" X Z")
r22 := CellsFromString("Y2")
canvas2.AppendLine(r21, false)
canvas2.AppendLine(r22, false)
canvas.MergeUnder(canvas2, 0, 0, false)
cs = canvas.String()
if cs != "aXc\nY2 " {
t.Errorf("Failed")
}
assert.Equal(t, canvas.BoxColumns(), 3)
var n int
var err error
n, err = canvas.Write([]byte{'1', '2', '3', 'Q'})
assert.NoError(t, err)
assert.Equal(t, 4, n)
assert.Equal(t, canvas.String(), "123\nQ2 ")
n, err = canvas.Write([]byte{'5', '\n'})
assert.NoError(t, err)
assert.Equal(t, 2, n)
assert.Equal(t, canvas.String(), "5 \nQ2 ")
n, err = canvas.Write([]byte{0xe4, 0xbd, 0xa0, '\n'})
assert.NoError(t, err)
assert.Equal(t, 4, n)
assert.Equal(t, "你 \nQ2 ", canvas.String())
n, err = canvas.Write([]byte{'1', '2', '\n', 'R'})
assert.NoError(t, err)
assert.Equal(t, 4, n)
assert.Equal(t, "12 \nR2 ", canvas.String())
}
type MyString string
func (s MyString) Tester() int {
return len(s)
}
type FooType interface {
Tester() int
}
func MyTestFn(f FooType) {
}
func TestCanvas1(t *testing.T) {
f := MyString("xyz")
MyTestFn(f)
assert.Equal(t, f.Tester(), 3)
}
//======================================================================
// Local Variables:
// mode: Go
// fill-column: 110
// End: