Use LINQ to simplify tests
This commit is contained in:
parent
4eac2cd9fc
commit
f65baccd86
@ -78,15 +78,15 @@ namespace Parser.Tests
|
|||||||
|
|
||||||
public static IEnumerable<(TokenKind kind, string text)> GetTokens()
|
public static IEnumerable<(TokenKind kind, string text)> GetTokens()
|
||||||
{
|
{
|
||||||
var fixedTokens = Enum.GetValues(typeof(TokenKind))
|
var fixedTokens =
|
||||||
.Cast<TokenKind>()
|
from TokenKind kind in Enum.GetValues(typeof(TokenKind))
|
||||||
.Select(k => (kind: k, text: SyntaxFacts.GetText(k)))
|
let text = SyntaxFacts.GetText(kind)
|
||||||
.Where(t => !(t.text is null))
|
where !(text is null)
|
||||||
.Where(t => !(SyntaxFacts.IsUnaryTokenKind(t.kind)
|
where !(SyntaxFacts.IsUnaryTokenKind(kind)
|
||||||
|| SyntaxFacts.IsOpeningToken(t.kind)
|
|| SyntaxFacts.IsOpeningToken(kind)
|
||||||
|| SyntaxFacts.IsClosingToken(t.kind)
|
|| SyntaxFacts.IsClosingToken(kind)
|
||||||
|| t.kind == TokenKind.ApostropheToken));
|
|| kind == TokenKind.ApostropheToken)
|
||||||
|
select (kind, text);
|
||||||
|
|
||||||
var dynamicTokens = new[]
|
var dynamicTokens = new[]
|
||||||
{
|
{
|
||||||
@ -105,33 +105,21 @@ namespace Parser.Tests
|
|||||||
|
|
||||||
public static IEnumerable<(TokenKind kind1, string text1, TokenKind kind2, string text2)> GetPairsOfTokens()
|
public static IEnumerable<(TokenKind kind1, string text1, TokenKind kind2, string text2)> GetPairsOfTokens()
|
||||||
{
|
{
|
||||||
foreach (var token1 in GetTokens())
|
return
|
||||||
{
|
from token1 in GetTokens()
|
||||||
foreach (var token2 in GetTokens())
|
from token2 in GetTokens()
|
||||||
{
|
where !RequiresSeparator(token1.kind, token2.kind)
|
||||||
if (!RequiresSeparator(token1.kind, token2.kind))
|
select (token1.kind, token1.text, token2.kind, token2.text);
|
||||||
{
|
|
||||||
yield return (token1.kind, token1.text, token2.kind, token2.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IEnumerable<(TokenKind kind1, string text1, string separatorText, TokenKind kind2, string text2)> GetPairsOfTokensWithSeparators()
|
public static IEnumerable<(TokenKind kind1, string text1, string separatorText, TokenKind kind2, string text2)> GetPairsOfTokensWithSeparators()
|
||||||
{
|
{
|
||||||
foreach (var token1 in GetTokens())
|
return
|
||||||
{
|
from token1 in GetTokens()
|
||||||
foreach (var token2 in GetTokens())
|
from token2 in GetTokens()
|
||||||
{
|
where RequiresSeparator(token1.kind, token2.kind)
|
||||||
if (RequiresSeparator(token1.kind, token2.kind))
|
from separatorText in GetSeparators()
|
||||||
{
|
select (token1.kind, token1.text, separatorText, token2.kind, token2.text);
|
||||||
foreach (var separatorText in GetSeparators())
|
|
||||||
{
|
|
||||||
yield return (token1.kind, token1.text, separatorText, token2.kind, token2.text);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool RequiresSeparator(TokenKind kind1, TokenKind kind2)
|
private static bool RequiresSeparator(TokenKind kind1, TokenKind kind2)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user