package x2j import ( "fmt" "testing" ) var doc1 = ` William H. Gaddis The Recognitions One of the great seminal American novels of the 20th century. Austin Tappan Wright Islandia An example of earlier 20th century American utopian fiction. John Hawkes The Beetle Leg A lyrical novel about the construction of Ft. Peck Dam in Montana. T.E. Porter King's Day A magical novella. ` var doc2 = ` William H. Gaddis The Recognitions One of the great seminal American novels of the 20th century. JR Won the National Book Award John Hawkes The Beetle Leg The Blood Oranges ` var msg1 = ` test This is a long cold winter ` var msg2 = ` test This is a long cold winter test2 I hope we have a cool summer, though ` func TestValuesAtKeyPath(t *testing.T) { fmt.Println("\n============================ x2jat_test.go") fmt.Println("\n=============== TestValuesAtKeyPath ...") fmt.Println("\nValuesAtKeyPath ... doc1#author") m, _ := DocToMap(doc1) ss := PathsForKey(m,"author") fmt.Println("ss:", ss) for _,v := range ss { vv := ValuesAtKeyPath(m,v,true) fmt.Println("vv:", vv) } fmt.Println("\nValuesAtKeyPath ... doc1#first_name") // m, _ := DocToMap(doc1) ss = PathsForKey(m,"first_name") fmt.Println("ss:", ss) for _,v := range ss { vv := ValuesAtKeyPath(m,v,true) fmt.Println("vv:", vv) } fmt.Println("\nGetKeyPaths...doc2#book") m, _ = DocToMap(doc2) ss = PathsForKey(m,"book") fmt.Println("ss:", ss) for _,v := range ss { vv := ValuesAtKeyPath(m,v,true) fmt.Println("vv:", vv) } s := PathForKeyShortest(m,"book") vv := ValuesAtKeyPath(m,s) fmt.Println("vv,shortest_path:",vv) fmt.Println("\nValuesAtKeyPath ... msg1#pub") m, _ = DocToMap(msg1) ss = PathsForKey(m,"pub") fmt.Println("ss:", ss) for _,v := range ss { vv := ValuesAtKeyPath(m,v,true) fmt.Println("vv:", vv) } fmt.Println("\nValuesAtKeyPath ... msg2#pub") m, _ = DocToMap(msg2) ss = PathsForKey(m,"pub") fmt.Println("ss:", ss) for _,v := range ss { vv := ValuesAtKeyPath(m,v,true) fmt.Println("vv:", vv) } } func TestValuesAtTagPath(t *testing.T) { fmt.Println("\n=============== TestValuesAtTagPath ...") fmt.Println("\nValuesAtTagPath ... doc1#author") m, _ := DocToMap(doc1) ss := PathsForKey(m,"author") fmt.Println("ss:", ss) for _,v := range ss { vv,_ := ValuesAtTagPath(doc1,v,true) fmt.Println("vv:", vv) } fmt.Println("\nValuesAtTagPath ... doc1#first_name") // m, _ := DocToMap(doc1) ss = PathsForKey(m,"first_name") fmt.Println("ss:", ss) for _,v := range ss { vv,_ := ValuesAtTagPath(doc1,v,true) fmt.Println("vv:", vv) } fmt.Println("\nValuesAtTagPath...doc2#book") m, _ = DocToMap(doc2) ss = PathsForKey(m,"book") fmt.Println("ss:", ss) for _,v := range ss { vv,_ := ValuesAtTagPath(doc2,v,true) fmt.Println("vv:", vv) } s := PathForKeyShortest(m,"book") vv,_ := ValuesAtTagPath(doc2,s) fmt.Println("vv,shortest_path:",vv) }