1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109
|
package x2j
import (
"fmt"
"testing"
)
var doc01 = `
<doc>
<books>
<book seq="1">
<author>William H. Gaddis</author>
<title>The Recognitions</title>
<review>One of the great seminal American novels of the 20th century.</review>
</book>
<book seq="2">
<author>Austin Tappan Wright</author>
<title>Islandia</title>
<review>An example of earlier 20th century American utopian fiction.</review>
</book>
<book seq="3">
<author>John Hawkes</author>
<title>The Beetle Leg</title>
<review>A lyrical novel about the construction of Ft. Peck Dam in Montana.</review>
</book>
<book seq="4">
<author>
<first_name>T.E.</first_name>
<last_name>Porter</last_name>
</author>
<title>King's Day</title>
<review>A magical novella.</review>
</book>
</books>
</doc>
`
var doc02 = `
<doc>
<books>
<author>
<name>William H. Gaddis</name>
<book seq="1">
<title>The Recognitions</title>
<review>One of the great seminal American novels of the 20th century.</review>
</book>
<book>
<title>JR</title>
<review>Won the National Book Award</review>
</book>
</author>
<author>
<name>John Hawkes</name>
<books>
<book>
<title>The Beetle Leg</title>
</book>
<book>
<title>The Blood Oranges</title>
</book>
</books>
</author>
</books>
</doc>
`
// the basic demo/test case - a small bibliography with mixed element types
func TestPathsForKey(t *testing.T) {
fmt.Println("\n================================ x2jfindPath_test.go")
fmt.Println("\n=============== TestPathsForKey ...")
fmt.Println("\nPathsForKey... doc01#author")
m, _ := DocToMap(doc01)
ss := PathsForKey(m, "author")
fmt.Println("ss:", ss)
fmt.Println("\nPathsForKey... doc01#books")
// m, _ := DocToMap(doc01)
ss = PathsForKey(m, "books")
fmt.Println("ss:", ss)
fmt.Println("\nPathsForKey...doc02#book")
m, _ = DocToMap(doc02)
ss = PathsForKey(m, "book")
fmt.Println("ss:", ss)
fmt.Println("\nPathForKeyShortest...doc02#book")
m, _ = DocToMap(doc02)
s := PathForKeyShortest(m, "book")
fmt.Println("s:", s)
}
// the basic demo/test case - a small bibliography with mixed element types
func TestPathsForTag(t *testing.T) {
fmt.Println("\n=============== TestPathsForTag ...")
fmt.Println("\nPathsForTag... doc01#author")
ss, _ := PathsForTag(doc01, "author")
fmt.Println("ss:", ss)
fmt.Println("\nPathsForTag... doc01#books")
ss, _ = PathsForTag(doc01, "books")
fmt.Println("ss:", ss)
fmt.Println("\nPathsForTag...doc02#book")
ss, _ = PathsForTag(doc02, "book")
fmt.Println("ss:", ss)
fmt.Println("\nPathForTagShortest...doc02#book")
s, _ := PathForTagShortest(doc02, "book")
fmt.Println("s:", s)
}
|