Ejemplo n.º 1
0
        public void testGetAstRoot()
        {
            ClangWrapper wrapper = new ClangWrapper();

            // Create temporary test file
            string fileName = "func.c";

            using (StreamWriter sw = System.IO.File.CreateText(fileName))
            {
                sw.Write("int main() { return 0; }");
            }

            // Load file
            wrapper.loadFile("func.c");

            // Assert root kind and first child kind
            Assert.AreEqual(CursorKind.TranslationUnit, wrapper.getRoot().Kind);
            Assert.AreEqual(CursorKind.FunctionDecl, wrapper.getRoot().Children[0].Kind);
            Assert.AreEqual("main", wrapper.getRoot().Children[0].Spelling);

            wrapper.dispose();
            System.IO.File.Delete(fileName);
        }
Ejemplo n.º 2
0
        private void assertCodeWithTranslation(string languageCode, string code, string expectedTranslation, int childIndex)
        {
            createTemplateFiles();

            Translator      translator = new Translator(languageCode, "");
            ClangWrapper    wrapper    = getWrapper(code);
            Cursor          root       = wrapper.getRoot();
            TranslationUnit tu         = wrapper.getTranslationUnit();
            Cursor          child      = root.Children[childIndex];

            string translation = translator.translate(child, tu);

            Assert.AreEqual(expectedTranslation, translation);

            deleteTemplateFiles();
        }