New Upstream Snapshot - golang-github-christrenkamp-goxpath

Ready changes

Summary

Merged new upstream version: 1.0~alpha3+git20210403.97928f7 (was: 1.0~alpha3+git20170922.c385f95).

Resulting package

Built on 2022-11-21T13:43 (took 4m1s)

The resulting binary packages can be installed (if you have the apt repository enabled) by running one of:

apt install -t fresh-snapshots golang-github-christrenkamp-goxpath-dev

Lintian Result

Diff

diff --git a/README.md b/README.md
index deb4962..49407dd 100644
--- a/README.md
+++ b/README.md
@@ -1,2 +1 @@
-# goxpath [![GoDoc](https://godoc.org/gopkg.in/src-d/go-git.v2?status.svg)](https://godoc.org/github.com/ChrisTrenkamp/goxpath) [![Build Status](https://travis-ci.org/ChrisTrenkamp/goxpath.svg?branch=master)](https://travis-ci.org/ChrisTrenkamp/goxpath)  [![codecov.io](https://codecov.io/github/ChrisTrenkamp/goxpath/coverage.svg?branch=master)](https://codecov.io/github/ChrisTrenkamp/goxpath?branch=master) [![Go Report Card](https://goreportcard.com/badge/github.com/ChrisTrenkamp/goxpath)](https://goreportcard.com/report/github.com/ChrisTrenkamp/goxpath)
-An XPath 1.0 implementation written in Go. See the [wiki](https://github.com/ChrisTrenkamp/goxpath/wiki) for more information.
+# Deprecated.  Use [xsel](https://github.com/ChrisTrenkamp/xsel) instead.
diff --git a/debian/changelog b/debian/changelog
index bedd082..fa5b0a6 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -1,3 +1,9 @@
+golang-github-christrenkamp-goxpath (1.0~alpha3+git20210403.97928f7-1) UNRELEASED; urgency=low
+
+  * New upstream snapshot.
+
+ -- Debian Janitor <janitor@jelmer.uk>  Mon, 21 Nov 2022 13:40:48 -0000
+
 golang-github-christrenkamp-goxpath (1.0~alpha3+git20170922.c385f95-2) unstable; urgency=medium
 
   [ Debian Janitor ]
diff --git a/misc_test.go b/misc_test.go
index 65c0bda..506d6aa 100644
--- a/misc_test.go
+++ b/misc_test.go
@@ -5,6 +5,8 @@ import (
 	"encoding/xml"
 	"testing"
 
+	"github.com/ChrisTrenkamp/goxpath/lexer"
+	"github.com/ChrisTrenkamp/goxpath/parser"
 	"github.com/ChrisTrenkamp/goxpath/tree"
 	"github.com/ChrisTrenkamp/goxpath/tree/xmltree"
 )
@@ -118,3 +120,119 @@ func TestVariable(t *testing.T) {
 		t.Error("Parse error not nil")
 	}
 }
+
+func TestFunctionInteractions(t *testing.T) {
+	cases := []struct {
+		name     string
+		expected *parser.Node
+		xpath    string
+	}{{
+		name: "TestFunctionInteractions_1",
+		expected: &parser.Node{
+			Val:   lexer.XItem{lexer.XItemOperator, "="},
+			Left:  &parser.Node{Val: lexer.XItem{lexer.XItemFunction, "current"}},
+			Right: &parser.Node{Val: lexer.XItem{lexer.XItemNumLit, "1"}},
+		},
+		xpath: `current()=1`,
+	}, {
+		name: "TestFunctionInteractions_2",
+		expected: &parser.Node{
+			Val:   lexer.XItem{lexer.XItemOperator, "="},
+			Left:  &parser.Node{Val: lexer.XItem{lexer.XItemFunction, "current"}},
+			Right: &parser.Node{Val: lexer.XItem{lexer.XItemStrLit, "abc"}},
+		},
+		xpath: `current() = 'abc'`,
+	}, {
+		name: "TestFunctionInteractions_3",
+		expected: &parser.Node{
+			Val:  lexer.XItem{lexer.XItemOperator, "="},
+			Left: &parser.Node{Val: lexer.XItem{lexer.XItemFunction, "current"}},
+			Right: &parser.Node{
+				Val:  lexer.XItem{lexer.XItemRelLocPath, ""},
+				Left: &parser.Node{Val: lexer.XItem{lexer.XItemQName, "abc"}},
+			},
+		},
+		xpath: `current() = abc`,
+	}, {
+		name: "TestFunctionInteractions_4",
+		expected: &parser.Node{
+			Val:  lexer.XItem{lexer.XItemFunction, "current"},
+			Left: nil,
+			Right: &parser.Node{Val: lexer.XItem{lexer.XItemRelLocPath, ""},
+				Left: &parser.Node{Val: lexer.XItem{lexer.XItemNCName, "ns"},
+					Left: &parser.Node{
+						Val: lexer.XItem{lexer.XItemQName, "sub"},
+					},
+				},
+			},
+		},
+		xpath: `current()/ns:sub`,
+	}, {
+		name: "TestFunctionInteractions_5",
+		expected: &parser.Node{
+			Val: lexer.XItem{lexer.XItemOperator, "="},
+			Left: &parser.Node{
+				Val:  lexer.XItem{lexer.XItemFunction, "current"},
+				Left: nil,
+				Right: &parser.Node{
+					Val: lexer.XItem{lexer.XItemRelLocPath, ""},
+					Left: &parser.Node{
+						Val: lexer.XItem{lexer.XItemNCName, "ns"},
+						Left: &parser.Node{
+							Val: lexer.XItem{lexer.XItemQName, "sub"},
+						},
+					},
+				},
+			},
+			Right: &parser.Node{
+				Val: lexer.XItem{lexer.XItemStrLit, "abc"},
+			},
+		},
+		xpath: `current()/ns:sub = 'abc'`,
+	}, {
+		name: "TestFunctionInteractions_6",
+		expected: &parser.Node{
+			Val: lexer.XItem{lexer.XItemOperator, "="},
+			Left: &parser.Node{
+				Val:  lexer.XItem{lexer.XItemFunction, "current"},
+				Left: nil,
+				Right: &parser.Node{
+					Val: lexer.XItem{lexer.XItemRelLocPath, ""},
+					Left: &parser.Node{
+						Val: lexer.XItem{lexer.XItemNCName, "ns"},
+						Left: &parser.Node{
+							Val: lexer.XItem{lexer.XItemQName, "sub"},
+						},
+					},
+				},
+			},
+			Right: &parser.Node{
+				Val: lexer.XItem{lexer.XItemRelLocPath, ""},
+				Left: &parser.Node{
+					Val: lexer.XItem{lexer.XItemQName, "abc"},
+				},
+			},
+		},
+		xpath: `current()/ns:sub = abc`,
+	},
+	}
+
+	for _, val := range cases {
+		t.Run(val.name, func(t *testing.T) {
+			actual := MustParse(val.xpath).n
+			if !isEquivalentAST(val.expected, actual) {
+				t.Errorf("Expected AST tree is not the same as actual tree that goxpath parser returns")
+			}
+		})
+	}
+}
+
+func isEquivalentAST(node1, node2 *parser.Node) bool {
+	if node1 == nil && node2 == nil {
+		return true
+	}
+	if node1 != nil && node2 != nil {
+		return (node1.Val == node2.Val && isEquivalentAST(node1.Left, node2.Left) && isEquivalentAST(node1.Right, node2.Right))
+	}
+	return false
+}
diff --git a/parser/ast.go b/parser/ast.go
index 89678f6..08196c6 100644
--- a/parser/ast.go
+++ b/parser/ast.go
@@ -27,12 +27,12 @@ var beginPathType = map[lexer.XItemType]bool{
 func (n *Node) add(i lexer.XItem) {
 	if n.Val.Typ == Empty {
 		n.Val = i
-	} else if n.Left == nil {
+	} else if n.Left == nil && n.Right == nil {
 		n.Left = &Node{Val: n.Val, Parent: n}
 		n.Val = i
 	} else if beginPathType[n.Val.Typ] {
-		next := &Node{Val: n.Val, Left: n.Left, Parent: n}
-		n.Left = next
+		next := &Node{Val: n.Val, Left: n.Left, Right: n.Right, Parent: n}
+		n.Left, n.Right = next, nil
 		n.Val = i
 	} else if n.Right == nil {
 		n.Right = &Node{Val: i, Parent: n}
diff --git a/parser/parser.go b/parser/parser.go
index ff664ff..e5ce822 100644
--- a/parser/parser.go
+++ b/parser/parser.go
@@ -128,6 +128,12 @@ func xiEndPath(p *parseStack, i lexer.XItem) {
 }
 
 func xiFunc(p *parseStack, i lexer.XItem) {
+	if p.cur.Val.Typ == Empty {
+		p.cur.pushNotEmpty(i)
+		p.push(funcState)
+		p.cur = p.cur.next
+		return
+	}
 	p.cur.push(i)
 	p.cur = p.cur.next
 	p.push(funcState)

Debdiff

File lists identical (after any substitutions)

No differences were encountered in the control files

More details

Full run details