File: m_streams_test.cpp

package info (click to toggle)
eureka 2.1.0-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 7,912 kB
  • sloc: cpp: 84,842; python: 495; sh: 91; makefile: 21; ansic: 3
file content (99 lines) | stat: -rw-r--r-- 3,129 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
//------------------------------------------------------------------------
//
//  Eureka DOOM Editor
//
//  Copyright (C) 2021 Ioan Chera
//
//  This program is free software; you can redistribute it and/or
//  modify it under the terms of the GNU General Public License
//  as published by the Free Software Foundation; either version 2
//  of the License, or (at your option) any later version.
//
//  This program 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.
//
//------------------------------------------------------------------------

#include "m_streams.h"
#include "m_strings.h"
#include "gtest/gtest.h"

TEST(MStreams, MReadTextLine)
{
    // Check that the BOM gets stripped, that both CRLF and LF are detected
    // and that no newline at the end of stream is fine
    std::string content = "\xef\xbb\xbfLine 1 is here\n"
    "Line 2 is here\r\n"
    "Line 3 is here\n"
    "Line 4 is here";

    SString line;
    {
        std::istringstream ss(content);

        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_EQ(line, "Line 1 is here");
        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_EQ(line, "Line 2 is here");
        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_EQ(line, "Line 3 is here");
        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_EQ(line, "Line 4 is here");
        ASSERT_FALSE(M_ReadTextLine(line, ss));
    }

    // Check that a trailing newline won't generate an empty line
    content = "Line 5 is here\n"
    "Line 6 is here\n";

    {
        std::istringstream ss(content);
        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_EQ(line, "Line 5 is here");
        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_EQ(line, "Line 6 is here");
        ASSERT_FALSE(M_ReadTextLine(line, ss));
    }

    // Check that a final line with just a space gets treated as an empty line
    content = "Line 5 is here\n"
    "Line 6 is here\n"
    " ";

    {
        std::istringstream ss(content);
        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_EQ(line, "Line 5 is here");
        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_EQ(line, "Line 6 is here");
        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_TRUE(line.empty());
        ASSERT_FALSE(M_ReadTextLine(line, ss));
    }

    // Check that a newline shall show up as one empty line
    content = "\n";
    {
        std::istringstream ss(content);
        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_TRUE(line.empty());
        ASSERT_FALSE(M_ReadTextLine(line, ss));
    }

    // Check that a mere space shows up as one empty line
    content = " ";
    {
        std::istringstream ss(content);
        ASSERT_TRUE(M_ReadTextLine(line, ss));
        ASSERT_TRUE(line.empty());
        ASSERT_FALSE(M_ReadTextLine(line, ss));
    }

    content = "";
    {
        std::istringstream ss(content);
        ASSERT_FALSE(M_ReadTextLine(line, ss));
    }
}