Skip to content

Commit 5c416a9

Browse files
authored
Merge pull request #57 from JansthcirlU/56-add-tests-for-exhaustive-enum-checking
Fixed enum exhaustiveness, treat warnings as errors
2 parents bbe06c8 + a9d38d4 commit 5c416a9

File tree

8 files changed

+36
-5
lines changed

8 files changed

+36
-5
lines changed

src/Mermaid.Flowcharts/Mermaid.Flowcharts.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
<TargetFrameworks>net8.0;net9.0;net10.0</TargetFrameworks>
55
<ImplicitUsings>enable</ImplicitUsings>
66
<Nullable>enable</Nullable>
7+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
78
</PropertyGroup>
89

910
<PropertyGroup>

src/Mermaid.Flowcharts/Styling/Attributes/DashOffset.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ private string ToSubtypeMermaidString()
6161
{
6262
LengthDashOffset ldo => ldo.LengthOffset.ToCss(),
6363
PercentageDashOffset pdo => pdo.PercentageOffset.ToNumericalString(),
64-
NumericalDashOffset ndo => ndo.Size.ToNumberString()
64+
NumericalDashOffset ndo => ndo.Size.ToNumberString(),
65+
_ => throw new NotImplementedException($"Cannot convert unsupported {nameof(DashOffset)} subtype to Mermaid string: {GetType().Name}.")
6566
};
6667
}

src/Mermaid.Flowcharts/Styling/Attributes/DashSize.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ public string ToMermaidString()
6161
{
6262
LengthDashSize lds => lds.LengthSize.ToCss(),
6363
PercentageDashSize pds => pds.PercentageSize.ToNumericalString(),
64-
NumericalDashSize nds => nds.Size.ToNumberString()
64+
NumericalDashSize nds => nds.Size.ToNumberString(),
65+
_ => throw new NotImplementedException($"Cannot convert unsupported {nameof(DashSize)} subtype to Mermaid string: {GetType().Name}.")
6566
};
6667
}

src/Mermaid.Flowcharts/Styling/Attributes/Fonts/FontSize.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ private string ToSubtypeMermaidString()
3939
AbsoluteFontSize afs => afs.Size.ToAbsoluteSizeString(),
4040
RelativeFontSize rfs => rfs.Size.ToRelativeSizeString(),
4141
PercentageFontSize pfs => pfs.SizePercentage.ToNumericalString(),
42-
LengthFontSize lfs => lfs.SizeLength.ToCss()
42+
LengthFontSize lfs => lfs.SizeLength.ToCss(),
43+
_ => throw new NotImplementedException($"Cannot convert unsupported {nameof(FontSize)} subtype to Mermaid string: {GetType().Name}.")
4344
};
4445
}

src/Mermaid.Flowcharts/Styling/Attributes/Fonts/FontWeight.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ private string ToSubtypeMermaidString()
4343
=> this switch
4444
{
4545
RelativeFontWeight rfw => rfw.Weight.ToFontWeightTypeString(),
46-
NumericalFontWeight nfw => nfw.Weight.ToNumberString()
46+
NumericalFontWeight nfw => nfw.Weight.ToNumberString(),
47+
_ => throw new NotImplementedException($"Cannot convert unsupported {nameof(FontWeight)} subtype to Mermaid string: {GetType().Name}.")
4748
};
4849
}

src/Mermaid.Flowcharts/Styling/Attributes/StrokeWidth.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,7 @@ private string ToSubtypeMermaidString()
5151
{
5252
LengthStrokeWidth lsw => lsw.Width.ToCss(),
5353
PercentageStrokeWidth psw => psw.PercentageWidth.ToNumericalString(),
54-
NumericalStrokeWidth nsw => nsw.Width.ToNumberString()
54+
NumericalStrokeWidth nsw => nsw.Width.ToNumberString(),
55+
_ => throw new NotImplementedException($"Cannot convert unsupported {nameof(StrokeWidth)} subtype to Mermaid string: {GetType().Name}.")
5556
};
5657
}

src/Mermaid.Flowcharts/Styling/EnumExtensions.cs

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,21 @@ public static string ToAbsoluteSizeString(this AbsoluteSize absoluteSize)
1515
AbsoluteSize.XLarge => "x-large",
1616
AbsoluteSize.XxLarge => "xx-large",
1717
AbsoluteSize.XxxLarge => "xxx-large",
18+
_ => throw new ArgumentOutOfRangeException(
19+
nameof(absoluteSize),
20+
absoluteSize,
21+
$"Unsupported {nameof(AbsoluteSize)} value: {absoluteSize}.")
1822
};
1923

2024
public static string ToRelativeSizeString(this RelativeSize relativeSize)
2125
=> relativeSize switch
2226
{
2327
RelativeSize.Larger => "larger",
2428
RelativeSize.Smaller => "smaller",
29+
_ => throw new ArgumentOutOfRangeException(
30+
nameof(relativeSize),
31+
relativeSize,
32+
$"Unsupported {nameof(RelativeSize)} value: {relativeSize}.")
2533
};
2634

2735
public static string ToFontWeightTypeString(this FontWeightType fontWeight)
@@ -31,6 +39,10 @@ public static string ToFontWeightTypeString(this FontWeightType fontWeight)
3139
FontWeightType.Bold => "bold",
3240
FontWeightType.Bolder => "bolder",
3341
FontWeightType.Lighter => "lighter",
42+
_ => throw new ArgumentOutOfRangeException(
43+
nameof(fontWeight),
44+
fontWeight,
45+
$"Unsupported {nameof(FontWeightType)} value: {fontWeight}.")
3446
};
3547

3648
public static string ToStrokeLineCapTypeString(this StrokeLineCapType strokeLineCapType)
@@ -39,6 +51,10 @@ public static string ToStrokeLineCapTypeString(this StrokeLineCapType strokeLine
3951
StrokeLineCapType.Butt => "butt",
4052
StrokeLineCapType.Round => "round",
4153
StrokeLineCapType.Square => "square",
54+
_ => throw new ArgumentOutOfRangeException(
55+
nameof(strokeLineCapType),
56+
strokeLineCapType,
57+
$"Unsupported {nameof(StrokeLineCapType)} value: {strokeLineCapType}.")
4258
};
4359

4460
public static string ToStrokeLineJoinTypeString(this StrokeLineJoinType strokeLineJoinType)
@@ -49,6 +65,10 @@ public static string ToStrokeLineJoinTypeString(this StrokeLineJoinType strokeLi
4965
StrokeLineJoinType.Bevel => "bevel",
5066
StrokeLineJoinType.MiterClip => "miter-clip",
5167
StrokeLineJoinType.Round => "round",
68+
_ => throw new ArgumentOutOfRangeException(
69+
nameof(strokeLineJoinType),
70+
strokeLineJoinType,
71+
$"Unsupported {nameof(StrokeLineJoinType)} value: {strokeLineJoinType}.")
5272
};
5373

5474
public static string ToUnitString(this Unit unit)
@@ -68,5 +88,9 @@ public static string ToUnitString(this Unit unit)
6888
Unit.Mm => "mm",
6989
Unit.Cm => "cm",
7090
Unit.In => "in",
91+
_ => throw new ArgumentOutOfRangeException(
92+
nameof(unit),
93+
unit,
94+
$"Unsupported {nameof(Unit)} value: {unit}.")
7195
};
7296
}

tests/Mermaid.Flowcharts.Tests/Mermaid.Flowcharts.Tests.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
<Nullable>enable</Nullable>
77
<IsPackable>false</IsPackable>
88
<IsTestProject>true</IsTestProject>
9+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
910
</PropertyGroup>
1011

1112
<ItemGroup>

0 commit comments

Comments
 (0)