<commit_before>﻿using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using OpenSage.Data.Ini;
using OpenSage.Logic.Object;
using Xunit;
using Xunit.Abstractions;

namespace OpenSage.Data.Tests.Ini
{
    public class IniFileTests
    {
        private readonly ITestOutputHelper _output;

        public IniFileTests(ITestOutputHelper output)
        {
            _output = output;
        }

        [Fact]
        public void CanReadIniFiles()
        {
            var tasks = new List<Task>();

            InstalledFilesTestData.ReadFiles(".ini", _output, entry =>
            {
                if (Path.GetFileName(entry.FilePath) == "ButtonSets.ini")
                    return; // This file doesn't seem to be used?

                if (Path.GetFileName(entry.FilePath).ToLowerInvariant() == "scripts.ini")
                    return; // Only needed by World Builder?

                tasks.Add(Task.Run(() =>
                {
                    var dataContext = new IniDataContext(entry.FileSystem);
                    dataContext.LoadIniFile(entry);

                    Assert.NotNull(dataContext.CommandMaps);

                    foreach (var objectDefinition in dataContext.Objects)
                    {
                        foreach (var draw in objectDefinition.Draws)
                        {
                            switch (draw)
                            {
                                case W3dModelDrawModuleData md:
                                    //if (md.DefaultConditionState != null)
                                    //{
                                    //    Assert.True(md.DefaultConditionState.Animations.Count <= 1);
                                    //}
                                    //foreach (var conditionState in md.ConditionStates)
                                    //{
                                    //    Assert.True(conditionState.Animations.Count <= 1);
                                    //}
                                    break;
                            }
                        }
                    }
                }));
            });

            Task.WaitAll(tasks.ToArray());
        }
    }
}<commit_msg>Make INI parsing tests synchronous<commit_after>﻿using System.Collections.Generic;
using System.IO;
using System.Threading.Tasks;
using OpenSage.Data.Ini;
using OpenSage.Logic.Object;
using Xunit;
using Xunit.Abstractions;

namespace OpenSage.Data.Tests.Ini
{
    public class IniFileTests
    {
        private readonly ITestOutputHelper _output;

        public IniFileTests(ITestOutputHelper output)
        {
            _output = output;
        }

        [Fact]
        public void CanReadIniFiles()
        {
            InstalledFilesTestData.ReadFiles(".ini", _output, entry =>
            {
                if (Path.GetFileName(entry.FilePath) == "ButtonSets.ini")
                {
                    return; // This file doesn't seem to be used?
                }

                if (Path.GetFileName(entry.FilePath).ToLowerInvariant() == "scripts.ini")
                {
                    return; // Only needed by World Builder?
                }

                var dataContext = new IniDataContext(entry.FileSystem);

                // BFME I and II need to have GameData.ini loaded before any other INI files,
                // because GameData.ini contains global macro definitions.
                if (entry.FilePath.ToLowerInvariant() != @"data\ini\gamedata.ini")
                {
                    dataContext.LoadIniFile(@"Data\INI\GameData.ini");
                }

                dataContext.LoadIniFile(entry);

                Assert.NotNull(dataContext.CommandMaps);

                foreach (var objectDefinition in dataContext.Objects)
                {
                    foreach (var draw in objectDefinition.Draws)
                    {
                        switch (draw)
                        {
                            case W3dModelDrawModuleData md:
                                //if (md.DefaultConditionState != null)
                                //{
                                //    Assert.True(md.DefaultConditionState.Animations.Count <= 1);
                                //}
                                //foreach (var conditionState in md.ConditionStates)
                                //{
                                //    Assert.True(conditionState.Animations.Count <= 1);
                                //}
                                break;
                        }
                    }
                }
            });
        }
    }
}
{'fraction_non_alphanumeric': 0.08356545961002786, 'fraction_numerical': 0.0012856224555388902, 'mean_word_length': 1.0691489361702127, 'pattern_counts': {'":': 0, '<': 8, '<?xml version=': 0, '>': 7, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 14, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5206512', 'n_tokens_mistral': 1133, 'n_tokens_neox': 1046, 'n_words': 212}