forked from tredoe/term
-
Notifications
You must be signed in to change notification settings - Fork 0
/
unix_test.go
86 lines (69 loc) · 1.67 KB
/
unix_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
// Copyright 2010 Jonas mg
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at http://mozilla.org/MPL/2.0/.
// +build !plan9,!windows
package term
import (
"syscall"
"testing"
)
func init() {
InputFD = syscall.Stderr
}
func TestRawMode(t *testing.T) {
ter, err := New()
if err != nil {
t.Fatal(err)
}
oldState := ter.oldState
if err = ter.RawMode(); err != nil {
t.Error("expected set raw mode:", err)
}
if err = ter.Restore(); err != nil {
t.Error("expected to restore:", err)
}
lastState := ter.lastState
if oldState.Iflag != lastState.Iflag ||
oldState.Oflag != lastState.Oflag ||
oldState.Cflag != lastState.Cflag ||
oldState.Lflag != lastState.Lflag {
t.Error("expected to restore all settings")
}
// Restore from a saved state
ter, _ = New()
state := ter.OriginalState()
if err = Restore(InputFD, state); err != nil {
t.Error("expected to restore from saved state:", err)
}
}
func TestInformation(t *testing.T) {
if !SupportANSI() {
t.Error("expected to support this terminal")
}
if !IsTerminal(InputFD) {
t.Error("expected to be a terminal")
}
/*ter, _ := New()
if _, err := TTYName(ter.fd); err != nil {
t.Error("expected to get the terminal name", err)
}
ter.Restore()*/
}
func TestSize(t *testing.T) {
ter, _ := New()
defer ter.Restore()
row, col, err := ter.GetSize()
if err != nil {
t.Error(err)
return
}
if row == 0 || col == 0 {
t.Error("expected to get size")
}
//rowE, colE := GetSizeFromEnv()
//if rowE == 0 || colE == 0 {
//t.Error("expected to get size from environment")
//}
}