Skip to content

Commit

Permalink
update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
zhengchun committed Mar 30, 2024
1 parent ec5c80c commit 6165646
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 56 deletions.
56 changes: 0 additions & 56 deletions func_test.go

This file was deleted.

21 changes: 21 additions & 0 deletions xpath_function_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@ func Test_func_concat(t *testing.T) {
test_xpath_eval(t, empty_example, `concat("1", "2", "3")`, "123")
//test_xpath_eval(t, empty_example, `concat("Ciao!", ())`, "Ciao!")
test_xpath_eval(t, book_example, `concat(//book[1]/title, ", ", //book[1]/year)`, "Everyday Italian, 2005")
result := concatFunc(testQuery("a"), testQuery("b"))(nil, nil).(string)
assertEqual(t, result, "ab")
}

func Test_func_contains(t *testing.T) {
Expand Down Expand Up @@ -220,7 +222,26 @@ func Test_func_namespace_uri(t *testing.T) {
}

func Test_func_normalize_space(t *testing.T) {
const testStr = "\t \rloooooooonnnnnnngggggggg \r \n tes \u00a0 t strin \n\n \r g "
const expectedStr = `loooooooonnnnnnngggggggg tes t strin g`
test_xpath_eval(t, employee_example, `normalize-space("`+testStr+`")`, expectedStr)

test_xpath_eval(t, empty_example, `normalize-space(' abc ')`, "abc")
test_xpath_eval(t, book_example, `normalize-space(//book/title)`, "Everyday Italian")
test_xpath_eval(t, book_example, `normalize-space(//book[1]/title)`, "Everyday Italian")
}

func Benchmark_NormalizeSpaceFunc(b *testing.B) {
b.ReportAllocs()
const strForNormalization = "\t \rloooooooonnnnnnngggggggg \r \n tes \u00a0 t strin \n\n \r g "
for i := 0; i < b.N; i++ {
_ = normalizespaceFunc(testQuery(strForNormalization), nil)
}
}

func Benchmark_ConcatFunc(b *testing.B) {
b.ReportAllocs()
for i := 0; i < b.N; i++ {
_ = concatFunc(testQuery("a"), testQuery("b"))(nil, nil)
}
}
22 changes: 22 additions & 0 deletions xpath_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,28 @@ var (
mybook_example = createMyBookExample()
)

type testQuery string

func (t testQuery) Select(_ iterator) NodeNavigator {
panic("implement me")
}

func (t testQuery) Clone() query {
return t
}

func (t testQuery) Evaluate(_ iterator) interface{} {
return string(t)
}

func (t testQuery) ValueType() resultType {
return xpathResultType.Any
}

func (t testQuery) Properties() queryProp {
return queryProps.None
}

func test_xpath_elements(t *testing.T, root *TNode, expr string, expected ...int) {
result := selectNodes(root, expr)
assertEqual(t, len(expected), len(result))
Expand Down

0 comments on commit 6165646

Please sign in to comment.