File: status-message-parser.cpp

package info (click to toggle)
ktp-kded-integration-module 22.12.3-1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 1,232 kB
  • sloc: cpp: 2,720; sh: 3; makefile: 2
file content (132 lines) | stat: -rw-r--r-- 3,803 bytes parent folder | download | duplicates (2)
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
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
/*
    Copyright (C) 2017  James D. Smith <smithjd15@gmail.com>

    This library is free software; you can redistribute it and/or
    modify it under the terms of the GNU Lesser General Public
    License as published by the Free Software Foundation; either
    version 2.1 of the License, or (at your option) any later version.

    This library 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
    Lesser General Public License for more details.

    You should have received a copy of the GNU Lesser General Public
    License along with this library; if not, write to the Free Software
    Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
*/

#include "status-message-parser.h"

#include <QtGui/QApplication>
#include <QtTest/QtTest>
#include <QString>

class testParser: public QObject
{
    Q_OBJECT
private Q_SLOTS:

    void tokenMatch();
    void hiddenMatch();
    void escapedToken();
    void commandMatch();
    void hiddenCommand();
    void escapedCommand();
    void commandMatchWithQuotes();
    void hiddenCommandWithQuotes();
    void escapedCommandWithQuotes();
    void nestedCommandWithQuotes();
    void nestedHiddenCommandWithQuotes();
    void escapedNestedCommandWithQuotes();

private:
    StatusMessageParser *parser = new StatusMessageParser();
};

void testParser::tokenMatch()
{
    QString parsed = parser->parseStatusMessage("%utc %time");
    QVERIFY( !parsed.isEmpty() );
    parser->clearStatusMessage();
}

void testParser::hiddenMatch()
{
    QString parsed = parser->parseStatusMessage("%um %sp");
    QVERIFY( parsed.isEmpty() );
    parser->clearStatusMessage();
}

void testParser::escapedToken()
{
    QString parsed = parser->parseStatusMessage("\\%te \\%sp");
    QVERIFY( parsed == ("%te %sp") );
    parser->clearStatusMessage();
}

void testParser::commandMatch()
{
    QString parsed = parser->parseStatusMessage("%te+3 ( %tr+1.5) One Two");
    QVERIFY( parsed == ("3 ( 1) One Two") );
    parser->clearStatusMessage();
}

void testParser::hiddenCommand()
{
    QString parsed = parser->parseStatusMessage("%tx+3 %tu+2");
    QVERIFY( parsed.isEmpty() );
    parser->clearStatusMessage();
}

void testParser::escapedCommand()
{
    QString parsed = parser->parseStatusMessage("\\%te+3 \\%sp+.");
    QVERIFY( parsed == ("%te+3 %sp+.") );
    parser->clearStatusMessage();
}

void testParser::commandMatchWithQuotes()
{
    QString parsed = parser->parseStatusMessage("%te+\"3\" %tr+\"1.5\" One Two");
    QVERIFY( parsed == ("3 1 One Two") );
    parser->clearStatusMessage();
}

void testParser::hiddenCommandWithQuotes()
{
    QString parsed = parser->parseStatusMessage("%tx+\"3\" %xm+\"One Two\"");
    QVERIFY( parsed.isEmpty() );
    parser->clearStatusMessage();
}

void testParser::escapedCommandWithQuotes()
{
    QString parsed = parser->parseStatusMessage("\\%te+\"3\" \\%xm+\"One Two\"");
    QVERIFY( parsed == ("%te+\"3\" %xm+\"One Two\"") );
    parser->clearStatusMessage();
}

void testParser::nestedCommandWithQuotes()
{
    QString parsed = parser->parseStatusMessage("%sp+\". . .\" %xm+\"%te+\"3\"\"");
    QVERIFY( parsed.isEmpty() );
    parser->clearStatusMessage();
}

void testParser::nestedHiddenCommandWithQuotes()
{
    QString parsed = parser->parseStatusMessage("%xm+\"%tx+\"3\"\"");
    QVERIFY( parsed.isEmpty() );
    parser->clearStatusMessage();
}

void testParser::escapedNestedCommandWithQuotes()
{
    QString parsed = parser->parseStatusMessage("\\%sp+\". . .\" \\%xm+\"%te+\"3\"\"");
    QVERIFY( parsed == ("%sp+\". . .\" %xm+\"%te+\"3\"\"") );
    parser->clearStatusMessage();
}

QTEST_MAIN(testParser)
#include "status-message-parser.moc"