1
/* -*- mode: c; c-basic-offset: 2; indent-tabs-mode: nil; -*-
2
* vim:expandtab:shiftwidth=2:tabstop=2:smarttab:
4
* Copyright (C) 2010 Monty Taylor
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
25
#include <gtest/gtest.h>
26
#include <drizzled/utf8/utf8.h>
28
using namespace drizzled;
32
ASSERT_TRUE(utf8::is_single('a'));
33
const char *multi_byte= "ç";
34
ASSERT_FALSE(utf8::is_single(*multi_byte));
35
ASSERT_FALSE(utf8::is_single(*(multi_byte + 1)));
38
TEST(utf8, codepoint_length)
40
uint32_t one_byte= 0x0024;
41
uint32_t two_bytes= 0x00A2;
42
uint32_t three_bytes= 0x20AC;
43
uint32_t four_bytes= 0x024B62;
44
EXPECT_EQ(1, utf8::codepoint_length(one_byte));
45
EXPECT_EQ(2, utf8::codepoint_length(two_bytes));
46
EXPECT_EQ(3, utf8::codepoint_length(three_bytes));
47
EXPECT_EQ(4, utf8::codepoint_length(four_bytes));
50
TEST(utf8, sequence_length)
52
const char *one_byte= "$";
53
const char *two_bytes= "¢";
54
const char *three_bytes= "€";
55
const char *four_bytes= "𤭢";
56
EXPECT_EQ(1, utf8::sequence_length(*one_byte));
57
EXPECT_EQ(2, utf8::sequence_length(*two_bytes));
58
EXPECT_EQ(3, utf8::sequence_length(*three_bytes));
59
EXPECT_EQ(4, utf8::sequence_length(*four_bytes));
62
TEST(utf8, char_length)
64
const char *one_byte= "$";
65
const char *two_bytes= "¢";
66
const char *three_bytes= "€";
67
const char *four_bytes= "𤭢";
68
const char *test_string= "__tañgè Ñãmé";
69
EXPECT_EQ(1, utf8::char_length(one_byte));
70
EXPECT_EQ(1, utf8::char_length(two_bytes));
71
EXPECT_EQ(1, utf8::char_length(three_bytes));
72
EXPECT_EQ(1, utf8::char_length(four_bytes));
73
EXPECT_EQ(12, utf8::char_length(test_string));
76
TEST(utf8, char_length_string)
78
std::string one_byte= "$";
79
std::string two_bytes= "¢";
80
std::string three_bytes= "€";
81
std::string four_bytes= "𤭢";
82
std::string test_string= "__tañgè Ñãmé";
83
EXPECT_EQ(1, utf8::char_length(one_byte));
84
EXPECT_EQ(1, utf8::char_length(two_bytes));
85
EXPECT_EQ(1, utf8::char_length(three_bytes));
86
EXPECT_EQ(1, utf8::char_length(four_bytes));
87
EXPECT_EQ(12, utf8::char_length(test_string));