Skip to content

Commit 5fd3dcb

Browse files
committed
Fix busted tests due to a bug in PeriodicValueConverter
Some places was using just .Periodic() without any labels specified which triggered the debug assertion that the label count was 2 or 4. Because all the value converter stuff is static, the exception raised during the static constructor crashed the XUnit test runner process and masked the fact these tests were failing because they was never actually being run. Fixed by treating the case of no labels the same as 4 for backwards compatibility.
1 parent b11b12e commit 5fd3dcb

1 file changed

Lines changed: 6 additions & 6 deletions

File tree

src/ExCSS/ValueConverters/PeriodicValueConverter.cs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ internal sealed class PeriodicValueConverter : IValueConverter
1111

1212
public PeriodicValueConverter(IValueConverter converter, string[] labels)
1313
{
14-
Debug.Assert(labels.Length == 4 || labels.Length == 2);
14+
Debug.Assert(labels.Length == 0 || labels.Length == 4 || labels.Length == 2);
1515

1616
_converter = converter;
1717
_labels = labels;
@@ -20,7 +20,7 @@ public PeriodicValueConverter(IValueConverter converter, string[] labels)
2020
public IPropertyValue Convert(IEnumerable<Token> value)
2121
{
2222
var list = new List<Token>(value);
23-
var options = new IPropertyValue[_labels.Length];
23+
var options = new IPropertyValue[_labels.Length == 0 ? 4 : _labels.Length];
2424

2525
if (list.Count == 0) return null;
2626

@@ -53,11 +53,11 @@ private sealed class PeriodicValue : IPropertyValue
5353

5454
public PeriodicValue(IPropertyValue[] options, IEnumerable<Token> tokens, string[] labels)
5555
{
56-
Debug.Assert(labels.Length == 2 || labels.Length == 4);
56+
Debug.Assert(labels.Length == 0 || labels.Length == 2 || labels.Length == 4);
5757

58-
_values = new IPropertyValue[labels.Length];
58+
_values = new IPropertyValue[labels.Length == 0 ? 4 : labels.Length];
5959

60-
if (labels.Length == 4)
60+
if (_values.Length == 0 || _values.Length == 4)
6161
{
6262
//Top, right, bottom, left
6363
_values[0] = options[0];
@@ -79,7 +79,7 @@ private string[] Values
7979
{
8080
get
8181
{
82-
if (_values.Length == 4)
82+
if (_values.Length == 0 || _values.Length == 4)
8383
{
8484
var top = _values[0].CssText;
8585
var right = _values[1].CssText;

0 commit comments

Comments
 (0)