aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/unit/testUnicodeFromUTF8.cxx
blob: 116f4cf190afcca9a708590d7a07cde1b195ed4c (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
// Unit Tests for Scintilla internal data structures

#include <cstring>

#include <algorithm>

#include "Platform.h"

#include "UnicodeFromUTF8.h"

#include "catch.hpp"

// Test UnicodeFromUTF8.
// Use examples from Wikipedia:
// http://en.wikipedia.org/wiki/UTF-8

TEST_CASE("UnicodeFromUTF8") {

	SECTION("ASCII") {
		const unsigned char s[]={'a', 0};
		REQUIRE(UnicodeFromUTF8(s) == 'a');
	}

	SECTION("Example1") {
		const unsigned char s[]={0x24, 0};
		REQUIRE(UnicodeFromUTF8(s) == 0x24);
	}

	SECTION("Example2") {
		const unsigned char s[]={0xC2, 0xA2, 0};
		REQUIRE(UnicodeFromUTF8(s) == 0xA2);
	}

	SECTION("Example3") {
		const unsigned char s[]={0xE2, 0x82, 0xAC, 0};
		REQUIRE(UnicodeFromUTF8(s) == 0x20AC);
	}

	SECTION("Example4") {
		const unsigned char s[]={0xF0, 0x90, 0x8D, 0x88, 0};
		REQUIRE(UnicodeFromUTF8(s) == 0x10348);
	}

}