Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 0 additions & 6 deletions XPathParser/XPathScanner.cs
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,6 @@ private void ScanNumber() {
while (IsAsciiDigit(curChar)) {
NextChar();
}
throw ScientificNotationException();
}
}

Expand Down Expand Up @@ -497,11 +496,6 @@ public XPathParserException PredicateAfterDotDotException() {
"Abbreviated step '..' cannot be followed by a predicate. Use the full form 'parent::node()[predicate]' instead."
);
}
public XPathParserException ScientificNotationException() {
return new XPathParserException(xpathExpr, lexStart, curIndex,
"Scientific notation is not allowed."
);
}
public XPathParserException UnclosedStringException() {
return new XPathParserException(xpathExpr, lexStart, curIndex,
"String literal was not closed."
Expand Down
25 changes: 18 additions & 7 deletions XPathParserTest/Test.cs
Original file line number Diff line number Diff line change
@@ -1,14 +1,21 @@
using CodePlex.XPathParser;
using System;
using System.Diagnostics;
using System.Text;
using System.Xml;
using System.Xml.Linq;
using Xunit;
using Xunit.Abstractions;

namespace XPathParserTest
{
public class Test
{
private readonly ITestOutputHelper _output;

public Test(ITestOutputHelper output)
{
_output = output;
}

// Expressions from http://www.w3.org/TR/xpath#location-paths
[InlineData(@"child::para")]
[InlineData(@"child::*")]
Expand Down Expand Up @@ -36,6 +43,9 @@ public class Test
[InlineData(@"/child::doc/child::chapter[position()=5]/child::section[position()=2]")]
[InlineData(@"child::para[attribute::type=""warning""]")]
[InlineData(@"child::para[attribute::type='warning'][position()=5]")]
[InlineData(@"3e8")]
[InlineData(@"3.5e8")]
[InlineData(@"-3.5e8")]
[InlineData(@"child::para[position()=5][attribute::type=""warning""]")]
[InlineData(@"child::chapter[child::title='Introduction']")]
[InlineData(@"child::chapter[child::title]")]
Expand All @@ -57,31 +67,32 @@ public void CorrectTest(string expression)
[InlineData(@")")]
[InlineData(@"a[']")]
[InlineData(@"b[""]")]
[InlineData(@"3e8")]
[InlineData(@"child::*[self::chapter or self::appendix][position()=last()] child::*[self::chapter or self::appendix][position()=last()]")]
[Theory]
public void ErrorTest(string expression)
{
Assert.Throws<XPathParserException>(() => RunTestTree(expression));
}

static void RunTestString(string xpathExpr)
void RunTestString(string xpathExpr)
{
Debug.WriteLine("Translated one: {0}", new XPathParser<string>().Parse(xpathExpr, new XPathStringBuilder()));
_output.WriteLine("Translated one: {0}", new XPathParser<string>().Parse(xpathExpr, new XPathStringBuilder()));
}

static void RunTestTree(string xpathExpr)
void RunTestTree(string xpathExpr)
{
XElement xe = new XPathParser<XElement>().Parse(xpathExpr, new XPathTreeBuilder());
XmlWriterSettings ws = new XmlWriterSettings();
{
ws.Indent = true;
ws.OmitXmlDeclaration = true;
}
using (XmlWriter w = XmlWriter.Create(Console.Out, ws))
var sb = new StringBuilder();
using (XmlWriter w = XmlWriter.Create(sb, ws))
{
xe.WriteTo(w);
}
_output.WriteLine(sb.ToString());
}
}
}
Expand Down