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

0001 /*
0002  * This file is part of KDevelop
0003  * Copyright (C) 2014-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 #include <QtTest/QtTest>
0021 #include <rails/switchers.h>
0022 #include <rails/helpers.h>
0023 #include <rails/tests/rails.h>
0024 #include <util/path.h>
0025 
0026 
0027 QTEST_MAIN(ruby::rails::Test)
0028 
0029 using namespace ruby::rails;
0030 
0031 Test::Test()
0032 {
0033     /* There's nothing to do here. */
0034 }
0035 
0036 void Test::TestFindRailsRoot()
0037 {
0038     KDevelop::Path path;
0039 
0040     // Empty URL.
0041     path = Helpers::findRailsRoot(QUrl(""));
0042     Q_ASSERT(!path.isValid());
0043 
0044     // App.
0045     path = Helpers::findRailsRoot(QUrl("/rails/app/controllers/file.rb"));
0046     Q_ASSERT(path.isValid());
0047     QCOMPARE(path.toLocalFile(), QString("/rails"));
0048     path = Helpers::findRailsRoot(QUrl("/rails/app/models/file.rb"));
0049     Q_ASSERT(path.isValid());
0050     QCOMPARE(path.toLocalFile(), QString("/rails"));
0051     path = Helpers::findRailsRoot(QUrl("/rails/app/views/file.rb"));
0052     Q_ASSERT(path.isValid());
0053     QCOMPARE(path.toLocalFile(), QString("/rails"));
0054 
0055     // Tests.
0056     path = Helpers::findRailsRoot(QUrl("/rails/test/file.rb"));
0057     Q_ASSERT(path.isValid());
0058     QCOMPARE(path.toLocalFile(), QString("/rails"));
0059     path = Helpers::findRailsRoot(QUrl("/rails/dir/test/file.rb"));
0060     Q_ASSERT(path.isValid());
0061     QCOMPARE(path.toLocalFile(), QString("/rails/dir"));
0062 
0063     // Invalids
0064     path = Helpers::findRailsRoot(QUrl("/rails/app/test/file.rb"));
0065     Q_ASSERT(!path.isValid());
0066     path = Helpers::findRailsRoot(QUrl("/rails/app/controllers"));
0067     Q_ASSERT(!path.isValid());
0068 }
0069