Skip to content

Commit b96184f

Browse files
author
David Chu
committed
test: add test for .Sections() and .Keys()
1 parent 740a588 commit b96184f

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

test/tests.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,22 @@
66

77
using namespace inih;
88

9+
TEST(INIReader, get_sections) {
10+
INIReader r{"./fixtures/config.ini"};
11+
12+
const std::set<std::string> ans = {"section1", "section2"};
13+
14+
EXPECT_EQ(r.Sections(), ans);
15+
}
16+
17+
TEST(INIReader, get_keys) {
18+
INIReader r{"./fixtures/config.ini"};
19+
20+
const std::set<std::string> ans = {"any", "any2", "not_int", "not_int_arr"};
21+
22+
EXPECT_EQ(r.Keys("section1"), ans);
23+
}
24+
925
TEST(INIReader, get_single_value) {
1026
INIReader r{"./fixtures/config.ini"};
1127

@@ -68,12 +84,16 @@ TEST(INIReader, exception) {
6884

6985
INIReader r{"./fixtures/config.ini"};
7086

87+
// section not found error
88+
EXPECT_THROW(r.Get("section3"), std::runtime_error);
89+
7190
// key not found error
7291
EXPECT_THROW(r.Get<int>("section1", "not_exist"), std::runtime_error);
7392
EXPECT_THROW(r.GetVector<int>("section1", "not_exist"), std::runtime_error);
7493

7594
// parse error
7695
EXPECT_THROW(r.Get<int>("section1", "not_int"), std::runtime_error);
96+
EXPECT_THROW(r.Get<bool>("section1", "not_int"), std::runtime_error);
7797
EXPECT_THROW(r.GetVector<int>("section1", "not_int_arr"), std::runtime_error);
7898

7999
}

0 commit comments

Comments
 (0)