Add scalar bencode tests
This commit is contained in:
parent
e86ff58b44
commit
dd5e8e460f
2 changed files with 27 additions and 2 deletions
|
@ -3,7 +3,7 @@
|
|||
// which can be found in the LICENSE file.
|
||||
|
||||
// Package bencode implements bencoding of objects as defined in BEP 3 using
|
||||
// type assertion rather than the use of reflection.
|
||||
// type assertion over reflection for performance.
|
||||
package bencode
|
||||
|
||||
import (
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue