소스 검색

value receiver for StringList.Len()

v2ray 9 년 전
부모
커밋
933e244d92
2개의 변경된 파일12개의 추가작업 그리고 2개의 파일을 삭제
  1. 2 2
      common/collect/string_list.go
  2. 10 0
      common/collect/string_list_json_test.go

+ 2 - 2
common/collect/string_list.go

@@ -7,6 +7,6 @@ func NewStringList(raw []string) *StringList {
 	return &list
 }
 
-func (this *StringList) Len() int {
-	return len(*this)
+func (this StringList) Len() int {
+	return len(this)
 }

+ 10 - 0
common/collect/string_list_json_test.go

@@ -18,3 +18,13 @@ func TestStringListUnmarshalError(t *testing.T) {
 	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)
+}