From 93de1301f8eb43c359cf7cdabbca570e9880d344 Mon Sep 17 00:00:00 2001 From: Gregory Diaz Date: Fri, 24 Jul 2015 14:54:49 -0700 Subject: [PATCH] Added Testing for detecting foreign strings in lines where there should be only English --- .../MatterControl.Tests.csproj | 1 + .../MatterControl/TranslationsTests.cs | 106 ++++++++++++++++++ 2 files changed, 107 insertions(+) create mode 100644 Tests/MatterControl.Tests/MatterControl/TranslationsTests.cs diff --git a/Tests/MatterControl.Tests/MatterControl.Tests.csproj b/Tests/MatterControl.Tests/MatterControl.Tests.csproj index 01cc0291b..522f1a278 100644 --- a/Tests/MatterControl.Tests/MatterControl.Tests.csproj +++ b/Tests/MatterControl.Tests/MatterControl.Tests.csproj @@ -61,6 +61,7 @@ + diff --git a/Tests/MatterControl.Tests/MatterControl/TranslationsTests.cs b/Tests/MatterControl.Tests/MatterControl/TranslationsTests.cs new file mode 100644 index 000000000..deed81be8 --- /dev/null +++ b/Tests/MatterControl.Tests/MatterControl/TranslationsTests.cs @@ -0,0 +1,106 @@ +using MatterHackers.MatterControl; +using NUnit.Framework; +using System; +using System.IO; +using System.Collections.Generic; +using System.Diagnostics; +using System.Linq; +using System.Reflection; +using System.Text; +using System.Linq; + +namespace MatterControl.Tests.MatterControl +{ + + [TestFixture] + public class TranslationsTests + { + [Test, Category("Translations")] + public void EnglishLinesOnlyContainEnglishCharachters() + { + + var currentDirectory = new DirectoryInfo(Directory.GetCurrentDirectory()); + string pathToMatterControlFolder = currentDirectory.Parent.Parent.Parent.Parent.FullName; + string translationsPath = @"StaticData\Translations"; + string fullPath = Path.Combine(pathToMatterControlFolder,translationsPath); + + string[] translationFiles = Directory.GetDirectories(fullPath); + string translationsText = @"Translation.txt"; + + foreach (string file in translationFiles) + { + string fullPathToEachTranslation = Path.Combine(file, translationsText); + Console.Write(fullPathToEachTranslation); + readTranslationFile(fullPathToEachTranslation); + } + + + /*File.ReadAllLines(fullPath).Where(s => s.StartsWith("English:")).Select(s => + { + return s.Replace("English:", "").Trim(); + }) + .Where(s => + { + var items = s.ToCharArray().Select(c => (int)c); + var result1 = items.Where(i => i > 127); + var result2 = result1.Any(); + + return result2; + }).ToArray();//);*/ + + //checkForNonEnglishCharacters(fullPath); + + } + + + public void readTranslationFile(string pathToTranslations) + { + bool hasInvalid; + + foreach (string s in File.ReadAllLines(pathToTranslations)) + { + + var k = s; + if (k.StartsWith("English:")) + { + + k = k.Replace("English:", "").Trim(); + var chars = k.ToCharArray(); + var ints = chars.Select(c => (int)c).ToArray(); + + hasInvalid = checkForInvalidCharacters(ints); + if (hasInvalid) + { + + string result = hasInvalid.ToString(); + string fullResult = String.Format("{0}: {1}", k, result); + Console.WriteLine(fullResult); + + } + + } + } + } + + public bool checkForInvalidCharacters(int[] bytesInCharacter) + { + + bool hasInvalidCharacter = false; + + foreach (int i in bytesInCharacter) + { + + if (i > 127) + { + + hasInvalidCharacter = true; + return hasInvalidCharacter; + + } + } + + return hasInvalidCharacter; + + } + } +}