mirror of
https://github.com/wpilibsuite/allwpilib
synced 2026-06-20 00:51:42 +00:00
[wpiutil] Add remove_prefix() and remove_suffix() (#6118)
This commit is contained in:
35
wpiutil/src/test/native/cpp/StringExtrasTest.cpp
Normal file
35
wpiutil/src/test/native/cpp/StringExtrasTest.cpp
Normal file
@@ -0,0 +1,35 @@
|
||||
// Copyright (c) FIRST and other WPILib contributors.
|
||||
// Open Source Software; you can modify and/or share it under the terms of
|
||||
// the WPILib BSD license file in the root directory of this project.
|
||||
|
||||
#include <gtest/gtest.h>
|
||||
|
||||
#include "wpi/StringExtras.h"
|
||||
|
||||
TEST(StringExtrasTest, RemovePrefix) {
|
||||
std::string_view original = "wpilib";
|
||||
auto modified = wpi::remove_prefix(original, "wpi");
|
||||
EXPECT_EQ(original, "wpilib");
|
||||
EXPECT_EQ(modified, std::optional{"lib"});
|
||||
}
|
||||
|
||||
TEST(StringExtrasTest, RemoveSuffix) {
|
||||
std::string_view original = "wpilib";
|
||||
auto modified = wpi::remove_suffix(original, "lib");
|
||||
EXPECT_EQ(original, "wpilib");
|
||||
EXPECT_EQ(modified, std::optional{"wpi"});
|
||||
}
|
||||
|
||||
TEST(StringExtrasTest, RemovePrefixNoMatch) {
|
||||
std::string_view original = "wpilib";
|
||||
auto modified = wpi::remove_prefix(original, "foo");
|
||||
EXPECT_EQ(original, "wpilib");
|
||||
EXPECT_EQ(modified, std::nullopt);
|
||||
}
|
||||
|
||||
TEST(StringExtrasTest, RemoveSuffixNoMatch) {
|
||||
std::string_view original = "wpilib";
|
||||
auto modified = wpi::remove_suffix(original, "foo");
|
||||
EXPECT_EQ(original, "wpilib");
|
||||
EXPECT_EQ(modified, std::nullopt);
|
||||
}
|
||||
Reference in New Issue
Block a user