summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJoel Klinghed <the_jk@spawned.biz>2025-09-10 23:57:26 +0200
committerJoel Klinghed <the_jk@spawned.biz>2025-09-10 23:57:26 +0200
commit28c6425e4ed1cd2eab538e7cba08c18aa83d8af5 (patch)
tree311d9745ecc7f9ef8f95c2705c44530d0330c26b
parentac878281d42b9e5291f96204283c65229c8f392a (diff)
Improve test coverage of io and unicode
-rw-r--r--meson.build20
-rw-r--r--test/io.cc60
-rw-r--r--test/u.cc122
3 files changed, 164 insertions, 38 deletions
diff --git a/meson.build b/meson.build
index c3b6302..b0708c2 100644
--- a/meson.build
+++ b/meson.build
@@ -199,16 +199,27 @@ test('csv', executable(
],
))
-test('line', executable(
- 'test_line',
+io_test_helper_lib = library(
+ 'io_test_helper',
sources: [
- 'test/line.cc',
- 'test/io_test_helper.hh',
'test/io_test_helper.cc',
+ 'test/io_test_helper.hh',
],
include_directories: inc,
+ dependencies: io_dep,
+)
+io_test_helper_dep = declare_dependency(
+ link_with: io_test_helper_lib,
+ dependencies: io_dep,
+)
+
+test('line', executable(
+ 'test_line',
+ sources: ['test/line.cc'],
+ include_directories: inc,
dependencies: [
io_dep,
+ io_test_helper_dep,
test_dependencies,
],
))
@@ -229,6 +240,7 @@ test('io', executable(
include_directories: inc,
dependencies: [
io_dep,
+ io_test_helper_dep,
test_dependencies,
],
))
diff --git a/test/io.cc b/test/io.cc
index ad192ed..23c10d4 100644
--- a/test/io.cc
+++ b/test/io.cc
@@ -1,6 +1,7 @@
#include <gtest/gtest.h>
#include "io.hh"
+#include "io_test_helper.hh"
#include <cstdlib>
#include <cerrno>
@@ -105,7 +106,7 @@ class IoTest : public testing::Test {
}
private:
- int dirfd_;
+ int dirfd_{-1};
std::string tmpdir_;
};
@@ -128,6 +129,16 @@ TEST_F(IoTest, read_empty) {
EXPECT_EQ(0, ret2.value());
}
+TEST_F(IoTest, skip_empty) {
+ touch("test");
+
+ auto ret = io::openat(dirfd(), "test");
+ ASSERT_TRUE(ret.has_value());
+ auto ret2 = ret.value()->skip(10);
+ ASSERT_TRUE(ret2.has_value());
+ EXPECT_EQ(0, ret2.value());
+}
+
TEST_F(IoTest, read) {
touch("test", "hello world");
@@ -140,3 +151,50 @@ TEST_F(IoTest, read) {
tmp.resize(ret2.value());
EXPECT_EQ("hello world", tmp);
}
+
+TEST_F(IoTest, skip) {
+ touch("test", "hello world");
+
+ auto ret = io::openat(dirfd(), "test");
+ ASSERT_TRUE(ret.has_value());
+ auto ret2 = ret.value()->repeat_skip(6);
+ ASSERT_TRUE(ret2.has_value());
+ EXPECT_EQ(6, ret2.value());
+ std::string tmp(12, ' ');
+ auto ret3 = ret.value()->repeat_read(tmp);
+ ASSERT_TRUE(ret3.has_value());
+ EXPECT_EQ(5, ret3.value());
+ tmp.resize(ret3.value());
+ EXPECT_EQ("world", tmp);
+}
+
+TEST_F(IoTest, read_block) {
+ touch("test", "hello world");
+
+ auto ret = io::openat(dirfd(), "test");
+ ASSERT_TRUE(ret.has_value());
+ auto ret2 = io_make_max_block(std::move(ret.value()), 2);
+ std::string tmp(12, ' ');
+ auto ret3 = ret2->repeat_read(tmp);
+ ASSERT_TRUE(ret3.has_value());
+ EXPECT_EQ(11, ret3.value());
+ tmp.resize(ret3.value());
+ EXPECT_EQ("hello world", tmp);
+}
+
+TEST_F(IoTest, skip_block) {
+ touch("test", "hello world");
+
+ auto ret = io::openat(dirfd(), "test");
+ ASSERT_TRUE(ret.has_value());
+ auto ret2 = io_make_max_block(std::move(ret.value()), 2);
+ auto ret3 = ret2->repeat_skip(6);
+ ASSERT_TRUE(ret3.has_value());
+ EXPECT_EQ(6, ret3.value());
+ std::string tmp(12, ' ');
+ auto ret4 = ret2->repeat_read(tmp);
+ ASSERT_TRUE(ret4.has_value());
+ EXPECT_EQ(5, ret4.value());
+ tmp.resize(ret4.value());
+ EXPECT_EQ("world", tmp);
+}
diff --git a/test/u.cc b/test/u.cc
index de04e39..53455f2 100644
--- a/test/u.cc
+++ b/test/u.cc
@@ -6,6 +6,13 @@
#include <vector>
+namespace {
+
+class UnicodeVersionTest : public testing::TestWithParam<u::Version> {
+};
+
+} // namespace
+
TEST(u8, empty) {
std::vector<uint8_t> empty;
auto it = empty.begin();
@@ -682,44 +689,93 @@ TEST(u16, invalid) {
}
}
-TEST(u, lookup_gc) {
- EXPECT_EQ(u::lookup_gc(0x41), u::GeneralCategory::LETTER_UPPERCASE);
- EXPECT_EQ(u::lookup_gc(0x61), u::GeneralCategory::LETTER_LOWERCASE);
- EXPECT_EQ(u::lookup_gc(0x1c5), u::GeneralCategory::LETTER_TITLECASE);
- EXPECT_EQ(u::lookup_gc(0x374), u::GeneralCategory::LETTER_MODIFIER);
- EXPECT_EQ(u::lookup_gc(0x34ff), u::GeneralCategory::LETTER_OTHER);
+TEST_P(UnicodeVersionTest, lookup_gc) {
+ EXPECT_EQ(u::lookup_gc(0x41, GetParam()),
+ u::GeneralCategory::LETTER_UPPERCASE);
+ EXPECT_EQ(u::lookup_gc(0x61, GetParam()),
+ u::GeneralCategory::LETTER_LOWERCASE);
+ EXPECT_EQ(u::lookup_gc(0x1c5, GetParam()),
+ u::GeneralCategory::LETTER_TITLECASE);
+ EXPECT_EQ(u::lookup_gc(0x374, GetParam()),
+ u::GeneralCategory::LETTER_MODIFIER);
+ EXPECT_EQ(u::lookup_gc(0x34ff, GetParam()),
+ u::GeneralCategory::LETTER_OTHER);
- EXPECT_EQ(u::lookup_gc(0x483), u::GeneralCategory::MARK_NONSPACING);
- EXPECT_EQ(u::lookup_gc(0x93b), u::GeneralCategory::MARK_SPACING_COMBINDING);
- EXPECT_EQ(u::lookup_gc(0x20de), u::GeneralCategory::MARK_SPACING_ENCLOSING);
+ EXPECT_EQ(u::lookup_gc(0x483, GetParam()),
+ u::GeneralCategory::MARK_NONSPACING);
+ EXPECT_EQ(u::lookup_gc(0x93b, GetParam()),
+ u::GeneralCategory::MARK_SPACING_COMBINDING);
+ EXPECT_EQ(u::lookup_gc(0x20de, GetParam()),
+ u::GeneralCategory::MARK_SPACING_ENCLOSING);
- EXPECT_EQ(u::lookup_gc(0xa620), u::GeneralCategory::NUMBER_DIGIT);
- EXPECT_EQ(u::lookup_gc(0xa6e6), u::GeneralCategory::NUMBER_LETTER);
- EXPECT_EQ(u::lookup_gc(0xa830), u::GeneralCategory::NUMBER_OTHER);
+ EXPECT_EQ(u::lookup_gc(0xa620, GetParam()),
+ u::GeneralCategory::NUMBER_DIGIT);
+ EXPECT_EQ(u::lookup_gc(0xa6e6, GetParam()),
+ u::GeneralCategory::NUMBER_LETTER);
+ EXPECT_EQ(u::lookup_gc(0xa830, GetParam()),
+ u::GeneralCategory::NUMBER_OTHER);
- EXPECT_EQ(u::lookup_gc(0xfe33), u::GeneralCategory::PUNCTUATION_CONNECTOR);
- EXPECT_EQ(u::lookup_gc(0xfe58), u::GeneralCategory::PUNCTUATION_DASH);
- EXPECT_EQ(u::lookup_gc(0xff08), u::GeneralCategory::PUNCTUATION_OPEN);
- EXPECT_EQ(u::lookup_gc(0xff09), u::GeneralCategory::PUNCTUATION_CLOSE);
- EXPECT_EQ(u::lookup_gc(0xab), u::GeneralCategory::PUNCTUATION_INITIAL_QUOTE);
- EXPECT_EQ(u::lookup_gc(0xbb), u::GeneralCategory::PUNCTUATION_FINAL_QUOTE);
- EXPECT_EQ(u::lookup_gc(0xff1a), u::GeneralCategory::PUNCTUATION_OTHER);
+ EXPECT_EQ(u::lookup_gc(0xfe33, GetParam()),
+ u::GeneralCategory::PUNCTUATION_CONNECTOR);
+ EXPECT_EQ(u::lookup_gc(0xfe58, GetParam()),
+ u::GeneralCategory::PUNCTUATION_DASH);
+ EXPECT_EQ(u::lookup_gc(0xff08, GetParam()),
+ u::GeneralCategory::PUNCTUATION_OPEN);
+ EXPECT_EQ(u::lookup_gc(0xff09, GetParam()),
+ u::GeneralCategory::PUNCTUATION_CLOSE);
+ EXPECT_EQ(u::lookup_gc(0xab, GetParam()),
+ u::GeneralCategory::PUNCTUATION_INITIAL_QUOTE);
+ EXPECT_EQ(u::lookup_gc(0xbb, GetParam()),
+ u::GeneralCategory::PUNCTUATION_FINAL_QUOTE);
+ EXPECT_EQ(u::lookup_gc(0xff1a, GetParam()),
+ u::GeneralCategory::PUNCTUATION_OTHER);
- EXPECT_EQ(u::lookup_gc(0xd7), u::GeneralCategory::SYMBOL_MATH);
- EXPECT_EQ(u::lookup_gc(0x58f), u::GeneralCategory::SYMBOL_CURRENCY);
- EXPECT_EQ(u::lookup_gc(0x5e), u::GeneralCategory::SYMBOL_MODIFIER);
- EXPECT_EQ(u::lookup_gc(0xf03), u::GeneralCategory::SYMBOL_OTHER);
+ EXPECT_EQ(u::lookup_gc(0xd7, GetParam()),
+ u::GeneralCategory::SYMBOL_MATH);
+ EXPECT_EQ(u::lookup_gc(0x58f, GetParam()),
+ u::GeneralCategory::SYMBOL_CURRENCY);
+ EXPECT_EQ(u::lookup_gc(0x5e, GetParam()),
+ u::GeneralCategory::SYMBOL_MODIFIER);
+ EXPECT_EQ(u::lookup_gc(0xf03, GetParam()),
+ u::GeneralCategory::SYMBOL_OTHER);
- EXPECT_EQ(u::lookup_gc(0x20), u::GeneralCategory::SEPARATOR_SPACE);
- EXPECT_EQ(u::lookup_gc(0x2028), u::GeneralCategory::SEPARATOR_LINE);
- EXPECT_EQ(u::lookup_gc(0x2029), u::GeneralCategory::SEPARATOR_PARAGRAPH);
+ EXPECT_EQ(u::lookup_gc(0x20, GetParam()),
+ u::GeneralCategory::SEPARATOR_SPACE);
+ EXPECT_EQ(u::lookup_gc(0x2028, GetParam()),
+ u::GeneralCategory::SEPARATOR_LINE);
+ EXPECT_EQ(u::lookup_gc(0x2029, GetParam()),
+ u::GeneralCategory::SEPARATOR_PARAGRAPH);
- EXPECT_EQ(u::lookup_gc(0xa), u::GeneralCategory::OTHER_CONTROL);
- EXPECT_EQ(u::lookup_gc(0x202d), u::GeneralCategory::OTHER_FORMAT);
- EXPECT_EQ(u::lookup_gc(0xd800), u::GeneralCategory::OTHER_SURROGATE);
- EXPECT_EQ(u::lookup_gc(0xdbff), u::GeneralCategory::OTHER_SURROGATE);
- EXPECT_EQ(u::lookup_gc(0xdfff), u::GeneralCategory::OTHER_SURROGATE);
- EXPECT_EQ(u::lookup_gc(0xe000), u::GeneralCategory::OTHER_PRIVATE_USE);
+ EXPECT_EQ(u::lookup_gc(0xa, GetParam()),
+ u::GeneralCategory::OTHER_CONTROL);
+ EXPECT_EQ(u::lookup_gc(0x202d, GetParam()),
+ u::GeneralCategory::OTHER_FORMAT);
+ EXPECT_EQ(u::lookup_gc(0xd800, GetParam()),
+ u::GeneralCategory::OTHER_SURROGATE);
+ EXPECT_EQ(u::lookup_gc(0xdbff, GetParam()),
+ u::GeneralCategory::OTHER_SURROGATE);
+ EXPECT_EQ(u::lookup_gc(0xdfff, GetParam()),
+ u::GeneralCategory::OTHER_SURROGATE);
+ EXPECT_EQ(u::lookup_gc(0xe000, GetParam()),
+ u::GeneralCategory::OTHER_PRIVATE_USE);
- EXPECT_EQ(u::lookup_gc(0xffffffff), u::GeneralCategory::OTHER_UNASSIGNED);
+ EXPECT_EQ(u::lookup_gc(0xffffffff, GetParam()),
+ u::GeneralCategory::OTHER_UNASSIGNED);
}
+
+INSTANTIATE_TEST_SUITE_P(
+ AllVersions,
+ UnicodeVersionTest,
+ testing::Values(
+ u::Version::u6_2_0,
+ u::Version::u8_0_0,
+ u::Version::u10_0_0,
+ u::Version::u11_0_0,
+ u::Version::u12_1_0,
+ u::Version::u13_0_0,
+ u::Version::u14_0_0,
+ u::Version::u15_0_0,
+ u::Version::u15_1_0,
+ u::Version::u16_0_0
+ )
+);