2019-06-26 08:14:52 -07:00
|
|
|
package stanza_test
|
2019-02-10 08:53:18 -08:00
|
|
|
|
|
|
|
import (
|
|
|
|
"encoding/xml"
|
|
|
|
|
|
|
|
"github.com/google/go-cmp/cmp"
|
|
|
|
)
|
|
|
|
|
|
|
|
// Compare iq structure but ignore empty namespace as they are set properly on
|
|
|
|
// marshal / unmarshal. There is no need to manage them on the manually
|
|
|
|
// crafted structure.
|
|
|
|
func xmlEqual(x, y interface{}) bool {
|
2019-06-27 05:30:23 -07:00
|
|
|
return cmp.Equal(x, y, xmlOpts())
|
|
|
|
}
|
|
|
|
|
|
|
|
// xmlDiff compares xml structures ignoring namespace preferences
|
|
|
|
func xmlDiff(x, y interface{}) string {
|
|
|
|
return cmp.Diff(x, y, xmlOpts())
|
|
|
|
}
|
|
|
|
|
|
|
|
func xmlOpts() cmp.Options {
|
2019-02-10 08:53:18 -08:00
|
|
|
alwaysEqual := cmp.Comparer(func(_, _ interface{}) bool { return true })
|
|
|
|
opts := cmp.Options{
|
|
|
|
cmp.FilterValues(func(x, y interface{}) bool {
|
|
|
|
xx, xok := x.(xml.Name)
|
|
|
|
yy, yok := y.(xml.Name)
|
|
|
|
if xok && yok {
|
|
|
|
zero := xml.Name{}
|
|
|
|
if xx == zero || yy == zero {
|
|
|
|
return true
|
|
|
|
}
|
2019-06-27 05:30:23 -07:00
|
|
|
if xx.Space == "" || yy.Space == "" {
|
|
|
|
return true
|
|
|
|
}
|
2019-02-10 08:53:18 -08:00
|
|
|
}
|
|
|
|
return false
|
|
|
|
}, alwaysEqual),
|
|
|
|
}
|
2019-06-27 05:30:23 -07:00
|
|
|
return opts
|
2019-02-10 08:53:18 -08:00
|
|
|
}
|