-
-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #81 from sveinungf/dev/srcgen-columnignore
Source generator - ColumnIgnore
- Loading branch information
Showing
16 changed files
with
160 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
SpreadCheetah.SourceGenerator.SnapshotTest/Tests/ColumnIgnoreTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
using SpreadCheetah.SourceGenerator.SnapshotTest.Helpers; | ||
|
||
namespace SpreadCheetah.SourceGenerator.SnapshotTest.Tests; | ||
|
||
public class ColumnIgnoreTests | ||
{ | ||
[Fact] | ||
public Task ColumnIgnore_ClassPropertyWithAnotherSpreadCheetahAttribute() | ||
{ | ||
// Arrange | ||
var context = AnalyzerTest.CreateContext(); | ||
context.TestCode = """ | ||
using SpreadCheetah.SourceGeneration; | ||
|
||
namespace MyNamespace; | ||
|
||
public class ClassWithColumnIgnore | ||
{ | ||
[{|SPCH1008:CellFormat("#.0#")|}] | ||
[ColumnIgnore] | ||
[{|SPCH1008:ColumnWidth(10)|}] | ||
public decimal Value { get; set; } | ||
} | ||
|
||
[WorksheetRow(typeof(ClassWithColumnIgnore))] | ||
public partial class MyGenRowContext : WorksheetRowContext; | ||
"""; | ||
|
||
// Act & Assert | ||
return context.RunAsync(); | ||
} | ||
|
||
[Fact] | ||
public Task ColumnIgnore_ClassPropertyWithAnotherUnrelatedAttribute() | ||
{ | ||
// Arrange | ||
var context = AnalyzerTest.CreateContext(); | ||
context.TestCode = """ | ||
using SpreadCheetah.SourceGeneration; | ||
using System.ComponentModel.DataAnnotations; | ||
|
||
namespace MyNamespace; | ||
|
||
public class ClassWithColumnIgnore | ||
{ | ||
[Required] | ||
[ColumnIgnore] | ||
public decimal Value { get; set; } | ||
} | ||
|
||
[WorksheetRow(typeof(ClassWithColumnIgnore))] | ||
public partial class MyGenRowContext : WorksheetRowContext; | ||
"""; | ||
|
||
// Act & Assert | ||
return context.RunAsync(); | ||
} | ||
} |
14 changes: 14 additions & 0 deletions
14
SpreadCheetah.SourceGenerator.Test/Models/ColumnIgnore/ClassWithMultipleProperties.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
using SpreadCheetah.SourceGeneration; | ||
|
||
namespace SpreadCheetah.SourceGenerator.Test.Models.ColumnIgnore; | ||
|
||
public class ClassWithMultipleProperties | ||
{ | ||
[ColumnIgnore] | ||
public int Id { get; set; } | ||
|
||
public string? Name { get; set; } | ||
|
||
[ColumnIgnore] | ||
public decimal Price { get; set; } | ||
} |
6 changes: 6 additions & 0 deletions
6
SpreadCheetah.SourceGenerator.Test/Models/ColumnIgnore/ColumnIgnoreContext.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
using SpreadCheetah.SourceGeneration; | ||
|
||
namespace SpreadCheetah.SourceGenerator.Test.Models.ColumnIgnore; | ||
|
||
[WorksheetRow(typeof(ClassWithMultipleProperties))] | ||
public partial class ColumnIgnoreContext : WorksheetRowContext; |
32 changes: 32 additions & 0 deletions
32
SpreadCheetah.SourceGenerator.Test/Tests/ColumnIgnoreTests.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
using SpreadCheetah.SourceGenerator.Test.Models.ColumnIgnore; | ||
using SpreadCheetah.TestHelpers.Assertions; | ||
using Xunit; | ||
|
||
namespace SpreadCheetah.SourceGenerator.Test.Tests; | ||
|
||
public class ColumnIgnoreTests | ||
{ | ||
[Fact] | ||
public async Task ColumnIgnore_ClassWithMultipleProperties() | ||
{ | ||
// Arrange | ||
using var stream = new MemoryStream(); | ||
await using var spreadsheet = await Spreadsheet.CreateNewAsync(stream); | ||
await spreadsheet.StartWorksheetAsync("Sheet"); | ||
var obj = new ClassWithMultipleProperties | ||
{ | ||
Id = 1, | ||
Name = "Foo", | ||
Price = 199.90m | ||
}; | ||
|
||
// Act | ||
await spreadsheet.AddAsRowAsync(obj, ColumnIgnoreContext.Default.ClassWithMultipleProperties); | ||
await spreadsheet.FinishAsync(); | ||
|
||
// Assert | ||
using var sheet = SpreadsheetAssert.SingleSheet(stream); | ||
Assert.Equal(obj.Name, sheet["A1"].StringValue); | ||
Assert.Single(sheet.Columns); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
namespace SpreadCheetah.SourceGenerator.Models; | ||
|
||
internal readonly record struct ColumnIgnore; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace SpreadCheetah.SourceGeneration; | ||
|
||
/// <summary> | ||
/// Instructs the SpreadCheetah source generator to ignore a property. | ||
/// </summary> | ||
[AttributeUsage(AttributeTargets.Property, AllowMultiple = false)] | ||
public sealed class ColumnIgnoreAttribute : Attribute; |