1
0
mirror of https://github.com/v2fly/v2ray-core.git synced 2024-12-22 01:57:12 -05:00

remove string list

This commit is contained in:
Darien Raymond 2016-10-18 16:10:50 +02:00
parent 2320bc3304
commit 2af4b16913
No known key found for this signature in database
GPG Key ID: 7251FFA14BB18169
6 changed files with 0 additions and 155 deletions

View File

@ -1,12 +0,0 @@
package collect
type StringList []string
func NewStringList(raw []string) *StringList {
list := StringList(raw)
return &list
}
func (this StringList) Len() int {
return len(this)
}

View File

@ -1,25 +0,0 @@
// +build json
package collect
import (
"encoding/json"
"errors"
"strings"
)
func (this *StringList) UnmarshalJSON(data []byte) error {
var strarray []string
if err := json.Unmarshal(data, &strarray); err == nil {
*this = *NewStringList(strarray)
return nil
}
var rawstr string
if err := json.Unmarshal(data, &rawstr); err == nil {
strlist := strings.Split(rawstr, ",")
*this = *NewStringList(strlist)
return nil
}
return errors.New("Unknown format of a string list: " + string(data))
}

View File

@ -1,30 +0,0 @@
// +build json
package collect_test
import (
"encoding/json"
"testing"
. "v2ray.com/core/common/collect"
"v2ray.com/core/testing/assert"
)
func TestStringListUnmarshalError(t *testing.T) {
assert := assert.On(t)
rawJson := `1234`
list := new(StringList)
err := json.Unmarshal([]byte(rawJson), list)
assert.Error(err).IsNotNil()
}
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)
}

View File

@ -2,8 +2,6 @@ package net
import (
"strings"
"v2ray.com/core/common/collect"
)
func ParseNetwork(nwStr string) Network {
@ -56,17 +54,6 @@ func (this Network) UrlPrefix() string {
}
}
// NewNetworkList construsts a NetWorklist from the given StringListeralList.
func NewNetworkList(networks collect.StringList) *NetworkList {
list := &NetworkList{
Network: make([]Network, networks.Len()),
}
for idx, network := range networks {
list.Network[idx] = ParseNetwork(network)
}
return list
}
// HashNetwork returns true if the given network is in this NetworkList.
func (this NetworkList) HasNetwork(network Network) bool {
for _, value := range this.Network {

View File

@ -1,27 +0,0 @@
// +build json
package net
import (
"encoding/json"
"v2ray.com/core/common/collect"
)
func (this *Network) UnmarshalJSON(data []byte) error {
var str string
if err := json.Unmarshal(data, &str); err != nil {
return err
}
*this = ParseNetwork(str)
return nil
}
func (this *NetworkList) UnmarshalJSON(data []byte) error {
var strlist collect.StringList
if err := json.Unmarshal(data, &strlist); err != nil {
return err
}
*this = *NewNetworkList(strlist)
return nil
}

View File

@ -1,48 +0,0 @@
// +build json
package net_test
import (
"encoding/json"
"testing"
. "v2ray.com/core/common/net"
"v2ray.com/core/testing/assert"
)
func TestStringNetwork(t *testing.T) {
assert := assert.On(t)
var network Network
err := json.Unmarshal([]byte(`"tcp"`), &network)
assert.Error(err).IsNil()
assert.Bool(network == Network_TCP).IsTrue()
}
func TestArrayNetworkList(t *testing.T) {
assert := assert.On(t)
var list NetworkList
err := json.Unmarshal([]byte("[\"Tcp\"]"), &list)
assert.Error(err).IsNil()
assert.Bool(list.HasNetwork(ParseNetwork("tcp"))).IsTrue()
assert.Bool(list.HasNetwork(ParseNetwork("udp"))).IsFalse()
}
func TestStringNetworkList(t *testing.T) {
assert := assert.On(t)
var list NetworkList
err := json.Unmarshal([]byte("\"TCP, ip\""), &list)
assert.Error(err).IsNil()
assert.Bool(list.HasNetwork(ParseNetwork("tcp"))).IsTrue()
assert.Bool(list.HasNetwork(ParseNetwork("udp"))).IsFalse()
}
func TestInvalidNetworkJson(t *testing.T) {
assert := assert.On(t)
var list NetworkList
err := json.Unmarshal([]byte("0"), &list)
assert.Error(err).IsNotNil()
}