From ac47be51b79f4c3e49656870e135453eefe759ea Mon Sep 17 00:00:00 2001 From: Steven Le Rouzic Date: Thu, 7 Nov 2024 23:38:52 +0100 Subject: Some more work on asl::string_view --- asl/tests/format_tests.cpp | 4 ++-- asl/tests/span_tests.cpp | 18 +++++++++--------- asl/tests/string_view_tests.cpp | 24 ++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 11 deletions(-) (limited to 'asl/tests') diff --git a/asl/tests/format_tests.cpp b/asl/tests/format_tests.cpp index 81395c2..bfde454 100644 --- a/asl/tests/format_tests.cpp +++ b/asl/tests/format_tests.cpp @@ -12,11 +12,11 @@ static_assert(asl::formattable); class StringSink : public asl::writer { - int64_t m_current_len{}; + isize_t m_current_len{}; char* m_data{}; public: - void write(const char* str, int64_t len) override + void write(const char* str, isize_t len) override { m_data = (char*)realloc(m_data, (size_t)(m_current_len + len + 1)); memcpy(m_data + m_current_len, str, (size_t)len); diff --git a/asl/tests/span_tests.cpp b/asl/tests/span_tests.cpp index aca0fb3..3baaf5c 100644 --- a/asl/tests/span_tests.cpp +++ b/asl/tests/span_tests.cpp @@ -94,14 +94,14 @@ ASL_TEST(conversion) ASL_TEST_EXPECT(span4[2] == 3); } -template +template [[maybe_unused]] static auto try_static_subspan(int) -> decltype(asl::declval().template subspan()); -template +template [[maybe_unused]] static auto try_static_subspan(...) -> asl::empty; -template +template concept invalid_subspan = asl::same_as(0)), asl::empty>; static_assert(asl::same_as, @@ -216,14 +216,14 @@ ASL_TEST(subspan_dynamic) ASL_TEST_EXPECT(s4[1] == 3); } -template +template [[maybe_unused]] static auto try_static_first(int) -> decltype(asl::declval().template first()); -template +template [[maybe_unused]] static auto try_static_first(...) -> asl::empty; -template +template concept invalid_first = asl::same_as(0)), asl::empty>; static_assert(asl::same_as, @@ -320,14 +320,14 @@ ASL_TEST(first_dynamic) ASL_TEST_EXPECT(s3[3] == 4); } -template +template [[maybe_unused]] static auto try_static_last(int) -> decltype(asl::declval().template last()); -template +template [[maybe_unused]] static auto try_static_last(...) -> asl::empty; -template +template concept invalid_last = asl::same_as(0)), asl::empty>; static_assert(asl::same_as, diff --git a/asl/tests/string_view_tests.cpp b/asl/tests/string_view_tests.cpp index f3cc752..dafb91c 100644 --- a/asl/tests/string_view_tests.cpp +++ b/asl/tests/string_view_tests.cpp @@ -1,3 +1,27 @@ #include "asl/string_view.hpp" #include "asl/testing/testing.hpp" +// @Todo Don't use stdlib, remake memcmp +#include + +static_assert(asl::trivially_destructible); +static_assert(asl::trivially_copyable); + +ASL_TEST(default) +{ + asl::string_view s1; + ASL_TEST_EXPECT(s1.is_empty()); + + asl::string_view s2 = nullptr; + ASL_TEST_EXPECT(s2.is_empty()); +} + +ASL_TEST(from_literal) +{ + asl::string_view s1 = "Hello"_sv; + ASL_TEST_ASSERT(s1.size() == 5); + ASL_TEST_EXPECT(memcmp(s1.data(), "Hello", 5) == 0); + + asl::string_view s2 = ""_sv; + ASL_TEST_EXPECT(s2.is_empty()); +} -- cgit