File: TestDesktopEntryReaderLexer.cpp

package info (click to toggle)
xdg-utils-cxx 1.0.1-3.1
  • links: PTS, VCS
  • area: main
  • in suites: bookworm, forky, sid, trixie
  • size: 456 kB
  • sloc: cpp: 2,461; ansic: 10; makefile: 6
file content (68 lines) | stat: -rw-r--r-- 1,478 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
#include <gtest/gtest.h>

#include <Reader/Lexer.h>

using namespace XdgUtils::DesktopEntry::Reader;

TEST(TestDesktopEntryReaderLexer, consume) {
    const auto str = "[Desktop Entry]\n";
    std::stringstream in(str);
    Lexer l(in);

    int i = 0;
    while (l.consume()) {
        ASSERT_EQ(l.top(), str[i]);
        i++;
    }
}

TEST(TestDesktopEntryReaderLexer, classify) {
    const auto str = "#"   // Comment begin char
                     " "    // white space
                     "\t"   // white space
                     "\n"   // EOL
                     "["    // Group Open
                     "]"    // Group Close
                     "="    // Assignment
                     "R";   // Regular char

    std::stringstream strStream(str);
    Lexer l(strStream);

    l.consume();
    ASSERT_TRUE(l.isHash());
    ASSERT_FALSE(l.isAlfaNumeric());

    l.consume();
    ASSERT_TRUE(l.isSpace());

    l.consume();
    ASSERT_TRUE(l.isSpace());

    l.consume();
    ASSERT_TRUE(l.isEOL());

    l.consume();
    ASSERT_TRUE(l.isOpenSquareBracket());

    l.consume();
    ASSERT_TRUE(l.isCloseSquareBracket());

    l.consume();
    ASSERT_TRUE(l.isAssignment());

    l.consume();
    ASSERT_TRUE(l.isAlfaNumeric());
}

TEST(TestDesktopEntryReaderLexer, lineCount) {
    const auto str = "\n\na";
    std::stringstream strStream(str);
    Lexer l(strStream);

    int i = 0;
    while (l.consume()) {
        ASSERT_EQ(l.line(), i);
        i++;
    }
}