Skip to content

Commit

Permalink
Progress in #33
Browse files Browse the repository at this point in the history
  • Loading branch information
zspitz committed Jul 25, 2021
1 parent 7a80aa7 commit a1a97bc
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 11 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
Expand Up @@ -61,3 +61,5 @@
#*.PDF diff=astextplain
#*.rtf diff=astextplain
#*.RTF diff=astextplain

*.g4 -linguist-vendored
37 changes: 26 additions & 11 deletions Test/Test.Shared/TestContainer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,17 +10,20 @@

namespace ParseTreeVisualizer.Test {
public class TestContainer {
public static readonly (string lexer, string parser, string rule) InvalidSelection = (
"Invalid lexer",
"Invalid parser",
"Invalid rule"
);

public static readonly TheoryData<object, Config> TestData = IIFE(() => {
var filesLexersParsers = new[] {
IIFE(() => {
var parserType = typeof(SQLiteParser);
return (
(
"WindowsFunctionsForSqLite.sql",
typeof(SQLiteLexer),
parserType,
parserType.GetMethod(nameof(SQLiteParser.parse))!
);
})
typeof(SQLiteParser),
typeof(SQLiteParser).GetMethod(nameof(SQLiteParser.parse))!
)
};

var sources = filesLexersParsers.SelectManyT((filename, lexerType, parserType, parseMethod) => {
Expand All @@ -33,18 +36,24 @@ public class TestContainer {
return new object[] {
source, tokens, tree
}.Select(x => (
source: x,
lexerName: lexerType.Name,
parserName: parserType.Name,
source: x,
lexerName: lexerType.Name,
parserName: parserType.Name,
parseMethodName: parseMethod.Name
));
}).ToList();

return sources.SelectManyT((source, lexerName, parserName, parseMethodName) => {
var configs = Enumerable.Range(0, 4).Select(x => new Config()).ToArray();
var configs = Enumerable.Range(0, 5).Select(x => new Config()).ToArray();
configs.Skip(1).ForEach(x => x.SelectedLexerName = lexerName);
configs.Skip(2).ForEach(x => x.SelectedParserName = parserName);
configs.Skip(3).ForEach(x => x.ParseTokensWithRule = parseMethodName);

var invalid = configs[3];
invalid.SelectedLexerName = InvalidSelection.lexer;
invalid.SelectedParserName = InvalidSelection.parser;
invalid.ParseTokensWithRule = InvalidSelection.rule;

return configs.Select(config => (source, config));
}).ToTheoryData();
});
Expand All @@ -55,6 +64,12 @@ public void TestMethod(object source, Config config) {
var vd = new VisualizerData(source, config);
_ = new ConfigViewModel(vd);
_ = new VisualizerDataViewModel(vd, null, null, null);

if (config.SelectedLexerName == InvalidSelection.lexer) {
Assert.NotEqual(InvalidSelection.lexer, vd.Config.SelectedLexerName);
Assert.NotEqual(InvalidSelection.parser, vd.Config.SelectedParserName);
Assert.NotEqual(InvalidSelection.rule, vd.Config.ParseTokensWithRule);
}
}
}
}

0 comments on commit a1a97bc

Please sign in to comment.