2016-01-21 18:53:51 -05:00
|
|
|
// +build json
|
|
|
|
|
2016-05-24 16:41:51 -04:00
|
|
|
package collect_test
|
2016-01-21 18:53:51 -05:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/json"
|
|
|
|
"testing"
|
|
|
|
|
2016-08-20 14:55:45 -04:00
|
|
|
. "v2ray.com/core/common/collect"
|
|
|
|
"v2ray.com/core/testing/assert"
|
2016-01-21 18:53:51 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
func TestStringListUnmarshalError(t *testing.T) {
|
2016-05-24 15:55:46 -04:00
|
|
|
assert := assert.On(t)
|
2016-01-21 18:53:51 -05:00
|
|
|
|
|
|
|
rawJson := `1234`
|
2016-05-24 16:41:51 -04:00
|
|
|
list := new(StringList)
|
2016-01-21 18:53:51 -05:00
|
|
|
err := json.Unmarshal([]byte(rawJson), list)
|
|
|
|
assert.Error(err).IsNotNil()
|
|
|
|
}
|
2016-08-18 01:56:31 -04:00
|
|
|
|
|
|
|
func TestStringListLen(t *testing.T) {
|
|
|
|
assert := assert.On(t)
|
|
|
|
|
|
|
|
rawJson := `"a, b, c, d"`
|
|
|
|
list := new(StringList)
|
|
|
|
err := json.Unmarshal([]byte(rawJson), list)
|
|
|
|
assert.Error(err).IsNil()
|
|
|
|
assert.Int(list.Len()).Equals(4)
|
|
|
|
}
|