コード例 #1
0
        public void ForLoopRemover_Test1()
        {
            ForLoopRemover target = new ForLoopRemover();

            List <Token> tokenList = Tokenizer.Tokenize("int j = 5; for (i = 0; i < 20 ; i++) {int var; if (1) { var = 10; }}");
            List <Token> expected  = Tokenizer.Tokenize("int j = 5; i = 0; if (i < 20) { do {int var; if (1) { var = 10; } i++;} while (i < 20); }");

            List <Token> actual;

            actual = target.Run(tokenList);

            Assert.IsTrue(expected.SequenceEqual <Token>(actual),
                          "Expected: \"" + string.Join <Token>(String.Empty, expected.ToArray()) + "\" " +
                          "Actual: \"" + string.Join <Token>(String.Empty, actual.ToArray()) + "\"");
        }
コード例 #2
0
        public void ForLoopRemover_Test2()
        {
            ForLoopRemover target = new ForLoopRemover();

            List <Token> tokenList = Tokenizer.Tokenize("for (i = 0; i < 20 + (4 * 4); i++);");
            List <Token> expected  = Tokenizer.Tokenize("i = 0; if (i < 20 + (4 * 4)) { do { i++; } while (i < 20 + (4 * 4)); }");

            List <Token> actual;

            actual = target.Run(tokenList);

            Assert.IsTrue(expected.SequenceEqual <Token>(actual),
                          "Expected: \"" + string.Join <Token>(String.Empty, expected.ToArray()) + "\" " +
                          "Actual: \"" + string.Join <Token>(String.Empty, actual.ToArray()) + "\"");
        }
コード例 #3
0
        public void ForLoopRemover_Test6()
        {
            ForLoopRemover target = new ForLoopRemover();

            List <Token> tokenList = Tokenizer.Tokenize("for (i = 0; i < 20; i++) i = 5;");
            List <Token> expected  = Tokenizer.Tokenize("i = 0; if (i < 20) { do { i = 5; i++ } while (i < 20); }");

            List <Token> actual;

            try
            {
                actual = target.Run(tokenList);
            }
            catch (Exception ex)
            {
                Assert.AreEqual("Invalid token of some kind", ex.Message);
                return;
            }
            Assert.Fail("No exception thrown");
        }