mirror of
https://github.com/sot-tech/mochi.git
synced 2026-04-27 16:10:00 -07:00
Add scalar bencode tests
This commit is contained in:
@@ -4,4 +4,29 @@
|
||||
|
||||
package bencode
|
||||
|
||||
// TODO Write bencode tests
|
||||
import (
|
||||
"testing"
|
||||
"time"
|
||||
)
|
||||
|
||||
var scalarTests = map[interface{}]string{
|
||||
int(42): "i42e",
|
||||
int(-42): "i-42e",
|
||||
uint(42): "i42e",
|
||||
int64(42): "i42e",
|
||||
uint64(42): "i42e",
|
||||
|
||||
"example": "7:example",
|
||||
30 * time.Minute: "i1800e",
|
||||
}
|
||||
|
||||
func TestScalar(t *testing.T) {
|
||||
for val, expected := range scalarTests {
|
||||
got, err := Marshal(val)
|
||||
if err != nil {
|
||||
t.Error(err)
|
||||
} else if string(got) != expected {
|
||||
t.Errorf("\ngot: %s\nexpected: %s", got, expected)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user