toutiao/article/article_test.go

33 lines
672 B
Go
Raw Normal View History

2018-12-23 14:31:50 +00:00
package main
import (
"io/ioutil"
"log"
"regexp"
"testing"
"github.com/tidwall/gjson"
)
func TestTaskEx_Execute(t *testing.T) {
rule := regexp.MustCompile(`\\"label\\"\:\\"广告\\"|\\"label_style\\"\:3`)
data, err := ioutil.ReadFile("../s.json")
if err != nil {
panic(err)
}
log.Println(rule.MatchString(string(data)))
log.Println(gjson.Valid(string(data)))
P := gjson.Parse(string(data))
gADDate := P.Get(`data.ordered_info.#.ad_data`)
log.Println(gADDate.Exists(), gADDate.IsArray())
if !(gADDate.Exists() && gADDate.IsArray()) {
t.Error("path is error")
}
for _, result := range gADDate.Array() {
log.Println(gjson.Valid(result.Raw))
}
}