summaryrefslogtreecommitdiffstats
path: root/src/parser/parser_base_test.cpp
blob: 74994da3fcaeb982b30a7536a128bb8a49249e60 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 */

#include "test_global.hpp"
#include "orcus/parser_base.hpp"

using namespace std;
using namespace orcus;

void test_skip_space_and_control()
{
    class _test_type : public orcus::parser_base
    {
    public:
        _test_type(const char* p, size_t n) : orcus::parser_base(p, n) {}

        void run()
        {
            skip_space_and_control();
        }

        bool has_char() const
        {
            return orcus::parser_base::has_char();
        }

        size_t available_size() const
        {
            return orcus::parser_base::available_size();
        }

        char get_char() const
        {
            return *mp_char;
        }
    };

    // Create a series of variable-legnth blank strings and make sure the
    // function correctly skips all the empty characters.

    for (size_t i = 0; i < 32; ++i)
    {
        std::string s(i, ' ');
        assert(s.size() == i);

        _test_type test(s.data(), s.size());
        assert(test.available_size() == s.size());

        test.run();
        assert(!test.has_char()); // There should be no more characters to parse.

        s.push_back('a');

        _test_type test2(s.data(), s.size());
        assert(test2.available_size() == s.size());

        test2.run();
        assert(test2.has_char()); // The current position should be on the 'a'.
        assert(test2.get_char() == 'a');
    }
}

int main()
{
    test_skip_space_and_control();

    return EXIT_SUCCESS;
}

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */