File indexing completed on 2024-05-05 04:35:22

0001 /* This file is part of KDevelop
0002     Copyright 2010 Niko Sams <niko.sams@gmail.com>
0003 
0004    This library is free software; you can redistribute it and/or
0005    modify it under the terms of the GNU Library General Public
0006    License version 2 as published by the Free Software Foundation.
0007 
0008    This library is distributed in the hope that it will be useful,
0009    but WITHOUT ANY WARRANTY; without even the implied warranty of
0010    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
0011    Library General Public License for more details.
0012 
0013    You should have received a copy of the GNU Library General Public License
0014    along with this library; see the file COPYING.LIB.  If not, write to
0015    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
0016    Boston, MA 02110-1301, USA.
0017 */
0018 
0019 #include "duchain.h"
0020 
0021 #include <QTest>
0022 
0023 #include <language/duchain/parsingenvironment.h>
0024 #include <language/duchain/duchain.h>
0025 #include <language/duchain/duchainlock.h>
0026 #include <language/duchain/topducontext.h>
0027 #include <language/duchain/declaration.h>
0028 
0029 QTEST_MAIN(Css::TestDUChain)
0030 
0031 namespace Css
0032 {
0033 
0034 TestDUChain::TestDUChain()
0035 {
0036 }
0037 
0038 void TestDUChain::testContext()
0039 {
0040     //                 01234567890123456
0041     QByteArray method("a { color: red; }");
0042 
0043     KDevelop::TopDUContext* top = parse(method, DumpAll);
0044     DUChainReleaser releaseTop(top);
0045     KDevelop::DUChainWriteLocker lock(KDevelop::DUChain::lock());
0046 
0047     QCOMPARE(top->childContexts().count(), 1);
0048     QVERIFY(top->childContexts().first()->range() == KDevelop::RangeInRevision(0, 3, 0, 16));
0049     KDevelop::Declaration *dec = top->findDeclarationAt(KDevelop::CursorInRevision(0, 0));
0050     QCOMPARE(dec->qualifiedIdentifier().toString(), QString("a ")); //TODO: this should not include the space
0051     QVERIFY(dec->range() == KDevelop::RangeInRevision(0, 0, 0, 2)); 
0052 }
0053 
0054 void TestDUChain::testPseudoClass()
0055 {
0056     //                 0123456789012345678901234
0057     QByteArray method("a:active { color: red; }");
0058 
0059     KDevelop::TopDUContext* top = parse(method, DumpAll);
0060     DUChainReleaser releaseTop(top);
0061     KDevelop::DUChainWriteLocker lock(KDevelop::DUChain::lock());
0062 
0063     QCOMPARE(top->childContexts().count(), 1);
0064     QVERIFY(top->childContexts().first()->range() == KDevelop::RangeInRevision(0, 10, 0, 23));
0065     KDevelop::Declaration *dec = top->findDeclarationAt(KDevelop::CursorInRevision(0, 0));
0066     QVERIFY(dec->range() == KDevelop::RangeInRevision(0, 0, 0, 9));
0067     QCOMPARE(dec->qualifiedIdentifier().toString(), QString("a:active ")); //TODO: this should not include the space
0068 }
0069 
0070 
0071 }
0072