Commit d7d21bea authored by Christoph Cullmann's avatar Christoph Cullmann 🐮
Browse files

add unit test, just on non windows

parent 2e6a1ea9
......@@ -5,9 +5,9 @@ find_package(Qt5Test ${QT_MIN_VERSION} QUIET REQUIRED)
macro(kate_executable_tests)
foreach(_testname ${ARGN})
add_executable(${_testname} ${_testname}.cpp)
target_link_libraries(
${_testname}
${_testname}
PRIVATE
kate-lib
Qt5::Test
......@@ -22,4 +22,5 @@ kate_executable_tests(
session_test
session_manager_test
sessions_action_test
urlinfo_test
)
/*
SPDX-FileCopyrightText: 2020 Christoph Cullmann <cullmann@kde.org>
SPDX-License-Identifier: MIT
*/
#include "urlinfo_test.h"
#include <QDir>
#include <QFile>
#include <QFileInfo>
#include <QTemporaryDir>
#include <QTest>
QTEST_MAIN(UrlInfoTest)
void UrlInfoTest::someUrls()
{
// check that some things convert correctly to urls
QCOMPARE(UrlInfo(QStringLiteral("file:///for_sure_not_there_path_xxcv123/to/file")).url.toString(), QStringLiteral("file:///for_sure_not_there_path_xxcv123/to/file"));
QCOMPARE(UrlInfo(QStringLiteral("sftp://127.0.0.1:1234/path/to/file")).url.toString(), QStringLiteral("sftp://127.0.0.1:1234/path/to/file"));
}
void UrlInfoTest::someCursors()
{
// check that some things convert correctly to urls + cursors
QCOMPARE(UrlInfo(QStringLiteral("file:///for_sure_not_there_path_xxcv123/to/file:1234:12")).url.toString(), QStringLiteral("file:///for_sure_not_there_path_xxcv123/to/file"));
QCOMPARE(UrlInfo(QStringLiteral("file:///for_sure_not_there_path_xxcv123/to/file:1234:12")).cursor, KTextEditor::Cursor(1233, 11));
QCOMPARE(UrlInfo(QStringLiteral("sftp://127.0.0.1:1234/path/to/file:1:1")).url.toString(), QStringLiteral("sftp://127.0.0.1:1234/path/to/file"));
QCOMPARE(UrlInfo(QStringLiteral("sftp://127.0.0.1:1234/path/to/file:1:1")).cursor, KTextEditor::Cursor(0, 0));
}
void UrlInfoTest::urlWithColonAtStart()
{
#ifndef WIN32 // : invalid for filenames on Windows
// create test file in temporary directory, as qt sees :test..... as absolute, hack with ./:
QTemporaryDir dir;
const auto oldCurrent = QDir::currentPath();
QDir::setCurrent(dir.path());
QFile test(QStringLiteral("./:test.txt"));
QVERIFY(test.open(QFile::WriteOnly));
// see bug 430216 => before this was some absolute file name
const UrlInfo info(QStringLiteral(":test.txt:123:1"));
QCOMPARE(info.cursor, KTextEditor::Cursor(122, 0));
QVERIFY(info.url.isLocalFile());
QVERIFY(QFileInfo::exists(info.url.toLocalFile()));
// back to old working dir
QDir::setCurrent(oldCurrent);
#endif
}
/*
SPDX-FileCopyrightText: 2020 Christoph Cullmann <cullmann@kde.org>
SPDX-License-Identifier: MIT
*/
#pragma once
#include <QObject>
#include "../../urlinfo.h"
class UrlInfoTest : public QObject
{
Q_OBJECT
private Q_SLOTS:
void someUrls();
void someCursors();
void urlWithColonAtStart();
};
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment