...

Source file src/github.com/clbanning/mxj/v2/x2j-wrapper/x2jfindPath_test.go

Documentation: github.com/clbanning/mxj/v2/x2j-wrapper

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

View as plain text