Skip to content

Commit a394959

Browse files
committed
Added more tests for grid-template
1 parent 6343924 commit a394959

File tree

4 files changed

+106
-3
lines changed

4 files changed

+106
-3
lines changed

src/AngleSharp.Css.Tests/Declarations/CssGridProperty.cs

Lines changed: 84 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -628,7 +628,7 @@ public void CssGridLengthAndLengthLegal()
628628
}
629629

630630
[Test]
631-
public void CssGridStirngMinmaxAndStringLegal()
631+
public void CssGridStringMinmaxAndStringLegal()
632632
{
633633
var snippet = @"grid: ""a"" minmax(100px, max-content) ""b"" 20%";
634634
var property = ParseDeclaration(snippet);
@@ -676,5 +676,88 @@ public void CssGridNoneLegal()
676676
Assert.IsTrue(property.HasValue);
677677
Assert.AreEqual("none", property.Value);
678678
}
679+
680+
[Test]
681+
public void CssGridTemplateNoneLegal()
682+
{
683+
var snippet = @"grid-template: none";
684+
var property = ParseDeclaration(snippet);
685+
Assert.AreEqual("grid-template", property.Name);
686+
Assert.IsTrue(property.HasValue);
687+
Assert.AreEqual("none", property.Value);
688+
}
689+
690+
[Test]
691+
public void CssGridTemplateLineNamesAndStringWithFractionsLegal()
692+
{
693+
var snippet = @"grid-template: [header-top] ""a a a"" [header-bottom]
694+
[main-top] ""b b b"" 1fr [main-bottom] / auto 1fr auto";
695+
var property = ParseDeclaration(snippet);
696+
Assert.AreEqual("grid-template", property.Name);
697+
Assert.IsTrue(property.HasValue);
698+
Assert.AreEqual("[header-top] \"a a a\" [header-bottom] [main-top] \"b b b\" 1fr [main-bottom] / auto 1fr auto", property.Value);
699+
}
700+
701+
[Test]
702+
public void CssGridTemplateStirngsAndWidthsLegal()
703+
{
704+
var snippet = @"grid-template: ""a a a"" 20%
705+
""b b b"" auto";
706+
var property = ParseDeclaration(snippet);
707+
Assert.AreEqual("grid-template", property.Name);
708+
Assert.IsTrue(property.HasValue);
709+
Assert.AreEqual("\"a a a\" 20% \"b b b\" auto", property.Value);
710+
}
711+
712+
[Test]
713+
public void CssGridTemplateStringsLegal()
714+
{
715+
var snippet = @"grid-template: ""a a a""
716+
""b b b""";
717+
var property = ParseDeclaration(snippet);
718+
Assert.AreEqual("grid-template", property.Name);
719+
Assert.IsTrue(property.HasValue);
720+
Assert.AreEqual("\"a a a\" \"b b b\"", property.Value);
721+
}
722+
723+
[Test]
724+
public void CssGridTemplateFitContentColumnsAndRowsLegal()
725+
{
726+
var snippet = @"grid-template: fit-content(100px) / fit-content(40%)";
727+
var property = ParseDeclaration(snippet);
728+
Assert.AreEqual("grid-template", property.Name);
729+
Assert.IsTrue(property.HasValue);
730+
Assert.AreEqual("fit-content(100px) / fit-content(40%)", property.Value);
731+
}
732+
733+
[Test]
734+
public void CssGridTemplateLineNamesAndPercentagesLegal()
735+
{
736+
var snippet = @"grid-template: [linename] 100px / [columnname1] 30% [columnname2] 70%";
737+
var property = ParseDeclaration(snippet);
738+
Assert.AreEqual("grid-template", property.Name);
739+
Assert.IsTrue(property.HasValue);
740+
Assert.AreEqual("[linename] 100px / [columnname1] 30% [columnname2] 70%", property.Value);
741+
}
742+
743+
[Test]
744+
public void CssGridTemplateRowsAndColumnsWithAutoLegal()
745+
{
746+
var snippet = @"grid-template: auto 1fr / auto 1fr auto";
747+
var property = ParseDeclaration(snippet);
748+
Assert.AreEqual("grid-template", property.Name);
749+
Assert.IsTrue(property.HasValue);
750+
Assert.AreEqual("auto 1fr / auto 1fr auto", property.Value);
751+
}
752+
753+
[Test]
754+
public void CssGridTemplateRowsAndColumnsWithFractionsLegal()
755+
{
756+
var snippet = @"grid-template: 100px 1fr / 50px 1fr";
757+
var property = ParseDeclaration(snippet);
758+
Assert.AreEqual("grid-template", property.Name);
759+
Assert.IsTrue(property.HasValue);
760+
Assert.AreEqual("100px 1fr / 50px 1fr", property.Value);
761+
}
679762
}
680763
}

src/AngleSharp.Css/Declarations/GridDeclaration.cs

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,11 @@ public ICssValue Merge(ICssValue[] values)
122122
var templateColumns = values[1];
123123
var templateAreas = values[2];
124124

125-
if (templateRows != null && templateColumns != null)
125+
if (templateRows == templateColumns && templateRows == templateAreas)
126+
{
127+
return templateRows;
128+
}
129+
else if (templateRows != null && templateColumns != null)
126130
{
127131
return new GridTemplate(templateRows, templateColumns, templateAreas);
128132
}
@@ -150,6 +154,22 @@ public ICssValue[] Split(ICssValue value)
150154
null,
151155
};
152156
}
157+
else if (value is Identifier)
158+
{
159+
return new[]
160+
{
161+
value,
162+
value,
163+
value,
164+
null,
165+
null,
166+
null,
167+
null,
168+
null,
169+
null,
170+
null,
171+
};
172+
}
153173

154174
return null;
155175
}

src/AngleSharp.Css/DefaultDeclarationFactory.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1374,6 +1374,7 @@ public class DefaultDeclarationFactory : IDeclarationFactory
13741374
GridDeclaration.Name, new DeclarationInfo(
13751375
name: GridDeclaration.Name,
13761376
converter: GridDeclaration.Converter,
1377+
longhands: GridDeclaration.Longhands,
13771378
flags: GridDeclaration.Flags)
13781379
},
13791380
{

src/AngleSharp.Css/Parser/Micro/GridParser.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,6 @@ public static ICssValue ParseGridTemplate(this StringSource source)
3232
return new GridTemplate(rows, cols, null);
3333
}
3434
}
35-
3635
}
3736
else
3837
{

0 commit comments

Comments
 (0)