diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 00000000..38ab6a8d --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +repos: + - repo: https://github.com/pre-commit/mirrors-clang-format + rev: v18.1.0 + hooks: + - id: clang-format + types_or: [c++, c, cuda] + + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v6.0.0 + hooks: + - id: check-case-conflict + - id: check-illegal-windows-names + - id: check-json + - id: check-toml + - id: check-xml + - id: check-yaml + - id: detect-private-key + - id: end-of-file-fixer + - id: fix-byte-order-marker + - id: trailing-whitespace + exclude: .ink$ + - repo: https://github.com/pre-commit/pygrep-hooks + rev: v1.10.0 # Use the ref you want to point at + hooks: + - id: text-unicode-replacement-char + - repo: https://github.com/cheshirekow/cmake-format-precommit + rev: v0.6.10 + hooks: + - id: cmake-format + - id: cmake-lint diff --git a/inkcpp/output.cpp b/inkcpp/output.cpp index 43fa35b5..6162db2c 100644 --- a/inkcpp/output.cpp +++ b/inkcpp/output.cpp @@ -392,15 +392,10 @@ char* basic_stream::get_alloc(string_table& strings, list_table& lists) _size = start; // Return processed string - end = clean_string(buffer, buffer + c_str_len(buffer)); + end = clean_string(buffer, buffer + c_str_len(buffer)); *end = 0; if (end != buffer) { _last_char = end[-1]; - if constexpr (RemoveTail) { - if (_last_char == ' ') { - end[-1] = 0; - } - } } else { _last_char = 'e'; } diff --git a/inkcpp_test/Fixes.cpp b/inkcpp_test/Fixes.cpp index e49c8c92..33134408 100644 --- a/inkcpp_test/Fixes.cpp +++ b/inkcpp_test/Fixes.cpp @@ -101,3 +101,28 @@ SCENARIO("snapshot failed inside execution _ #111", "[fixes]") } } } + +SCENARIO("missing leading whitespace inside choice-only text and glued text _ #130 #131", "[fixes]") +{ + GIVEN("story with problematic text") + { + auto ink = story::from_file(INK_TEST_RESOURCE_DIR "130_131_missing_whitespace.bin"); + runner thread = ink->new_runner(); + WHEN("run story") + { + auto line = thread->getline(); + THEN("expect spaces in glued text") { REQUIRE(line == "Glue with no gaps.\n"); } + THEN("choice contains space") + { + REQUIRE(thread->num_choices() == 1); + REQUIRE(std::string(thread->get_choice(0)->text()) == "Look around"); + } + thread->choose(0); + line = thread->getall(); + THEN("no space in post choice text") + { + REQUIRE(line == "Looking around the saloon, you don't find much."); + } + } + } +} diff --git a/inkcpp_test/ink/130_131_missing_whitespace.ink b/inkcpp_test/ink/130_131_missing_whitespace.ink new file mode 100644 index 00000000..dc592c14 --- /dev/null +++ b/inkcpp_test/ink/130_131_missing_whitespace.ink @@ -0,0 +1,8 @@ +~temp test = true +Glue <> + { + - test: with + } <> { + - test: no + } <> gaps. ++ Look[ around]ing around the saloon, you don't find much.->DONE