From badda797933aa42340f6f6f07290683c92e569f7 Mon Sep 17 00:00:00 2001 From: Andy Ford Date: Thu, 6 Jan 2022 21:51:16 +0000 Subject: [PATCH] fix(includes): iterate airports by rule, then by airport (#168) * fix(includes): iterate airports by rule, then by airport Currently, we iterate each of the airport directories and within that, iterate through the rules. This has the effect of making the ordering of the rules essentially useless, as all the rules get applied to the current airport before moving on. This change modifies the processing order so it applies each rule in turn to each folder, which produces the desired effect. fix #167 * Remove test variable --- src/Compiler/Config/ConfigIncludeLoader.cs | 92 ++++++-- src/Compiler/Parser/DataParserFactory.cs | 2 +- .../Config/ConfigIncludeLoaderTest.cs | 209 ++++++++++++++---- .../AirportOrder/Airports/EGKK/.gitignore | 4 + .../AirportOrder/Airports/EGLL/.gitignore | 4 + .../AirportOrder/config.json | 29 +++ 6 files changed, 266 insertions(+), 74 deletions(-) create mode 100644 tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGKK/.gitignore create mode 100644 tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGLL/.gitignore create mode 100644 tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/config.json diff --git a/src/Compiler/Config/ConfigIncludeLoader.cs b/src/Compiler/Config/ConfigIncludeLoader.cs index caf2ebea..d00ad394 100644 --- a/src/Compiler/Config/ConfigIncludeLoader.cs +++ b/src/Compiler/Config/ConfigIncludeLoader.cs @@ -16,16 +16,18 @@ public class ConfigIncludeLoader public ConfigIncludeLoader( FolderInclusionRuleLoaderFactory folderFactory, FileInclusionRuleLoaderFactory fileFactory - ) { + ) + { this.folderFactory = folderFactory; this.fileFactory = fileFactory; } - + public void LoadConfig( ConfigInclusionRules inclusionRules, JObject jsonConfig, string fileName - ) { + ) + { // Load airport data JToken airportData = jsonConfig.SelectToken("includes.airports"); if (airportData != null) @@ -61,7 +63,7 @@ string fileName ); } } - + private string GetMissingTypeMessage(string section) { return $"Invalid type field for section {section} - must be \"files\" or \"folders\""; @@ -101,19 +103,54 @@ string configFilePath // Get the airport folders string configFileFolder = GetFolderForConfigFile(configFilePath); - string[] directories = Directory.GetDirectories(configFileFolder + Path.DirectorySeparatorChar + configItem.Key); + string[] directories = + Directory.GetDirectories(configFileFolder + Path.DirectorySeparatorChar + configItem.Key); - // For each airport, iterate the config file sections - foreach (string directory in directories) + /* + * Airports are a bit special as there are lots of them. + * Rather than cycling each airport and applying all the rules, cycle the rules and then apply the + * airports, that way we maintain any desired ordering. + */ + foreach (ConfigFileSection configSection in AirfieldConfigFileSections.ConfigFileSections) { - IterateConfigFileSections( - configItem.Value, - AirfieldConfigFileSections.ConfigFileSections, - x => OutputGroupFactory.CreateAirport(x, Path.GetFileName(directory)), - config.AddAirportInclusionRule, - directory, - "airport" - ); + JToken configObjectSection = configItem.Value.SelectToken(configSection.JsonPath); + if (configObjectSection == null) + { + continue; + } + + + if (configObjectSection.Type == JTokenType.Array) + { + foreach (JToken token in (JArray)configObjectSection) + { + foreach (var directory in directories) + { + ProcessConfigSectionObject( + token, + configSection, + OutputGroupFactory.CreateAirport(configSection, Path.GetFileName(directory)), + config.AddAirportInclusionRule, + directory, + "airport" + ); + } + } + } + else + { + foreach (var directory in directories) + { + ProcessConfigSectionObject( + configObjectSection, + configSection, + OutputGroupFactory.CreateAirport(configSection, Path.GetFileName(directory)), + config.AddAirportInclusionRule, + directory, + "airport" + ); + } + } } } } @@ -125,7 +162,8 @@ private void IterateConfigFileSections( Action addInclusionRule, string configFilePath, string sectionRootString - ) { + ) + { foreach (ConfigFileSection configSection in configFileSections) { JToken configObjectSection = jsonConfig.SelectToken(configSection.JsonPath); @@ -133,7 +171,7 @@ string sectionRootString { continue; } - + LoadConfigSection( configObjectSection, configSection, @@ -155,10 +193,11 @@ private void LoadConfigSection( Action addInclusionRule, string configFilePath, string sectionRootString - ) { + ) + { if (jsonConfig.Type == JTokenType.Array) { - foreach (JToken token in (JArray) jsonConfig) + foreach (JToken token in (JArray)jsonConfig) { ProcessConfigSectionObject( token, @@ -169,7 +208,9 @@ string sectionRootString sectionRootString ); } - } else { + } + else + { ProcessConfigSectionObject( jsonConfig, configFileSection, @@ -188,7 +229,8 @@ private void ProcessConfigSectionObject( Action addInclusionRule, string rootPath, string sectionRootString - ) { + ) + { if (jsonConfig.Type != JTokenType.Object) { throw new ConfigFileInvalidException(GetInvalidConfigParentSectionFormatMessage(sectionRootString)); @@ -200,8 +242,9 @@ string sectionRootString if ( !configObject.TryGetValue("type", out var typeToken) || typeToken.Type != JTokenType.String || - ((string) typeToken != "files" && (string) typeToken != "folder") - ) { + ((string)typeToken != "files" && (string)typeToken != "folder") + ) + { throw new ConfigFileInvalidException( GetMissingTypeMessage($"{sectionRootString}.{configFileSection.JsonPath}") ); @@ -216,7 +259,8 @@ string sectionRootString rootPath ).CreateRule(configObject) ); - } else + } + else { addInclusionRule( folderFactory.Create( diff --git a/src/Compiler/Parser/DataParserFactory.cs b/src/Compiler/Parser/DataParserFactory.cs index 658ce2da..6ef69cb7 100644 --- a/src/Compiler/Parser/DataParserFactory.cs +++ b/src/Compiler/Parser/DataParserFactory.cs @@ -27,7 +27,7 @@ public ISectorDataParser GetParserForFile(AbstractSectorDataFile file) new FrequencyParser(108, 117, 50), sectorElements, logger - ), + ), InputDataType.SCT_NDBS => new NdbParser(new FrequencyParser(108, 950, 500), sectorElements, logger), InputDataType.SCT_ARTCC => new ArtccParser(ArtccType.REGULAR, sectorElements, logger), InputDataType.SCT_ARTCC_LOW => new ArtccParser(ArtccType.LOW, sectorElements, logger), diff --git a/tests/CompilerTest/Config/ConfigIncludeLoaderTest.cs b/tests/CompilerTest/Config/ConfigIncludeLoaderTest.cs index c06f879a..198f116c 100644 --- a/tests/CompilerTest/Config/ConfigIncludeLoaderTest.cs +++ b/tests/CompilerTest/Config/ConfigIncludeLoaderTest.cs @@ -26,30 +26,52 @@ public ConfigIncludeLoaderTest() fileLoader = ConfigIncludeLoaderFactory.Make(new CompilerArguments()); includes = new ConfigInclusionRules(); } - + [Theory] - [InlineData("_TestData/ConfigIncludeLoader/AirportNotObject/config.json", "Invalid airport config in _TestData/ConfigIncludeLoader/AirportNotObject/config.json must be an object")] - [InlineData("_TestData/ConfigIncludeLoader/AirportKeyNotObject/config.json", "Invalid airport config[Airports] in _TestData/ConfigIncludeLoader/AirportKeyNotObject/config.json must be an object")] - [InlineData("_TestData/ConfigIncludeLoader/InvalidTypeType/config.json", "Invalid type field for section misc.regions - must be \"files\" or \"folders\"")] - [InlineData("_TestData/ConfigIncludeLoader/InvalidType/config.json", "Invalid type field for section misc.regions - must be \"files\" or \"folders\"")] - [InlineData("_TestData/ConfigIncludeLoader/NoFolder/config.json", "Folder invalid in section enroute.ownership - must be string under key \"folder\"")] - [InlineData("_TestData/ConfigIncludeLoader/FolderInvalid/config.json", "Folder invalid in section enroute.ownership - must be string under key \"folder\"")] - [InlineData("_TestData/ConfigIncludeLoader/RecursiveInvalid/config.json", "Recursive must be a boolean in section enroute.ownership")] - [InlineData("_TestData/ConfigIncludeLoader/IncludeAndExclude/config.json", "Cannot specify both include and exclude for folders in section enroute.ownership")] - [InlineData("_TestData/ConfigIncludeLoader/ExcludeNotAnArray/config.json", "Exclude list must be an array in section enroute.ownership")] - [InlineData("_TestData/ConfigIncludeLoader/ExcludeFilesNotAString/config.json", "Exclude file must be a string in section enroute.ownership")] - [InlineData("_TestData/ConfigIncludeLoader/IncludeNotAnArray/config.json", "Include list must be an array in section enroute.ownership")] - [InlineData("_TestData/ConfigIncludeLoader/IncludeFilesNotAString/config.json", "Include file must be a string in section enroute.ownership")] - [InlineData("_TestData/ConfigIncludeLoader/FilesListNotAnArray/config.json", "Files list invalid in section misc.regions - must be array under key \"files\"")] - [InlineData("_TestData/ConfigIncludeLoader/FilesListMissing/config.json", "Files list invalid in section misc.regions - must be array under key \"files\"")] - [InlineData("_TestData/ConfigIncludeLoader/IgnoreMissingNotBoolean/config.json", "Invalid ignore_missing value in section misc.regions - must be a boolean")] - [InlineData("_TestData/ConfigIncludeLoader/ExceptWhereExistsNotString/config.json", "Invalid except_where_exists value in section misc.regions - must be a string")] - [InlineData("_TestData/ConfigIncludeLoader/FilePathInvalid/config.json", "Invalid file path in section misc.regions - must be a string")] - [InlineData("_TestData/ConfigIncludeLoader/ParentSectionNotArrayOrObject/config.json", "Invalid config section for enroute - must be an object or array of objects") ] - [InlineData("_TestData/ConfigIncludeLoader/ParentSectionNotArrayOfObjects/config.json", "Invalid config section for enroute - must be an object or array of objects")] - [InlineData("_TestData/ConfigIncludeLoader/PatternNotAString/config.json", "Pattern invalid in section enroute.ownership - must be a regular expression string")] - [InlineData("_TestData/ConfigIncludeLoader/ExcludeDirectoryNotAnArray/config.json", "Invalid exclude_directory invalid in section misc.regions - must be an array of strings")] - [InlineData("_TestData/ConfigIncludeLoader/ExcludeDirectoryContainsNonString/config.json", "Invalid exclude_directory invalid in section misc.regions - must be an array of strings")] + [InlineData("_TestData/ConfigIncludeLoader/AirportNotObject/config.json", + "Invalid airport config in _TestData/ConfigIncludeLoader/AirportNotObject/config.json must be an object")] + [InlineData("_TestData/ConfigIncludeLoader/AirportKeyNotObject/config.json", + "Invalid airport config[Airports] in _TestData/ConfigIncludeLoader/AirportKeyNotObject/config.json must be an object")] + [InlineData("_TestData/ConfigIncludeLoader/InvalidTypeType/config.json", + "Invalid type field for section misc.regions - must be \"files\" or \"folders\"")] + [InlineData("_TestData/ConfigIncludeLoader/InvalidType/config.json", + "Invalid type field for section misc.regions - must be \"files\" or \"folders\"")] + [InlineData("_TestData/ConfigIncludeLoader/NoFolder/config.json", + "Folder invalid in section enroute.ownership - must be string under key \"folder\"")] + [InlineData("_TestData/ConfigIncludeLoader/FolderInvalid/config.json", + "Folder invalid in section enroute.ownership - must be string under key \"folder\"")] + [InlineData("_TestData/ConfigIncludeLoader/RecursiveInvalid/config.json", + "Recursive must be a boolean in section enroute.ownership")] + [InlineData("_TestData/ConfigIncludeLoader/IncludeAndExclude/config.json", + "Cannot specify both include and exclude for folders in section enroute.ownership")] + [InlineData("_TestData/ConfigIncludeLoader/ExcludeNotAnArray/config.json", + "Exclude list must be an array in section enroute.ownership")] + [InlineData("_TestData/ConfigIncludeLoader/ExcludeFilesNotAString/config.json", + "Exclude file must be a string in section enroute.ownership")] + [InlineData("_TestData/ConfigIncludeLoader/IncludeNotAnArray/config.json", + "Include list must be an array in section enroute.ownership")] + [InlineData("_TestData/ConfigIncludeLoader/IncludeFilesNotAString/config.json", + "Include file must be a string in section enroute.ownership")] + [InlineData("_TestData/ConfigIncludeLoader/FilesListNotAnArray/config.json", + "Files list invalid in section misc.regions - must be array under key \"files\"")] + [InlineData("_TestData/ConfigIncludeLoader/FilesListMissing/config.json", + "Files list invalid in section misc.regions - must be array under key \"files\"")] + [InlineData("_TestData/ConfigIncludeLoader/IgnoreMissingNotBoolean/config.json", + "Invalid ignore_missing value in section misc.regions - must be a boolean")] + [InlineData("_TestData/ConfigIncludeLoader/ExceptWhereExistsNotString/config.json", + "Invalid except_where_exists value in section misc.regions - must be a string")] + [InlineData("_TestData/ConfigIncludeLoader/FilePathInvalid/config.json", + "Invalid file path in section misc.regions - must be a string")] + [InlineData("_TestData/ConfigIncludeLoader/ParentSectionNotArrayOrObject/config.json", + "Invalid config section for enroute - must be an object or array of objects")] + [InlineData("_TestData/ConfigIncludeLoader/ParentSectionNotArrayOfObjects/config.json", + "Invalid config section for enroute - must be an object or array of objects")] + [InlineData("_TestData/ConfigIncludeLoader/PatternNotAString/config.json", + "Pattern invalid in section enroute.ownership - must be a regular expression string")] + [InlineData("_TestData/ConfigIncludeLoader/ExcludeDirectoryNotAnArray/config.json", + "Invalid exclude_directory invalid in section misc.regions - must be an array of strings")] + [InlineData("_TestData/ConfigIncludeLoader/ExcludeDirectoryContainsNonString/config.json", + "Invalid exclude_directory invalid in section misc.regions - must be an array of strings")] public void TestItThrowsExceptionOnBadData(string fileToLoad, string expectedMessage) { ConfigFileInvalidException exception = Assert.Throws( @@ -87,7 +109,7 @@ public void TestItLoadsAConfigFile() Assert.Equal(6, ruleList.Count); // Airport - Basic - InclusionRule airportBasicRule = (InclusionRule) ruleList[0]; + InclusionRule airportBasicRule = (InclusionRule)ruleList[0]; Assert.IsType(airportBasicRule.ListGenerator); Assert.Equal(2, airportBasicRule.ListGenerator.GetPaths().Count()); Assert.Equal( @@ -99,18 +121,22 @@ public void TestItLoadsAConfigFile() airportBasicRule.ListGenerator.GetPaths().ToList() ); Assert.Contains(airportBasicRule.Validators, validator => validator.GetType() == typeof(FileExists)); - Assert.DoesNotContain(airportBasicRule.Filters, fileFilter => fileFilter.GetType() == typeof(IgnoreWhenFileExists)); - Assert.Contains(airportBasicRule.Filters, fileFilter => fileFilter.GetType() == typeof(ExcludeByParentFolder)); + Assert.DoesNotContain(airportBasicRule.Filters, + fileFilter => fileFilter.GetType() == typeof(IgnoreWhenFileExists)); + Assert.Contains(airportBasicRule.Filters, + fileFilter => fileFilter.GetType() == typeof(ExcludeByParentFolder)); Assert.Contains( "EGLL", - (airportBasicRule.Filters.First(fileFilter => fileFilter.GetType() == typeof(ExcludeByParentFolder)) as ExcludeByParentFolder)?.ParentFolders - ?? throw new InvalidOperationException() + (airportBasicRule.Filters.First(fileFilter => fileFilter.GetType() == typeof(ExcludeByParentFolder)) as + ExcludeByParentFolder)?.ParentFolders + ?? throw new InvalidOperationException() ); Assert.Equal(InputDataType.SCT_AIRPORT_BASIC, airportBasicRule.DataType); - Assert.Equal(new OutputGroup("airport.SCT_AIRPORT_BASIC.EGLL", "Start EGLL Basic"), airportBasicRule.GetOutputGroup()); - + Assert.Equal(new OutputGroup("airport.SCT_AIRPORT_BASIC.EGLL", "Start EGLL Basic"), + airportBasicRule.GetOutputGroup()); + // Airport - Geo - InclusionRule airportGeoRule = (InclusionRule) ruleList[1]; + InclusionRule airportGeoRule = (InclusionRule)ruleList[1]; Assert.IsType(airportGeoRule.ListGenerator); Assert.Single(airportGeoRule.ListGenerator.GetPaths()); Assert.Equal( @@ -124,26 +150,29 @@ public void TestItLoadsAConfigFile() Assert.Contains(airportGeoRule.Filters, validator => validator.GetType() == typeof(IgnoreWhenFileExists)); Assert.Equal( GetFullFilePath("_TestData/ConfigIncludeLoader/ValidConfig/Airports/EGLL/SMR/Foo.txt"), - (airportGeoRule.Filters.Where(validator => validator.GetType() == typeof(IgnoreWhenFileExists)).FirstOrDefault() as IgnoreWhenFileExists)?.FileToCheckAgainst + (airportGeoRule.Filters.Where(validator => validator.GetType() == typeof(IgnoreWhenFileExists)) + .FirstOrDefault() as IgnoreWhenFileExists)?.FileToCheckAgainst ); Assert.Equal(InputDataType.SCT_GEO, airportGeoRule.DataType); Assert.Equal(new OutputGroup("airport.SCT_GEO.EGLL", "Start EGLL Geo"), airportGeoRule.GetOutputGroup()); - + // Enroute ownership folder 1 - InclusionRule ownershipRule1 = (InclusionRule) ruleList[2]; + InclusionRule ownershipRule1 = (InclusionRule)ruleList[2]; Assert.Equal( - new List{GetFullFilePath("_TestData/ConfigIncludeLoader/ValidConfig/Ownership/Alternate/Foo.txt")}, + new List + { GetFullFilePath("_TestData/ConfigIncludeLoader/ValidConfig/Ownership/Alternate/Foo.txt") }, ownershipRule1.ListGenerator.GetPaths().ToList() ); Assert.IsType(ownershipRule1.ListGenerator); Assert.Empty(ownershipRule1.Filters); Assert.Empty(ownershipRule1.Validators); - Assert.Equal(new OutputGroup("enroute.ESE_OWNERSHIP", "Start enroute Ownership"), ownershipRule1.GetOutputGroup()); - + Assert.Equal(new OutputGroup("enroute.ESE_OWNERSHIP", "Start enroute Ownership"), + ownershipRule1.GetOutputGroup()); + // Enroute ownership folder 2 - InclusionRule ownershipRule2 = (InclusionRule) ruleList[3]; + InclusionRule ownershipRule2 = (InclusionRule)ruleList[3]; Assert.Equal( - new List{GetFullFilePath("_TestData/ConfigIncludeLoader/ValidConfig/Ownership/Foo/Foo.txt")}, + new List { GetFullFilePath("_TestData/ConfigIncludeLoader/ValidConfig/Ownership/Foo/Foo.txt") }, ownershipRule2.ListGenerator.GetPaths().ToList() ); Assert.IsType(ownershipRule2.ListGenerator); @@ -153,12 +182,14 @@ public void TestItLoadsAConfigFile() ) as IncludeFileFilter ?? throw new InvalidOperationException(); Assert.Single(filter.FileNames); Assert.Equal("Foo.txt", filter.FileNames.First()); - Assert.Equal(new OutputGroup("enroute.ESE_OWNERSHIP", "Start enroute Ownership"), ownershipRule2.GetOutputGroup()); - + Assert.Equal(new OutputGroup("enroute.ESE_OWNERSHIP", "Start enroute Ownership"), + ownershipRule2.GetOutputGroup()); + // Enroute ownership folder 3 - InclusionRule ownershipRule3 = (InclusionRule) ruleList[4]; + InclusionRule ownershipRule3 = (InclusionRule)ruleList[4]; Assert.Equal( - new List{GetFullFilePath("_TestData/ConfigIncludeLoader/ValidConfig/Ownership/Non-UK/EUR Islands.txt")}, + new List + { GetFullFilePath("_TestData/ConfigIncludeLoader/ValidConfig/Ownership/Non-UK/EUR Islands.txt") }, ownershipRule3.ListGenerator.GetPaths().ToList() ); Assert.IsType(ownershipRule3.ListGenerator); @@ -168,16 +199,17 @@ public void TestItLoadsAConfigFile() ) as ExcludeFileFilter ?? throw new InvalidOperationException(); Assert.Single(excludeFileFilter.FileNames); Assert.Equal("EUR Islands.txt", excludeFileFilter.FileNames.First()); - + Assert.Contains(ownershipRule3.Filters, fileFilter => fileFilter.GetType() == typeof(FilePatternFilter)); var patternFilter = ownershipRule3.Filters.First( fileFilter => fileFilter.GetType() == typeof(FilePatternFilter) ) as FilePatternFilter ?? throw new InvalidOperationException(); Assert.Equal(".*?", patternFilter.Pattern.ToString()); - Assert.Equal(new OutputGroup("enroute.ESE_OWNERSHIP", "Start enroute Ownership"), ownershipRule3.GetOutputGroup()); - + Assert.Equal(new OutputGroup("enroute.ESE_OWNERSHIP", "Start enroute Ownership"), + ownershipRule3.GetOutputGroup()); + // Misc regions - InclusionRule miscRegions = (InclusionRule) ruleList[5]; + InclusionRule miscRegions = (InclusionRule)ruleList[5]; Assert.IsType(miscRegions.ListGenerator); Assert.Equal(3, miscRegions.ListGenerator.GetPaths().Count()); Assert.Equal( @@ -190,9 +222,88 @@ public void TestItLoadsAConfigFile() miscRegions.ListGenerator.GetPaths().ToList() ); Assert.Contains(airportBasicRule.Validators, validator => validator.GetType() == typeof(FileExists)); - Assert.DoesNotContain(airportBasicRule.Filters, validator => validator.GetType() == typeof(IgnoreWhenFileExists)); + Assert.DoesNotContain(airportBasicRule.Filters, + validator => validator.GetType() == typeof(IgnoreWhenFileExists)); Assert.Equal(InputDataType.SCT_AIRPORT_BASIC, airportBasicRule.DataType); - Assert.Equal(new OutputGroup("airport.SCT_AIRPORT_BASIC.EGLL", "Start EGLL Basic"), airportBasicRule.GetOutputGroup()); + Assert.Equal(new OutputGroup("airport.SCT_AIRPORT_BASIC.EGLL", "Start EGLL Basic"), + airportBasicRule.GetOutputGroup()); + } + + [Fact] + public void TestItLoadsAirportConfigInRuleOrder() + { + fileLoader.LoadConfig( + includes, + JObject.Parse(File.ReadAllText("_TestData/ConfigIncludeLoader/AirportOrder/config.json")), + "_TestData/ConfigIncludeLoader/AirportOrder/config.json" + ); + + List ruleList = includes.ToList(); + Assert.Equal(4, ruleList.Count); + + // Airport - Basic, first rule for EGKK + InclusionRule gatwickFirstRule = (InclusionRule)ruleList[0]; + Assert.Equal( + new List + { + GetFullFilePath("_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGKK/Basic.txt"), + GetFullFilePath("_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGKK/Basic2.txt"), + }, + gatwickFirstRule.ListGenerator.GetPaths().ToList() + ); + Assert.Contains(gatwickFirstRule.Filters, + fileFilter => fileFilter.GetType() == typeof(ExcludeByParentFolder)); + Assert.Contains( + "EGKK", + (gatwickFirstRule.Filters.First( + fileFilter => fileFilter.GetType() == typeof(ExcludeByParentFolder)) as ExcludeByParentFolder) + ?.ParentFolders + ?? throw new InvalidOperationException() + ); + + // Airport - Basic, first rule for EGLL + InclusionRule heathrowFirstRule = (InclusionRule)ruleList[1]; + Assert.Equal( + new List + { + GetFullFilePath("_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGLL/Basic.txt"), + GetFullFilePath("_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGLL/Basic2.txt"), + }, + heathrowFirstRule.ListGenerator.GetPaths().ToList() + ); + Assert.Contains(heathrowFirstRule.Filters, + fileFilter => fileFilter.GetType() == typeof(ExcludeByParentFolder)); + Assert.Contains( + "EGKK", + (heathrowFirstRule.Filters.First( + fileFilter => fileFilter.GetType() == typeof(ExcludeByParentFolder)) as ExcludeByParentFolder) + ?.ParentFolders + ?? throw new InvalidOperationException() + ); + + // Airport - Basic, second rule for EGKK + InclusionRule gatwickSecondRule = (InclusionRule)ruleList[2]; + Assert.Equal( + new List + { + GetFullFilePath("_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGKK/Basic.txt"), + GetFullFilePath("_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGKK/Basic2.txt"), + }, + gatwickSecondRule.ListGenerator.GetPaths().ToList() + ); + Assert.Empty(gatwickSecondRule.Filters); + + // Airport - Basic, second rule for EGLL + InclusionRule heathrowSecondRule = (InclusionRule)ruleList[3]; + Assert.Equal( + new List + { + GetFullFilePath("_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGLL/Basic.txt"), + GetFullFilePath("_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGLL/Basic2.txt"), + }, + heathrowSecondRule.ListGenerator.GetPaths().ToList() + ); + Assert.Empty(heathrowSecondRule.Filters); } } } diff --git a/tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGKK/.gitignore b/tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGKK/.gitignore new file mode 100644 index 00000000..44c5ea8f --- /dev/null +++ b/tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGKK/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGLL/.gitignore b/tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGLL/.gitignore new file mode 100644 index 00000000..44c5ea8f --- /dev/null +++ b/tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/Airports/EGLL/.gitignore @@ -0,0 +1,4 @@ +# Ignore everything in this directory +* +# Except this file +!.gitignore \ No newline at end of file diff --git a/tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/config.json b/tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/config.json new file mode 100644 index 00000000..bf404495 --- /dev/null +++ b/tests/CompilerTest/_TestData/ConfigIncludeLoader/AirportOrder/config.json @@ -0,0 +1,29 @@ +{ + "includes": { + "airports": { + "Airports": { + "basic": [ + { + "type": "files", + "files": [ + "Basic.txt", + "Basic2.txt" + ], + "exclude_directory": [ + "EGKK" + ] + }, + { + "type": "files", + "files": [ + "Basic.txt", + "Basic2.txt" + ] + } + ] + } + }, + "enroute": {}, + "misc": {} + } +}