summaryrefslogtreecommitdiffstats
path: root/kdecore/tests/kshelltest.cpp
blob: eaca1fcbe4e41da2310e9f005df167798af7a88e (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
#include <kshell.h>

#include <iostream>

static QCString
ps(const QString &s)
{
  if (s.isNull())
    return "(null)";
  else
    return s.local8Bit();
}

static void
tx(const char *t)
{
    std::cout << t << " -> " << ps(KShell::tildeExpand(t)) << std::endl;
}

static void
sj(const char *t, int flg)
{
    int err;
    std::cout << t << " (" << flg << ") -> " << ps(KShell::joinArgsDQ(KShell::splitArgs(t, flg, &err))) << " (" << err << ")" << std::endl;
}

int main()
{
#if 1
    tx("~");
    tx("~/sulli");
    tx("~root");
    tx("~root/sulli");
    tx("~sulli");
#endif
#if 1
    QStringList lst;
    lst << "this" << "is" << "text";
    std::cout << KShell::joinArgs(lst).latin1() << std::endl;
#endif
#if 1
    sj("\"~sulli\" 'text' 'jo'\"jo\" $'crap' $'\\\\\\'\\ca\\e\\x21' ha\\ lo ", KShell::NoOptions);
    sj("\"~sulli\" 'text'", KShell::TildeExpand);
    sj("~\"sulli\" 'text'", KShell::TildeExpand);
    sj("~/\"sulli\" 'text'", KShell::TildeExpand);
    sj("~ 'text' ~", KShell::TildeExpand);
    sj("~sulli ~root", KShell::TildeExpand);
#endif
    sj("say \" error", KShell::NoOptions);
    sj("say `echo no error`", KShell::NoOptions);
    sj("say \" still error", KShell::AbortOnMeta);
    sj("say `echo meta error`", KShell::AbortOnMeta);
    sj("BLA=say echo meta", KShell::AbortOnMeta);
    sj("B\"L\"A=say FOO=bar echo meta", KShell::AbortOnMeta);
}