Skip to content
Merged
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
2 changes: 1 addition & 1 deletion src/Css/Css.cs
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ public override void Append(StringBuilder builder)
else if (Matching != null)
{
// Remove quotes around the value since we always add them back for XPath.
var value = Value.Trim('"');
var value = Value.Trim('"', '\'');

switch (Matching)
{
Expand Down
1 change: 0 additions & 1 deletion src/Tests/CssParserTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,6 @@ internal void CanParseTextSelector(string expression, string attributeName, stri
Assert.Equal(matching, selector.Matching);
}


[Fact]
public void CanParseSelector1()
{
Expand Down
30 changes: 30 additions & 0 deletions src/Tests/XPathTests.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.Linq;
using System.Text;
using System.Xml.Linq;
using Superpower;

Expand Down Expand Up @@ -90,4 +91,33 @@ public void ParseSelector()

Assert.NotNull(div);
}

[InlineData("[text()=hello world]", "[text()=\"hello world\"]")]
[InlineData("[text()='hello world']", "[text()=\"hello world\"]")]
[InlineData("[text()=\"hello world\"]", "[text()=\"hello world\"]")]
[InlineData("[text()*=\"hello world\"]", "[contains(text(),\"hello world\")]")]
[InlineData("[text()*='hello world']", "[contains(text(),\"hello world\")]")]
[InlineData("[data='hello world']", "[@data=\"hello world\"]")]
[InlineData("[data=hello world]", "[@data=\"hello world\"]")]
[InlineData("[data=\"hello world\"]", "[@data=\"hello world\"]")]
[InlineData("[data*=\"hello world\"]", "[contains(@data,\"hello world\")]")]
[InlineData("[data*='hello world']", "[contains(@data,\"hello world\")]")]
[Theory]
internal void AttributeSelectorNormalizesQuotes(string expression, string xpath)
{
var selector = (AttributeSelector)Parser.AttributeSelector.Parse(expression);

var builder = new StringBuilder();
selector.Append(builder);

Assert.Equal(xpath, builder.ToString());
}


[Fact]
public void RenderExpression()
{
var expression = "*[text()$=\"to go\"]";
Console.WriteLine(Parser.Parse(expression).ToXPath());
}
}