|
| 1 | +/* |
| 2 | + * Cppcheck - A tool for static C/C++ code analysis |
| 3 | + * Copyright (C) 2007-2019 Cppcheck team. |
| 4 | + * |
| 5 | + * This program is free software: you can redistribute it and/or modify |
| 6 | + * it under the terms of the GNU General Public License as published by |
| 7 | + * the Free Software Foundation, either version 3 of the License, or |
| 8 | + * (at your option) any later version. |
| 9 | + * |
| 10 | + * This program is distributed in the hope that it will be useful, |
| 11 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | + * GNU General Public License for more details. |
| 14 | + * |
| 15 | + * You should have received a copy of the GNU General Public License |
| 16 | + * along with this program. If not, see <http://www.gnu.org/licenses/>. |
| 17 | + */ |
| 18 | + |
| 19 | + |
| 20 | +#include "testsuite.h" |
| 21 | +#include "utils.h" |
| 22 | + |
| 23 | +class TestUtils : public TestFixture { |
| 24 | +public: |
| 25 | + TestUtils() : TestFixture("TestUtils") { |
| 26 | + } |
| 27 | + |
| 28 | +private: |
| 29 | + void run() OVERRIDE { |
| 30 | + TEST_CASE(isValidGlobPattern); |
| 31 | + TEST_CASE(matchglob); |
| 32 | + } |
| 33 | + |
| 34 | + void isValidGlobPattern() { |
| 35 | + ASSERT_EQUALS(true, ::isValidGlobPattern("*")); |
| 36 | + ASSERT_EQUALS(true, ::isValidGlobPattern("*x")); |
| 37 | + ASSERT_EQUALS(true, ::isValidGlobPattern("x*")); |
| 38 | + ASSERT_EQUALS(true, ::isValidGlobPattern("*/x/*")); |
| 39 | + ASSERT_EQUALS(true, ::isValidGlobPattern("x/*/z")); |
| 40 | + ASSERT_EQUALS(false, ::isValidGlobPattern("**")); |
| 41 | + ASSERT_EQUALS(false, ::isValidGlobPattern("**x")); |
| 42 | + ASSERT_EQUALS(false, ::isValidGlobPattern("x**")); |
| 43 | + |
| 44 | + ASSERT_EQUALS(true, ::isValidGlobPattern("?")); |
| 45 | + ASSERT_EQUALS(true, ::isValidGlobPattern("?x")); |
| 46 | + ASSERT_EQUALS(true, ::isValidGlobPattern("x?")); |
| 47 | + ASSERT_EQUALS(true, ::isValidGlobPattern("?/x/?")); |
| 48 | + ASSERT_EQUALS(true, ::isValidGlobPattern("x/?/z")); |
| 49 | + ASSERT_EQUALS(false, ::isValidGlobPattern("??")); |
| 50 | + ASSERT_EQUALS(false, ::isValidGlobPattern("??x")); |
| 51 | + ASSERT_EQUALS(false, ::isValidGlobPattern("x??")); |
| 52 | + } |
| 53 | + |
| 54 | + void matchglob() { |
| 55 | + ASSERT_EQUALS(true, ::matchglob("*", "xyz")); |
| 56 | + ASSERT_EQUALS(true, ::matchglob("x*", "xyz")); |
| 57 | + ASSERT_EQUALS(true, ::matchglob("*z", "xyz")); |
| 58 | + ASSERT_EQUALS(true, ::matchglob("*y*", "xyz")); |
| 59 | + ASSERT_EQUALS(true, ::matchglob("*y*", "yz")); |
| 60 | + ASSERT_EQUALS(false, ::matchglob("*y*", "abc")); |
| 61 | + ASSERT_EQUALS(true, ::matchglob("*", "x/y/z")); |
| 62 | + ASSERT_EQUALS(true, ::matchglob("*/y/z", "x/y/z")); |
| 63 | + |
| 64 | + ASSERT_EQUALS(false, ::matchglob("?", "xyz")); |
| 65 | + ASSERT_EQUALS(false, ::matchglob("x?", "xyz")); |
| 66 | + ASSERT_EQUALS(false, ::matchglob("?z", "xyz")); |
| 67 | + ASSERT_EQUALS(true, ::matchglob("?y?", "xyz")); |
| 68 | + ASSERT_EQUALS(true, ::matchglob("?/?/?", "x/y/z")); |
| 69 | + } |
| 70 | +}; |
| 71 | + |
| 72 | +REGISTER_TEST(TestUtils) |
0 commit comments