2016-01-03 17:03:39 -05:00
|
|
|
package term
|
|
|
|
|
2017-09-08 18:00:14 -04:00
|
|
|
import (
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/stretchr/testify/assert"
|
|
|
|
"github.com/stretchr/testify/require"
|
|
|
|
)
|
2016-01-03 17:03:39 -05:00
|
|
|
|
|
|
|
func TestToBytes(t *testing.T) {
|
|
|
|
codes, err := ToBytes("ctrl-a,a")
|
2017-09-08 18:00:14 -04:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, []byte{1, 97}, codes)
|
2016-01-03 17:03:39 -05:00
|
|
|
|
2017-09-08 18:00:14 -04:00
|
|
|
_, err = ToBytes("shift-z")
|
|
|
|
assert.Error(t, err)
|
2016-01-03 17:03:39 -05:00
|
|
|
|
|
|
|
codes, err = ToBytes("ctrl-@,ctrl-[,~,ctrl-o")
|
2017-09-08 18:00:14 -04:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, []byte{0, 27, 126, 15}, codes)
|
2016-01-03 17:03:39 -05:00
|
|
|
|
|
|
|
codes, err = ToBytes("DEL,+")
|
2017-09-08 18:00:14 -04:00
|
|
|
require.NoError(t, err)
|
|
|
|
assert.Equal(t, []byte{127, 43}, codes)
|
2016-01-03 17:03:39 -05:00
|
|
|
}
|