diff --git a/CMakeLists.txt b/CMakeLists.txt index b1d9f67..3c84adf 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -33,6 +33,7 @@ add_library(${PROJECT_NAME} src/directory_map.cpp src/directory_parent_tree.cpp src/directory.cpp + src/entry.cpp src/eptree_iterator.cpp src/eptree.cpp src/errors.cpp @@ -55,7 +56,6 @@ add_library(${PROJECT_NAME} src/sub_block_allocator.cpp src/transactions_area.cpp src/wfs_device.cpp - src/wfs_item.cpp ) if(BUILD_STATIC AND MSVC) diff --git a/include/wfslib/directory.h b/include/wfslib/directory.h index 74b25bd..682dd53 100644 --- a/include/wfslib/directory.h +++ b/include/wfslib/directory.h @@ -13,21 +13,21 @@ #include "directory_iterator.h" #include "directory_map.h" +#include "entry.h" #include "errors.h" -#include "wfs_item.h" class Area; class Block; class File; -class Directory : public WfsItem, public std::enable_shared_from_this { +class Directory : public Entry, public std::enable_shared_from_this { public: using iterator = DirectoryIterator; // TODO: Replace name with tree iterator? Directory(std::string name, AttributesRef attributes, std::shared_ptr quota, std::shared_ptr block); - std::expected, WfsError> GetObject(const std::string& name) const; + std::expected, WfsError> GetEntry(const std::string& name) const; std::expected, WfsError> GetDirectory(const std::string& name) const; std::expected, WfsError> GetFile(const std::string& name) const; diff --git a/include/wfslib/wfs_item.h b/include/wfslib/entry.h similarity index 74% rename from include/wfslib/wfs_item.h rename to include/wfslib/entry.h index 0e786fe..f75619c 100644 --- a/include/wfslib/wfs_item.h +++ b/include/wfslib/entry.h @@ -7,6 +7,7 @@ #pragma once +#include #include #include @@ -17,10 +18,10 @@ class QuotaArea; using AttributesRef = Block::DataRef; -class WfsItem { +class Entry { public: - WfsItem(std::string name, AttributesRef block); - virtual ~WfsItem(); + Entry(std::string name, AttributesRef block); + virtual ~Entry(); const std::string& name() const { return name_; } bool is_directory() const { return !attributes()->is_link() && attributes()->is_directory(); } @@ -28,9 +29,9 @@ class WfsItem { bool is_link() const { return attributes()->is_link(); } bool is_quota() const { return attributes()->is_directory() && attributes()->is_quota(); } - static std::expected, WfsError> Load(std::shared_ptr quota, - std::string name, - AttributesRef attributes_ref); + static std::expected, WfsError> Load(std::shared_ptr quota, + std::string name, + AttributesRef attributes_ref); protected: // TODO: Attributes copy as it can change? diff --git a/include/wfslib/errors.h b/include/wfslib/errors.h index f4b7bb8..1c8120b 100644 --- a/include/wfslib/errors.h +++ b/include/wfslib/errors.h @@ -11,7 +11,7 @@ #include enum WfsError { - kItemNotFound, + kEntryNotFound, kNotDirectory, kNotFile, kBlockBadHash, diff --git a/include/wfslib/file.h b/include/wfslib/file.h index 2f678d6..51ccef7 100644 --- a/include/wfslib/file.h +++ b/include/wfslib/file.h @@ -12,11 +12,11 @@ #include #include #include -#include "wfs_item.h" +#include "entry.h" class QuotaArea; -class File : public WfsItem, public std::enable_shared_from_this { +class File : public Entry, public std::enable_shared_from_this { public: class DataCategoryReader; class DataCategory0Reader; @@ -27,7 +27,7 @@ class File : public WfsItem, public std::enable_shared_from_this { class DataCategory4Reader; File(std::string name, AttributesRef attributes, std::shared_ptr quota) - : WfsItem(std::move(name), std::move(attributes)), quota_(std::move(quota)) {} + : Entry(std::move(name), std::move(attributes)), quota_(std::move(quota)) {} uint32_t Size() const; uint32_t SizeOnDisk() const; diff --git a/include/wfslib/link.h b/include/wfslib/link.h index 52992fc..fea266b 100644 --- a/include/wfslib/link.h +++ b/include/wfslib/link.h @@ -9,14 +9,14 @@ #include -#include "wfs_item.h" +#include "entry.h" class QuotaArea; -class Link : public WfsItem, public std::enable_shared_from_this { +class Link : public Entry, public std::enable_shared_from_this { public: Link(std::string name, AttributesRef attributes, std::shared_ptr quota) - : WfsItem(std::move(name), std::move(attributes)), quota_(std::move(quota)) {} + : Entry(std::move(name), std::move(attributes)), quota_(std::move(quota)) {} private: // TODO: We may have cyclic reference here if we do cache in area. diff --git a/include/wfslib/wfs_device.h b/include/wfslib/wfs_device.h index e05e554..7c89f9b 100644 --- a/include/wfslib/wfs_device.h +++ b/include/wfslib/wfs_device.h @@ -22,7 +22,7 @@ class BlocksDevice; class Area; class QuotaArea; class TransactionsArea; -class WfsItem; +class Entry; class Device; class File; class Directory; @@ -35,7 +35,7 @@ class WfsDevice : public std::enable_shared_from_this { BlocksDevice* device() { return device_.get(); } - std::shared_ptr GetObject(const std::string& filename); + std::shared_ptr GetEntry(const std::string& filename); std::shared_ptr GetFile(const std::string& filename); std::shared_ptr GetDirectory(const std::string& filename); diff --git a/src/directory.cpp b/src/directory.cpp index 84e2061..f8f94ab 100644 --- a/src/directory.cpp +++ b/src/directory.cpp @@ -18,44 +18,43 @@ Directory::Directory(std::string name, AttributesRef attributes, std::shared_ptr quota, std::shared_ptr block) - : WfsItem(std::move(name), std::move(attributes)), + : Entry(std::move(name), std::move(attributes)), quota_(std::move(quota)), block_(std::move(block)), map_{quota_, block_} {} -std::expected, WfsError> Directory::GetObject(const std::string& name) const { +std::expected, WfsError> Directory::GetEntry(const std::string& name) const { try { - // TODO: Case insensitive auto it = find(name); if (it.is_end()) { - return std::unexpected(WfsError::kItemNotFound); + return std::unexpected(WfsError::kEntryNotFound); } - return (*it).item; + return (*it).entry; } catch (const WfsException& e) { return std::unexpected(e.error()); } } std::expected, WfsError> Directory::GetDirectory(const std::string& name) const { - auto obj = GetObject(name); - if (!obj.has_value()) - return std::unexpected(obj.error()); - if (!(*obj)->is_directory()) { + auto entry = GetEntry(name); + if (!entry.has_value()) + return std::unexpected(entry.error()); + if (!(*entry)->is_directory()) { // Not a directory return std::unexpected(kNotDirectory); } - return std::dynamic_pointer_cast(*obj); + return std::dynamic_pointer_cast(*entry); } std::expected, WfsError> Directory::GetFile(const std::string& name) const { - auto obj = GetObject(name); - if (!obj.has_value()) - return std::unexpected(obj.error()); - if (!(*obj)->is_file()) { + auto entry = GetEntry(name); + if (!entry.has_value()) + return std::unexpected(entry.error()); + if (!(*entry)->is_file()) { // Not a file return std::unexpected(kNotFile); } - return std::dynamic_pointer_cast(*obj); + return std::dynamic_pointer_cast(*entry); } Directory::iterator Directory::find(std::string key) const { diff --git a/src/directory_iterator.cpp b/src/directory_iterator.cpp index 9b7977b..36b460e 100644 --- a/src/directory_iterator.cpp +++ b/src/directory_iterator.cpp @@ -7,15 +7,15 @@ #include "directory_iterator.h" +#include "entry.h" #include "quota_area.h" -#include "wfs_item.h" DirectoryIterator::DirectoryIterator(DirectoryMapIterator base) : base_(base) {} DirectoryIterator::reference DirectoryIterator::operator*() const { auto val = *base_; auto name = val.attributes.get()->GetCaseSensitiveName(val.name); - return {name, WfsItem::Load(base_.quota(), name, val.attributes)}; + return {name, Entry::Load(base_.quota(), name, val.attributes)}; } DirectoryIterator& DirectoryIterator::operator++() { diff --git a/src/directory_iterator.h b/src/directory_iterator.h index 50b6c18..f3b9657 100644 --- a/src/directory_iterator.h +++ b/src/directory_iterator.h @@ -11,11 +11,11 @@ #include "errors.h" class QuotaArea; -class WfsItem; +class Entry; -struct DiretoryItem { +struct DiretoryEntry { std::string name; - std::expected, WfsError> item; + std::expected, WfsError> entry; }; class DirectoryIterator { @@ -23,8 +23,8 @@ class DirectoryIterator { using iterator_category = std::bidirectional_iterator_tag; using difference_type = ptrdiff_t; - using value_type = DiretoryItem; - using ref_type = DiretoryItem; + using value_type = DiretoryEntry; + using ref_type = DiretoryEntry; using reference = ref_type; diff --git a/src/directory_map.cpp b/src/directory_map.cpp index ae2ef84..6e6b5ce 100644 --- a/src/directory_map.cpp +++ b/src/directory_map.cpp @@ -104,7 +104,7 @@ bool DirectoryMap::erase(std::string_view name) { return false; } auto parents = it.parents(); - // Free the item attributes first + // Free the entry attributes first it.leaf().node.Free((*it.leaf().iterator).value(), static_cast(1 << (*it).attributes->entry_log2_size.value())); it.leaf().node.erase(it.leaf().iterator); diff --git a/src/directory_map_iterator.h b/src/directory_map_iterator.h index b645ca4..aa8b682 100644 --- a/src/directory_map_iterator.h +++ b/src/directory_map_iterator.h @@ -14,7 +14,7 @@ class QuotaArea; struct Attributes; -struct DiretoryMapItem { +struct DiretoryMapEntry { std::string name; Block::DataRef attributes; }; @@ -24,8 +24,8 @@ class DirectoryMapIterator { using iterator_category = std::bidirectional_iterator_tag; using difference_type = ptrdiff_t; - using value_type = DiretoryMapItem; - using ref_type = DiretoryMapItem; + using value_type = DiretoryMapEntry; + using ref_type = DiretoryMapEntry; using reference = ref_type; diff --git a/src/wfs_item.cpp b/src/entry.cpp similarity index 76% rename from src/wfs_item.cpp rename to src/entry.cpp index f756bf6..feaf3d6 100644 --- a/src/wfs_item.cpp +++ b/src/entry.cpp @@ -5,22 +5,21 @@ * of the MIT license. See the LICENSE file for details. */ -#include "wfs_item.h" +#include "entry.h" #include "directory.h" #include "file.h" #include "link.h" #include "quota_area.h" -WfsItem::WfsItem(std::string name, AttributesRef attributes) - : name_(std::move(name)), attributes_(std::move(attributes)) {} +Entry::Entry(std::string name, AttributesRef attributes) : name_(std::move(name)), attributes_(std::move(attributes)) {} -WfsItem::~WfsItem() = default; +Entry::~Entry() = default; // static -std::expected, WfsError> WfsItem::Load(std::shared_ptr quota, - std::string name, - AttributesRef attributes_ref) { +std::expected, WfsError> Entry::Load(std::shared_ptr quota, + std::string name, + AttributesRef attributes_ref) { auto* attributes = attributes_ref.get(); if (attributes->is_link()) { // TODO, I think that the link info is in the attributes metadata diff --git a/src/errors.cpp b/src/errors.cpp index 73b5685..eebeee0 100644 --- a/src/errors.cpp +++ b/src/errors.cpp @@ -9,8 +9,8 @@ char const* WfsException::what() const noexcept { switch (error_) { - case WfsError::kItemNotFound: - return "Item not found"; + case WfsError::kEntryNotFound: + return "Entry not found"; case WfsError::kNotDirectory: return "Not a directory"; case WfsError::kNotFile: diff --git a/src/quota_area.h b/src/quota_area.h index 1643de1..54f497f 100644 --- a/src/quota_area.h +++ b/src/quota_area.h @@ -10,8 +10,8 @@ #include #include "area.h" +#include "entry.h" #include "errors.h" -#include "wfs_item.h" class Directory; class FreeBlocksAllocator; diff --git a/src/wfs_device.cpp b/src/wfs_device.cpp index d91b23e..c8a9fc7 100644 --- a/src/wfs_device.cpp +++ b/src/wfs_device.cpp @@ -27,21 +27,21 @@ WfsDevice::~WfsDevice() { Flush(); } -std::shared_ptr WfsDevice::GetObject(const std::string& filename) { +std::shared_ptr WfsDevice::GetEntry(const std::string& filename) { if (filename == "/") return GetDirectory("/"); std::filesystem::path path(filename); auto dir = GetDirectory(path.parent_path().string()); if (!dir) return nullptr; - auto obj = dir->GetObject(path.filename().string()); - if (!obj.has_value()) { - if (obj.error() == WfsError::kItemNotFound) + auto entry = dir->GetEntry(path.filename().string()); + if (!entry.has_value()) { + if (entry.error() == WfsError::kEntryNotFound) return nullptr; else - throw WfsException(obj.error()); + throw WfsException(entry.error()); } - return *obj; + return *entry; } std::shared_ptr WfsDevice::GetFile(const std::string& filename) { @@ -51,7 +51,7 @@ std::shared_ptr WfsDevice::GetFile(const std::string& filename) { return nullptr; auto file = dir->GetFile(path.filename().string()); if (!file.has_value()) { - if (file.error() == WfsError::kItemNotFound) + if (file.error() == WfsError::kEntryNotFound) return nullptr; else throw WfsException(file.error()); @@ -63,7 +63,7 @@ std::shared_ptr WfsDevice::GetDirectory(const std::string& filename) std::filesystem::path path(filename); auto current_directory = GetRootDirectory(); if (!current_directory.has_value()) { - if (current_directory.error() == WfsError::kItemNotFound) + if (current_directory.error() == WfsError::kEntryNotFound) return nullptr; else throw WfsException(current_directory.error()); @@ -75,7 +75,7 @@ std::shared_ptr WfsDevice::GetDirectory(const std::string& filename) continue; current_directory = (*current_directory)->GetDirectory(part.string()); if (!current_directory.has_value()) { - if (current_directory.error() == WfsError::kItemNotFound) + if (current_directory.error() == WfsError::kEntryNotFound) return nullptr; else throw WfsException(current_directory.error()); diff --git a/tests/directory_map_tests.cpp b/tests/directory_map_tests.cpp index e4475a2..84faa1a 100644 --- a/tests/directory_map_tests.cpp +++ b/tests/directory_map_tests.cpp @@ -49,33 +49,33 @@ TEST_CASE("DirectoryMapTests") { REQUIRE(dir_tree.size() == 0); } - SECTION("insert items sorted") { - const int kItemsCount = 100000; + SECTION("insert entries sorted") { + const int kEntriesCount = 100000; TestAttributes attributes(6); - for (uint32_t i = 0; i < kItemsCount; ++i) { + for (uint32_t i = 0; i < kEntriesCount; ++i) { attributes.data()->flags = i; REQUIRE(dir_tree.insert(std::format("{:05}", i), attributes.data())); } - REQUIRE(dir_tree.size() == kItemsCount); - REQUIRE(std::ranges::distance(dir_tree.begin(), dir_tree.end()) == kItemsCount); - for (auto [i, item] : std::views::enumerate(dir_tree)) { - CHECK(item.name == std::format("{:05}", i)); - CHECK(item.attributes.get()->flags.value() == i); - CHECK(item.attributes.get()->entry_log2_size.value() == 6); + REQUIRE(dir_tree.size() == kEntriesCount); + REQUIRE(std::ranges::distance(dir_tree.begin(), dir_tree.end()) == kEntriesCount); + for (auto [i, entry] : std::views::enumerate(dir_tree)) { + CHECK(entry.name == std::format("{:05}", i)); + CHECK(entry.attributes.get()->flags.value() == i); + CHECK(entry.attributes.get()->entry_log2_size.value() == 6); } REQUIRE(std::ranges::equal( std::views::transform(std::views::reverse(dir_tree), - [](const auto& item) -> int { return item.attributes.get()->flags.value(); }), - std::views::reverse(std::views::iota(0, kItemsCount)))); - for (uint32_t i = 0; i < kItemsCount; ++i) { - auto item = dir_tree.find(std::format("{:05}", i)); - REQUIRE(!item.is_end()); - CHECK((*item).attributes.get()->flags.value() == i); - CHECK((*item).name == std::format("{:05}", i)); + [](const auto& entry) -> int { return entry.attributes.get()->flags.value(); }), + std::views::reverse(std::views::iota(0, kEntriesCount)))); + for (uint32_t i = 0; i < kEntriesCount; ++i) { + auto entry = dir_tree.find(std::format("{:05}", i)); + REQUIRE(!entry.is_end()); + CHECK((*entry).attributes.get()->flags.value() == i); + CHECK((*entry).name == std::format("{:05}", i)); } } - SECTION("insert and remove one two items") { + SECTION("insert and remove one two entries") { SubBlockAllocator allocator{root_block}; auto free_bytes_1 = allocator.GetFreeBytes(); TestAttributes attributes(6); @@ -90,68 +90,68 @@ TEST_CASE("DirectoryMapTests") { CHECK(free_bytes_1 == allocator.GetFreeBytes()); } - SECTION("insert items unsorted") { - constexpr int kItemsCount = 100000; - auto unsorted_keys = createShuffledKeysArray(); + SECTION("insert entries unsorted") { + constexpr int kEntriesCount = 100000; + auto unsorted_keys = createShuffledKeysArray(); TestAttributes attributes(6); for (auto i : unsorted_keys) { attributes.data()->flags = i; REQUIRE(dir_tree.insert(std::format("{:05}", i), attributes.data())); } - REQUIRE(dir_tree.size() == kItemsCount); - REQUIRE(std::ranges::distance(dir_tree.begin(), dir_tree.end()) == kItemsCount); - for (auto [i, item] : std::views::enumerate(dir_tree)) { - CHECK(item.name == std::format("{:05}", i)); - CHECK(item.attributes.get()->flags.value() == i); - CHECK(item.attributes.get()->entry_log2_size.value() == 6); + REQUIRE(dir_tree.size() == kEntriesCount); + REQUIRE(std::ranges::distance(dir_tree.begin(), dir_tree.end()) == kEntriesCount); + for (auto [i, entry] : std::views::enumerate(dir_tree)) { + CHECK(entry.name == std::format("{:05}", i)); + CHECK(entry.attributes.get()->flags.value() == i); + CHECK(entry.attributes.get()->entry_log2_size.value() == 6); } - for (uint32_t i = 0; i < kItemsCount; ++i) { - auto item = dir_tree.find(std::format("{:05}", i)); - REQUIRE(!item.is_end()); - CHECK((*item).attributes.get()->flags.value() == i); - CHECK((*item).name == std::format("{:05}", i)); + for (uint32_t i = 0; i < kEntriesCount; ++i) { + auto entry = dir_tree.find(std::format("{:05}", i)); + REQUIRE(!entry.is_end()); + CHECK((*entry).attributes.get()->flags.value() == i); + CHECK((*entry).name == std::format("{:05}", i)); } } - SECTION("insert items unsorted different attributes size") { - constexpr int kItemsCount = 10000; - auto unsorted_keys = createShuffledKeysArray(); + SECTION("insert entries unsorted different attributes size") { + constexpr int kEntriesCount = 10000; + auto unsorted_keys = createShuffledKeysArray(); for (auto i : unsorted_keys) { TestAttributes attributes((i % 5) + 6); attributes.data()->flags = i; REQUIRE(dir_tree.insert(std::format("{:04}", i), attributes.data())); } - REQUIRE(dir_tree.size() == kItemsCount); - REQUIRE(std::ranges::distance(dir_tree.begin(), dir_tree.end()) == kItemsCount); - for (auto [i, item] : std::views::enumerate(dir_tree)) { - CHECK(item.name == std::format("{:04}", i)); - CHECK(item.attributes.get()->flags.value() == i); - CHECK(item.attributes.get()->entry_log2_size.value() == (i % 5) + 6); + REQUIRE(dir_tree.size() == kEntriesCount); + REQUIRE(std::ranges::distance(dir_tree.begin(), dir_tree.end()) == kEntriesCount); + for (auto [i, entry] : std::views::enumerate(dir_tree)) { + CHECK(entry.name == std::format("{:04}", i)); + CHECK(entry.attributes.get()->flags.value() == i); + CHECK(entry.attributes.get()->entry_log2_size.value() == (i % 5) + 6); } } - SECTION("remove items randomly") { - constexpr int kItemsCount = 100000; + SECTION("remove entries randomly") { + constexpr int kEntriesCount = 100000; auto free_blocks = (*wfs_device->GetRootArea()->GetFreeBlocksAllocator())->free_blocks_count(); TestAttributes attributes(6); - for (uint32_t i = 0; i < kItemsCount; ++i) { + for (uint32_t i = 0; i < kEntriesCount; ++i) { attributes.data()->flags = i; REQUIRE(dir_tree.insert(std::format("{:05}", i), attributes.data())); } CHECK(free_blocks != (*wfs_device->GetRootArea()->GetFreeBlocksAllocator())->free_blocks_count()); - auto unsorted_indexes = createShuffledKeysArray(); - auto middle = unsorted_indexes.begin() + kItemsCount / 2; - // Remove half the items first + auto unsorted_indexes = createShuffledKeysArray(); + auto middle = unsorted_indexes.begin() + kEntriesCount / 2; + // Remove half the entries first for (auto i : std::ranges::subrange(unsorted_indexes.begin(), middle)) { REQUIRE(dir_tree.erase(std::format("{:05}", i))); } auto sorted_upper_half = std::ranges::subrange(middle, unsorted_indexes.end()) | std::ranges::to(); std::ranges::sort(sorted_upper_half); - // Ensure that the right items were deleted + // Ensure that the right entries were deleted REQUIRE(std::ranges::equal( - std::views::transform(dir_tree, [](const auto& item) -> int { return item.attributes.get()->flags.value(); }), + std::views::transform(dir_tree, [](const auto& entry) -> int { return entry.attributes.get()->flags.value(); }), sorted_upper_half)); // Remove the second half @@ -166,28 +166,28 @@ TEST_CASE("DirectoryMapTests") { CHECK(free_blocks == (*wfs_device->GetRootArea()->GetFreeBlocksAllocator())->free_blocks_count()); } - SECTION("remove items randomly") { - constexpr int kItemsCount = 100000; + SECTION("remove entries randomly") { + constexpr int kEntriesCount = 100000; auto free_blocks = (*wfs_device->GetRootArea()->GetFreeBlocksAllocator())->free_blocks_count(); TestAttributes attributes(6); - for (uint32_t i = 0; i < kItemsCount; ++i) { + for (uint32_t i = 0; i < kEntriesCount; ++i) { attributes.data()->flags = i; REQUIRE(dir_tree.insert(std::format("{:05}", i), attributes.data())); } CHECK(free_blocks != (*wfs_device->GetRootArea()->GetFreeBlocksAllocator())->free_blocks_count()); - auto unsorted_indexes = createShuffledKeysArray(); - auto middle = unsorted_indexes.begin() + kItemsCount / 2; - // Remove half the items first + auto unsorted_indexes = createShuffledKeysArray(); + auto middle = unsorted_indexes.begin() + kEntriesCount / 2; + // Remove half the entries first for (auto i : std::ranges::subrange(unsorted_indexes.begin(), middle)) { REQUIRE(dir_tree.erase(std::format("{:05}", i))); } auto sorted_upper_half = std::ranges::subrange(middle, unsorted_indexes.end()) | std::ranges::to(); std::ranges::sort(sorted_upper_half); - // Ensure that the right items were deleted + // Ensure that the right entries were deleted REQUIRE(std::ranges::equal( - std::views::transform(dir_tree, [](const auto& item) -> int { return item.attributes.get()->flags.value(); }), + std::views::transform(dir_tree, [](const auto& entry) -> int { return entry.attributes.get()->flags.value(); }), sorted_upper_half)); // Remove the second half @@ -203,9 +203,9 @@ TEST_CASE("DirectoryMapTests") { } SECTION("check backward/forward iterator") { - constexpr int kItemsCount = 100000; + constexpr int kEntriesCount = 100000; TestAttributes attributes(6); - for (uint32_t i = 0; i < kItemsCount; ++i) { + for (uint32_t i = 0; i < kEntriesCount; ++i) { REQUIRE(dir_tree.insert(std::format("{:05}", i), attributes.data())); } @@ -216,7 +216,7 @@ TEST_CASE("DirectoryMapTests") { ++it; ++steps; } - REQUIRE(steps == kItemsCount); + REQUIRE(steps == kEntriesCount); REQUIRE(it.is_end()); while (it != dir_tree.begin()) { --it; @@ -254,13 +254,13 @@ TEST_CASE("DirectoryMapTests") { for (uint32_t i = 0; i < 200; ++i) { REQUIRE(dir_tree.erase(std::format("{:05}", 11000 + i))); } - for (auto [i, item] : std::views::enumerate(dir_tree)) { - CHECK(item.name == std::format("{:05}", 10000 + i)); + for (auto [i, entry] : std::views::enumerate(dir_tree)) { + CHECK(entry.name == std::format("{:05}", 10000 + i)); } for (uint32_t i = 0; i < 80; ++i) { - auto item = dir_tree.find(std::format("{:05}", 10000 + i)); - REQUIRE(!item.is_end()); - CHECK((*item).name == std::format("{:05}", 10000 + i)); + auto entry = dir_tree.find(std::format("{:05}", 10000 + i)); + REQUIRE(!entry.is_end()); + CHECK((*entry).name == std::format("{:05}", 10000 + i)); } } } diff --git a/tests/directory_tree_tests.cpp b/tests/directory_tree_tests.cpp index 7281fe1..7309516 100644 --- a/tests/directory_tree_tests.cpp +++ b/tests/directory_tree_tests.cpp @@ -70,31 +70,31 @@ TEST_CASE("DirectoryTreeTests") { REQUIRE(dir_tree.size() == 0); } - SECTION("insert linear items sorted") { - const int kItems = 10; - for (uint16_t i = 0; i < kItems; ++i) { + SECTION("insert linear entries sorted") { + const int kEntries = 10; + for (uint16_t i = 0; i < kEntries; ++i) { REQUIRE(dir_tree.insert({std::string(i + 1, 'a'), i})); } - REQUIRE(dir_tree.size() == kItems); - for (auto [i, item] : std::views::enumerate(dir_tree)) { - CHECK(item.key() == std::string(i + 1, 'a')); - CHECK(item.value() == static_cast(i)); + REQUIRE(dir_tree.size() == kEntries); + for (auto [i, entry] : std::views::enumerate(dir_tree)) { + CHECK(entry.key() == std::string(i + 1, 'a')); + CHECK(entry.value() == static_cast(i)); } } - SECTION("insert linear items reverse") { - const int kItems = 10; - for (int i = 0; i < kItems; ++i) { - REQUIRE(dir_tree.insert({std::string(kItems - i, 'a'), static_cast(kItems - 1 - i)})); + SECTION("insert linear entries reverse") { + const int kEntries = 10; + for (int i = 0; i < kEntries; ++i) { + REQUIRE(dir_tree.insert({std::string(kEntries - i, 'a'), static_cast(kEntries - 1 - i)})); } - REQUIRE(dir_tree.size() == kItems); - for (auto [i, item] : std::views::enumerate(dir_tree)) { - CHECK(item.key() == std::string(i + 1, 'a')); - CHECK(item.value() == static_cast(i)); + REQUIRE(dir_tree.size() == kEntries); + for (auto [i, entry] : std::views::enumerate(dir_tree)) { + CHECK(entry.key() == std::string(i + 1, 'a')); + CHECK(entry.value() == static_cast(i)); } } - SECTION("insert and erase items randomlly") { + SECTION("insert and erase entries randomlly") { constexpr std::array chars = {'a', 'b', 'c'}; auto one_char = std::views::cartesian_product(chars) | std::views::transform([](auto tuple) { return tuple_to_string(tuple); }) | @@ -118,9 +118,9 @@ TEST_CASE("DirectoryTreeTests") { } REQUIRE(dir_tree.size() == keys.size()); REQUIRE(std::ranges::distance(dir_tree.begin(), dir_tree.end()) == static_cast(keys.size())); - for (auto [i, item] : std::views::enumerate(dir_tree)) { - CHECK(item.key() == keys[i]); - CHECK(item.value() == static_cast(i)); + for (auto [i, entry] : std::views::enumerate(dir_tree)) { + CHECK(entry.key() == keys[i]); + CHECK(entry.value() == static_cast(i)); } for (uint16_t i = 0; i < keys.size(); ++i) { auto it = dir_tree.find(keys[unsorted_keys_indxes[i]]); @@ -139,9 +139,9 @@ TEST_CASE("DirectoryTreeTests") { } REQUIRE(dir_tree.size() == 26); char i = 'a'; - for (const auto& item : dir_tree) { - CHECK(item.key() == std::string{i}); - CHECK(item.value() == static_cast(i++)); + for (const auto& entry : dir_tree) { + CHECK(entry.key() == std::string{i}); + CHECK(entry.value() == static_cast(i++)); } }