From a69e005e3180f5c54cea2c0fe12aab15a3225215 Mon Sep 17 00:00:00 2001 From: gazebo Date: Wed, 31 Oct 2018 11:48:49 +0800 Subject: [PATCH] - reimplement TrimBlanChar --- platformapi/jdapi/store_test.go | 26 ++++++++++++++++++++++++++ utils/utils.go | 5 +---- utils/utils_test.go | 9 +++++++++ 3 files changed, 36 insertions(+), 4 deletions(-) diff --git a/platformapi/jdapi/store_test.go b/platformapi/jdapi/store_test.go index 0ffc2a0c..72309396 100644 --- a/platformapi/jdapi/store_test.go +++ b/platformapi/jdapi/store_test.go @@ -105,3 +105,29 @@ func TestUpdateStoreConfig4Open(t *testing.T) { t.Fatalf("UpdateStoreConfig4Open failed, isAutoOrder:%d", isAutoOrder) } } + +func TestGetDeliveryRangeByStationNo(t *testing.T) { + const testStoreID = "11738152" + result, err := jdapi.GetDeliveryRangeByStationNo(testStoreID) + if err != nil { + t.Fatal(err) + } + result2, err := jdapi.GetStoreInfoByStationNo(testStoreID) + if err != nil { + t.Fatal(err) + } + baseapi.SugarLogger.Debug(utils.Format4Output(result, false)) + baseapi.SugarLogger.Debug(utils.Format4Output(result2, false)) + deliveryRange := result["deliveryRange"].(string) + params := map[string]interface{}{ + "lng": result2["lng"], + "lat": result2["lat"], + "coordinateType": 3, + "deliveryRangeType": 2, + "coordinatePoints": deliveryRange, + } + err = jdapi.UpdateStoreInfo4Open(testStoreID, "test", params) + if err != nil { + t.Fatal(err) + } +} diff --git a/utils/utils.go b/utils/utils.go index b3cb35a0..a10d0d92 100644 --- a/utils/utils.go +++ b/utils/utils.go @@ -196,10 +196,7 @@ func FilterMb4(content string) string { } func TrimBlanChar(str string) string { - return strings.TrimFunc(str, func(value rune) bool { - strValue := string(value) - return strValue == " " || strValue == "\t" || strValue == "\n" || strValue == "\r" - }) + return strings.Trim(str, "\n\r\t ") } func RemoveGeneralMapKeys(obj map[string]interface{}, keys ...string) map[string]interface{} { diff --git a/utils/utils_test.go b/utils/utils_test.go index e5d8c135..3082d854 100644 --- a/utils/utils_test.go +++ b/utils/utils_test.go @@ -125,3 +125,12 @@ func TestRemoveGeneralMapKeys(t *testing.T) { t.Fatal("RemoveGeneralMapKeys handle nil wrong") } } + +func TestTrimBlanChar(t *testing.T) { + str := ` + 大小21 + ` + if TrimBlanChar(str) != "大小21" { + t.Fatal("TrimBlanChar doesn't work") + } +}