feat(unicode): add SUniSPutUTF8

This commit is contained in:
fallenoak 2020-11-22 00:24:32 -06:00
parent 4bef36fcae
commit 9e00ad7036
No known key found for this signature in database
GPG key ID: 7628F8E61AEA070D
3 changed files with 85 additions and 0 deletions

View file

@ -1,4 +1,5 @@
#include "storm/Unicode.hpp"
#include "storm/String.hpp"
#include "test/Test.hpp"
TEST_CASE("SUniSGetUTF8", "[unicode]") {
@ -30,3 +31,31 @@ TEST_CASE("SUniSGetUTF8", "[unicode]") {
REQUIRE(chars == 0);
}
}
TEST_CASE("SUniSPutUTF8", "[unicode]") {
SECTION("writes ascii-range utf-8 first character") {
auto code = 'f';
char buffer[100] = { 0 };
SUniSPutUTF8(code, buffer);
REQUIRE(SStrLen(buffer) == 1);
REQUIRE(!SStrCmp(buffer, "f", SStrLen(buffer)));
}
SECTION("writes non-ascii-range utf-8 first character") {
auto code = 0x1F642;
char buffer[100] = { 0 };
SUniSPutUTF8(code, buffer);
REQUIRE(SStrLen(buffer) == 4);
REQUIRE(!SStrCmp(buffer, "\xF0\x9F\x99\x82", SStrLen(buffer)));
}
SECTION("writes null first character") {
auto code = '\0';
char buffer[100] = { 0 };
SUniSPutUTF8(code, buffer);
REQUIRE(SStrLen(buffer) == 0);
}
}