blob: e4585e69b3e7e900e9299835e8fc97931a2bc7d6 [file] [log] [blame]
Alexandre Lisionddd731e2014-01-31 11:50:08 -05001// Copyright (C) 2009-2010 David Sugar, Tycho Softworks.
2//
3// This file is part of GNU uCommon C++.
4//
5// GNU uCommon C++ is free software: you can redistribute it and/or modify
6// it under the terms of the GNU Lesser General Public License as published
7// by the Free Software Foundation, either version 3 of the License, or
8// (at your option) any later version.
9//
10// GNU uCommon C++ 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 Lesser General Public License for more details.
14//
15// You should have received a copy of the GNU Lesser General Public License
16// along with GNU uCommon C++. If not, see <http://www.gnu.org/licenses/>.
17
18#ifndef DEBUG
19#define DEBUG
20#endif
21
22#include <ucommon/ucommon.h>
23
24#include <stdio.h>
25
26using namespace UCOMMON_NAMESPACE;
27
28extern "C" int main()
29{
30 int test_argc;
31 char *test_argv[6];
32
33 shell::bind("test");
34
35 test_argc = 5;
36 test_argv[0] = (char *)"test";
37
38 test_argv[1] = (char *)"--lines=5";
39 test_argv[2] = (char *)"-r";
40 test_argv[3] = (char *)"a";
41 test_argv[4] = (char *)"b";
42 test_argv[5] = NULL;
43
44 shell::flagopt rflag('r', "--reverse", "reverse order of arguments");
45 shell::flagopt tflag('t', "--testing", "never hit this flag");
46 shell::numericopt lines('l', "--lines", "number of lines in output");
47 shell args(test_argc, test_argv);
48
49 assert(!tflag);
50 assert(is(rflag));
51 assert(*lines == 5);
52 assert(args() == 2); // two file arguments left
53 assert(eq(args[0], "a")); // first file argument is "a"
54
55 string_t prefix, subdir, basedir;
56
57 prefix = shell::path(shell::SYSTEM_PREFIX);
58 subdir = shell::path(shell::SYSTEM_PREFIX, "test");
59 basedir = shell::path(shell::SYSTEM_PREFIX, "/test");
60
61 prefix = prefix + "/test";
62
63 assert(eq(basedir, "/test"));
64 assert(eq(subdir, prefix));
65}