mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Fix -Wsign-compare errors
This commit is contained in:
parent
2ace512a70
commit
681d7f7e57
16 changed files with 70 additions and 69 deletions
|
@ -11,6 +11,7 @@ add_project_arguments(
|
|||
'-Werror=switch',
|
||||
'-Werror=switch-enum',
|
||||
'-Werror=unused-result',
|
||||
'-Werror=sign-compare',
|
||||
'-Wignored-qualifiers',
|
||||
'-Wimplicit-fallthrough',
|
||||
'-Wno-deprecated-declarations',
|
||||
|
|
|
@ -33,7 +33,7 @@ namespace nix {
|
|||
ASSERT_EQ(PrintToString(e.info().msg),
|
||||
PrintToString(HintFmt("puppy")));
|
||||
auto trace = e.info().traces.rbegin();
|
||||
ASSERT_EQ(e.info().traces.size(), 2);
|
||||
ASSERT_EQ(e.info().traces.size(), 2u);
|
||||
ASSERT_EQ(PrintToString(trace->hint),
|
||||
PrintToString(HintFmt("doggy")));
|
||||
trace++;
|
||||
|
@ -54,8 +54,8 @@ namespace nix {
|
|||
} catch (Error & e2) {
|
||||
e.addTrace(state.positions[noPos], "beans2");
|
||||
//e2.addTrace(state.positions[noPos], "Something", "");
|
||||
ASSERT_TRUE(e.info().traces.size() == 2);
|
||||
ASSERT_TRUE(e2.info().traces.size() == 0);
|
||||
ASSERT_TRUE(e.info().traces.size() == 2u);
|
||||
ASSERT_TRUE(e2.info().traces.size() == 0u);
|
||||
ASSERT_FALSE(&e.info() == &e2.info());
|
||||
}
|
||||
}
|
||||
|
@ -71,7 +71,7 @@ namespace nix {
|
|||
} catch (BaseError & e) { \
|
||||
ASSERT_EQ(PrintToString(e.info().msg), \
|
||||
PrintToString(message)); \
|
||||
ASSERT_EQ(e.info().traces.size(), 1) << "while testing " args << std::endl << e.what(); \
|
||||
ASSERT_EQ(e.info().traces.size(), 1u) << "while testing " args << std::endl << e.what(); \
|
||||
auto trace = e.info().traces.rbegin(); \
|
||||
ASSERT_EQ(PrintToString(trace->hint), \
|
||||
PrintToString(HintFmt("while calling the '%s' builtin", name))); \
|
||||
|
@ -90,7 +90,7 @@ namespace nix {
|
|||
} catch (BaseError & e) { \
|
||||
ASSERT_EQ(PrintToString(e.info().msg), \
|
||||
PrintToString(message)); \
|
||||
ASSERT_EQ(e.info().traces.size(), 2) << "while testing " args << std::endl << e.what(); \
|
||||
ASSERT_EQ(e.info().traces.size(), 2u) << "while testing " args << std::endl << e.what(); \
|
||||
auto trace = e.info().traces.rbegin(); \
|
||||
ASSERT_EQ(PrintToString(trace->hint), \
|
||||
PrintToString(context)); \
|
||||
|
@ -112,7 +112,7 @@ namespace nix {
|
|||
} catch (BaseError & e) { \
|
||||
ASSERT_EQ(PrintToString(e.info().msg), \
|
||||
PrintToString(message)); \
|
||||
ASSERT_EQ(e.info().traces.size(), 3) << "while testing " args << std::endl << e.what(); \
|
||||
ASSERT_EQ(e.info().traces.size(), 3u) << "while testing " args << std::endl << e.what(); \
|
||||
auto trace = e.info().traces.rbegin(); \
|
||||
ASSERT_EQ(PrintToString(trace->hint), \
|
||||
PrintToString(context1)); \
|
||||
|
@ -137,7 +137,7 @@ namespace nix {
|
|||
} catch (BaseError & e) { \
|
||||
ASSERT_EQ(PrintToString(e.info().msg), \
|
||||
PrintToString(message)); \
|
||||
ASSERT_EQ(e.info().traces.size(), 4) << "while testing " args << std::endl << e.what(); \
|
||||
ASSERT_EQ(e.info().traces.size(), 4u) << "while testing " args << std::endl << e.what(); \
|
||||
auto trace = e.info().traces.rbegin(); \
|
||||
ASSERT_EQ(PrintToString(trace->hint), \
|
||||
PrintToString(context1)); \
|
||||
|
|
|
@ -222,7 +222,7 @@ TEST_F(nix_api_expr_test, nix_expr_realise_context)
|
|||
names.push_back(name);
|
||||
}
|
||||
std::sort(names.begin(), names.end());
|
||||
ASSERT_EQ(3, names.size());
|
||||
ASSERT_EQ(3u, names.size());
|
||||
EXPECT_THAT(names[0], testing::StrEq("just-a-file"));
|
||||
EXPECT_THAT(names[1], testing::StrEq("letsbuild"));
|
||||
EXPECT_THAT(names[2], testing::StrEq("not-actually-built-yet.drv"));
|
||||
|
|
|
@ -134,12 +134,12 @@ TEST_F(nix_api_expr_test, nix_build_and_init_list_invalid)
|
|||
{
|
||||
ASSERT_EQ(nullptr, nix_get_list_byidx(ctx, nullptr, state, 0));
|
||||
assert_ctx_err();
|
||||
ASSERT_EQ(0, nix_get_list_size(ctx, nullptr));
|
||||
ASSERT_EQ(0u, nix_get_list_size(ctx, nullptr));
|
||||
assert_ctx_err();
|
||||
|
||||
ASSERT_EQ(nullptr, nix_get_list_byidx(ctx, value, state, 0));
|
||||
assert_ctx_err();
|
||||
ASSERT_EQ(0, nix_get_list_size(ctx, value));
|
||||
ASSERT_EQ(0u, nix_get_list_size(ctx, value));
|
||||
assert_ctx_err();
|
||||
}
|
||||
|
||||
|
@ -163,7 +163,7 @@ TEST_F(nix_api_expr_test, nix_build_and_init_list)
|
|||
ASSERT_EQ(42, nix_get_int(ctx, nix_get_list_byidx(ctx, value, state, 0)));
|
||||
ASSERT_EQ(43, nix_get_int(ctx, nix_get_list_byidx(ctx, value, state, 1)));
|
||||
ASSERT_EQ(nullptr, nix_get_list_byidx(ctx, value, state, 2));
|
||||
ASSERT_EQ(10, nix_get_list_size(ctx, value));
|
||||
ASSERT_EQ(10u, nix_get_list_size(ctx, value));
|
||||
|
||||
ASSERT_STREQ("a list", nix_get_typename(ctx, value));
|
||||
ASSERT_EQ(NIX_TYPE_LIST, nix_get_type(ctx, value));
|
||||
|
@ -180,7 +180,7 @@ TEST_F(nix_api_expr_test, nix_build_and_init_attr_invalid)
|
|||
assert_ctx_err();
|
||||
ASSERT_EQ(nullptr, nix_get_attr_name_byidx(ctx, nullptr, state, 0));
|
||||
assert_ctx_err();
|
||||
ASSERT_EQ(0, nix_get_attrs_size(ctx, nullptr));
|
||||
ASSERT_EQ(0u, nix_get_attrs_size(ctx, nullptr));
|
||||
assert_ctx_err();
|
||||
ASSERT_EQ(false, nix_has_attr_byname(ctx, nullptr, state, "no-value"));
|
||||
assert_ctx_err();
|
||||
|
@ -191,7 +191,7 @@ TEST_F(nix_api_expr_test, nix_build_and_init_attr_invalid)
|
|||
assert_ctx_err();
|
||||
ASSERT_EQ(nullptr, nix_get_attr_name_byidx(ctx, value, state, 0));
|
||||
assert_ctx_err();
|
||||
ASSERT_EQ(0, nix_get_attrs_size(ctx, value));
|
||||
ASSERT_EQ(0u, nix_get_attrs_size(ctx, value));
|
||||
assert_ctx_err();
|
||||
ASSERT_EQ(false, nix_has_attr_byname(ctx, value, state, "no-value"));
|
||||
assert_ctx_err();
|
||||
|
@ -215,7 +215,7 @@ TEST_F(nix_api_expr_test, nix_build_and_init_attr)
|
|||
nix_make_attrs(ctx, value, builder);
|
||||
nix_bindings_builder_free(builder);
|
||||
|
||||
ASSERT_EQ(2, nix_get_attrs_size(ctx, value));
|
||||
ASSERT_EQ(2u, nix_get_attrs_size(ctx, value));
|
||||
|
||||
nix_value * out_value = nix_get_attr_byname(ctx, value, state, "a");
|
||||
ASSERT_EQ(42, nix_get_int(ctx, out_value));
|
||||
|
@ -374,7 +374,7 @@ TEST_F(nix_api_expr_test, nix_value_init_apply_lazy_arg)
|
|||
|
||||
auto n = nix_get_attrs_size(ctx, r);
|
||||
assert_ctx_ok();
|
||||
ASSERT_EQ(1, n);
|
||||
ASSERT_EQ(1u, n);
|
||||
|
||||
// nix_get_attr_byname isn't lazy (it could have been) so it will throw the exception
|
||||
nix_value * foo = nix_get_attr_byname(ctx, r, state, "foo");
|
||||
|
|
|
@ -204,7 +204,7 @@ namespace nix {
|
|||
auto v = eval("builtins.listToAttrs []");
|
||||
ASSERT_THAT(v, IsAttrsOfSize(0));
|
||||
ASSERT_EQ(v.type(), nAttrs);
|
||||
ASSERT_EQ(v.attrs()->size(), 0);
|
||||
ASSERT_EQ(v.attrs()->size(), 0u);
|
||||
}
|
||||
|
||||
TEST_F(PrimOpTest, listToAttrsNotFieldName) {
|
||||
|
@ -383,7 +383,7 @@ namespace nix {
|
|||
TEST_F(PrimOpTest, genList) {
|
||||
auto v = eval("builtins.genList (x: x + 1) 3");
|
||||
ASSERT_EQ(v.type(), nList);
|
||||
ASSERT_EQ(v.listSize(), 3);
|
||||
ASSERT_EQ(v.listSize(), 3u);
|
||||
for (const auto [i, elem] : enumerate(v.listItems())) {
|
||||
ASSERT_THAT(*elem, IsThunk());
|
||||
state.forceValue(*elem, noPos);
|
||||
|
@ -394,7 +394,7 @@ namespace nix {
|
|||
TEST_F(PrimOpTest, sortLessThan) {
|
||||
auto v = eval("builtins.sort builtins.lessThan [ 483 249 526 147 42 77 ]");
|
||||
ASSERT_EQ(v.type(), nList);
|
||||
ASSERT_EQ(v.listSize(), 6);
|
||||
ASSERT_EQ(v.listSize(), 6u);
|
||||
|
||||
const std::vector<int> numbers = { 42, 77, 147, 249, 483, 526 };
|
||||
for (const auto [n, elem] : enumerate(v.listItems()))
|
||||
|
@ -414,7 +414,7 @@ namespace nix {
|
|||
auto wrong = v.attrs()->get(createSymbol("wrong"));
|
||||
ASSERT_NE(wrong, nullptr);
|
||||
ASSERT_EQ(wrong->value->type(), nList);
|
||||
ASSERT_EQ(wrong->value->listSize(), 3);
|
||||
ASSERT_EQ(wrong->value->listSize(), 3u);
|
||||
ASSERT_THAT(*wrong->value, IsListOfSize(3));
|
||||
ASSERT_THAT(*wrong->value->listElems()[0], IsIntEq(1));
|
||||
ASSERT_THAT(*wrong->value->listElems()[1], IsIntEq(9));
|
||||
|
@ -424,7 +424,7 @@ namespace nix {
|
|||
TEST_F(PrimOpTest, concatMap) {
|
||||
auto v = eval("builtins.concatMap (x: x ++ [0]) [ [1 2] [3 4] ]");
|
||||
ASSERT_EQ(v.type(), nList);
|
||||
ASSERT_EQ(v.listSize(), 6);
|
||||
ASSERT_EQ(v.listSize(), 6u);
|
||||
|
||||
const std::vector<int> numbers = { 1, 2, 0, 3, 4, 0 };
|
||||
for (const auto [n, elem] : enumerate(v.listItems()))
|
||||
|
|
|
@ -90,11 +90,11 @@ TEST_F(GitUtilsTest, sink_basic)
|
|||
auto result = repo->dereferenceSingletonDirectory(sink->flush());
|
||||
auto accessor = repo->getAccessor(result, false, getRepoName());
|
||||
auto entries = accessor->readDirectory(CanonPath::root);
|
||||
ASSERT_EQ(entries.size(), 5);
|
||||
ASSERT_EQ(entries.size(), 5u);
|
||||
ASSERT_EQ(accessor->readFile(CanonPath("hello")), "hello world");
|
||||
ASSERT_EQ(accessor->readFile(CanonPath("bye")), "thanks for all the fish");
|
||||
ASSERT_EQ(accessor->readLink(CanonPath("bye-link")), "bye");
|
||||
ASSERT_EQ(accessor->readDirectory(CanonPath("empty")).size(), 0);
|
||||
ASSERT_EQ(accessor->readDirectory(CanonPath("empty")).size(), 0u);
|
||||
ASSERT_EQ(accessor->readFile(CanonPath("links/foo")), "hello world");
|
||||
};
|
||||
|
||||
|
|
|
@ -173,7 +173,7 @@ TEST_F(DerivationAdvancedAttrsTest, Derivation_advancedAttributes_structuredAttr
|
|||
ASSERT_TRUE(checksPerOutput_ != nullptr);
|
||||
auto & checksPerOutput = *checksPerOutput_;
|
||||
|
||||
EXPECT_EQ(checksPerOutput.size(), 0);
|
||||
EXPECT_EQ(checksPerOutput.size(), 0u);
|
||||
}
|
||||
|
||||
EXPECT_EQ(options.getRequiredSystemFeatures(got), StringSet());
|
||||
|
|
|
@ -93,7 +93,7 @@ TEST_F(PathInfoTest, PathInfo_full_shortRefs) {
|
|||
ValidPathInfo it = makeFullKeyed(*store, true);
|
||||
// it.references = unkeyed.references;
|
||||
auto refs = it.shortRefs();
|
||||
ASSERT_EQ(refs.size(), 2);
|
||||
ASSERT_EQ(refs.size(), 2u);
|
||||
ASSERT_EQ(*refs.begin(), "g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-bar");
|
||||
ASSERT_EQ(*++refs.begin(), "n5wkd9frr45pa74if5gpz9j7mifg27fh-foo");
|
||||
}
|
||||
|
|
|
@ -702,7 +702,7 @@ TEST_F(WorkerProtoTest, handshake_features)
|
|||
clientThread.join();
|
||||
|
||||
EXPECT_EQ(clientResult, daemonResult);
|
||||
EXPECT_EQ(std::get<0>(clientResult), 123);
|
||||
EXPECT_EQ(std::get<0>(clientResult), 123u);
|
||||
EXPECT_EQ(std::get<1>(clientResult), std::set<WorkerProto::Feature>({"bar", "xyzzy"}));
|
||||
}
|
||||
|
||||
|
|
|
@ -9,7 +9,7 @@ namespace nix {
|
|||
|
||||
TEST(parseShebangContent, basic) {
|
||||
std::list<std::string> r = parseShebangContent("hi there");
|
||||
ASSERT_EQ(r.size(), 2);
|
||||
ASSERT_EQ(r.size(), 2u);
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(*i++, "hi");
|
||||
ASSERT_EQ(*i++, "there");
|
||||
|
@ -17,26 +17,26 @@ namespace nix {
|
|||
|
||||
TEST(parseShebangContent, empty) {
|
||||
std::list<std::string> r = parseShebangContent("");
|
||||
ASSERT_EQ(r.size(), 0);
|
||||
ASSERT_EQ(r.size(), 0u);
|
||||
}
|
||||
|
||||
TEST(parseShebangContent, doubleBacktick) {
|
||||
std::list<std::string> r = parseShebangContent("``\"ain't that nice\"``");
|
||||
ASSERT_EQ(r.size(), 1);
|
||||
ASSERT_EQ(r.size(), 1u);
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(*i++, "\"ain't that nice\"");
|
||||
}
|
||||
|
||||
TEST(parseShebangContent, doubleBacktickEmpty) {
|
||||
std::list<std::string> r = parseShebangContent("````");
|
||||
ASSERT_EQ(r.size(), 1);
|
||||
ASSERT_EQ(r.size(), 1u);
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(*i++, "");
|
||||
}
|
||||
|
||||
TEST(parseShebangContent, doubleBacktickMarkdownInlineCode) {
|
||||
std::list<std::string> r = parseShebangContent("``# I'm markdown section about `coolFunction` ``");
|
||||
ASSERT_EQ(r.size(), 1);
|
||||
ASSERT_EQ(r.size(), 1u);
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(*i++, "# I'm markdown section about `coolFunction`");
|
||||
}
|
||||
|
@ -44,49 +44,49 @@ namespace nix {
|
|||
TEST(parseShebangContent, doubleBacktickMarkdownCodeBlockNaive) {
|
||||
std::list<std::string> r = parseShebangContent("``Example 1\n```nix\na: a\n``` ``");
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(r.size(), 1);
|
||||
ASSERT_EQ(r.size(), 1u);
|
||||
ASSERT_EQ(*i++, "Example 1\n``nix\na: a\n``");
|
||||
}
|
||||
|
||||
TEST(parseShebangContent, doubleBacktickMarkdownCodeBlockCorrect) {
|
||||
std::list<std::string> r = parseShebangContent("``Example 1\n````nix\na: a\n```` ``");
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(r.size(), 1);
|
||||
ASSERT_EQ(r.size(), 1u);
|
||||
ASSERT_EQ(*i++, "Example 1\n```nix\na: a\n```");
|
||||
}
|
||||
|
||||
TEST(parseShebangContent, doubleBacktickMarkdownCodeBlock2) {
|
||||
std::list<std::string> r = parseShebangContent("``Example 1\n````nix\na: a\n````\nExample 2\n````nix\na: a\n```` ``");
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(r.size(), 1);
|
||||
ASSERT_EQ(r.size(), 1u);
|
||||
ASSERT_EQ(*i++, "Example 1\n```nix\na: a\n```\nExample 2\n```nix\na: a\n```");
|
||||
}
|
||||
|
||||
TEST(parseShebangContent, singleBacktickInDoubleBacktickQuotes) {
|
||||
std::list<std::string> r = parseShebangContent("``` ``");
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(r.size(), 1);
|
||||
ASSERT_EQ(r.size(), 1u);
|
||||
ASSERT_EQ(*i++, "`");
|
||||
}
|
||||
|
||||
TEST(parseShebangContent, singleBacktickAndSpaceInDoubleBacktickQuotes) {
|
||||
std::list<std::string> r = parseShebangContent("``` ``");
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(r.size(), 1);
|
||||
ASSERT_EQ(r.size(), 1u);
|
||||
ASSERT_EQ(*i++, "` ");
|
||||
}
|
||||
|
||||
TEST(parseShebangContent, doubleBacktickInDoubleBacktickQuotes) {
|
||||
std::list<std::string> r = parseShebangContent("````` ``");
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(r.size(), 1);
|
||||
ASSERT_EQ(r.size(), 1u);
|
||||
ASSERT_EQ(*i++, "``");
|
||||
}
|
||||
|
||||
TEST(parseShebangContent, increasingQuotes) {
|
||||
std::list<std::string> r = parseShebangContent("```` ``` `` ````` `` `````` ``");
|
||||
auto i = r.begin();
|
||||
ASSERT_EQ(r.size(), 4);
|
||||
ASSERT_EQ(r.size(), 4u);
|
||||
ASSERT_EQ(*i++, "");
|
||||
ASSERT_EQ(*i++, "`");
|
||||
ASSERT_EQ(*i++, "``");
|
||||
|
@ -146,7 +146,7 @@ RC_GTEST_PROP(
|
|||
auto escaped = escape(orig);
|
||||
// RC_LOG() << "escaped: <[[" << escaped << "]]>" << std::endl;
|
||||
auto ss = parseShebangContent(escaped);
|
||||
RC_ASSERT(ss.size() == 1);
|
||||
RC_ASSERT(ss.size() == 1u);
|
||||
RC_ASSERT(*ss.begin() == orig);
|
||||
}
|
||||
|
||||
|
@ -156,7 +156,7 @@ RC_GTEST_PROP(
|
|||
(const std::string & one, const std::string & two))
|
||||
{
|
||||
auto ss = parseShebangContent(escape(one) + " " + escape(two));
|
||||
RC_ASSERT(ss.size() == 2);
|
||||
RC_ASSERT(ss.size() == 2u);
|
||||
auto i = ss.begin();
|
||||
RC_ASSERT(*i++ == one);
|
||||
RC_ASSERT(*i++ == two);
|
||||
|
|
|
@ -5,12 +5,12 @@
|
|||
namespace nix {
|
||||
TEST(ChunkedVector, InitEmpty) {
|
||||
auto v = ChunkedVector<int, 2>(100);
|
||||
ASSERT_EQ(v.size(), 0);
|
||||
ASSERT_EQ(v.size(), 0u);
|
||||
}
|
||||
|
||||
TEST(ChunkedVector, GrowsCorrectly) {
|
||||
auto v = ChunkedVector<int, 2>(100);
|
||||
for (auto i = 1; i < 20; i++) {
|
||||
for (uint32_t i = 1; i < 20; i++) {
|
||||
v.add(i);
|
||||
ASSERT_EQ(v.size(), i);
|
||||
}
|
||||
|
@ -31,7 +31,7 @@ namespace nix {
|
|||
for (auto i = 1; i < 20; i++) {
|
||||
v.add(i);
|
||||
}
|
||||
int count = 0;
|
||||
uint32_t count = 0;
|
||||
v.forEach([&count](int elt) {
|
||||
count++;
|
||||
});
|
||||
|
|
|
@ -50,7 +50,7 @@ TEST(from_json, optionalInt) {
|
|||
TEST(from_json, vectorOfOptionalInts) {
|
||||
nlohmann::json json = { 420, nullptr };
|
||||
std::vector<std::optional<int>> vals = json;
|
||||
ASSERT_EQ(vals.size(), 2);
|
||||
ASSERT_EQ(vals.size(), 2u);
|
||||
ASSERT_TRUE(vals.at(0).has_value());
|
||||
ASSERT_EQ(*vals.at(0), 420);
|
||||
ASSERT_FALSE(vals.at(1).has_value());
|
||||
|
|
|
@ -9,13 +9,13 @@ namespace nix {
|
|||
|
||||
TEST(LRUCache, sizeOfEmptyCacheIsZero) {
|
||||
LRUCache<std::string, std::string> c(10);
|
||||
ASSERT_EQ(c.size(), 0);
|
||||
ASSERT_EQ(c.size(), 0u);
|
||||
}
|
||||
|
||||
TEST(LRUCache, sizeOfSingleElementCacheIsOne) {
|
||||
LRUCache<std::string, std::string> c(10);
|
||||
c.upsert("foo", "bar");
|
||||
ASSERT_EQ(c.size(), 1);
|
||||
ASSERT_EQ(c.size(), 1u);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
|
@ -55,12 +55,12 @@ namespace nix {
|
|||
|
||||
auto val = c.get("foo");
|
||||
ASSERT_EQ(val.value_or("error"), "bar");
|
||||
ASSERT_EQ(c.size(), 1);
|
||||
ASSERT_EQ(c.size(), 1u);
|
||||
|
||||
c.upsert("foo", "changed");
|
||||
val = c.get("foo");
|
||||
ASSERT_EQ(val.value_or("error"), "changed");
|
||||
ASSERT_EQ(c.size(), 1);
|
||||
ASSERT_EQ(c.size(), 1u);
|
||||
}
|
||||
|
||||
TEST(LRUCache, overwriteOldestWhenCapacityIsReached) {
|
||||
|
@ -69,13 +69,13 @@ namespace nix {
|
|||
c.upsert("two", "zwei");
|
||||
c.upsert("three", "drei");
|
||||
|
||||
ASSERT_EQ(c.size(), 3);
|
||||
ASSERT_EQ(c.size(), 3u);
|
||||
ASSERT_EQ(c.get("one").value_or("error"), "eins");
|
||||
|
||||
// exceed capacity
|
||||
c.upsert("another", "whatever");
|
||||
|
||||
ASSERT_EQ(c.size(), 3);
|
||||
ASSERT_EQ(c.size(), 3u);
|
||||
// Retrieving "one" makes it the most recent element thus
|
||||
// two will be the oldest one and thus replaced.
|
||||
ASSERT_EQ(c.get("two").has_value(), false);
|
||||
|
@ -89,7 +89,7 @@ namespace nix {
|
|||
TEST(LRUCache, clearEmptyCache) {
|
||||
LRUCache<std::string, std::string> c(10);
|
||||
c.clear();
|
||||
ASSERT_EQ(c.size(), 0);
|
||||
ASSERT_EQ(c.size(), 0u);
|
||||
}
|
||||
|
||||
TEST(LRUCache, clearNonEmptyCache) {
|
||||
|
@ -97,9 +97,9 @@ namespace nix {
|
|||
c.upsert("one", "eins");
|
||||
c.upsert("two", "zwei");
|
||||
c.upsert("three", "drei");
|
||||
ASSERT_EQ(c.size(), 3);
|
||||
ASSERT_EQ(c.size(), 3u);
|
||||
c.clear();
|
||||
ASSERT_EQ(c.size(), 0);
|
||||
ASSERT_EQ(c.size(), 0u);
|
||||
}
|
||||
|
||||
/* ----------------------------------------------------------------------------
|
||||
|
@ -109,14 +109,14 @@ namespace nix {
|
|||
TEST(LRUCache, eraseFromEmptyCache) {
|
||||
LRUCache<std::string, std::string> c(10);
|
||||
ASSERT_EQ(c.erase("foo"), false);
|
||||
ASSERT_EQ(c.size(), 0);
|
||||
ASSERT_EQ(c.size(), 0u);
|
||||
}
|
||||
|
||||
TEST(LRUCache, eraseMissingFromNonEmptyCache) {
|
||||
LRUCache<std::string, std::string> c(10);
|
||||
c.upsert("one", "eins");
|
||||
ASSERT_EQ(c.erase("foo"), false);
|
||||
ASSERT_EQ(c.size(), 1);
|
||||
ASSERT_EQ(c.size(), 1u);
|
||||
ASSERT_EQ(c.get("one").value_or("error"), "eins");
|
||||
}
|
||||
|
||||
|
@ -124,7 +124,7 @@ namespace nix {
|
|||
LRUCache<std::string, std::string> c(10);
|
||||
c.upsert("one", "eins");
|
||||
ASSERT_EQ(c.erase("one"), true);
|
||||
ASSERT_EQ(c.size(), 0);
|
||||
ASSERT_EQ(c.size(), 0u);
|
||||
ASSERT_EQ(c.get("one").value_or("empty"), "empty");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -26,8 +26,8 @@ namespace nix {
|
|||
|
||||
Pool<TestResource> pool = Pool<TestResource>((size_t)1, createResource, isGood);
|
||||
|
||||
ASSERT_EQ(pool.count(), 0);
|
||||
ASSERT_EQ(pool.capacity(), 1);
|
||||
ASSERT_EQ(pool.count(), 0u);
|
||||
ASSERT_EQ(pool.capacity(), 1u);
|
||||
}
|
||||
|
||||
TEST(Pool, freshPoolCanGetAResource) {
|
||||
|
@ -35,12 +35,12 @@ namespace nix {
|
|||
auto createResource = []() { return make_ref<TestResource>(); };
|
||||
|
||||
Pool<TestResource> pool = Pool<TestResource>((size_t)1, createResource, isGood);
|
||||
ASSERT_EQ(pool.count(), 0);
|
||||
ASSERT_EQ(pool.count(), 0u);
|
||||
|
||||
TestResource r = *(pool.get());
|
||||
|
||||
ASSERT_EQ(pool.count(), 1);
|
||||
ASSERT_EQ(pool.capacity(), 1);
|
||||
ASSERT_EQ(pool.count(), 1u);
|
||||
ASSERT_EQ(pool.capacity(), 1u);
|
||||
ASSERT_EQ(r.dummyValue, 1);
|
||||
ASSERT_EQ(r.good, true);
|
||||
}
|
||||
|
@ -50,9 +50,9 @@ namespace nix {
|
|||
auto createResource = []() { return make_ref<TestResource>(); };
|
||||
|
||||
Pool<TestResource> pool = Pool<TestResource>((size_t)1, createResource, isGood);
|
||||
ASSERT_EQ(pool.capacity(), 1);
|
||||
ASSERT_EQ(pool.capacity(), 1u);
|
||||
pool.incCapacity();
|
||||
ASSERT_EQ(pool.capacity(), 2);
|
||||
ASSERT_EQ(pool.capacity(), 2u);
|
||||
}
|
||||
|
||||
TEST(Pool, capacityCanBeDecremented) {
|
||||
|
@ -60,9 +60,9 @@ namespace nix {
|
|||
auto createResource = []() { return make_ref<TestResource>(); };
|
||||
|
||||
Pool<TestResource> pool = Pool<TestResource>((size_t)1, createResource, isGood);
|
||||
ASSERT_EQ(pool.capacity(), 1);
|
||||
ASSERT_EQ(pool.capacity(), 1u);
|
||||
pool.decCapacity();
|
||||
ASSERT_EQ(pool.capacity(), 0);
|
||||
ASSERT_EQ(pool.capacity(), 0u);
|
||||
}
|
||||
|
||||
TEST(Pool, flushBadDropsOutOfScopeResources) {
|
||||
|
@ -73,11 +73,11 @@ namespace nix {
|
|||
|
||||
{
|
||||
auto _r = pool.get();
|
||||
ASSERT_EQ(pool.count(), 1);
|
||||
ASSERT_EQ(pool.count(), 1u);
|
||||
}
|
||||
|
||||
pool.flushBad();
|
||||
ASSERT_EQ(pool.count(), 0);
|
||||
ASSERT_EQ(pool.count(), 0u);
|
||||
}
|
||||
|
||||
// Test that the resources we allocate are being reused when they are still good.
|
||||
|
|
|
@ -34,10 +34,10 @@ namespace nix {
|
|||
TEST(Suggestions, Trim) {
|
||||
auto suggestions = Suggestions::bestMatches({"foooo", "bar", "fo", "gao"}, "foo");
|
||||
auto onlyOne = suggestions.trim(1);
|
||||
ASSERT_EQ(onlyOne.suggestions.size(), 1);
|
||||
ASSERT_EQ(onlyOne.suggestions.size(), 1u);
|
||||
ASSERT_TRUE(onlyOne.suggestions.begin()->suggestion == "fo");
|
||||
|
||||
auto closest = suggestions.trim(999, 2);
|
||||
ASSERT_EQ(closest.suggestions.size(), 3);
|
||||
ASSERT_EQ(closest.suggestions.size(), 3u);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -79,7 +79,7 @@ TEST(base64Encode, encodeAndDecodeNonPrintable)
|
|||
auto encoded = base64Encode(s);
|
||||
auto decoded = base64Decode(encoded);
|
||||
|
||||
EXPECT_EQ(decoded.length(), 255);
|
||||
EXPECT_EQ(decoded.length(), 255u);
|
||||
ASSERT_EQ(decoded, s);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue