From 3cc82a51d8bc8ab72a55e0ec18e26e02f20a8fef Mon Sep 17 00:00:00 2001 From: Leonard Hecker Date: Sat, 30 Mar 2024 00:15:46 +0100 Subject: [PATCH] Replace til::some with til::small_vector (#16952) `til::small_vector` had a bug: Its internal backing buffer didn't prevent default initialization! Wrapping it in an `union` fixed that. `til::some` had the same issue, but thinking about it I realized we don't need both classes to exist, so I removed `til::some` since `til::small_vector` is more flexible. Checking the assembly, I noticed that `til::small_vector` with the `union` fix produced a more compact result. I also noticed that in combination with function calls and inlining the bit-wise ANDs in the point/size/rect boolean operators produced poor-ish results. Since their impact on performance is negligible to begin with I simplified that code slightly. Finally, I noticed that the boolean operator for `til::point` was incorrect since it checked for `>0` instead of `>=0`. Luckily nothing seemed to have used that operator yet. (= No inbox regression.) --- src/inc/til/point.h | 2 +- src/inc/til/rect.h | 18 +- src/inc/til/rle.h | 2 - src/inc/til/size.h | 2 +- src/inc/til/small_vector.h | 7 +- src/inc/til/some.h | 267 -------------- src/renderer/atlas/BackendD3D.h | 1 - src/renderer/gdi/paint.cpp | 2 - src/server/ApiMessage.h | 2 - src/til/ut_til/BitmapTests.cpp | 8 +- src/til/ut_til/PointTests.cpp | 18 + src/til/ut_til/RectangleTests.cpp | 64 ++-- src/til/ut_til/SizeTests.cpp | 30 +- src/til/ut_til/SmallVectorTests.cpp | 2 - src/til/ut_til/SomeTests.cpp | 340 ------------------ src/til/ut_til/UnicodeTests.cpp | 4 +- src/til/ut_til/sources | 1 - src/til/ut_til/til.unit.tests.vcxproj | 4 +- src/til/ut_til/til.unit.tests.vcxproj.filters | 6 +- src/types/inc/IInputEvent.hpp | 2 - src/types/inc/viewport.hpp | 2 +- 21 files changed, 77 insertions(+), 707 deletions(-) delete mode 100644 src/inc/til/some.h delete mode 100644 src/til/ut_til/SomeTests.cpp diff --git a/src/inc/til/point.h b/src/inc/til/point.h index 4da8d5c6ddb..678afe706f6 100644 --- a/src/inc/til/point.h +++ b/src/inc/til/point.h @@ -58,7 +58,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" constexpr explicit operator bool() const noexcept { - return (x > 0) & (y > 0); + return x >= 0 && y >= 0; } constexpr bool operator<(const point other) const noexcept diff --git a/src/inc/til/rect.h b/src/inc/til/rect.h index 7ad7fe7ab7d..bc7b07b6c83 100644 --- a/src/inc/til/rect.h +++ b/src/inc/til/rect.h @@ -4,11 +4,11 @@ #pragma once #include "bit.h" -#include "some.h" #include "math.h" #include "size.h" #include "point.h" #include "operators.h" +#include "small_vector.h" namespace til // Terminal Implementation Library. Also: "Today I Learned" { @@ -31,8 +31,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" explicit constexpr operator bool() const noexcept { - return (left >= 0) & (top >= 0) & - (right >= left) & (bottom >= top); + return left >= 0 && top >= 0 && right >= left && bottom >= top; } }; @@ -204,8 +203,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" explicit constexpr operator bool() const noexcept { - return (left >= 0) & (top >= 0) & - (right > left) & (bottom > top); + return left >= 0 && top >= 0 && right > left && bottom > top; } constexpr const_iterator begin() const @@ -294,9 +292,9 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" } // - = subtract - constexpr some operator-(const rect& other) const + small_vector operator-(const rect& other) const { - some result; + small_vector result; // We could have up to four rectangles describing the area resulting when you take removeMe out of main. // Find the intersection of the two so we know which bits of removeMe are actually applicable @@ -566,14 +564,12 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" constexpr bool contains(point pt) const noexcept { - return (pt.x >= left) & (pt.x < right) & - (pt.y >= top) & (pt.y < bottom); + return pt.x >= left && pt.x < right && pt.y >= top && pt.y < bottom; } constexpr bool contains(const rect& rc) const noexcept { - return (rc.left >= left) & (rc.top >= top) & - (rc.right <= right) & (rc.bottom <= bottom); + return rc.left >= left && rc.top >= top && rc.right <= right && rc.bottom <= bottom; } template diff --git a/src/inc/til/rle.h b/src/inc/til/rle.h index 34b6c929a0b..99bdf734c45 100644 --- a/src/inc/til/rle.h +++ b/src/inc/til/rle.h @@ -3,8 +3,6 @@ #pragma once -#include "small_vector.h" - #ifdef UNIT_TESTING class RunLengthEncodingTests; #endif diff --git a/src/inc/til/size.h b/src/inc/til/size.h index 72dbb602852..98800ad7539 100644 --- a/src/inc/til/size.h +++ b/src/inc/til/size.h @@ -39,7 +39,7 @@ namespace til // Terminal Implementation Library. Also: "Today I Learned" constexpr explicit operator bool() const noexcept { - return (width > 0) & (height > 0); + return width > 0 && height > 0; } constexpr size operator+(const size other) const diff --git a/src/inc/til/small_vector.h b/src/inc/til/small_vector.h index f078d37fbe4..b47cd1ead14 100644 --- a/src/inc/til/small_vector.h +++ b/src/inc/til/small_vector.h @@ -652,7 +652,7 @@ namespace til reference emplace_back(Args&&... args) { const auto new_size = _ensure_fits(1); - const auto it = new (_data + _size) T(std::forward(args)...); + const auto it = std::construct_at(_data + _size, std::forward(args)...); _size = new_size; return *it; } @@ -930,7 +930,10 @@ namespace til T* _data; size_t _capacity; size_t _size; - T _buffer[N]; + union + { + T _buffer[N]; + }; }; } diff --git a/src/inc/til/some.h b/src/inc/til/some.h deleted file mode 100644 index ec34a470ca4..00000000000 --- a/src/inc/til/some.h +++ /dev/null @@ -1,267 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -#pragma once - -#include - -namespace til // Terminal Implementation Library. Also: "Today I Learned" -{ - template - class some - { - private: - std::array _array; - size_t _used; - -#ifdef UNIT_TESTING - friend class SomeTests; -#endif - - public: - using value_type = T; - using size_type = size_t; - using difference_type = ptrdiff_t; - using pointer = T*; - using const_pointer = const T*; - using reference = T&; - using const_reference = const T&; - - using iterator = typename decltype(_array)::iterator; - using const_iterator = typename decltype(_array)::const_iterator; - - using reverse_iterator = typename decltype(_array)::reverse_iterator; - using const_reverse_iterator = typename decltype(_array)::const_reverse_iterator; - - constexpr some() noexcept : - _array{}, - _used{ 0 } - { - } - - constexpr some(std::initializer_list init) - { - if (init.size() > N) - { - _invalidArg(); - } - - std::copy(init.begin(), init.end(), _array.begin()); - _used = init.size(); - } - - constexpr bool operator==(const til::some& other) const noexcept - { - return std::equal(cbegin(), cend(), other.cbegin(), other.cend()); - } - - constexpr bool operator!=(const til::some& other) const noexcept - { - return !(*this == other); - } - - constexpr void fill(const T& _Value) - { - _array.fill(_Value); - _used = N; - } - - constexpr void swap(some& _Other) noexcept(std::is_nothrow_swappable_v) - { - _array.swap(_Other._array); - std::swap(_used, _Other._used); - } - - constexpr const_iterator begin() const noexcept - { - return _array.begin(); - } - - constexpr const_iterator end() const noexcept - { - return _array.begin() + _used; - } - - constexpr const_reverse_iterator rbegin() const noexcept - { - return const_reverse_iterator(end()); - } - - constexpr const_reverse_iterator rend() const noexcept - { - return const_reverse_iterator(begin()); - } - - constexpr const_iterator cbegin() const noexcept - { - return begin(); - } - - constexpr const_iterator cend() const noexcept - { - return end(); - } - - constexpr const_reverse_iterator crbegin() const noexcept - { - return rbegin(); - } - - constexpr const_reverse_iterator crend() const noexcept - { - return rend(); - } - - constexpr size_type size() const noexcept - { - return _used; - } - - constexpr size_type max_size() const noexcept - { - return N; - } - - constexpr bool empty() const noexcept - { - return !_used; - } - - constexpr void clear() noexcept - { - _used = 0; - _array = {}; // should free members, if necessary. - } - - constexpr const_reference at(size_type pos) const - { - if (_used <= pos) - { - _outOfRange(); - } - - return _array[pos]; - } - - constexpr const_reference operator[](size_type pos) const noexcept - { - return _array[pos]; - } - - constexpr const_reference front() const noexcept - { - return _array[0]; - } - - constexpr const_reference back() const noexcept - { - return _array[_used - 1]; - } - - constexpr const T* data() const noexcept - { - return _array.data(); - } - - constexpr void push_back(const T& val) - { - if (_used >= N) - { - _outOfRange(); - } - - til::at(_array, _used) = val; - - ++_used; - } - - constexpr void push_back(T&& val) - { - if (_used >= N) - { - _outOfRange(); - } - - til::at(_array, _used) = std::move(val); - - ++_used; - } - - constexpr void pop_back() - { - if (_used <= 0) - { - _outOfRange(); - } - - --_used; - - til::at(_array, _used) = 0; - } - - [[noreturn]] constexpr void _invalidArg() const - { - throw std::invalid_argument("invalid argument"); - } - - [[noreturn]] constexpr void _outOfRange() const - { - throw std::out_of_range("invalid some subscript"); - } - - std::wstring to_string() const - { - std::wstringstream wss; - wss << std::endl - << L"Some contains " << size() << " of max size " << max_size() << ":" << std::endl; - wss << L"Elements:" << std::endl; - - for (auto& item : *this) - { - wss << L"\t- " << item.to_string() << std::endl; - } - - return wss.str(); - } - }; -} - -#ifdef __WEX_COMMON_H__ -namespace WEX::TestExecution -{ - template - class VerifyOutputTraits<::til::some> - { - public: - static WEX::Common::NoThrowString ToString(const ::til::some& some) - { - return WEX::Common::NoThrowString(some.to_string().c_str()); - } - }; - - template - class VerifyCompareTraits<::til::some, ::til::some> - { - public: - static bool AreEqual(const ::til::some& expected, const ::til::some& actual) noexcept - { - return expected == actual; - } - - static bool AreSame(const ::til::some& expected, const ::til::some& actual) noexcept - { - return &expected == &actual; - } - - static bool IsLessThan(const ::til::some& expectedLess, const ::til::some& expectedGreater) = delete; - - static bool IsGreaterThan(const ::til::some& expectedGreater, const ::til::some& expectedLess) = delete; - - static bool IsNull(const ::til::some& object) noexcept - { - return object == til::some{}; - } - }; - -}; -#endif diff --git a/src/renderer/atlas/BackendD3D.h b/src/renderer/atlas/BackendD3D.h index 25833b831dc..6a12e704a4d 100644 --- a/src/renderer/atlas/BackendD3D.h +++ b/src/renderer/atlas/BackendD3D.h @@ -5,7 +5,6 @@ #include #include -#include #include "Backend.h" diff --git a/src/renderer/gdi/paint.cpp b/src/renderer/gdi/paint.cpp index 29f8dfc43ad..c449b4d0835 100644 --- a/src/renderer/gdi/paint.cpp +++ b/src/renderer/gdi/paint.cpp @@ -4,8 +4,6 @@ #include "precomp.h" #include "gdirenderer.hpp" -#include - #include "../inc/unicode.hpp" #pragma hdrstop diff --git a/src/server/ApiMessage.h b/src/server/ApiMessage.h index d730cff9e00..6c1809aa9d7 100644 --- a/src/server/ApiMessage.h +++ b/src/server/ApiMessage.h @@ -20,8 +20,6 @@ Revision History: #include "ApiMessageState.h" #include "IApiRoutines.h" -#include - class ConsoleProcessHandle; class ConsoleHandleData; diff --git a/src/til/ut_til/BitmapTests.cpp b/src/til/ut_til/BitmapTests.cpp index ee093f52a79..b17bf0fff4e 100644 --- a/src/til/ut_til/BitmapTests.cpp +++ b/src/til/ut_til/BitmapTests.cpp @@ -868,7 +868,7 @@ class BitmapTests // C _ D D // _ _ E _ // _ F F _ - til::some expected; + std::vector expected; expected.push_back(til::rect{ til::point{ 0, 0 }, til::size{ 2, 1 } }); expected.push_back(til::rect{ til::point{ 3, 0 }, til::size{ 1, 1 } }); expected.push_back(til::rect{ til::point{ 0, 1 }, til::size{ 1, 1 } }); @@ -877,7 +877,7 @@ class BitmapTests expected.push_back(til::rect{ til::point{ 1, 3 }, til::size{ 2, 1 } }); Log::Comment(L"Run the iterator and collect the runs."); - til::some actual; + std::vector actual; for (auto run : map.runs()) { actual.push_back(run); @@ -1006,7 +1006,7 @@ class BitmapTests // C _ D D // _ _ E _ // _ F F _ - til::some expected; + std::vector expected; expected.push_back(til::rect{ til::point{ 0, 0 }, til::size{ 2, 1 } }); expected.push_back(til::rect{ til::point{ 3, 0 }, til::size{ 1, 1 } }); expected.push_back(til::rect{ til::point{ 0, 1 }, til::size{ 1, 1 } }); @@ -1015,7 +1015,7 @@ class BitmapTests expected.push_back(til::rect{ til::point{ 1, 3 }, til::size{ 2, 1 } }); Log::Comment(L"Run the iterator and collect the runs."); - til::some actual; + std::vector actual; for (auto run : map.runs()) { actual.push_back(run); diff --git a/src/til/ut_til/PointTests.cpp b/src/til/ut_til/PointTests.cpp index cd069153c77..738847cee75 100644 --- a/src/til/ut_til/PointTests.cpp +++ b/src/til/ut_til/PointTests.cpp @@ -221,6 +221,24 @@ class PointTests } } + TEST_METHOD(Boolean) + { + SetVerifyOutput verifyOutputScope{ VerifyOutputSettings::LogOnlyFailures }; + + static constexpr til::CoordType values[] = { til::CoordTypeMin, -1, 0, 1, til::CoordTypeMax }; + + for (const auto x : values) + { + for (const auto y : values) + { + const til::point p{ x, y }; + const auto expected = x >= 0 && y >= 0; + const auto actual = static_cast(p); + VERIFY_ARE_EQUAL(expected, actual); + } + } + } + TEST_METHOD(Addition) { Log::Comment(L"Addition of two things that should be in bounds."); diff --git a/src/til/ut_til/RectangleTests.cpp b/src/til/ut_til/RectangleTests.cpp index 8709d1f8d66..f7a882fb987 100644 --- a/src/til/ut_til/RectangleTests.cpp +++ b/src/til/ut_til/RectangleTests.cpp @@ -300,22 +300,26 @@ class RectangleTests TEST_METHOD(Boolean) { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_METHOD_PROPERTY(L"Data:left", L"{0,10}") - TEST_METHOD_PROPERTY(L"Data:top", L"{0,10}") - TEST_METHOD_PROPERTY(L"Data:right", L"{0,10}") - TEST_METHOD_PROPERTY(L"Data:bottom", L"{0,10}") - END_TEST_METHOD_PROPERTIES() + SetVerifyOutput verifyOutputScope{ VerifyOutputSettings::LogOnlyFailures }; - til::CoordType left, top, right, bottom; - VERIFY_SUCCEEDED_RETURN(TestData::TryGetValue(L"left", left)); - VERIFY_SUCCEEDED_RETURN(TestData::TryGetValue(L"top", top)); - VERIFY_SUCCEEDED_RETURN(TestData::TryGetValue(L"right", right)); - VERIFY_SUCCEEDED_RETURN(TestData::TryGetValue(L"bottom", bottom)); + static constexpr til::CoordType values[] = { til::CoordTypeMin, -1, 0, 1, til::CoordTypeMax }; - const auto expected = left < right && top < bottom; - const til::rect actual{ left, top, right, bottom }; - VERIFY_ARE_EQUAL(expected, (bool)actual); + for (const auto left : values) + { + for (const auto top : values) + { + for (const auto right : values) + { + for (const auto bottom : values) + { + const til::rect r{ left, top, right, bottom }; + const auto expected = left >= 0 && top >= 0 && right > left && bottom > top; + const auto actual = static_cast(r); + VERIFY_ARE_EQUAL(expected, actual); + } + } + } + } } TEST_METHOD(OrUnion) @@ -364,7 +368,7 @@ class RectangleTests const auto removal = original; // Since it's the same rectangle, nothing's left. We should get no results. - const til::some expected; + const til::small_vector expected; const auto actual = original - removal; VERIFY_ARE_EQUAL(expected, actual); } @@ -375,7 +379,7 @@ class RectangleTests const til::rect removal{ 12, 12, 15, 15 }; // Since they don't overlap, we expect the original to be given back. - const til::some expected{ original }; + const til::small_vector expected{ original }; const auto actual = original - removal; VERIFY_ARE_EQUAL(expected, actual); } @@ -401,7 +405,7 @@ class RectangleTests const til::rect original{ 0, 0, 10, 10 }; const til::rect removal{ -12, 3, 15, 15 }; - const til::some expected{ + const til::small_vector expected{ til::rect{ original.left, original.top, original.right, removal.top } }; const auto actual = original - removal; @@ -428,7 +432,7 @@ class RectangleTests const til::rect original{ 0, 0, 10, 10 }; const til::rect removal{ 3, 3, 15, 15 }; - const til::some expected{ + const til::small_vector expected{ til::rect{ original.left, original.top, original.right, removal.top }, til::rect{ original.left, removal.top, removal.left, original.bottom } }; @@ -452,7 +456,7 @@ class RectangleTests const til::rect original{ 0, 0, 10, 10 }; const til::rect removal{ 3, 3, 15, 6 }; - const til::some expected{ + const til::small_vector expected{ til::rect{ original.left, original.top, original.right, removal.top }, til::rect{ original.left, removal.bottom, original.right, original.bottom }, til::rect{ original.left, removal.top, removal.left, removal.bottom } @@ -483,7 +487,7 @@ class RectangleTests const til::rect original{ 0, 0, 10, 10 }; const til::rect removal{ 3, 3, 6, 6 }; - const til::some expected{ + const til::small_vector expected{ til::rect{ original.left, original.top, original.right, removal.top }, til::rect{ original.left, removal.bottom, original.right, original.bottom }, til::rect{ original.left, removal.top, removal.left, removal.bottom }, @@ -706,26 +710,6 @@ class RectangleTests VERIFY_ARE_EQUAL(expected, rc.size()); } - TEST_METHOD(Empty) - { - BEGIN_TEST_METHOD_PROPERTIES() - TEST_METHOD_PROPERTY(L"Data:left", L"{0,10}") - TEST_METHOD_PROPERTY(L"Data:top", L"{0,10}") - TEST_METHOD_PROPERTY(L"Data:right", L"{0,10}") - TEST_METHOD_PROPERTY(L"Data:bottom", L"{0,10}") - END_TEST_METHOD_PROPERTIES() - - til::CoordType left, top, right, bottom; - VERIFY_SUCCEEDED_RETURN(TestData::TryGetValue(L"left", left)); - VERIFY_SUCCEEDED_RETURN(TestData::TryGetValue(L"top", top)); - VERIFY_SUCCEEDED_RETURN(TestData::TryGetValue(L"right", right)); - VERIFY_SUCCEEDED_RETURN(TestData::TryGetValue(L"bottom", bottom)); - - const auto expected = !(left < right && top < bottom); - const til::rect actual{ left, top, right, bottom }; - VERIFY_ARE_EQUAL(expected, actual.empty()); - } - TEST_METHOD(ContainsPoint) { BEGIN_TEST_METHOD_PROPERTIES() diff --git a/src/til/ut_til/SizeTests.cpp b/src/til/ut_til/SizeTests.cpp index a75b48922a2..dce512aa1a7 100644 --- a/src/til/ut_til/SizeTests.cpp +++ b/src/til/ut_til/SizeTests.cpp @@ -147,26 +147,20 @@ class SizeTests TEST_METHOD(Boolean) { - const til::size empty; - VERIFY_IS_FALSE(!!empty); + SetVerifyOutput verifyOutputScope{ VerifyOutputSettings::LogOnlyFailures }; - const til::size yOnly{ 0, 10 }; - VERIFY_IS_FALSE(!!yOnly); + static constexpr til::CoordType values[] = { til::CoordTypeMin, -1, 0, 1, til::CoordTypeMax }; - const til::size xOnly{ 10, 0 }; - VERIFY_IS_FALSE(!!xOnly); - - const til::size both{ 10, 10 }; - VERIFY_IS_TRUE(!!both); - - const til::size yNegative{ 10, -10 }; - VERIFY_IS_FALSE(!!yNegative); - - const til::size xNegative{ -10, 10 }; - VERIFY_IS_FALSE(!!xNegative); - - const til::size bothNegative{ -10, -10 }; - VERIFY_IS_FALSE(!!bothNegative); + for (const auto width : values) + { + for (const auto height : values) + { + const til::size s{ width, height }; + const auto expected = width > 0 && height > 0; + const auto actual = static_cast(s); + VERIFY_ARE_EQUAL(expected, actual); + } + } } TEST_METHOD(Addition) diff --git a/src/til/ut_til/SmallVectorTests.cpp b/src/til/ut_til/SmallVectorTests.cpp index f1a2ed88e54..55a338ae86d 100644 --- a/src/til/ut_til/SmallVectorTests.cpp +++ b/src/til/ut_til/SmallVectorTests.cpp @@ -3,8 +3,6 @@ #include "precomp.h" -#include - using namespace std::literals; using namespace WEX::Common; using namespace WEX::Logging; diff --git a/src/til/ut_til/SomeTests.cpp b/src/til/ut_til/SomeTests.cpp deleted file mode 100644 index 98ea25fd64d..00000000000 --- a/src/til/ut_til/SomeTests.cpp +++ /dev/null @@ -1,340 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT license. - -#include "precomp.h" - -using namespace WEX::Common; -using namespace WEX::Logging; -using namespace WEX::TestExecution; - -class SomeTests -{ - TEST_CLASS(SomeTests); - - TEST_METHOD(Construct) - { - Log::Comment(L"Default Constructor"); - til::some s; - - Log::Comment(L"Valid Initializer List Constructor"); - til::some t{ 1 }; - til::some u{ 1, 2 }; - - Log::Comment(L"Invalid Initializer List Constructor"); - auto f = []() { - til::some v{ 1, 2, 3 }; - }; - - VERIFY_THROWS(f(), std::invalid_argument); - } - - TEST_METHOD(Equality) - { - til::some a{ 1, 2 }; - til::some b{ 1, 2 }; - VERIFY_IS_TRUE(a == b); - - til::some c{ 3, 2 }; - VERIFY_IS_FALSE(a == c); - - til::some d{ 2, 3 }; - VERIFY_IS_FALSE(a == d); - - til::some e{ 1 }; - VERIFY_IS_FALSE(a == e); - } - - TEST_METHOD(Inequality) - { - til::some a{ 1, 2 }; - til::some b{ 1, 2 }; - VERIFY_IS_FALSE(a != b); - - til::some c{ 3, 2 }; - VERIFY_IS_TRUE(a != c); - - til::some d{ 2, 3 }; - VERIFY_IS_TRUE(a != d); - - til::some e{ 1 }; - VERIFY_IS_TRUE(a != e); - } - - TEST_METHOD(Fill) - { - til::some s; - - const auto val = 12; - s.fill(val); - - VERIFY_ARE_EQUAL(s.max_size(), s.size()); - - for (const auto& i : s) - { - VERIFY_ARE_EQUAL(val, i); - } - } - - TEST_METHOD(Swap) - { - til::some a; - til::some b; - - const auto aVal = 900; - a.fill(900); - - const auto bVal = 45; - b.push_back(45); - - const auto aSize = a.size(); - const auto bSize = b.size(); - - a.swap(b); - - VERIFY_ARE_EQUAL(aSize, b.size()); - VERIFY_ARE_EQUAL(bSize, a.size()); - - VERIFY_ARE_EQUAL(bVal, a[0]); - - for (const auto& i : b) - { - VERIFY_ARE_EQUAL(aVal, i); - } - } - - TEST_METHOD(Size) - { - til::some c; - - VERIFY_ARE_EQUAL(0u, c.size()); - - c.push_back(3); - VERIFY_ARE_EQUAL(1u, c.size()); - - c.push_back(12); - VERIFY_ARE_EQUAL(2u, c.size()); - - c.pop_back(); - VERIFY_ARE_EQUAL(1u, c.size()); - - c.pop_back(); - VERIFY_ARE_EQUAL(0u, c.size()); - } - - TEST_METHOD(MaxSize) - { - til::some c; - - VERIFY_ARE_EQUAL(2u, c.max_size()); - - c.push_back(3); - VERIFY_ARE_EQUAL(2u, c.max_size()); - - c.push_back(12); - VERIFY_ARE_EQUAL(2u, c.size()); - - c.pop_back(); - VERIFY_ARE_EQUAL(2u, c.max_size()); - - c.pop_back(); - VERIFY_ARE_EQUAL(2u, c.max_size()); - } - - TEST_METHOD(PushBack) - { - til::some s; - s.push_back(12); - VERIFY_THROWS(s.push_back(12), std::out_of_range); - } - - TEST_METHOD(PopBack) - { - til::some s; - VERIFY_THROWS(s.pop_back(), std::out_of_range); - - s.push_back(12); - VERIFY_THROWS(s.push_back(12), std::out_of_range); - } - - TEST_METHOD(Empty) - { - til::some s; - VERIFY_IS_TRUE(s.empty()); - s.push_back(12); - VERIFY_IS_FALSE(s.empty()); - s.pop_back(); - VERIFY_IS_TRUE(s.empty()); - } - - TEST_METHOD(Clear) - { - til::some s; - VERIFY_IS_TRUE(s.empty()); - s.push_back(12); - VERIFY_IS_FALSE(s.empty()); - VERIFY_ARE_EQUAL(1u, s.size()); - s.clear(); - VERIFY_IS_TRUE(s.empty()); - VERIFY_ARE_EQUAL(0u, s.size()); - } - - TEST_METHOD(ClearFreesMembers) - { - til::some, 2> s; - - auto a = std::make_shared(4); - auto weakA = std::weak_ptr(a); - - auto b = std::make_shared(6); - auto weakB = std::weak_ptr(b); - - s.push_back(std::move(a)); - s.push_back(std::move(b)); - - VERIFY_IS_FALSE(weakA.expired()); - VERIFY_IS_FALSE(weakB.expired()); - - s.clear(); - - VERIFY_IS_TRUE(weakA.expired()); - VERIFY_IS_TRUE(weakB.expired()); - } - - TEST_METHOD(Data) - { - til::some s; - const auto one = 1; - const auto two = 2; - s.push_back(one); - s.push_back(two); - - auto data = s.data(); - - VERIFY_ARE_EQUAL(one, *data); - VERIFY_ARE_EQUAL(two, *(data + 1)); - } - - TEST_METHOD(FrontBack) - { - til::some s; - const auto one = 1; - const auto two = 2; - s.push_back(one); - s.push_back(two); - - VERIFY_ARE_EQUAL(one, s.front()); - VERIFY_ARE_EQUAL(two, s.back()); - } - - TEST_METHOD(Indexing) - { - const auto one = 14; - const auto two = 28; - - til::some s; - VERIFY_THROWS(s.at(0), std::out_of_range); - VERIFY_THROWS(s.at(1), std::out_of_range); - auto a = s[0]; - a = s[1]; - - s.push_back(one); - VERIFY_ARE_EQUAL(one, s.at(0)); - VERIFY_ARE_EQUAL(one, s[0]); - VERIFY_THROWS(s.at(1), std::out_of_range); - a = s[1]; - - s.push_back(two); - VERIFY_ARE_EQUAL(one, s.at(0)); - VERIFY_ARE_EQUAL(one, s[0]); - VERIFY_ARE_EQUAL(two, s.at(1)); - VERIFY_ARE_EQUAL(two, s[1]); - - s.pop_back(); - VERIFY_ARE_EQUAL(one, s.at(0)); - VERIFY_ARE_EQUAL(one, s[0]); - VERIFY_THROWS(s.at(1), std::out_of_range); - a = s[1]; - - s.pop_back(); - VERIFY_THROWS(s.at(0), std::out_of_range); - VERIFY_THROWS(s.at(1), std::out_of_range); - a = s[0]; - a = s[1]; - } - - TEST_METHOD(ForwardIter) - { - const int vals[] = { 17, 99 }; - const int valLength = ARRAYSIZE(vals); - - til::some s; - VERIFY_ARE_EQUAL(s.begin(), s.end()); - VERIFY_ARE_EQUAL(s.cbegin(), s.cend()); - VERIFY_ARE_EQUAL(s.begin(), s.cbegin()); - VERIFY_ARE_EQUAL(s.end(), s.cend()); - - s.push_back(vals[0]); - s.push_back(vals[1]); - - VERIFY_ARE_EQUAL(s.begin() + valLength, s.end()); - VERIFY_ARE_EQUAL(s.cbegin() + valLength, s.cend()); - - auto count = 0; - for (const auto& i : s) - { - VERIFY_ARE_EQUAL(vals[count], i); - ++count; - } - VERIFY_ARE_EQUAL(valLength, count); - - count = 0; - for (auto i = s.cbegin(); i < s.cend(); ++i) - { - VERIFY_ARE_EQUAL(vals[count], *i); - ++count; - } - VERIFY_ARE_EQUAL(valLength, count); - - count = 0; - for (auto i = s.begin(); i < s.end(); ++i) - { - VERIFY_ARE_EQUAL(vals[count], *i); - ++count; - } - VERIFY_ARE_EQUAL(valLength, count); - } - - TEST_METHOD(ReverseIter) - { - const int vals[] = { 17, 99 }; - const int valLength = ARRAYSIZE(vals); - - til::some s; - VERIFY_ARE_EQUAL(s.rbegin(), s.rend()); - VERIFY_ARE_EQUAL(s.crbegin(), s.crend()); - VERIFY_ARE_EQUAL(s.rbegin(), s.crbegin()); - VERIFY_ARE_EQUAL(s.rend(), s.crend()); - - s.push_back(vals[0]); - s.push_back(vals[1]); - - VERIFY_ARE_EQUAL(s.rbegin() + valLength, s.rend()); - VERIFY_ARE_EQUAL(s.crbegin() + valLength, s.crend()); - - auto count = 0; - for (auto i = s.crbegin(); i < s.crend(); ++i) - { - VERIFY_ARE_EQUAL(vals[valLength - count - 1], *i); - ++count; - } - VERIFY_ARE_EQUAL(valLength, count); - - count = 0; - for (auto i = s.rbegin(); i < s.rend(); ++i) - { - VERIFY_ARE_EQUAL(vals[valLength - count - 1], *i); - ++count; - } - VERIFY_ARE_EQUAL(valLength, count); - } -}; diff --git a/src/til/ut_til/UnicodeTests.cpp b/src/til/ut_til/UnicodeTests.cpp index 24d62beeaf6..e81d5b9a7a9 100644 --- a/src/til/ut_til/UnicodeTests.cpp +++ b/src/til/ut_til/UnicodeTests.cpp @@ -51,10 +51,10 @@ class UnicodeTests struct Test { std::wstring_view input; - til::some expected; + std::vector expected; }; - static constexpr std::array tests{ + const std::array tests{ Test{ L"", {} }, Test{ L"a", { L"a" } }, Test{ L"abc", { L"a", L"b", L"c" } }, diff --git a/src/til/ut_til/sources b/src/til/ut_til/sources index ffe976d7cab..2e39e378a84 100644 --- a/src/til/ut_til/sources +++ b/src/til/ut_til/sources @@ -30,7 +30,6 @@ SOURCES = \ RunLengthEncodingTests.cpp \ SizeTests.cpp \ SmallVectorTests.cpp \ - SomeTests.cpp \ StaticMapTests.cpp \ string.cpp \ u8u16convertTests.cpp \ diff --git a/src/til/ut_til/til.unit.tests.vcxproj b/src/til/ut_til/til.unit.tests.vcxproj index 04694e68a16..d6b183d1282 100644 --- a/src/til/ut_til/til.unit.tests.vcxproj +++ b/src/til/ut_til/til.unit.tests.vcxproj @@ -32,7 +32,6 @@ - @@ -64,7 +63,6 @@ - @@ -90,4 +88,4 @@ - \ No newline at end of file + diff --git a/src/til/ut_til/til.unit.tests.vcxproj.filters b/src/til/ut_til/til.unit.tests.vcxproj.filters index c25b0113980..15928ddb533 100644 --- a/src/til/ut_til/til.unit.tests.vcxproj.filters +++ b/src/til/ut_til/til.unit.tests.vcxproj.filters @@ -20,7 +20,6 @@ - @@ -96,9 +95,6 @@ inc - - inc - inc @@ -135,4 +131,4 @@ {7cf29ba4-d33d-4c3b-82e3-ab73e5a79685} - \ No newline at end of file + diff --git a/src/types/inc/IInputEvent.hpp b/src/types/inc/IInputEvent.hpp index 4641c17332d..655acd8f9b7 100644 --- a/src/types/inc/IInputEvent.hpp +++ b/src/types/inc/IInputEvent.hpp @@ -3,8 +3,6 @@ #pragma once -#include - #define ALT_PRESSED (RIGHT_ALT_PRESSED | LEFT_ALT_PRESSED) #define CTRL_PRESSED (RIGHT_CTRL_PRESSED | LEFT_CTRL_PRESSED) #define MOD_PRESSED (SHIFT_PRESSED | ALT_PRESSED | CTRL_PRESSED) diff --git a/src/types/inc/viewport.hpp b/src/types/inc/viewport.hpp index d762f64348f..b8b2029504e 100644 --- a/src/types/inc/viewport.hpp +++ b/src/types/inc/viewport.hpp @@ -17,7 +17,7 @@ namespace Microsoft::Console::Types { class Viewport; - using SomeViewports = til::some; + using SomeViewports = til::small_vector; class Viewport final {