index: Make sure we can index into keys that don't exist

This should just return a set of size 0.

Signed-off-by: Anna Schumaker <schumaker.anna@gmail.com>
This commit is contained in:
Anna Schumaker 2013-08-27 09:15:49 -04:00 committed by Anna Schumaker
parent c72ffeb9b9
commit 755785799b
4 changed files with 15 additions and 2 deletions

View File

@ -27,7 +27,7 @@ public:
const std::set<std::string>::iterator keys_begin();
const std::set<std::string>::iterator keys_end();
const std::set<unsigned int> &operator[](std::string &);
const std::set<unsigned int> &operator[](const std::string &);
};
#endif /* OCARINA_INDEX_H */

View File

@ -84,7 +84,7 @@ const std::set<std::string>::iterator Index :: keys_end()
return keys.end();
}
const std::set<unsigned int> &Index :: operator[](std::string &key)
const std::set<unsigned int> &Index :: operator[](const std::string &key)
{
return index[key];
}

View File

@ -138,6 +138,16 @@ void test_4()
print_index(index);
}
/*
* Test access to keys that don't exist
*/
void test_5()
{
print("Test 5\n");
Index index("");
print("index[nokey].size() = %u\n", index["nokey"].size());
}
int main(int argc, char **argv)
{
test_0();
@ -145,5 +155,6 @@ int main(int argc, char **argv)
test_2();
test_3();
test_4();
test_5();
return 0;
}

View File

@ -102,3 +102,5 @@ index[x] = {1 2 3 4 5 6 7 8 9}
index[y] = {2 3 4 5 6 7 8 9}
index[z] = {3 4 5 6 7 8 9}
Test 5
index[nokey].size() = 0