forked from JBenda/inkcpp
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathUTF8.cpp
More file actions
58 lines (50 loc) · 1.33 KB
/
UTF8.cpp
File metadata and controls
58 lines (50 loc) · 1.33 KB
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
#include "catch.hpp"
#include <story.h>
#include <globals.h>
#include <runner.h>
#include <globals.h>
#include <compiler.h>
#include <sstream>
#include <fstream>
using namespace ink::runtime;
SCENARIO("a story supports UTF-8", "[utf-8]")
{
GIVEN("a story with UTF8 characters")
{
ink::compiler::run(INK_TEST_RESOURCE_DIR "UTF8Story.ink.json", "UTF8Story.bin");
auto ink = story::from_file("UTF8Story.bin");
runner thread = ink->new_runner();
std::ifstream demoFile(INK_TEST_RESOURCE_DIR "UTF-8-demo.txt");
if (!demoFile.is_open()) {
throw std::runtime_error("cannot open UTF-8 demo file");
}
char byte;
std::stringstream demo;
std::stringstream current;
while (demoFile.get(byte)) {
if (byte == '\r') continue; // skip windows carriage-return newlines
else if (byte == '\n' || byte == 0) { // newline or null byte
std::string s = current.str();
if (s.empty()) continue;
demo << s << '\n';
current.str("");
}
else { // normal char
current << byte;
}
}
std::string s = current.str();
if (!s.empty()) demo << s << '\n';
WHEN("consume lines") {
std::stringstream content;
while (thread->can_continue()) {
content << thread->getline();
}
THEN("lines match test file") {
std::string c = content.str();
std::string d = demo.str();
REQUIRE(c == d);
}
}
}
}