Skip to content

Commit

Permalink
adding more Model values and types
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeclayton committed May 27, 2024
1 parent 33e99e1 commit fac4cc6
Show file tree
Hide file tree
Showing 51 changed files with 1,418 additions and 746 deletions.
25 changes: 15 additions & 10 deletions src/Kingsland.MofParser.HtmlReport/Resources/DscResource.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
using Kingsland.MofParser.Models;
using Kingsland.MofParser.Models.Types;
using Kingsland.MofParser.Models.Values;
using System.Collections.ObjectModel;

namespace Kingsland.MofParser.HtmlReport.Resources;
Expand Down Expand Up @@ -53,13 +55,11 @@ public Instance Instance
: DscResource.GetResourceNameFromResourceId(this.ResourceId);

public ReadOnlyCollection<string> DependsOn =>
new(
new List<string>(
this.Instance.Properties.Single(
property => property.Name == "ResourceID"
).Value as string[] ?? Enumerable.Empty<string>()
)
);
this.Instance.Properties
.Where(property => property.Name == "ResourceID")
.SelectMany(property => ((LiteralValueArray)property.Value).Values)
.Select(literalValue => ((StringValue)literalValue).Value)
.ToList().AsReadOnly();

public string? ModuleName =>
this.GetStringProperty(nameof(this.ModuleName));
Expand Down Expand Up @@ -98,9 +98,14 @@ public static DscResource FromInstance(string filename, string computerName, Ins

protected string? GetStringProperty(string propertyName)
{
return this.Instance.Properties.SingleOrDefault(
property => property.Name == propertyName
)?.Value as string;
var property = this.Instance.Properties
.SingleOrDefault(property => property.Name == propertyName);
if (property is null)
{
return null;
}
var value = ((StringValue)property.Value).Value;
return value;
}

#endregion
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using Kingsland.MofParser.Models;
using Kingsland.MofParser.Models.Types;

namespace Kingsland.MofParser.HtmlReport.Resources;

Expand Down
8 changes: 3 additions & 5 deletions src/Kingsland.MofParser.HtmlReport/Wrappers/ResourceGroup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,9 @@ public ResourceGroup(
{
this.Filename = filename ?? throw new ArgumentNullException(nameof(filename));
this.ComputerName = computerName ?? throw new ArgumentNullException(nameof(computerName));
this.Wrappers = new(
new List<DscResource>(
wrappers ?? throw new ArgumentNullException(nameof(wrappers))
)
);
this.Wrappers = new List<DscResource>(
wrappers ?? throw new ArgumentNullException(nameof(wrappers))
).AsReadOnly();
}

public string Filename
Expand Down
9 changes: 8 additions & 1 deletion src/Kingsland.MofParser.UnitTests/CodeGen/RoundtripTests.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
using Kingsland.MofParser.Ast;
using Kingsland.MofParser.CodeGen;
using Kingsland.MofParser.Lexing;
using Kingsland.MofParser.Models;
using Kingsland.MofParser.Models.Converter;
using Kingsland.MofParser.Models.Types;
using Kingsland.MofParser.Parsing;
using Kingsland.MofParser.UnitTests.Helpers;
using Kingsland.ParseFx.Parsing;
Expand Down Expand Up @@ -80,6 +81,12 @@ private static void AssertRoundtrip(
)
);
Assert.That(actualAstText, Is.EqualTo(sourceText));
// check the model converter works
var actualModule = ModelConverter.ConvertMofSpecificationAst(actualAst);
if (expectedModule is not null)
{
ModelAssert.AreDeepEqual(actualModule, expectedModule);
}
}

private static void AssertRoundtripException(string sourceText, string expectedMessage, ParserQuirks parserQuirks = ParserQuirks.None)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,12 +36,12 @@ class GOLF_Base
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new ClassDeclarationAst.Builder {
ClassName = new IdentifierToken("GOLF_Base"),
ClassFeatures = []
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down Expand Up @@ -73,12 +73,12 @@ class GOLF_Base : GOLF_Superclass
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new ClassDeclarationAst.Builder {
ClassName = new IdentifierToken("GOLF_Base"),
SuperClass = new IdentifierToken("GOLF_Superclass"),
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down Expand Up @@ -125,10 +125,10 @@ class GOLF_Base
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new ClassDeclarationAst.Builder {
ClassName = new IdentifierToken("GOLF_Base"),
ClassFeatures = new List<IClassFeatureAst> {
ClassFeatures = [
new PropertyDeclarationAst.Builder {
ReturnType = new IdentifierToken("string"),
PropertyName = new IdentifierToken("InstanceID"),
Expand All @@ -140,9 +140,9 @@ class GOLF_Base
new NullLiteralToken("Null")
)
}.Build()
}
]
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down Expand Up @@ -227,61 +227,57 @@ class GOLF_Base
.StatementEndToken()
.ToList();
var expectedAst = new MofSpecificationAst.Builder {
Productions = new List<MofProductionAst> {
Productions = [
new ClassDeclarationAst.Builder {
ClassName = new IdentifierToken("GOLF_Base"),
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("an instance of a class that derives from the GOLF_Base class. "),
"an instance of a class that derives from the GOLF_Base class. "
)
QualifierList = new QualifierListAst([
new QualifierValueAst.Builder {
QualifierName = new IdentifierToken("Description"),
Initializer = new QualifierValueInitializerAst(
new StringValueAst(
new StringLiteralToken("an instance of a class that derives from the GOLF_Base class. "),
"an instance of a class that derives from the GOLF_Base class. "
)
}.Build(),
new QualifierValueAst.Builder {
QualifierName = new IdentifierToken("Key"),
}.Build()
}
),
)
}.Build(),
new QualifierValueAst.Builder {
QualifierName = new IdentifierToken("Key"),
}.Build()
]),
ReturnType = new IdentifierToken("string"),
PropertyName = new IdentifierToken("InstanceID")
}.Build(),
new PropertyDeclarationAst.Builder {
QualifierList = new QualifierListAst(
new List<QualifierValueAst> {
new QualifierValueAst.Builder {
QualifierName = new IdentifierToken("Description"),
Initializer = new QualifierValueInitializerAst(
new StringValueAst(
new StringLiteralToken("A short textual description (one- line string) of the"),
"an instance of a class that derives from the GOLF_Base class. "
)
QualifierList = new QualifierListAst([
new QualifierValueAst.Builder {
QualifierName = new IdentifierToken("Description"),
Initializer = new QualifierValueInitializerAst(
new StringValueAst(
new StringLiteralToken("A short textual description (one- line string) of the"),
"an instance of a class that derives from the GOLF_Base class. "
)
}.Build(),
new QualifierValueAst.Builder {
QualifierName = new IdentifierToken("MaxLen"),
Initializer = new QualifierValueInitializerAst(
new IntegerValueAst(
new IntegerLiteralToken(IntegerKind.DecimalValue, 64)
)
)
}.Build(),
new QualifierValueAst.Builder {
QualifierName = new IdentifierToken("MaxLen"),
Initializer = new QualifierValueInitializerAst(
new IntegerValueAst(
new IntegerLiteralToken(IntegerKind.DecimalValue, 64)
)
}.Build()
}
),
)
}.Build()
]),
ReturnType = new IdentifierToken("string"),
PropertyName = new IdentifierToken("Caption"),
Initializer = new NullValueAst(
new NullLiteralToken("Null")
)
}.Build()
},
],
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
using Kingsland.MofParser.Ast;
using Kingsland.MofParser.Models;
using Kingsland.MofParser.Models.Types;
using Kingsland.MofParser.Models.Values;
using Kingsland.MofParser.Tokens;
using Kingsland.MofParser.UnitTests.Extensions;
using NUnit.Framework;
Expand Down Expand Up @@ -48,25 +51,23 @@ 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()
PropertyValues = new PropertyValueListAst([
new PropertySlotAst.Builder {
PropertyName = new IdentifierToken("LastPaymentDate"),
PropertyValue = new ComplexValueAst.Builder {
Alias = new AliasIdentifierToken("MyAliasIdentifier")
}.Build()

}.Build()
}
),
}.Build()
]),
StatementEnd = new StatementEndToken()
}.Build()
}
]
}.Build();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst);
}
Expand Down Expand Up @@ -126,7 +127,52 @@ instance of GOLF_ClubMember
.BlockCloseToken()
.StatementEndToken()
.ToList();
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens);
var expectedAst = new MofSpecificationAst.Builder
{
Productions = [
new InstanceValueDeclarationAst.Builder {
Instance = new IdentifierToken("instance"),
Of = new IdentifierToken("of"),
TypeName = new IdentifierToken("GOLF_ClubMember"),
PropertyValues = new PropertyValueListAst([
new PropertySlotAst.Builder {
PropertyName = new IdentifierToken("LastPaymentDate"),
PropertyValue = new ComplexValueAst.Builder {
Value = new IdentifierToken("value"),
Of = new IdentifierToken("of"),
TypeName = new IdentifierToken("GOLF_Date"),
PropertyValues = new PropertyValueListAst([
new(
new("Month"),
new EnumValueAst(
new("July")
)
)
])
}.Build()
}.Build()
]),
StatementEnd = new StatementEndToken()
}.Build()
]
}.Build();
var expectedModule = new Module([
new Instance(
"GOLF_ClubMember",
[
new Property(
"LastPaymentDate",
new ComplexValueObject(
"GOLF_Date",
[
new("Month", new EnumValue("July"))
]
)
)
]
)
]);
RoundtripTests.AssertRoundtrip(sourceText, expectedTokens, expectedAst, expectedModule);
}

}
Expand Down
Loading

0 comments on commit fac4cc6

Please sign in to comment.