Sha256: 569adc28a22010eca09b1fb0512a80a6d2e349db8cd90871ca2ad8c0e5c4552f

Contents?: true

Size: 1.27 KB

Versions: 4

Compression:

Stored size: 1.27 KB

Contents

#include "catch.hpp"

#include <story.h>
#include <runner.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/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);
			}
		}
	}
}

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
inkcpp_rb-0.1.3 ext/inkcpp_rb/inkcpp/inkcpp_test/UTF8.cpp
inkcpp_rb-0.1.2 ext/inkcpp_rb/inkcpp/inkcpp_test/UTF8.cpp
inkcpp_rb-0.1.1 ext/inkcpp_rb/inkcpp/inkcpp_test/UTF8.cpp
inkcpp_rb-0.1.0 ext/inkcpp_rb/inkcpp/inkcpp_test/UTF8.cpp