File indexing completed on 2024-04-28 04:35:54

0001 /*
0002  * This file is part of KDevelop
0003  * Copyright (C) 2012-2015 Miquel Sabaté Solà <mikisabate@gmail.com>
0004  *
0005  * This program is free software: you can redistribute it and/or modify
0006  * it under the terms of the GNU General Public License as published by
0007  * the Free Software Foundation, either version 3 of the License, or
0008  * (at your option) any later version.
0009  *
0010  * This program is distributed in the hope that it will be useful,
0011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
0012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0013  * GNU General Public License for more details.
0014  *
0015  * You should have received a copy of the GNU General Public License
0016  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
0017  */
0018 
0019 
0020 #ifndef RUBY_TESTDUCHAIN_H
0021 #define RUBY_TESTDUCHAIN_H
0022 
0023 
0024 #include <duchain/tests/duchaintestbase.h>
0025 #include <language/duchain/types/typepointer.h>
0026 
0027 
0028 namespace KDevelop {
0029     class UnsureType;
0030 }
0031 
0032 namespace ruby {
0033 
0034 /**
0035  * @class TestDUChain
0036  * The DUChain test suite.
0037  */
0038 class TestDUChain : public DUChainTestBase
0039 {
0040     Q_OBJECT
0041 
0042 public:
0043     /// Constructor.
0044     TestDUChain();
0045 
0046 protected:
0047     /// Re-implemented from DUChainTestBase.
0048     KDevelop::TopDUContext * parse(const QByteArray &code, const QString &id) override;
0049 
0050 private:
0051     /**
0052      * Given an unsure @p type, compare its possible types with the given
0053      * @p list of class identifiers.
0054      * @note that the order of the @p list items is important.
0055      */
0056     void testUnsureTypes(KDevelop::TypePtr<KDevelop::UnsureType> type,
0057                          const QStringList &list);
0058 
0059     /**
0060      * Given a top context @p ctx, get all the encountered problems and
0061      * compare their descriptions to the given @p list of problem descriptions.
0062      * @note that the order of the @p list items is important.
0063      */
0064     void testProblems(KDevelop::TopDUContext *ctx, const QStringList &list);
0065 
0066 private slots:
0067     // Builtin classes
0068     void numeric();
0069     void range();
0070     void stringAndRegexp();
0071     void booleanAndNil();
0072     void lineFileEncoding();
0073     void symbol();
0074     void lambda();
0075     void self();
0076 
0077     // Statements
0078     void alias();
0079     void aliasGlobal1();
0080     void aliasGlobal2();
0081     void yield1();
0082     void yield2();
0083     void yield3();
0084     void ifStatement();
0085     void caseStatement();
0086     void forStatement();
0087     void hereDoc();
0088     void exceptions();
0089     void method();
0090     void classStatement();
0091 
0092     // Assignments
0093     void simpleUnsure();
0094     void unsureHash();
0095     void multipleAssignment1();
0096     void multipleAssignment2();
0097     void multipleAssignmentLeft();
0098     void multipleAssignmentRight1();
0099     void multipleAssignmentRight2();
0100     void multipleAssignmentStar();
0101     void multipleAssignmentNamedStar();
0102     void starAtTheBeginning();
0103     void starAtTheEnd();
0104     void emptyStar();
0105     void unpackArray1();
0106     void unpackArray2();
0107     void unpackArray3();
0108     void aliasedAssignment();
0109     void withMethodCallAndBlock();
0110 
0111     // ClassType
0112     void assignFromArrayItem1();
0113     void assignFromArrayItem2();
0114     void assignFromHashItem();
0115     void assignToArrayItem();
0116     void arrayInstanceVariable();
0117 
0118     // Declarations
0119     void checkVariableKind();
0120     void instanceClassMethodDeclaration();
0121     void reopenMethodDeclaration();
0122     void singletonMethods();
0123     void singletonClass1();
0124     void singletonClass2();
0125     void singletonClass3();
0126     void singletonMethodVisibility();
0127     void accessPolicyMethodInClass();
0128     void accessPolicyMethodInModule();
0129     void accessPolicyOnBlock();
0130     void nestedAccessPolicy();
0131     void checkSubClassing1();
0132     void checkSubClassing2();
0133     void checkSubClassingErrors();
0134     void errorOnInvalidRedeclaration1();
0135     void errorOnInvalidRedeclaration2();
0136     void instanceVariable();
0137     void classVariable();
0138     void classModulesScopes();
0139     void globals1();
0140     void globals2();
0141 
0142     // Returning values
0143     void multipleReturns();
0144     void implicitReturn();
0145     void mixedExplicitAndImplicitReturn();
0146     void nilReturn();
0147     void instanceClassMethodsReturn();
0148 
0149     // Methods
0150     void callingToInstanceMethod();
0151     void chainedCalls1();
0152     void chainedCalls2();
0153     void chainedCalls3();
0154     void super();
0155     void guessArgumentsType1();
0156     void guessArgumentsType2();
0157     void guessArgumentsType3();
0158     void showErrorOnTooFewArguments();
0159     void showErrorOnTooManyArguments();
0160     void hashArgument();
0161     void setUnsureArgument();
0162     void conflictOnSpecialMethods();
0163 
0164     // Include & Extend
0165     void include1();
0166     void include2();
0167     void extend();
0168     void problemOnInvalidMixin();
0169 };
0170 
0171 }
0172 
0173 
0174 #endif /* RUBY_TESTDUCHAIN_H */