Browse Source

Fix class selector string representation.

Steven Kirk 10 years ago
parent
commit
c68cd8a48b

+ 16 - 0
Tests/Perspex.Styling.UnitTests/SelectorTests_Class.cs

@@ -15,6 +15,22 @@ namespace Perspex.Styling.UnitTests
 
     public class SelectorTests_Class
     {
+        [Fact]
+        public void Class_Selector_Should_Have_Correct_String_Representation()
+        {
+            var target = new Selector().Class("foo");
+
+            Assert.Equal(".foo", target.ToString());
+        }
+
+        [Fact]
+        public void PesudoClass_Selector_Should_Have_Correct_String_Representation()
+        {
+            var target = new Selector().Class(":foo");
+
+            Assert.Equal(":foo", target.ToString());
+        }
+
         [Fact]
         public async Task Class_Matches_Control_With_Class()
         {

+ 1 - 1
src/Perspex.Styling/Styling/Selectors.cs

@@ -25,7 +25,7 @@ namespace Perspex.Styling
             Contract.Requires<ArgumentNullException>(previous != null);
             Contract.Requires<ArgumentNullException>(name != null);
 
-            return new Selector(previous, x => MatchClass(x, name), name);
+            return new Selector(previous, x => MatchClass(x, name), name[0] == ':' ? name : '.' + name);
         }
 
         public static Selector Descendent(this Selector previous)