Skip to content

Commit

Permalink
update namespace_uri() test case
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengchun committed Mar 30, 2024
1 parent d0cd197 commit be7a99a
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 12 deletions.
6 changes: 3 additions & 3 deletions xpath_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func Test_func_string_length(t *testing.T) {
func Test_func_substring(t *testing.T) {
test_xpath_eval(t, empty_example, `substring("motor car", 6)`, " car")
test_xpath_eval(t, empty_example, `substring("metadata", 4, 3)`, "ada")
//test_xpath_eval(t, empty_example, `substring("12345", 5, -3)`, "") ?? it should be 1 ??
//test_xpath_eval(t, empty_example, `substring("12345", 5, -3)`, "") // ?? it should be 1 ??
//test_xpath_eval(t, empty_example, `substring("12345", 1.5, 2.6)`, "234")
//test_xpath_eval(t, empty_example, `substring("12345", 0, 3)`, "12") // panic??
//test_xpath_eval(t, empty_example, `substring("12345", 5, -3)`, "1")
Expand Down Expand Up @@ -212,8 +212,8 @@ func Test_func_round(t *testing.T) {
}

func Test_func_namespace_uri(t *testing.T) {
//test_xpath_eval(t, mybook_example, `namespace-uri(//mybook:book)`, "http://www.contoso.com/books")
//test_xpath_elements(t, mybook_example, `//*[namespace-uri()='http://www.contoso.com/books']`, 3, 9)
test_xpath_eval(t, mybook_example, `namespace-uri(//mybook:book)`, "http://www.contoso.com/books")
test_xpath_elements(t, mybook_example, `//*[namespace-uri()='http://www.contoso.com/books']`, 3, 9)
}

func Test_func_normalize_space(t *testing.T) {
Expand Down
27 changes: 18 additions & 9 deletions xpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,10 +285,12 @@ type Attribute struct {
type TNode struct {
Parent, FirstChild, LastChild, PrevSibling, NextSibling *TNode

Type NodeType
Data string
Attr []Attribute
lines int
Type NodeType
Data string
Attr []Attribute
NamespaceURL string
Prefix string
lines int
}

func (n *TNode) Value() string {
Expand Down Expand Up @@ -346,7 +348,7 @@ func (n *TNodeNavigator) Prefix() string {
if n.attr == -1 && strings.Contains(n.curr.Data, ":") {
return strings.Split(n.curr.Data, ":")[0]
}
return ""
return n.curr.Prefix
}

func (n *TNodeNavigator) NamespaceURL() string {
Expand All @@ -357,7 +359,7 @@ func (n *TNodeNavigator) NamespaceURL() string {
}
}
}
return ""
return n.curr.NamespaceURL
}

func (n *TNodeNavigator) Value() string {
Expand Down Expand Up @@ -842,11 +844,16 @@ func createMyBookExample() *TNode {
</mybook:book>
</books>
*/
lines := 0
var (
prefix string = "mybook"
namespaceURL string = "http://www.contoso.com/books"
)
lines := 1
doc := createNode("", RootNode)
doc.lines = lines
lines++
books := doc.createChildNode("books", ElementNode)
books.addAttribute("xmlns:mybook", "http://www.contoso.com/books")
books.addAttribute("xmlns:mybook", namespaceURL)
books.lines = lines
lines++
data := []struct {
Expand All @@ -861,8 +868,10 @@ func createMyBookExample() *TNode {
}
for i := 0; i < len(data); i++ {
v := data[i]
book := books.createChildNode("mybook:book", ElementNode)
book := books.createChildNode("book", ElementNode)
book.addAttribute("id", v.id)
book.Prefix = prefix
book.NamespaceURL = namespaceURL
book.lines = lines
lines++
title := book.createChildNode("title", ElementNode)
Expand Down

0 comments on commit be7a99a

Please sign in to comment.