aboutsummaryrefslogtreecommitdiffstats
path: root/vespalib/src/tests/text/lowercase/lowercase_test.cpp
blob: 40803b8f29599dd24305144f3006413806b11575 (plain) (blame)
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
// Copyright Vespa.ai. Licensed under the terms of the Apache 2.0 license. See LICENSE in the project root.
#include <vespa/log/log.h>
LOG_SETUP("lowercase_test");
#include <vespa/vespalib/testkit/test_kit.h>
#include <vespa/vespalib/testkit/testapp.h>
#include <vespa/vespalib/text/lowercase.h>
#include <iostream>
#include <fstream>

using namespace vespalib;

TEST("test basic lowercase")
{
    EXPECT_EQUAL('a', LowerCase::convert('A'));
    EXPECT_EQUAL((int8_t)'a', LowerCase::convert((int8_t)'A'));
    EXPECT_EQUAL((uint8_t)'a', LowerCase::convert((uint8_t)'A'));

    std::ifstream yellData(TEST_PATH("yell-want.dat"));

    EXPECT_TRUE(yellData.good());

    while (yellData.good()) {
        uint32_t hi=0, lo=0;
        yellData >> hi >> lo;
        EXPECT_EQUAL(lo, LowerCase::convert(hi));
        if (lo != LowerCase::convert(hi)) {
            printf("lc(%04X) -> %04X\n", hi, LowerCase::convert(hi));
            printf("yell(%04X) -> %04X\n", hi, lo);
        }
        // printf("lowercase( %d )= %d\n", hi, lo);
    }
}

TEST("lowercase utf8 string to ucs4")
{
    auto res = LowerCase::convert_to_ucs4(std::string_view("ABC"));
    EXPECT_EQUAL(3u, res.size());
    EXPECT_EQUAL((uint32_t)'a', res[0]);
    EXPECT_EQUAL((uint32_t)'b', res[1]);
    EXPECT_EQUAL((uint32_t)'c', res[2]);
}

TEST_MAIN() { TEST_RUN_ALL(); }