package main

import (
	"io/ioutil"
	"testing"

	"github.com/tidwall/gjson"
)

func TestTaskEx_Execute(t *testing.T) {
	data, err := ioutil.ReadFile("../ssss.json")
	if err != nil {
		panic(err)
	}

	var adDataList []string
	if gjson.Valid(string(data)) {
		P := gjson.Parse(string(data))
		data := P.Get(`data`)
		if data.Exists() {
			adData := data.Get(`ordered_info.#.ad_data`)
			if adData.Exists() {
				for _, result := range adData.Array() {
					adDataList = append(adDataList, result.String())
				}
			} else {
				t.Error(`ordered_info.#.ad_data not exists`)
			}

			relatedVideo := data.Get(`related_video_toutiao.#[show_tag = "广告"]#`)
			if adData.Exists() {
				for _, result := range relatedVideo.Array() {
					adDataList = append(adDataList, result.String())
				}
			} else {
				t.Error(`related_video_toutiao.#[show_tag = "广告"]# not exists`)
			}

		}
	}

	if len(adDataList) != 2 {
		t.Error("adDataList != 2")
	}

}
