File indexing completed on 2024-04-28 05:50:34
0001 /* 0002 SPDX-FileCopyrightText: 2022 Ahmad Samir <a.samirh78@gmail.com> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #include "HotSpotFilterTest.h" 0008 #include <QTest> 0009 0010 QTEST_GUILESS_MAIN(HotSpotFilterTest) 0011 0012 void HotSpotFilterTest::testUrlFilterRegex_data() 0013 { 0014 QTest::addColumn<QString>("url"); 0015 QTest::addColumn<QString>("expectedUrl"); 0016 QTest::addColumn<bool>("matchResult"); 0017 0018 // A space, \n, or \t before the url to match what happens at runtime, 0019 // i.e. to match "http" but not "foohttp" 0020 QTest::newRow("url_simple") << " https://api.kde.org" 0021 << "https://api.kde.org" << true; 0022 QTest::newRow("url_with_port") << "\nhttps://api.kde.org:2098" 0023 << "https://api.kde.org:2098" << true; 0024 QTest::newRow("url_with_port_trailing_slash") << "\nhttps://api.kde.org:2098/" 0025 << "https://api.kde.org:2098/" << true; 0026 QTest::newRow("url_with_numeric_host") << "\nhttp://127.0.0.1" 0027 << "http://127.0.0.1" << true; 0028 QTest::newRow("url_with_numeric_host_port") << "\nhttp://127.0.0.1:4000" 0029 << "http://127.0.0.1:4000" << true; 0030 QTest::newRow("url_with_numeric_host_port_slash") << "\nhttp://127.0.0.1:4000/" 0031 << "http://127.0.0.1:4000/" << true; 0032 QTest::newRow("url_with_path") << "https://api.kde.org/path/to/somewhere" 0033 << "https://api.kde.org/path/to/somewhere" << true; 0034 QTest::newRow("url_with_query") << "https://user:pass@api.kde.org?somequery=foo" 0035 << "https://user:pass@api.kde.org?somequery=foo" << true; 0036 QTest::newRow("url_with_port_path") << " https://api.kde.org:2098/path/to/somewhere" 0037 << "https://api.kde.org:2098/path/to/somewhere" << true; 0038 QTest::newRow("url_with_user_password") << "\thttps://user:blah@api.kde.org" 0039 << "https://user:blah@api.kde.org" << true; 0040 QTest::newRow("url_with_user_password_port_fragment") << " https://user:blah@api.kde.org:2098#fragment" 0041 << "https://user:blah@api.kde.org:2098#fragment" << true; 0042 QTest::newRow("url_all_bells") << " https://user:pass@api.kde.org:2098/path/to/somewhere?somequery=foo#fragment" 0043 << "https://user:pass@api.kde.org:2098/path/to/somewhere?somequery=foo#fragment" << true; 0044 QTest::newRow("uppercase") << " https://invent.kde.org/frameworks/ktexteditor/-/blob/master/README.md" 0045 << "https://invent.kde.org/frameworks/ktexteditor/-/blob/master/README.md" << true; 0046 QTest::newRow("markup") << " [https://foobar](https://foobar)" 0047 << "https://foobar" << true; 0048 QTest::newRow("markup_parens") << "[unix-history-repo](https://github.com/dspinellis/unix-history-repo)" 0049 << "https://github.com/dspinellis/unix-history-repo" << true; 0050 QTest::newRow("markup_with_parens_inside_parens") << "[*Das verrückte Labyrinth*](https://en.wikipedia.org/wiki/Labyrinth_(board_game))" 0051 << "https://en.wikipedia.org/wiki/Labyrinth_(board_game)" << true; 0052 0053 QTest::newRow("bracket_before") << "[198]http://www.ietf.org/rfc/rfc2396.txt" 0054 << "http://www.ietf.org/rfc/rfc2396.txt" << true; 0055 QTest::newRow("quote_before") << "\"http://www.ietf.org/rfc/rfc2396.txt" 0056 << "http://www.ietf.org/rfc/rfc2396.txt" << true; 0057 0058 QTest::newRow("grave_before") << "`https://foo.bar`" 0059 << "https://foo.bar" << true; 0060 0061 QTest::newRow("equals_before") << "foo=https://foo.bar" 0062 << "https://foo.bar" << true; 0063 0064 QTest::newRow("url_inside_angle_brackets") << "<https://google.com>" 0065 << "https://google.com" << true; 0066 0067 QTest::newRow("file_scheme") << "file:///some/file" 0068 << "file:///some/file" << true; 0069 0070 QTest::newRow("uppercase_host") << "https://EXAMPLE.com" 0071 << "https://EXAMPLE.com" << true; 0072 QTest::newRow("uppercase_query") << "https://example.com?fooOpt=barVal" 0073 << "https://example.com?fooOpt=barVal" << true; 0074 QTest::newRow("uppercase_fragment") << "https://example.com?fooOpt=barVal#FRAG" 0075 << "https://example.com?fooOpt=barVal#FRAG" << true; 0076 0077 QTest::newRow("www") << " www.kde.org" 0078 << "www.kde.org" << true; 0079 0080 QTest::newRow("with_comma_in_path") << "https://example.com/foo,bar" 0081 << "https://example.com/foo,bar" << true; 0082 0083 QTest::newRow("empty_query") << "http://example.com/?" 0084 << "http://example.com/?" << true; 0085 QTest::newRow("empty_fragment") << "http://example.com/#" 0086 << "http://example.com/#" << true; 0087 0088 QTest::newRow("www_followed_by_colon") << "www.example.com:foo@bar.com" 0089 << "www.example.com" << true; 0090 0091 QTest::newRow("ipv6") << "http://[2a00:1450:4001:829::200e]/" 0092 << "http://[2a00:1450:4001:829::200e]/" << true; 0093 QTest::newRow("ipv6_with_port") << "http://[2a00:1450:4001:829::200e]:80/" 0094 << "http://[2a00:1450:4001:829::200e]:80/" << true; 0095 0096 QTest::newRow("query_with_question_marks") << "ldap://[2001:db8::7]/c=GB?objectClass?one" 0097 << "ldap://[2001:db8::7]/c=GB?objectClass?one" << true; 0098 0099 QTest::newRow("path_with_parens") << "https://en.wikipedia.org/wiki/C_(programming_language)" 0100 << "https://en.wikipedia.org/wiki/C_(programming_language)" << true; 0101 QTest::newRow("query_with_parens") << "http://en.wikipedia.org/w/index.php?title=Thresholding_(image_processing)&oldid=132306976" 0102 << "http://en.wikipedia.org/w/index.php?title=Thresholding_(image_processing)&oldid=132306976" << true; 0103 QTest::newRow("fragment_with_parens") << "https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences" 0104 << "https://en.wikipedia.org/wiki/ANSI_escape_code#CSI_(Control_Sequence_Introducer)_sequences" << true; 0105 QTest::newRow("url_with_lots_of_parens") << "(https://example.com/foo(bar(baz(qux)quux)quuux))))" 0106 << "https://example.com/foo(bar(baz(qux)quux)quuux)" << true; 0107 } 0108 0109 void HotSpotFilterTest::testUrlFilterRegex() 0110 { 0111 QFETCH(QString, url); 0112 QFETCH(QString, expectedUrl); 0113 QFETCH(bool, matchResult); 0114 0115 const QRegularExpression ®ex = Konsole::UrlFilter::FullUrlRegExp; 0116 const QRegularExpressionMatch match = regex.match(url); 0117 // qDebug() << match; 0118 0119 QCOMPARE(match.hasMatch(), matchResult); 0120 if (matchResult) { 0121 QCOMPARE(match.capturedView(0), expectedUrl); 0122 } 0123 } 0124 0125 #include "moc_HotSpotFilterTest.cpp"