<commit_before>#include "tests-base.hpp"

#include "utf8rewind.h"

TEST(Utf8SeekBackwards, Valid)
{
	const char* t = "\xCF\x84\xE1\xBD\xB4\xCE\xBD \xCE\xBA\xE1\xBD\xB9\xCF\x88\xCE\xB7";

	const char* r = utf8seek(t + strlen(t), t, -5, SEEK_CUR);

	EXPECT_EQ(t + 7, r);
	EXPECT_STREQ(" \xCE\xBA\xE1\xBD\xB9\xCF\x88\xCE\xB7", r);

	unicode_t o = 0;
	EXPECT_EQ(4, utf8toutf32(r, strlen(r), &o, sizeof(o), nullptr));
	EXPECT_EQ(' ', o);
}

TEST(Utf8SeekBackwards, EndsWithAscii)<commit_msg>suite-utf8-seek-backwards: Add tests for one byte sequences.<commit_after>#include "tests-base.hpp"

#include "utf8rewind.h"

#include "helpers-seeking.hpp"

TEST(Utf8SeekBackwards, OneByteSingle)
{
	const char* t = "*";

	EXPECT_SEEKEQ("*", 0, utf8seek(t + strlen(t), t, -1, SEEK_CUR));
}

TEST(Utf8SeekBackwards, OneByteSingleFirst)
{
	const char* t = "\0";

	EXPECT_SEEKEQ("", 0, utf8seek(t + strlen(t), t, -1, SEEK_CUR));
}

TEST(Utf8SeekBackwards, OneByteSingleLast)
{
	const char* t = "\x7F";

	EXPECT_SEEKEQ("\x7F", 0, utf8seek(t + strlen(t), t, -1, SEEK_CUR));
}

TEST(Utf8SeekBackwards, OneByteSingleInvalidContinuationByteFirst)
{
	const char* t = "\x80";

	EXPECT_SEEKEQ("\x80", 0, utf8seek(t + strlen(t), t, -1, SEEK_CUR));
}

TEST(Utf8SeekBackwards, OneByteSingleInvalidContinuationByteLast)
{
	const char* t = "\xBF";

	EXPECT_SEEKEQ("\xBF", 0, utf8seek(t + strlen(t), t, -1, SEEK_CUR));
}

TEST(Utf8SeekBackwards, OneByteSingleIllegalByteFirst)
{
	const char* t = "\xFE";

	EXPECT_SEEKEQ("\xFE", 0, utf8seek(t + strlen(t), t, -1, SEEK_CUR));
}

TEST(Utf8SeekBackwards, OneByteSingleIllegalByteLast)
{
	const char* t = "\xFF";

	EXPECT_SEEKEQ("\xFF", 0, utf8seek(t + strlen(t), t, -1, SEEK_CUR));
}

TEST(Utf8SeekBackwards, OneByteMultiple)
{
	const char* t = "Heartbreaker";

	EXPECT_SEEKEQ("breaker", 5, utf8seek(t + strlen(t), t, -7, SEEK_CUR));
}

TEST(Utf8SeekBackwards, OneByteMultipleInvalidContinuationByte)
{
	const char* t = "\x98\x92\xB4\x81\xA5\x88\x93";

	EXPECT_SEEKEQ("\x98\x92\xB4\x81\xA5\x88\x93", 0, utf8seek(t + strlen(t), t, -4, SEEK_CUR));
}

TEST(Utf8SeekBackwards, OneByteMultipleIllegal)
{
	const char* t = "\xFE\xFE\xFF\xFE\xFE\xFF";

	EXPECT_SEEKEQ("\xFE\xFF", 4, utf8seek(t + strlen(t), t, -2, SEEK_CUR));
}

TEST(Utf8SeekBackwards, Valid)
{
	const char* t = "\xCF\x84\xE1\xBD\xB4\xCE\xBD \xCE\xBA\xE1\xBD\xB9\xCF\x88\xCE\xB7";

	const char* r = utf8seek(t + strlen(t), t, -5, SEEK_CUR);

	EXPECT_EQ(t + 7, r);
	EXPECT_STREQ(" \xCE\xBA\xE1\xBD\xB9\xCF\x88\xCE\xB7", r);

	unicode_t o = 0;
	EXPECT_EQ(4, utf8toutf32(r, strlen(r), &o, sizeof(o), nullptr));
	EXPECT_EQ(' ', o);
}

TEST(Utf8SeekBackwards, EndsWithAscii)
{'fraction_non_alphanumeric': 0.18804388951948545, 'fraction_numerical': 0.0461596670450246, 'mean_word_length': 4.968397291196388, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2261844', 'n_tokens_mistral': 1288, 'n_tokens_neox': 1244, 'n_words': 212}