goutils icon indicating copy to clipboard operation
goutils copied to clipboard

Bug for DeleteWhiteSpace when str is other utf8 string, eg. chinese

Open si9ma opened this issue 5 years ago • 0 comments

func TestDeleteWhiteSpace(t *testing.T) {

	// Test 1
	str := " a b c "
	out := "abc"

	if x := DeleteWhiteSpace(str); x != out {
		t.Errorf("IndexOf(%v) = %v, want %v", str, x, out)
	}

	// Test 2
	str = "    "
	out = ""

	if x := DeleteWhiteSpace(str); x != out {
		t.Errorf("IndexOf(%v) = %v, want %v", str, x, out)
	}

	// Test 3
	str = " 测试 测试 测试 "
	out = "测试测试测试"

	if x := DeleteWhiteSpace(str); x != out {
		t.Errorf("IndexOf(%v) = %v, want %v", str, x, out)
	}
}
$ go test

--- FAIL: TestDeleteWhiteSpace (0.00s)
    stringutils_test.go:157: IndexOf( 测试 测试 测试 ) = æµ�è¯�æµ�è¯�æµ�è¯�, want 测试测试测试
FAIL
exit status 1
FAIL    _/Users/xxxx/Github/goutils       0.371s

si9ma avatar Jul 25 '20 09:07 si9ma