aboutsummaryrefslogtreecommitdiff
path: root/src/clients/reconcilio/util/wildcard_expander_TEST.cc
blob: e1bf74dbc2b3bcd60c27e8cb00920ecc12fc3d17 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
/* vim: set sw=4 sts=4 et foldmethod=syntax : */

/*
 * Copyright (c) 2007 David Leverton
 *
 * This file is part of the Paludis package manager. Paludis is free software;
 * you can redistribute it and/or modify it under the terms of the GNU General
 * Public License version 2, as published by the Free Software Foundation.
 *
 * Paludis is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
 * FOR A PARTICULAR PURPOSE.  See the GNU General Public License for more
 * details.
 *
 * You should have received a copy of the GNU General Public License along with
 * this program; if not, write to the Free Software Foundation, Inc., 59 Temple
 * Place, Suite 330, Boston, MA  02111-1307  USA
 */

#include "wildcard_expander.hh"

#include <paludis/util/fs_entry.hh>
#include <paludis/util/join.hh>

#include <test/test_runner.hh>
#include <test/test_framework.hh>

using namespace test;
using namespace paludis;

namespace test_cases
{
    struct WildcardExpanderGeneralTest : TestCase
    {
        WildcardExpanderGeneralTest() : TestCase("WildcardExpander general") {}

        std::string expand(const std::string & pattern)
        {
            return join(WildcardExpander(pattern, FSEntry::cwd() / "wildcard_expander_TEST_dir"),
                        WildcardExpander(), " ");
        }

        void run()
        {
            TEST_CHECK_EQUAL(expand("/xyz*zy"), "/xyz1zy /xyz22zy /xyzzy");
            TEST_CHECK_EQUAL(expand("/plugh"), "/plugh");
            TEST_CHECK_EQUAL(expand("/quux"), "/quux");
            TEST_CHECK_EQUAL(expand("/quux*quux"), "/quux*quux");
            TEST_CHECK_EQUAL(expand("/meh/?"), "/meh/1 /meh/2 /meh/3");
            TEST_CHECK_EQUAL(expand("/foo*\\*"), "/foo* /foo123*");
            TEST_CHECK_EQUAL(expand("/foo\\*"), "/foo*");
        }
    } wildcard_expander_general_test;

    struct WildcardExpanderIteratorSanityTest : TestCase
    {
        WildcardExpanderIteratorSanityTest() : TestCase("WildcardExpander iterator sanity") {}

        void run()
        {
            WildcardExpander it("/foo*bar", FSEntry::cwd() / "wildcard_expander_TEST_dir");
            TEST_CHECK(it == it);
            TEST_CHECK(! (it != it));
            TEST_CHECK(it != WildcardExpander());
            TEST_CHECK_STRINGIFY_EQUAL(*it, "/fooAbar");
            TEST_CHECK_EQUAL(it->basename(), "fooAbar");

            WildcardExpander it2(it);
            TEST_CHECK(it == it2);
            TEST_CHECK(! (it != it2));
            TEST_CHECK(it2 != WildcardExpander());
            TEST_CHECK_STRINGIFY_EQUAL(*++it2, "/fooBbar");
            TEST_CHECK_STRINGIFY_EQUAL(*it2, "/fooBbar");
            TEST_CHECK_EQUAL(it2->basename(), "fooBbar");
            TEST_CHECK(it != it2);
            TEST_CHECK(! (it == it2));
            TEST_CHECK(it2 != WildcardExpander());

            WildcardExpander it3(it2);
            TEST_CHECK(it2 == it3++);
            TEST_CHECK(it2 != it3);
            TEST_CHECK(it3 != WildcardExpander());
            TEST_CHECK_STRINGIFY_EQUAL(*it3, "/fooCbar");
            TEST_CHECK_EQUAL(it3->basename(), "fooCbar");

            it3 = it2;
            TEST_CHECK(it2 == it3);
            TEST_CHECK_STRINGIFY_EQUAL(*it3, "/fooBbar");
            TEST_CHECK_STRINGIFY_EQUAL(*it3++, "/fooBbar");
            TEST_CHECK(it3 != WildcardExpander());

            TEST_CHECK(++it3 != WildcardExpander());
            TEST_CHECK(++it3 != WildcardExpander());
            TEST_CHECK(++it3 == WildcardExpander());

            TEST_CHECK_EQUAL(join(WildcardExpander("/foo*bar", FSEntry::cwd() / "wildcard_expander_TEST_dir"),
                                  WildcardExpander(), " "),
                             "/fooAbar /fooBbar /fooCbar /fooDbar /fooEbar");
        }
    } wildcard_expander_iterator_sanity_test;
}