Skip to content

Commit

Permalink
delinting - collection initialisers, any() -> count, .ToList().AsRead…
Browse files Browse the repository at this point in the history
…Only()
  • Loading branch information
mikeclayton committed May 25, 2024
1 parent da9f20c commit 33e99e1
Show file tree
Hide file tree
Showing 50 changed files with 392 additions and 484 deletions.
5 changes: 1 addition & 4 deletions src/Kingsland.MofParser.UnitTests/CodeGen/RoundtripTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -58,10 +58,7 @@ private static void AssertRoundtrip(
ParserQuirks parserQuirks = ParserQuirks.None
)
{
if (expectedTokens is null)
{
throw new ArgumentNullException(nameof(expectedTokens));
}
ArgumentNullException.ThrowIfNull(expectedTokens);
// check the lexer generates the expected tokens
var actualTokens = Lexer.Lex(SourceReader.From(sourceText)).ToList();
LexerAssert.AreEqual(expectedTokens, actualTokens, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,15 +37,14 @@ association GOLF_MemberLocker
.ToList();
var expectedAst = new MofSpecificationAst.Builder
{
Productions = new List<MofProductionAst>
{
Productions = [
new AssociationDeclarationAst(
new QualifierListAst(),
new IdentifierToken("GOLF_MemberLocker"),
null,
new List<IClassFeatureAst>()
[]
)
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down Expand Up @@ -103,11 +102,11 @@ public static void AssociationDeclarationWithSuperAssociationShouldRoundtrip()
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new AssociationDeclarationAst.Builder {
AssociationName = new IdentifierToken("GOLF_MemberLocker"),
SuperAssociation = new IdentifierToken("GOLF_Base"),
ClassFeatures = new List<IClassFeatureAst> {
ClassFeatures = [
new PropertyDeclarationAst.Builder {
ReturnType = new IdentifierToken("GOLF_ClubMember"),
ReturnTypeRef = new IdentifierToken("REF"),
Expand All @@ -122,9 +121,9 @@ public static void AssociationDeclarationWithSuperAssociationShouldRoundtrip()
ReturnType = new IdentifierToken("GOLF_Date"),
PropertyName = new IdentifierToken("AssignedOnDate"),
}.Build()
}
]
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down Expand Up @@ -179,10 +178,10 @@ association GOLF_MemberLocker
.ToList();
var expectedAst = new MofSpecificationAst.Builder
{
Productions = new List<MofProductionAst> {
Productions = [
new AssociationDeclarationAst.Builder {
AssociationName = new IdentifierToken("GOLF_MemberLocker"),
ClassFeatures = new List<IClassFeatureAst> {
ClassFeatures = [
new PropertyDeclarationAst.Builder {
ReturnType = new IdentifierToken("GOLF_ClubMember"),
ReturnTypeRef = new IdentifierToken("REF"),
Expand All @@ -197,9 +196,9 @@ association GOLF_MemberLocker
ReturnType = new IdentifierToken("GOLF_Date"),
PropertyName = new IdentifierToken("AssignedOnDate"),
}.Build()
}
]
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,27 +53,26 @@ instance of myType as $Alias00000070
.ToList();
var expectedAst = new MofSpecificationAst.Builder
{
Productions = new List<MofProductionAst> {
Productions = [
new InstanceValueDeclarationAst.Builder {
Instance = new IdentifierToken("instance"),
Of = new IdentifierToken("of"),
TypeName = new IdentifierToken("myType"),
As = new IdentifierToken("as"),
Alias = new AliasIdentifierToken("Alias00000070"),
PropertyValues = new PropertyValueListAst.Builder {
PropertySlots = new()
{
new(
PropertySlots = [
new PropertySlotAst(
new("Reference"),
new BooleanValueAst(
new BooleanLiteralToken("TRUE", true)
)
)
}
]
}.Build(),
StatementEnd = new StatementEndToken()
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ class GOLF_Base
Productions = new List<MofProductionAst> {
new ClassDeclarationAst.Builder {
ClassName = new IdentifierToken("GOLF_Base"),
ClassFeatures = new List<IClassFeatureAst>()
ClassFeatures = []
}.Build()
}
}.Build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -51,30 +51,28 @@ class Sponsor
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new ClassDeclarationAst.Builder {
ClassName = new IdentifierToken("Sponsor"),
ClassFeatures = new List<IClassFeatureAst> {
ClassFeatures = [
new PropertyDeclarationAst.Builder {
QualifierList = new QualifierListAst(
new List<QualifierValueAst> {
new QualifierValueAst.Builder {
QualifierName = new IdentifierToken("Description"),
Initializer = new QualifierValueInitializerAst(
new StringValueAst(
new StringLiteralToken("Monthly salary in $US"),
"Monthly salary in $US"
)
QualifierList = new QualifierListAst( [
new QualifierValueAst.Builder {
QualifierName = new IdentifierToken("Description"),
Initializer = new QualifierValueInitializerAst(
new StringValueAst(
new StringLiteralToken("Monthly salary in $US"),
"Monthly salary in $US"
)
}.Build()
}
),
)
}.Build()
]),
ReturnType = new IdentifierToken("string"),
PropertyName = new IdentifierToken("Name")
}.Build()
},
],
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down Expand Up @@ -137,16 +135,16 @@ structure Nested
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new ClassDeclarationAst.Builder {
ClassName = new IdentifierToken("Sponsor"),
ClassFeatures = new List<IClassFeatureAst> {
ClassFeatures = [
new StructureDeclarationAst.Builder {
StructureName = new IdentifierToken("Nested")
}.Build()
},
],
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down Expand Up @@ -194,17 +192,17 @@ class Sponsor
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new ClassDeclarationAst.Builder {
ClassName = new IdentifierToken("Sponsor"),
ClassFeatures = new List<IClassFeatureAst> {
ClassFeatures = [
new EnumerationDeclarationAst.Builder {
EnumName = new IdentifierToken("MonthsEnum"),
EnumType = new IdentifierToken("Integer")
}.Build()
},
],
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down Expand Up @@ -240,17 +238,17 @@ class Sponsor
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new ClassDeclarationAst.Builder {
ClassName = new IdentifierToken("Sponsor"),
ClassFeatures = new List<IClassFeatureAst> {
ClassFeatures = [
new PropertyDeclarationAst.Builder {
PropertyName = new IdentifierToken("Name"),
ReturnType = new IdentifierToken("string")
}.Build()
},
],
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public static void CompilerDirectiveShouldRoundtrip()
.ParenthesisCloseToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new CompilerDirectiveAst.Builder {
PragmaKeyword = new PragmaToken("pragma"),
PragmaName = new IdentifierToken("include"),
Expand All @@ -40,7 +40,7 @@ public static void CompilerDirectiveShouldRoundtrip()
"GlobalStructs/GOLF_Address.mof"
)
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand All @@ -66,20 +66,20 @@ public static void CompilerDirectiveWithMultipleSingleStringsShouldRoundtrip() {
.ParenthesisCloseToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new CompilerDirectiveAst.Builder {
PragmaKeyword = new PragmaToken("pragma"),
PragmaName = new IdentifierToken("include"),
PragmaParameter = new StringValueAst(
new List<StringLiteralToken> {
[
new StringLiteralToken("GlobalStructs"),
new StringLiteralToken("/"),
new StringLiteralToken("GOLF_Address.mof")
},
],
"GlobalStructs/GOLF_Address.mof"
)
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,22 @@ instance of GOLF_ClubMember
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new InstanceValueDeclarationAst.Builder {
Instance = new IdentifierToken("instance"),
Of = new IdentifierToken("of"),
TypeName = new IdentifierToken("GOLF_ClubMember"),
PropertyValues = new PropertyValueListAst(
new List<PropertySlotAst> {
new PropertySlotAst.Builder {
PropertyName = new IdentifierToken("LastPaymentDate"),
PropertyValue = new ComplexValueAst.Builder {
Alias = new AliasIdentifierToken("MyAliasIdentifier")
}.Build()
}.Build()
}
),
PropertyValues = new PropertyValueListAst([
new PropertySlotAst.Builder {
PropertyName = new IdentifierToken("LastPaymentDate"),
PropertyValue = new ComplexValueAst.Builder {
Alias = new AliasIdentifierToken("MyAliasIdentifier")
}.Build()
}.Build()
]),
StatementEnd = new StatementEndToken()
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down Expand Up @@ -107,28 +105,24 @@ instance of GOLF_ClubMember
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new InstanceValueDeclarationAst.Builder {
Instance = new IdentifierToken("instance"),
Of = new IdentifierToken("of"),
TypeName = new IdentifierToken("GOLF_ClubMember"),
PropertyValues = new PropertyValueListAst(
new List<PropertySlotAst> {
new PropertySlotAst.Builder {
PropertyName = new IdentifierToken("LastPaymentDate"),
PropertyValue = new ComplexValueArrayAst(
new List<ComplexValueAst> {
new ComplexValueAst.Builder {
Alias = new AliasIdentifierToken("MyAliasIdentifier")
}.Build()
}
)
}.Build()
}
),
PropertyValues = new PropertyValueListAst([
new PropertySlotAst.Builder {
PropertyName = new IdentifierToken("LastPaymentDate"),
PropertyValue = new ComplexValueArrayAst([
new ComplexValueAst.Builder {
Alias = new AliasIdentifierToken("MyAliasIdentifier")
}.Build()
])
}.Build()
]),
StatementEnd = new StatementEndToken()
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down
Loading

0 comments on commit 33e99e1

Please sign in to comment.