-
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 3, 2024
1 parent
49f80d7
commit 2c370d0
Showing
9 changed files
with
185 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
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
1 change: 0 additions & 1 deletion
1
test/GqlPlus.Verifier.ClassTests/Merging/MergeConstantsTests.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 |
---|---|---|
@@ -1,5 +1,4 @@ | ||
using GqlPlus.Verifier.Ast; | ||
using Newtonsoft.Json.Linq; | ||
|
||
namespace GqlPlus.Verifier.Merging; | ||
|
||
|
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,92 @@ | ||
using GqlPlus.Verifier.Parse.Schema; | ||
using GqlPlus.Verifier.Result; | ||
using GqlPlus.Verifier.Token; | ||
using NSubstitute; | ||
|
||
namespace GqlPlus.Verifier.Parse; | ||
|
||
public class ClassTestBase | ||
{ | ||
protected static Tokenizer Tokens(string input) | ||
{ | ||
var tokens = new Tokenizer(input); | ||
tokens.Read(); | ||
return tokens; | ||
} | ||
|
||
internal static T NameFor<T>(string name) | ||
where T : class, INameParser | ||
{ | ||
var nameParser = Substitute.For<T>(); | ||
nameParser.ParseName(default!, out var _, out var _) | ||
.ReturnsForAnyArgs(c => { | ||
c[1] = name; | ||
return true; | ||
}); | ||
return nameParser; | ||
} | ||
|
||
protected static Parser<T>.D ParserFor<T>() | ||
=> ParserFor<T>(out var _); | ||
|
||
protected static Parser<T>.D ParserFor<T>(out Parser<T>.I parser) | ||
{ | ||
parser = Substitute.For<Parser<T>.I>(); | ||
parser.Parse<Tokenizer>(default!, default!) | ||
.ReturnsForAnyArgs(0.Empty<T>()); | ||
|
||
var result = Substitute.For<Parser<T>.D>(); | ||
result().Returns(parser); | ||
|
||
return result; | ||
} | ||
|
||
protected static Parser<IOptionParser<T>, T>.D OptionParserFor<T>() | ||
where T : struct | ||
=> OptionParserFor<T>(out var _); | ||
|
||
protected static Parser<IOptionParser<T>, T>.D OptionParserFor<T>(out Parser<T>.I parser) | ||
where T : struct | ||
{ | ||
parser = Substitute.For<IOptionParser<T>>(); | ||
parser.Parse<Tokenizer>(default!, default!) | ||
.ReturnsForAnyArgs(0.Empty<T>()); | ||
|
||
var result = Substitute.For<Parser<IOptionParser<T>, T>.D>(); | ||
result().Returns(parser); | ||
|
||
return result; | ||
} | ||
|
||
protected static Parser<IEnumParser<T>, T>.D EnumParserFor<T>() | ||
where T : struct | ||
=> EnumParserFor<T>(out var _); | ||
|
||
protected static Parser<IEnumParser<T>, T>.D EnumParserFor<T>(out Parser<T>.I parser) | ||
where T : struct | ||
{ | ||
parser = Substitute.For<IEnumParser<T>>(); | ||
parser.Parse<Tokenizer>(default!, default!) | ||
.ReturnsForAnyArgs(0.Empty<T>()); | ||
|
||
var result = Substitute.For<Parser<IEnumParser<T>, T>.D>(); | ||
result().Returns(parser); | ||
|
||
return result; | ||
} | ||
|
||
protected static Parser<T>.DA ArrayParserFor<T>() | ||
=> ArrayParserFor<T>(out var _); | ||
|
||
protected static Parser<T>.DA ArrayParserFor<T>(out Parser<T>.IA parser) | ||
{ | ||
parser = Substitute.For<Parser<T>.IA>(); | ||
parser.Parse<Tokenizer>(default!, default!) | ||
.ReturnsForAnyArgs(0.EmptyArray<T>()); | ||
|
||
var result = Substitute.For<Parser<T>.DA>(); | ||
result().Returns(parser); | ||
|
||
return result; | ||
} | ||
} |
29 changes: 29 additions & 0 deletions
29
test/GqlPlus.Verifier.ClassTests/Parse/ParseScalarClassTests.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,29 @@ | ||
using GqlPlus.Verifier.Ast; | ||
using GqlPlus.Verifier.Ast.Schema; | ||
using GqlPlus.Verifier.Result; | ||
using NSubstitute; | ||
|
||
namespace GqlPlus.Verifier.Parse.Schema; | ||
|
||
public class ParseScalarClassTests : ClassTestBase | ||
{ | ||
[Theory, RepeatData(Repeats)] | ||
public void Parse_UnknownKind_ReturnsExpected(string name) | ||
{ | ||
var tokens = Tokens("{ "); | ||
|
||
var simpleName = NameFor<ISimpleName>(name); | ||
var param = ArrayParserFor<NullAst>(); | ||
var aliases = ArrayParserFor<string>(); | ||
var option = OptionParserFor<NullOption>(); | ||
var definition = ParserFor<ScalarDefinition>(out var definitionParser); | ||
definitionParser.Parse(tokens, default!) | ||
.ReturnsForAnyArgs(new ScalarDefinition() { Kind = (ScalarKind)99 }.Ok()); | ||
|
||
var scalar = new ParseScalar(simpleName, param, aliases, option, definition); | ||
|
||
var result = scalar.Parse(tokens, "test"); | ||
|
||
result.Should().BeAssignableTo<IResultOk<ScalarDeclAst>>(); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
test/GqlPlus.Verifier.ClassTests/Parse/ParseScalarDefinitionClassTests.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,28 @@ | ||
using GqlPlus.Verifier.Ast.Schema; | ||
using GqlPlus.Verifier.Result; | ||
using NSubstitute; | ||
|
||
namespace GqlPlus.Verifier.Parse.Schema; | ||
|
||
public class ParseScalarDefinitionClassTests : ClassTestBase | ||
{ | ||
[Fact] | ||
public void Parse_UnknownKind_ReturnsExpected() | ||
{ | ||
var tokens = Tokens("{ "); | ||
|
||
var kind = EnumParserFor<ScalarKind>(out var kindParser); | ||
kindParser.Parse(tokens, default!) | ||
.ReturnsForAnyArgs(((ScalarKind)99).Ok()); | ||
|
||
var ranges = ArrayParserFor<ScalarRangeAst>(); | ||
var references = ArrayParserFor<ScalarReferenceAst>(); | ||
var regexes = ArrayParserFor<ScalarRegexAst>(); | ||
|
||
var scalar = new ParseScalarDefinition(kind, ranges, references, regexes); | ||
|
||
var result = scalar.Parse(tokens, "test"); | ||
|
||
result.Should().BeAssignableTo<IResultPartial<ScalarDefinition>>(); | ||
} | ||
} |
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