コード例 #1
0
        public void AddHeaderToCodeTest()
        {
            List<string> inputCode = new List<string>()
            {
                "1",
                "2",
                "5",
                "6"
            };
            PreProcessorParser target = new PreProcessorParser(inputCode);
            PrivateObject po = new PrivateObject(target);

            List<string> includeCode = new List<string>()
            {
                "3",
                "4"
            };
            po.Invoke("AddHeaderToCode",
                new Type[]{typeof(int), typeof(List<string>)},
                new Object[]{2, includeCode}
            );
            List<string> actual = (List<string>)po.GetField("code");

            List<string> expected = new List<string>()
            {
                "1",
                "2",
                "3",
                "4",
                "5",
                "6"
            };

            Assert.AreEqual(expected.Count, actual.Count);
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }
コード例 #2
0
        public void DefinitionsGatheringTest()
        {
            List<string> inputCode = new List<string>()
            {
                "#define dupa 2dupy\\",
                " a nawet 3 dupy"
            };
            PreProcessorParser target = new PreProcessorParser(inputCode);
            PrivateObject po = new PrivateObject(target);
            po.Invoke("GetMacros");

            List<KeyValuePair<string, string>> actual = (List<KeyValuePair<string, string>>)po.GetField("objectLikeMacros");

            Assert.AreEqual(1, actual.Count);
            Assert.AreEqual("dupa", actual[0].Key);
            Assert.AreEqual("2dupy a nawet 3 dupy", actual[0].Value);
        }
コード例 #3
0
        public void RemoveTextBlockTestFromOneLine()
        {
            List<string> inputCode = new List<string>()
            {
                "12345"
            };
            PreProcessorParser target = new PreProcessorParser(inputCode);
            PrivateObject po = new PrivateObject(target);
            int startLine = 0;
            int startChar = 1;
            int endLine = 0;
            int endChar = 3;
            po.Invoke(
                "RemoveTextBlock",
                new Type[] { typeof(int), typeof(int), typeof(int), typeof(int) },
                new object[] { startLine, startChar, endLine, endChar }
            );

            List<string> expected = new List<string>()
            {
                "145",
            };

            List<string> actual = (List<string>)po.GetField("code");

            Assert.AreEqual(expected.Count, actual.Count);
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }
コード例 #4
0
        public void RemoveOneLineCommentsTest()
        {
            var inputCode = new List<string>() {
                @"dsadsa /* fdsfjdis // iropew",
                @"dsadsa */ gdkops"
            };
            PreProcessorParser target = new PreProcessorParser(inputCode);
            PrivateObject po = new PrivateObject(target);
            po.Invoke("RemoveOneLineComments", new Type[] { }, new Object[] { });

            List<string> actual = (List<string>)po.GetField("code");

            Assert.AreEqual(2, actual.Count);
            Assert.AreEqual(@"dsadsa /* fdsfjdis ", actual[0]);
            Assert.AreEqual(@"dsadsa */ gdkops", actual[1]);
        }
コード例 #5
0
        public void ifndefendifTest()
        {
            List<string> inputCode = new List<string>()
            {
                "#ifndef dupa",
                "tekst1",
                "#endif",
                "#ifdef dupa",
                "tekst2",
                "#endif",
                "#define dupa",
                "#ifndef dupa",
                "tekst3",
                "#endif",
                "#ifdef dupa",
                "tekst4",
                "#endif"
            };
            PreProcessorParser target = new PreProcessorParser(inputCode);
            PrivateObject po = new PrivateObject(target);
            po.Invoke("GetMacros");

            List<string> expected = new List<string>()
            {
                "",
                "tekst1",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "",
                "tekst4",
                ""
            };

            List<string> actual = (List<string>)po.GetField("code");

            Assert.AreEqual(expected.Count, actual.Count);
            for (int i = 0; i < expected.Count; i++)
            {
                Assert.AreEqual(expected[i], actual[i]);
            }
        }
コード例 #6
0
        public void GetFileNameFromPathTest()
        {
            PreProcessorParser target = new PreProcessorParser(new List<string>());
            PrivateObject po = new PrivateObject(target);

            //test1
            string actual = (string)po.Invoke(
                "GetFileNameFromPath",
                new Type[]{typeof(string)},
                new Object[]{@"D:\cad\dupa.dupa"}
            );
            Assert.AreEqual("dupa.dupa", actual);

            //test2
            actual = (string)po.Invoke(
                "GetFileNameFromPath",
                new Type[] { typeof(string) },
                new Object[] { @"D:/cad/pupa.pupa" }
            );
            Assert.AreEqual("pupa.pupa", actual);
        }