sfizz/tests/HelpersT.cpp

145 lines
3.6 KiB
C++
Raw Permalink 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"
#include "sfizz/utility/Base64.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
}
TEST_CASE("[Parsing] Base64")
{
{
auto result = sfz::decodeBase64("");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "" );
}
{
auto result = sfz::decodeBase64("Zg==");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "f" );
}
{
auto result = sfz::decodeBase64("Zg");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "f" );
}
{
auto result = sfz::decodeBase64("Zm8=");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "fo" );
}
{
auto result = sfz::decodeBase64("Zm8");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "fo" );
}
{
auto result = sfz::decodeBase64("Zm9v");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "foo" );
}
{
auto result = sfz::decodeBase64("Zm9vYg==");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "foob" );
}
{
auto result = sfz::decodeBase64("Zm9vYg");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "foob" );
}
{
auto result = sfz::decodeBase64("Zm9vYmE=");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "fooba" );
}
{
auto result = sfz::decodeBase64("Zm9vYmE");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "fooba" );
}
{
auto result = sfz::decodeBase64("Zm9vYmFy");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "foobar" );
}
{
auto result = sfz::decodeBase64("Zm9v\r\n Ym \tFy");
absl::string_view view { result.data(), result.size() };
REQUIRE( view == "foobar" );
}
}