Skip to content

Commit

Permalink
Fix incorrect MoveNext in WorksheetStartXml
Browse files Browse the repository at this point in the history
  • Loading branch information
sveinungf committed Jul 12, 2024
1 parent f050b75 commit 000d4ab
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 6 deletions.
3 changes: 2 additions & 1 deletion SpreadCheetah.Test/Tests/SpreadsheetTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -348,7 +348,7 @@ public async Task Spreadsheet_StartWorksheet_MultipleWorksheets(int count)
[InlineData(10)]
[InlineData(100)]
[InlineData(2000)]
[InlineData(16384)]
[InlineData(16383)]
public async Task Spreadsheet_StartWorksheet_WorksheetWithMultipleColumnOptions(int count)
{
// Arrange
Expand All @@ -369,6 +369,7 @@ public async Task Spreadsheet_StartWorksheet_WorksheetWithMultipleColumnOptions(

// Assert
using var sheet = SpreadsheetAssert.SingleSheet(stream);
Assert.Equal(columnWidths.Count, sheet.Columns.Count);
Assert.Equal(columnWidths, sheet.Columns.Select(x => x.Width), new DoubleEqualityComparer(0.01d));
}

Expand Down
3 changes: 2 additions & 1 deletion SpreadCheetah.TestHelpers/Assertions/ClosedXmlAssertSheet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,8 @@ public ISpreadsheetAssertColumn Column(string columnName)
return new ClosedXmlAssertColumn(sheet.Column(columnName));
}

public IEnumerable<ISpreadsheetAssertColumn> Columns => sheet.Columns().Select(x => new ClosedXmlAssertColumn(x));
private IReadOnlyList<ISpreadsheetAssertColumn>? _columns;
public IReadOnlyList<ISpreadsheetAssertColumn> Columns => _columns ??= [.. sheet.Columns().Select(x => new ClosedXmlAssertColumn(x))];

public IEnumerable<ISpreadsheetAssertCell> Row(int rowNumber)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,6 @@ public interface ISpreadsheetAssertSheet : IDisposable
int RowCount { get; }

ISpreadsheetAssertColumn Column(string columnName);
IEnumerable<ISpreadsheetAssertColumn> Columns { get; }
IReadOnlyList<ISpreadsheetAssertColumn> Columns { get; }
IEnumerable<ISpreadsheetAssertCell> Row(int rowNumber);
}
8 changes: 5 additions & 3 deletions SpreadCheetah/MetadataXml/WorksheetStartXml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,16 +46,18 @@ private WorksheetStartXml(WorksheetOptions? options, SpreadsheetBuffer buffer)

public bool MoveNext()
{
var current = _next switch
Current = _next switch
{
Element.Header => _buffer.TryWrite(Header),
Element.SheetViews => TryWriteSheetViews(_buffer),
Element.Columns => TryWriteColumns(_buffer),
_ => _buffer.TryWrite(SheetDataBegin)
};

Current = current;
return current && ++_next < Element.Done;
if (Current)
++_next;

return _next < Element.Done;
}

private readonly bool TryWriteSheetViews(SpreadsheetBuffer buffer)
Expand Down

0 comments on commit 000d4ab

Please sign in to comment.