Skip to content

Commit

Permalink
restore missing parentheses (p4lang#4600)
Browse files Browse the repository at this point in the history
* restore missing parentheses

Restore parentheses that were accidentally dropped from begin call as
part of recent code improvements (p4lang#4513).

* add basic test for ValuesForKeys from map.h
  • Loading branch information
grg authored Apr 5, 2024
1 parent bd7bcd9 commit bc5346d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/map.h
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ class MapForKey {
M ↦
typename M::key_type key;
class iterator {
using MapIt = decltype(map.begin);
using MapIt = decltype(map.begin());

const MapForKey &self;
MapIt it;
Expand Down
1 change: 1 addition & 0 deletions test/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ set (GTEST_UNITTEST_SOURCES
gtest/hvec_map.cpp
gtest/indexed_vector.cpp
gtest/json_test.cpp
gtest/map.cpp
gtest/midend_def_use.cpp
gtest/midend_pass.cpp
gtest/midend_test.cpp
Expand Down
53 changes: 53 additions & 0 deletions test/gtest/map.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
/*
Copyright 2024 Intel Corp.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/

#include "lib/map.h"

#include <gtest/gtest.h>

#include <algorithm>

namespace Test {

TEST(ValuesForKey, set_equal) {
std::multimap<int, int> a;
std::multimap<int, int> b;

// Populate a
a.emplace(1, 1);
a.emplace(1, 2);
a.emplace(1, 3);
a.emplace(1, 4);

a.emplace(2, 1);
a.emplace(2, 2);

a.emplace(3, 1);

EXPECT_FALSE(a == b);

// Walk through the elements in a and populate in b
std::set<int> keys({1, 2, 3});
for (auto k : keys) {
for (auto v : ValuesForKey(a, k)) {
b.emplace(k, v);
}
}

EXPECT_TRUE(a == b);
}

} // namespace Test

0 comments on commit bc5346d

Please sign in to comment.