sfizz/tests/HelpersT.cpp

69 lines
1.6 KiB
C++
Raw Normal View History

2020-01-25 10:04:31 +01:00
// SPDX-License-Identifier: BSD-2-Clause
2020-01-25 13:13:07 +01:00
// This code is part of the sfizz library and is licensed under a BSD 2-clause
// license. You should have receive a LICENSE.md file along with the code.
// If not, contact the sfizz maintainers at https://github.com/sfztools/sfizz
2019-08-30 00:49:58 +02:00
2021-03-25 18:35:20 +01:00
#include "sfizz/utility/StringViewHelpers.h"
2019-08-25 14:01:03 +02:00
#include "catch2/catch.hpp"
2019-09-20 23:32:22 +02:00
#include "absl/strings/string_view.h"
2019-07-29 02:13:03 +02:00
using namespace Catch::literals;
TEST_CASE("[Helpers] trimInPlace")
{
SECTION("Trim nothing")
{
2019-09-20 23:32:22 +02:00
absl::string_view input { "view" };
2019-07-29 02:13:03 +02:00
trimInPlace(input);
2019-09-20 23:32:22 +02:00
REQUIRE(input == "view");
2019-07-29 02:13:03 +02:00
}
SECTION("Trim spaces")
{
2019-09-20 23:32:22 +02:00
absl::string_view input { " view " };
2019-07-29 02:13:03 +02:00
trimInPlace(input);
2019-09-20 23:32:22 +02:00
REQUIRE(input == "view");
2019-07-29 02:13:03 +02:00
}
SECTION("Trim other chars")
{
2019-09-20 23:32:22 +02:00
absl::string_view input { " \tview \t" };
2019-07-29 02:13:03 +02:00
trimInPlace(input);
2019-09-20 23:32:22 +02:00
REQUIRE(input == "view");
2019-07-29 02:13:03 +02:00
}
SECTION("Empty view")
{
2019-09-20 23:32:22 +02:00
absl::string_view input { " " };
2019-07-29 02:13:03 +02:00
trimInPlace(input);
2019-08-25 14:01:03 +02:00
REQUIRE(input.empty());
2019-07-29 02:13:03 +02:00
}
}
TEST_CASE("[Helpers] trim")
{
SECTION("Trim nothing")
{
2019-09-20 23:32:22 +02:00
absl::string_view input { "view" };
REQUIRE(trim(input) == "view");
2019-07-29 02:13:03 +02:00
}
SECTION("Trim spaces")
{
2019-09-20 23:32:22 +02:00
absl::string_view input { " view " };
REQUIRE(trim(input) == "view");
2019-07-29 02:13:03 +02:00
}
SECTION("Trim other chars")
{
2019-09-20 23:32:22 +02:00
absl::string_view input { " \tview \t" };
REQUIRE(trim(input) == "view");
2019-07-29 02:13:03 +02:00
}
SECTION("Empty view")
{
2019-09-20 23:32:22 +02:00
absl::string_view input { " " };
2019-08-25 14:01:03 +02:00
REQUIRE(trim(input).empty());
2019-07-29 02:13:03 +02:00
}
2020-01-25 10:04:31 +01:00
}