-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathunit-tests.cpp
More file actions
94 lines (79 loc) · 2.51 KB
/
unit-tests.cpp
File metadata and controls
94 lines (79 loc) · 2.51 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
#include <gtest/gtest.h>
#include <string>
#include "hide-secret.hpp"
TEST(HideSecretTest, BasicTest)
{
std::string text{"My silly password is '12345678'"};
ASSERT_NO_THROW(hide_secret(text.data(), "12345678"));
EXPECT_EQ(text, "My silly password is 'xxxxxxxx'");
}
TEST(HideSecretTest, SecretNotFound)
{
std::string text{"My silly password is '12345678'"};
ASSERT_NO_THROW(hide_secret(text.data(), "12345679"));
EXPECT_EQ(text, "My silly password is '12345678'");
}
TEST(HideSecretTest, PossibleOutOfBounds)
{
std::string text{"My silly password is 12345678"};
ASSERT_NO_THROW(hide_secret(text.data(), "123456789"));
EXPECT_EQ(text, "My silly password is 12345678");
}
TEST(HideSecretTest, EmptyText)
{
std::string text{};
ASSERT_NO_THROW(hide_secret(text.data(), "123456789"));
EXPECT_EQ(text, "");
}
TEST(HideSecretTest, EmptySecret)
{
std::string text{"My silly password is 12345678"};
ASSERT_NO_THROW(hide_secret(text.data(), ""));
EXPECT_EQ(text, "My silly password is 12345678");
}
TEST(HideSecretTest, NullptrText)
{
ASSERT_NO_THROW(hide_secret(nullptr, "12345678"));
}
TEST(HideSecretTest, NullptrSecret)
{
std::string text{"My silly password is 12345678"};
ASSERT_NO_THROW(hide_secret(text.data(), nullptr));
EXPECT_EQ(text, "My silly password is 12345678");
}
TEST(HideSecretTest, TextMatchesSecret)
{
std::string text{"12345678"};
ASSERT_NO_THROW(hide_secret(text.data(), "12345678"));
EXPECT_EQ(text, "xxxxxxxx");
}
TEST(HideSecretTest, TextStartsWithSecret)
{
std::string text{"12345678 is my password"};
ASSERT_NO_THROW(hide_secret(text.data(), "12345678"));
EXPECT_EQ(text, "xxxxxxxx is my password");
}
TEST(HideSecretTest, TextEndsWithSecret)
{
std::string text{"12345678 is my password"};
ASSERT_NO_THROW(hide_secret(text.data(), "password"));
EXPECT_EQ(text, "12345678 is my xxxxxxxx");
}
TEST(HideSecretTest, SecretInTheMiddleOfText)
{
std::string text{"12345678 is my password"};
ASSERT_NO_THROW(hide_secret(text.data(), "is my "));
EXPECT_EQ(text, "12345678 xxxxxxpassword");
}
TEST(HideSecret, SeveralMatches)
{
std::string text{"123 is my password, yes, 123, and nothing else"};
ASSERT_NO_THROW(hide_secret(text.data(), "123"));
EXPECT_EQ(text, "xxx is my password, yes, xxx, and nothing else");
}
TEST(HideSecret, OverlappingMatches)
{
std::string text{"My password is not aaaa"};
ASSERT_NO_THROW(hide_secret(text.data(), "aaa"));
EXPECT_EQ(text, "My password is not xxxx");
}