| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374 |
- //
- // cascade_iterator_test.cpp
- // iterator-test
- //
- // Created by Sam Jaffe on 9/24/25.
- // Copyright © 2025 Sam Jaffe. All rights reserved.
- //
- #include "iterator/projecting_recursive_iterator.h"
- #include "ranges.h"
- #include "xcode_gtest_helper.h"
- using iterator::ProjectingRecursiveIterator;
- struct Baz {
- std::vector<int> ints;
- std::map<int, std::vector<std::string>> tags;
- };
- struct Bar {
- std::vector<double> doubles;
- std::map<int, Baz> bazes;
- };
- struct Foo {
- std::map<int, std::map<std::string, int>> example;
- std::vector<Bar> bars_;
- std::vector<Bar> const & bars() const { return bars_; }
- std::vector<Bar> bars_copy() { return bars_; }
- };
- TEST(ProjectingRecursiveIterator, OneProjectorIsTwoLevels) {
- std::vector<Foo> foos;
- auto iter = ProjectingRecursiveIterator(foos, &Foo::bars);
- testing::StaticAssertTypeEq<decltype(*iter), Bar const &>();
- }
- TEST(ProjectingRecursiveIterator, TwoProjectorIsThreeLevels) {
- std::vector<Foo> foos;
- auto iter = ProjectingRecursiveIterator(foos, &Foo::bars, &Bar::bazes);
- testing::StaticAssertTypeEq<decltype(*iter),
- std::tuple<int const &, Baz const &>>();
- }
- TEST(ProjectingRecursiveIterator, IsRvalueSafe) {
- std::vector<Foo> foos;
- auto iter = ProjectingRecursiveIterator(foos, &Foo::bars_copy, &Bar::bazes);
- testing::StaticAssertTypeEq<decltype(*iter),
- std::tuple<int const &, Baz const &>>();
- }
- TEST(ProjectingRecursiveIterator, CanProjectUnboundedTail) {
- std::vector<Foo> foos;
- auto iter =
- ProjectingRecursiveIterator(foos, iterator::unbounded{}, &Foo::example);
- static_assert(
- std::same_as<decltype(*iter),
- std::tuple<int const &, std::string const &, int &>>);
- testing::StaticAssertTypeEq<
- decltype(*iter), std::tuple<int const &, std::string const &, int &>>();
- }
- TEST(ProjectingRecursiveIterator, CanProjectBoundedTail) {
- std::vector<Foo> foos;
- auto iter =
- ProjectingRecursiveIterator(foos, iterator::bounded<3>{}, &Foo::example);
- static_assert(
- std::same_as<decltype(*iter),
- std::tuple<int const &, std::string const &, int &>>);
- testing::StaticAssertTypeEq<
- decltype(*iter), std::tuple<int const &, std::string const &, int &>>();
- }
|