From 15adffe7861e947732fb598d00bae0ab5ba57dca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E7=99=BD=E8=8C=B6=E6=B8=85=E6=AC=A2?= Date: Mon, 4 Jul 2022 18:39:29 +0800 Subject: [PATCH] unit test --- lexical.go | 9 +++++---- lexical_test.go | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 5 deletions(-) diff --git a/lexical.go b/lexical.go index 32624e6..7208745 100644 --- a/lexical.go +++ b/lexical.go @@ -8,8 +8,9 @@ package filter import ( - "encoding/json" - "fmt" + "strings" + + "git.zhangdeman.cn/zhangdeman/util" "github.com/pkg/errors" ) @@ -20,6 +21,7 @@ import ( // // Date : 18:11 2022/7/4 func parseLexical(jsonData string) ([]lexicalNode, error) { + jsonData = strings.ReplaceAll(strings.ReplaceAll(jsonData, "\n", ""), "\t", "") if len(jsonData) < 2 { return nil, errors.New("input data is not json") } @@ -48,8 +50,7 @@ func parseLexical(jsonData string) ([]lexicalNode, error) { tmpStr = tmpStr + currentChar } } - byteData, _ := json.Marshal(lexicalList) - fmt.Println("============ : ", string(byteData)) + util.JSON.ConsoleOutput(lexicalList) return nil, nil } diff --git a/lexical_test.go b/lexical_test.go index 87e9e57..d823129 100644 --- a/lexical_test.go +++ b/lexical_test.go @@ -12,5 +12,23 @@ import ( ) func Test_parseLexical(t *testing.T) { - parseLexical("{iiiiiiiii}") + jsonData := `{ + "name":"zhangsan", + "age":"18", + "extension":{ + "sex":"man", + "height":"180" + }, + "teacher_list":[ + { + "name":"t1", + "age":"11" + }, + { + "name":"t2", + "age":"12" + } + ] +}` + parseLexical(jsonData) }