2018-02-05 16:05:59 -05:00
|
|
|
package term // import "github.com/docker/docker/pkg/term"
|
2016-01-03 17:03:39 -05:00
|
|
|
|
2017-09-08 18:00:14 -04:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
2018-06-11 09:32:11 -04:00
|
|
|
"gotest.tools/assert"
|
|
|
|
is "gotest.tools/assert/cmp"
|
2017-09-08 18:00:14 -04:00
|
|
|
)
|
2016-01-03 17:03:39 -05:00
|
|
|
|
|
|
|
func TestToBytes(t *testing.T) {
|
|
|
|
codes, err := ToBytes("ctrl-a,a")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.DeepEqual([]byte{1, 97}, codes))
|
2016-01-03 17:03:39 -05:00
|
|
|
|
2017-09-08 18:00:14 -04:00
|
|
|
_, err = ToBytes("shift-z")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.Check(t, is.ErrorContains(err, ""))
|
2016-01-03 17:03:39 -05:00
|
|
|
|
|
|
|
codes, err = ToBytes("ctrl-@,ctrl-[,~,ctrl-o")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.DeepEqual([]byte{0, 27, 126, 15}, codes))
|
2016-01-03 17:03:39 -05:00
|
|
|
|
|
|
|
codes, err = ToBytes("DEL,+")
|
2018-03-13 15:28:34 -04:00
|
|
|
assert.NilError(t, err)
|
|
|
|
assert.Check(t, is.DeepEqual([]byte{127, 43}, codes))
|
2016-01-03 17:03:39 -05:00
|
|
|
}
|