StefH / XPath2.Net

Lightweight XPath2 for .NET
Microsoft Public License
36 stars 14 forks source link

round(2.5) evaluates to 2 #25

Closed Lej closed 5 years ago

Lej commented 5 years ago

Happened upon a discrepancy in XPath2Evaluate compared to System.Xml.XPath.Evaluate which I think might be a bug. XPath2Evaluate seems to round 2.5 down to 2, while Evaluate rounds it up to 3.

According to the doc examples it seems like rounding up to 3 is the correct behavior: https://www.w3.org/TR/xquery-operators/#func-round

6.4.4.1 Examples fn:round(2.5) returns 3.

Example test case that fails:

    [TestClass]
    public class RoundTests
    {
        [TestMethod]
        public void TwoPointFive()
        {
            var xpath = "round(number(value))";
            var xml = @"<value>2.5</value>";
            using (var reader = new StringReader(xml))
            {
                var doc = XDocument.Load(reader);
                var nav = doc.CreateNavigator();
                var v1 = nav.Evaluate(xpath); // 3
                var v2 = nav.XPath2Evaluate(xpath); // 2
                Assert.AreEqual(v1, v2); // Fails
            }
        }
    }
StefH commented 5 years ago

Can you please verify changes + unit-test in https://github.com/StefH/XPath2.Net/pull/26 and tell me if this is correct ?