telegabber/xmpp/component_test.go

48 lines
933 B
Go
Raw Normal View History

package xmpp
import (
"testing"
)
func TestParseSizeGarbage(t *testing.T) {
_, err := parseSize("abc")
if err == nil {
t.Error("abc should not be accepted")
}
}
func TestParseSizeAsphalt(t *testing.T) {
size, err := parseSize("2B")
if size != 2 {
t.Errorf("Error parsing two bytes: %v %v", size, err)
}
}
func TestParseSize9K(t *testing.T) {
size, err := parseSize("9 KB")
if size != 9216 {
t.Errorf("Error parsing 9K: %v %v", size, err)
}
}
func TestParseSizeBits(t *testing.T) {
size, err := parseSize("9 Kb")
if err == nil {
t.Errorf("Error parsing kilobits: %v %v", size, err)
}
}
func TestParseSizeEB(t *testing.T) {
size, err := parseSize("3EB")
if size != 3458764513820540928 {
t.Errorf("Error parsing exabytes: %v %v", size, err)
}
}
func TestParseSizeOverflow(t *testing.T) {
size, err := parseSize("314EB")
if err == nil {
t.Errorf("Overflow is not overflowing: %v %v", size, err)
}
}