Exemplo n.º 1
0
        public void EmptyDict_ShouldReturnDefaultSubstitutions()
        {
            var file = File.Create("testDict1.txt");

            file.Close();
            var args = new[]
            {
                "subs",
                "C",
                "-d",
                "testDict1.txt"
            };
            var subsOptions = ParseSubOptions(args);
            var expected    = "C\r\n" +
                              "[\r\n" +
                              "{\r\n" +
                              "(\r\n" +
                              "<\r\n";
            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                subsInstance.Process();
                File.Delete("testDict1.txt");
                Assert.That(consoleOutput.GetOuput().Contains(expected), Is.True);
            }
        }
Exemplo n.º 2
0
        public void VerboseDictWithGoodLeetOnly_ShouldPrintVerbose()
        {
            var content = "{\r\n\t\"GLeet\": {\r\n\t\t\"C\": [\r\n\t\t\t\"[\",\r\n\t\t\t\"(\"\r\n\t\t]\r\n\t}\r\n}";

            File.WriteAllText("testDict1.txt", content, Encoding.UTF8);

            var args = new[]
            {
                "subs",
                "C",
                "-d",
                "testDict1.txt",
                "-v"
            };
            var subsOptions  = ParseSubOptions(args);
            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                subsInstance.Process();
                File.Delete("testDict1.txt");
                var consoleText = consoleOutput.GetOuput();
                Assert.That(consoleText.Contains($"[DICTIONARY]: testDict1.txt{Environment.NewLine}"));
                Assert.That(consoleText.Contains($"[METHOD]: GLeet{Environment.NewLine}"));
            }
        }
Exemplo n.º 3
0
        public void SourceWord_ShouldReturnSubstitutions(string[] args, string expected)
        {
            var subsOptions  = ParseSubOptions(args);
            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                subsInstance.Process();
                Assert.That(consoleOutput.GetOuput().Contains(expected), Is.True);
            }
        }
Exemplo n.º 4
0
        public string Methods_ShouldReturnSubstitutions(string[] args)
        {
            var subsOptions  = ParseSubOptions(args);
            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                subsInstance.Process();
                return(consoleOutput.GetOuput());
            }
        }
Exemplo n.º 5
0
        public void StdInputOneWrongSymbolInput_ShouldPrintErrorAndContinueWork()
        {
            var args = new[]
            {
                "subs",
                "-i"
            };
            var subsOptions  = ParseSubOptions(args);
            var subsInstance = new Substitution(subsOptions);

            using (var consoleInput = new ConsoleInput("q\r\n"))
            {
                using (var consoleOutput = new ConsoleOutput())
                {
                    subsInstance.Process();
                    var consoleText = consoleOutput.GetOuput();
                    Assert.That(consoleText.Contains("[ERROR]"));
                    consoleInput.SetInput("B\r\n");
                    subsInstance.Process();
                    consoleText = consoleOutput.GetOuput();
                    Assert.That(consoleText.Contains("B\r\n|3\r\n8\r\n"));
                }
            }
        }
Exemplo n.º 6
0
        public void SourceWordThreeLetterLowercase_ShouldReturnErrorAndHelp()
        {
            var args = new[]
            {
                "subs",
                "bzs"
            };
            var subsOptions  = ParseSubOptions(args);
            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                subsInstance.Process();
                var consoleText = consoleOutput.GetOuput();
                Assert.That(consoleText.Contains("[ERROR]: "), Is.True);
            }
        }
Exemplo n.º 7
0
        public void OutputFileNotSpecified_ShouldPrintInConsole()
        {
            var args = new[]
            {
                "subs",
                "B"
            };
            var subsOptions  = ParseSubOptions(args);
            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                subsInstance.Process();
                var consoleText = consoleOutput.GetOuput();
                Assert.That(consoleText.Contains("B\r\n|3\r\n8\r\n"), Is.True);
            }
        }
Exemplo n.º 8
0
        public void StdInputWithSourceWord_ShouldIgnoreSourceWord()
        {
            var args = new[]
            {
                "subs",
                "B",
                "-i"
            };
            var subsOptions = ParseSubOptions(args);

            using (var consoleOutput = new ConsoleOutput())
            {
                var subsInstance = new Substitution(subsOptions);
                subsInstance.Process();
                var consoleText = consoleOutput.GetOuput();
                Assert.That(consoleText.Equals(""), Is.True);
            }
        }
Exemplo n.º 9
0
        public void OutputFileSpecified_ShouldPrintInFile()
        {
            var args = new[]
            {
                "subs",
                "B",
                "-o",
                "outputTest.txt"
            };
            var subsOptions  = ParseSubOptions(args);
            var subsInstance = new Substitution(subsOptions);

            subsInstance.Process();
            var text = File.ReadAllText("outputTest.txt");

            File.Delete("outputTest.txt");
            Assert.That(text.Contains("B\r\n|3\r\n8\r\n"), Is.True);
        }
Exemplo n.º 10
0
        public void MadLeetThreeSymbols_ShouldReturnSubstitutions()
        {
            var args = new[]
            {
                "subs",
                "BZS",
                "-m",
                "MadLeet"
            };
            var subsOptions  = ParseSubOptions(args);
            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                subsInstance.Process();
                Assert.AreEqual(1041, consoleOutput.GetOuput().Split('\n').Length);
            }
        }
Exemplo n.º 11
0
        public void SourceWordThreeLetterIgnoreCase_ShouldReturnSubstitutions()
        {
            var args = new[]
            {
                "subs",
                "bzs",
                "--ignore-case"
            };
            var subsOptions = ParseSubOptions(args);
            var expected    = "bzs\r\n" +
                              "|3zs\r\n" +
                              "8zs\r\n" +
                              "b2s\r\n" +
                              "b7_s\r\n" +
                              "|32s\r\n" +
                              "|37_s\r\n" +
                              "82s\r\n" +
                              "87_s\r\n" +
                              "bz5\r\n" +
                              "bz$\r\n" +
                              "|3z5\r\n" +
                              "|3z$\r\n" +
                              "8z5\r\n" +
                              "8z$\r\n" +
                              "b25\r\n" +
                              "b2$\r\n" +
                              "b7_5\r\n" +
                              "b7_$\r\n" +
                              "|325\r\n" +
                              "|32$\r\n" +
                              "|37_5\r\n" +
                              "|37_$\r\n" +
                              "825\r\n" +
                              "82$\r\n" +
                              "87_5\r\n" +
                              "87_$\r\n";
            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                subsInstance.Process();
                Assert.That(consoleOutput.GetOuput().Contains(expected), Is.True);
            }
        }
Exemplo n.º 12
0
        public void StdInputThreeSymbolsInput_ShouldPrintSubstitution()
        {
            var args = new[]
            {
                "subs",
                "-i"
            };
            var subsOptions = ParseSubOptions(args);

            using (new ConsoleInput("B\r\nC\r\n"))
            {
                using (var consoleOutput = new ConsoleOutput())
                {
                    var subsInstance = new Substitution(subsOptions);
                    subsInstance.Process();
                    var consoleText = consoleOutput.GetOuput();
                    Assert.That(consoleText.Equals("B\r\n|3\r\n8\r\nC\r\n[\r\n{\r\n(\r\n<\r\n"));
                }
            }
        }
Exemplo n.º 13
0
        public void SourceWord_ShouldReturnErrorAndHelp(string[] args)
        {
            var subsOptions = ParseSubOptions(args);

            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                try
                {
                    subsInstance.Process();
                }
                catch (VerbOptionException e)
                {
                    Logger.ErrorAndPrint(e.Message);
                }
                var consoleText = consoleOutput.GetOuput();
                Assert.That(consoleText.Contains("[ERROR]: "), Is.True);
            }
        }
Exemplo n.º 14
0
        public void StdDictMethodAndEncoding_ShouldPrintVerbose()
        {
            var args = new[]
            {
                "subs",
                "QW",
                "-v"
            };
            var subsOptions = ParseSubOptions(args);

            using (new ConsoleInput("B\r\nC\r\n"))
            {
                using (var consoleOutput = new ConsoleOutput())
                {
                    var subsInstance = new Substitution(subsOptions);
                    subsInstance.Process();
                    var consoleText = consoleOutput.GetOuput();
                    Assert.That(consoleText.Contains($"[METHOD]: GoodLeet{Environment.NewLine}"));
                    Assert.That(consoleText.Contains($"[DICTIONARY]: default{Environment.NewLine}"));
                }
            }
        }
Exemplo n.º 15
0
        public void DictWithGoodLeetOnlySymbols_ShouldReturnSubstitutions()
        {
            var content = "{\r\n\t\"GoodLeet\": {\r\n\t\t\"{\": [\r\n\t\t\t\"[\",\r\n\t\t\t\"(\"\r\n\t\t]\r\n\t}\r\n}";

            File.WriteAllText("testDict1.txt", content, Encoding.UTF8);
            var args = new[]
            {
                "subs",
                "{",
                "-d",
                "testDict1.txt"
            };
            var subsOptions  = ParseSubOptions(args);
            var expected     = "{\r\n[\r\n(\r\n";
            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                subsInstance.Process();
                File.Delete("testDict1.txt");
                Assert.That(consoleOutput.GetOuput().Contains(expected), Is.True);
            }
        }
Exemplo n.º 16
0
        public void WrongMethod_ShouldReturnSubstitutionsFromFirstAvailableMethod()
        {
            var args = new[]
            {
                "subs",
                "C",
                "-m",
                "balabala"
            };
            var subsOptions = ParseSubOptions(args);
            var expected    = "C\r\n" +
                              "[\r\n" +
                              "{\r\n" +
                              "(\r\n" +
                              "<\r\n";
            var subsInstance = new Substitution(subsOptions);

            using (var consoleOutput = new ConsoleOutput())
            {
                subsInstance.Process();
                Assert.That(consoleOutput.GetOuput().Contains(expected), Is.True);
            }
        }
Exemplo n.º 17
0
        private void SubstitutionButton_OnClick(object sender, RoutedEventArgs e) => SafeAction(() =>
        {
            var substitution = new Substitution(SubstitutionKeyTextBox.Text);

            SubstitutionOutputTextBlock.Text = substitution.Process(SubstitutionInputTextBox.Text);
        });
Exemplo n.º 18
0
        private static void BaseTest(string text, string expected, string key)
        {
            var substitution = new Substitution(key);

            Assert.AreEqual(expected, substitution.Process(text));
        }