-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Struan Judd
committed
Jan 2, 2024
1 parent
c27e7da
commit da564ea
Showing
6 changed files
with
122 additions
and
11 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
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,56 @@ | ||
using System.Diagnostics.CodeAnalysis; | ||
using GqlPlus.Verifier.Ast; | ||
using GqlPlus.Verifier.Ast.Schema; | ||
using GqlPlus.Verifier.Result; | ||
using GqlPlus.Verifier.Token; | ||
|
||
namespace GqlPlus.Verifier.Parse.Schema; | ||
|
||
internal class ParseOption( | ||
SimpleName name, | ||
Parser<NullAst>.DA param, | ||
Parser<string>.DA aliases, | ||
Parser<NullAst>.D option, | ||
Parser<OptionDefinition>.D definition | ||
) : DeclarationParser<SimpleName, NullAst, NullAst, OptionDefinition, OptionDeclAst>(name, param, aliases, option, definition) | ||
{ | ||
protected override void ApplyDefinition(OptionDeclAst result, OptionDefinition value) | ||
=> result.Settings = value.Settings; | ||
|
||
protected override bool ApplyOption(OptionDeclAst result, IResult<NullAst> option) => true; | ||
protected override bool ApplyParameters(OptionDeclAst result, IResultArray<NullAst> parameter) => true; | ||
|
||
[return: NotNull] | ||
protected override OptionDeclAst MakeResult(TokenAt at, string? name, string description) | ||
=> new(at, name!, description); | ||
} | ||
|
||
internal class OptionDefinition | ||
{ | ||
internal OptionSettingAst[] Settings { get; set; } = []; | ||
} | ||
|
||
internal class ParseOptionDefinition( | ||
Parser<OptionSettingAst>.D setting | ||
) : Parser<OptionDefinition>.I | ||
{ | ||
private readonly Parser<OptionSettingAst>.L _setting = setting; | ||
|
||
public IResult<OptionDefinition> Parse<TContext>(TContext tokens, string label) | ||
where TContext : Tokenizer | ||
{ | ||
OptionDefinition result = new(); | ||
|
||
List<OptionSettingAst> values = []; | ||
while (!tokens.Take("}")) { | ||
var setting = _setting.Parse(tokens, "Option Setting"); | ||
if (!setting.Required(values.Add)) { | ||
result.Settings = [.. values]; | ||
return setting.AsResult(result); | ||
} | ||
} | ||
|
||
result.Settings = [.. values]; | ||
return result.Ok(); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
test/GqlPlus.Verifier.ComponentTests/Parse/Schema/ParseOptionChecks.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,18 @@ | ||
using GqlPlus.Verifier.Ast.Schema; | ||
|
||
namespace GqlPlus.Verifier.Parse.Schema; | ||
|
||
internal sealed class ParseOptionChecks | ||
: BaseAliasedChecks<string, OptionDeclAst> | ||
{ | ||
public ParseOptionChecks(Parser<OptionDeclAst>.D parser) | ||
: base(parser) { } | ||
|
||
internal static readonly string[] Settings = ["setting"]; | ||
|
||
protected internal override OptionDeclAst AliasedFactory(string input) | ||
=> new(AstNulls.At, input) { Settings = Settings.OptionSettings() }; | ||
|
||
protected internal override string AliasesString(string input, string aliases) | ||
=> input + aliases + "{setting='setting'}"; | ||
} |
33 changes: 33 additions & 0 deletions
33
test/GqlPlus.Verifier.ComponentTests/Parse/Schema/ParseOptionTests.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,33 @@ | ||
using GqlPlus.Verifier.Ast.Schema; | ||
|
||
namespace GqlPlus.Verifier.Parse.Schema; | ||
|
||
public sealed class ParseOptionTests( | ||
Parser<OptionDeclAst>.D parser | ||
) : BaseAliasedTests<string> | ||
{ | ||
[Theory, RepeatData(Repeats)] | ||
public void WithNameBad_ReturnsFalse(decimal id) | ||
=> _test.False($"{id}{{}}"); | ||
|
||
[Theory, RepeatData(Repeats)] | ||
public void WithSettings_ReturnsCorrectAst(string name) | ||
=> _test.TrueExpected( | ||
name + "{setting='setting'}", | ||
new OptionDeclAst(AstNulls.At, name) { | ||
Settings = s_settings.OptionSettings(), | ||
}); | ||
|
||
[Theory, RepeatData(Repeats)] | ||
public void WithSettingsBad_ReturnsFalse(string name) | ||
=> _test.False(name + "{random}"); | ||
|
||
[Theory, RepeatData(Repeats)] | ||
public void WithSettingsNone_ReturnsTrue(string name) | ||
=> _test.TrueExpected(name + "{}", new OptionDeclAst(AstNulls.At, name)); | ||
|
||
internal override IBaseAliasedChecks<string> AliasChecks => _test; | ||
|
||
private readonly ParseOptionChecks _test = new(parser); | ||
private static readonly string[] s_settings = ["setting"]; | ||
} |
19 changes: 10 additions & 9 deletions
19
test/GqlPlus.Verifier.ComponentTests/SampleTests/VerifySchema/Intro_Object.verified.txt
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 |
---|---|---|
@@ -1,12 +1,13 @@ | ||
[ | ||
!!! I@7/2 : Invalid Output. '_BaseType' not defined. - '_BaseType' !!!, | ||
!!! I@25/3 : Invalid Output. '_Named' not defined. - '_Named' !!!, | ||
!!! I@7/10 : Invalid Output. '_BaseType' not defined. - '_BaseType' !!!, | ||
!!! I@17/10 : Invalid Output. '_TypeKind' not defined. - '_TypeKind' !!!, | ||
!!! I@7/11 : Invalid Output. '_TypeSimple' not defined. - '_TypeSimple' !!!, | ||
!!! I@20/17 : Invalid Output. '_Collection' not defined. - '_Collection' !!!, | ||
!!! I@7/21 : Invalid Output. '_Aliased' not defined. - '_Aliased' !!!, | ||
!!! I@18/23 : Invalid Output. '_Modifier' not defined. - '_Modifier' !!!, | ||
!!! I@18/27 : Invalid Output. '_InputBase' not defined. - '_InputBase' !!!, | ||
!!! I@18/28 : Invalid Output. '_Constant' not defined. - '_Constant' !!! | ||
!!! I@25/4 : Invalid Output. '_Named' not defined. - '_Named' !!!, | ||
!!! I@36/7 : Invalid Output. '_Named' not defined. - '_Named' !!!, | ||
!!! I@7/13 : Invalid Output. '_BaseType' not defined. - '_BaseType' !!!, | ||
!!! I@17/13 : Invalid Output. '_TypeKind' not defined. - '_TypeKind' !!!, | ||
!!! I@7/14 : Invalid Output. '_TypeSimple' not defined. - '_TypeSimple' !!!, | ||
!!! I@20/20 : Invalid Output. '_Collection' not defined. - '_Collection' !!!, | ||
!!! I@7/29 : Invalid Output. '_Aliased' not defined. - '_Aliased' !!!, | ||
!!! I@18/31 : Invalid Output. '_Modifier' not defined. - '_Modifier' !!!, | ||
!!! I@18/35 : Invalid Output. '_InputBase' not defined. - '_InputBase' !!!, | ||
!!! I@18/36 : Invalid Output. '_Constant' not defined. - '_Constant' !!! | ||
] |