Esempio n. 1
0
        public void TestGenerateSrcMLFromStrings()
        {
            List <String> bufferList = new List <String>();
            List <String> fileList   = new List <String>();

            String str  = "int main(){int c; c = 0; ++c;}";
            String str2 = "int foo(){int c; c = 0; ++c;}";

            fileList.Add("input.cpp");
            fileList.Add("input2.cpp");
            bufferList.Add(str);
            bufferList.Add(str2);

            LibSrcMLRunner run = new LibSrcMLRunner();

            try {
                List <string> b = run.GenerateSrcMLFromStrings(bufferList, fileList, Language.CPlusPlus, new Collection <UInt32>()
                {
                    LibSrcMLRunner.SrcMLOptions.SRCML_OPTION_MODIFIER
                }, false).ToList <string>();
                Assert.True(Convert.ToBoolean(b.Count));
                XDocument doc   = XDocument.Parse(b.ElementAt(0));
                var       units = from unit in doc.Descendants(XName.Get("unit", "http://www.srcML.org/srcML/src"))
                                  where unit.Attribute("filename") != null
                                  select unit;

                string file = "input.cpp";
                var    f1   = (from ele in units
                               where ele.Attribute("filename").Value == file
                               select ele);
                Assert.AreEqual(file, f1.FirstOrDefault().Attribute("filename").Value);

                string file2 = "input2.cpp";
                var    f2    = (from ele in units
                                where ele.Attribute("filename").Value == file2
                                select ele);
                Assert.AreEqual(file2, f2.FirstOrDefault().Attribute("filename").Value);
            }
            catch (SrcMLException e) {
                throw e;
            }
        }