Add ascii encoding
This commit is contained in:
58
encoding/ascii_test.go
Normal file
58
encoding/ascii_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package encoding
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestASCIIEncodeSimpleASCIIString(t *testing.T) {
|
||||
coder := &ASCIICoder{}
|
||||
var buf bytes.Buffer
|
||||
input := "Hello, World!"
|
||||
|
||||
expected := []byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}
|
||||
coder.Encode(input, &buf)
|
||||
|
||||
if !bytes.Equal(buf.Bytes(), expected) {
|
||||
t.Errorf("Expected %v, but got %v", expected, buf.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
func TestASCIIDecodeSimpleASCIIString(t *testing.T) {
|
||||
coder := &ASCIICoder{}
|
||||
var buf bytes.Buffer
|
||||
input := []byte{72, 101, 108, 108, 111, 44, 32, 87, 111, 114, 108, 100, 33}
|
||||
|
||||
expected := "Hello, World!"
|
||||
buf.Write(input)
|
||||
output := coder.Decode(&buf)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf("Expected %v, but got %v", expected, output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestASCIIEncodeEmptyString(t *testing.T) {
|
||||
coder := &ASCIICoder{}
|
||||
var buf bytes.Buffer
|
||||
input := ""
|
||||
|
||||
expected := []byte{}
|
||||
coder.Encode(input, &buf)
|
||||
|
||||
if !bytes.Equal(buf.Bytes(), expected) {
|
||||
t.Errorf("Expected %v, but got %v", expected, buf.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
func TestASCIIDecodeEmptyString(t *testing.T) {
|
||||
coder := &ASCIICoder{}
|
||||
buf := bytes.NewBuffer([]byte{})
|
||||
|
||||
expected := ""
|
||||
output := coder.Decode(buf)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf("Expected %v, but got %v", expected, output)
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user