File indexing completed on 2024-05-05 04:35:22
0001 #include "parsejobtest.h" 0002 0003 #include <tests/autotestshell.h> 0004 #include <tests/testcore.h> 0005 #include <interfaces/ilanguagecontroller.h> 0006 #include <language/backgroundparser/backgroundparser.h> 0007 #include <tests/testproject.h> 0008 #include <tests/testfile.h> 0009 #include <language/duchain/duchainlock.h> 0010 #include <language/duchain/duchain.h> 0011 #include <language/duchain/parsingenvironment.h> 0012 0013 #include <QTest> 0014 0015 QTEST_MAIN(Css::TestParseJob) 0016 0017 using namespace KDevelop; 0018 0019 namespace Css { 0020 0021 void TestParseJob::initTestCase() 0022 { 0023 AutoTestShell::init(); 0024 TestCore* core = TestCore::initialize(Core::NoUi); 0025 m_projectController = new TestProjectController(core); 0026 core->setProjectController(m_projectController); 0027 } 0028 0029 void TestParseJob::cleanupTestCase() 0030 { 0031 TestCore::shutdown(); 0032 } 0033 0034 void TestParseJob::testSimple() 0035 { 0036 TopDUContext::Features features = TopDUContext::VisibleDeclarationsAndContexts; 0037 0038 TestProject* project = new TestProject; 0039 m_projectController->closeAllProjects(); 0040 m_projectController->addProject(project); 0041 0042 TestFile f("a { color: red; }", "css", project); 0043 f.parse(features); 0044 0045 ReferencedTopDUContext top = f.topContext(); 0046 0047 DUChainReadLocker lock; 0048 QVERIFY(top); 0049 QVERIFY(top->parsingEnvironmentFile()->language() == IndexedString("Css")); 0050 QCOMPARE(top->childContexts().count(), 1); 0051 } 0052 0053 void TestParseJob::testSimpleHtml() 0054 { 0055 TopDUContext::Features features = TopDUContext::VisibleDeclarationsAndContexts; 0056 0057 TestProject* project = new TestProject; 0058 m_projectController->closeAllProjects(); 0059 m_projectController->addProject(project); 0060 0061 TestFile f("<html><style>a { color: red; }</style></html>", "html", project); 0062 f.parse(features); 0063 0064 ReferencedTopDUContext top = f.topContext(); 0065 0066 DUChainReadLocker lock; 0067 QVERIFY(top); 0068 QVERIFY(top->parsingEnvironmentFile()->language() == IndexedString("Css")); 0069 QCOMPARE(top->childContexts().count(), 1); 0070 } 0071 0072 void TestParseJob::testHtmlTwoStyleElements() 0073 { 0074 TopDUContext::Features features = TopDUContext::VisibleDeclarationsAndContexts; 0075 0076 TestProject* project = new TestProject; 0077 m_projectController->closeAllProjects(); 0078 m_projectController->addProject(project); 0079 0080 TestFile f("<html><style>a { color: red; }</style><style>h1 { font-weight:normal; }</style></html>", 0081 "html", project); 0082 f.parse(features); 0083 0084 ReferencedTopDUContext top = f.topContext(); 0085 0086 DUChainReadLocker lock; 0087 QVERIFY(top); 0088 QVERIFY(top->parsingEnvironmentFile()->language() == IndexedString("Css")); 0089 QCOMPARE(top->childContexts().count(), 2); 0090 } 0091 0092 0093 } 0094