Add tests for gsm7
This commit is contained in:
18
encoding/gsm7.go
Normal file
18
encoding/gsm7.go
Normal file
@@ -0,0 +1,18 @@
|
||||
package encoding
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"log"
|
||||
)
|
||||
|
||||
type GSM7Coder struct{}
|
||||
|
||||
func (c *GSM7Coder) Encode(s string, buf *bytes.Buffer) {
|
||||
utf8 := []byte(s)
|
||||
log.Println(utf8)
|
||||
buf.Write(utf8)
|
||||
}
|
||||
|
||||
func (c *GSM7Coder) Decode(buf *bytes.Buffer) string {
|
||||
return buf.String()
|
||||
}
|
58
encoding/gsm7_test.go
Normal file
58
encoding/gsm7_test.go
Normal file
@@ -0,0 +1,58 @@
|
||||
package encoding
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"testing"
|
||||
)
|
||||
|
||||
func TestGSM7EncodeSimpleASCIIString(t *testing.T) {
|
||||
coder := &GSM7Coder{}
|
||||
var buf bytes.Buffer
|
||||
input := "Sunshine"
|
||||
|
||||
expected := []byte{0b11010011, 0b10111001, 0b10111011, 0b10001110, 0b01001110, 0b10111011, 0b11001011}
|
||||
coder.Encode(input, &buf)
|
||||
|
||||
if !bytes.Equal(buf.Bytes(), expected) {
|
||||
t.Errorf("Expected %v, but got %v", expected, buf.Bytes())
|
||||
}
|
||||
}
|
||||
|
||||
func TestGSM7DecodeSimpleASCIIString(t *testing.T) {
|
||||
coder := &GSM7Coder{}
|
||||
var buf bytes.Buffer
|
||||
input := []byte{0b11010011, 0b10111001, 0b10111011, 0b10001110, 0b01001110, 0b10111011, 0b11001011}
|
||||
|
||||
expected := "Sunshine"
|
||||
buf.Write(input)
|
||||
output := coder.Decode(&buf)
|
||||
|
||||
if output != expected {
|
||||
t.Errorf("Expected %v, but got %v", expected, output)
|
||||
}
|
||||
}
|
||||
|
||||
func TestGSM7EncodeEmptyString(t *testing.T) {
|
||||
coder := &GSM7Coder{}
|
||||
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 TestGSM7DecodeEmptyString(t *testing.T) {
|
||||
coder := &GSM7Coder{}
|
||||
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