Skip to content

Commit

Permalink
Fixed w3c example styling-css-08-f (#692)
Browse files Browse the repository at this point in the history
* Remove unnecessary condition.
* Revert to List.
* Added test.
  • Loading branch information
H1Gdev committed Mar 26, 2020
1 parent 4802007 commit 7f72d36
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
6 changes: 3 additions & 3 deletions Source/Css/SvgElementOps.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ public SvgElementOps(SvgElementFactory elementFactory)

public Selector<SvgElement> Type(NamespacePrefix prefix, string name)
{
SvgElementFactory.ElementInfo type = null;
if (_elementFactory.AvailableElements.TryGetValue(name, out type))
var types = _elementFactory.AvailableElements.Where(e => e.ElementName.Equals(name)).Select(e => e.ElementType);
if (types.Any())
{
return nodes => nodes.Where(n => n.GetType() == type.ElementType);
return nodes => nodes.Where(n => types.Contains(n.GetType()));
}
return nodes => Enumerable.Empty<SvgElement>();
}
Expand Down
14 changes: 6 additions & 8 deletions Source/SvgElementFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,13 @@ namespace Svg
/// </summary>
internal class SvgElementFactory
{
private Dictionary<string, ElementInfo> availableElements;
private List<ElementInfo> availableElements;
private Parser cssParser = new Parser();

/// <summary>
/// Gets a list of available types that can be used when creating an <see cref="SvgElement"/>.
/// </summary>
public Dictionary<string, ElementInfo> AvailableElements
public List<ElementInfo> AvailableElements
{
get
{
Expand All @@ -31,10 +31,7 @@ internal class SvgElementFactory
&& t.IsSubclassOf(typeof(SvgElement))
select new ElementInfo { ElementName = ((SvgElementAttribute)t.GetCustomAttributes(typeof(SvgElementAttribute), true)[0]).ElementName, ElementType = t };

availableElements = (from t in svgTypes
where t.ElementName != "svg"
group t by t.ElementName into types
select types).ToDictionary(e => e.Key, e => e.SingleOrDefault());
availableElements = svgTypes.ToList();
}

return availableElements;
Expand Down Expand Up @@ -94,8 +91,9 @@ private SvgElement CreateElement<T>(XmlReader reader, bool fragmentIsDocument, S
}
else
{
ElementInfo validType = null;
if (AvailableElements.TryGetValue(elementName, out validType))
ElementInfo validType;
if (AvailableElements.Where(e => !e.ElementName.Equals("svg", StringComparison.OrdinalIgnoreCase))
.ToDictionary(e => e.ElementName, e => e).TryGetValue(elementName, out validType))
{
createdElement = (SvgElement)Activator.CreateInstance(validType.ElementType);
}
Expand Down
1 change: 1 addition & 0 deletions Tests/Svg.UnitTests/PassingTests.csv
Original file line number Diff line number Diff line change
Expand Up @@ -155,6 +155,7 @@ styling-css-01-b
styling-css-02-b
styling-css-03-b
styling-css-07-f
styling-css-08-f
styling-inherit-01-b
styling-pres-01-t
text-align-01-b
Expand Down
1 change: 1 addition & 0 deletions Tests/W3CTestSuite/PassingTests.txt
Original file line number Diff line number Diff line change
Expand Up @@ -170,6 +170,7 @@ styling-css-02-b.svg
styling-css-03-b.svg
styling-css-04-f.svg
styling-css-07-f.svg
styling-css-08-f.svg
styling-inherit-01-b.svg
styling-pres-01-t.svg
text-align-01-b.svg
Expand Down

0 comments on commit 7f72d36

Please sign in to comment.