@@ -119,44 +119,33 @@ TEST_CASE("should correctly parse durations", "[config]") {
119
119
auto conf = config::parse_file_any_syntax (TEST_FILE_DIR + string (" /fixtures/test01.conf" ))->resolve ();
120
120
121
121
SECTION (" should be able to fetch number nodes as durations" , " [config]" ) {
122
- REQUIRE (1 == conf->get_duration_as_long (" durations.secondAsNumber" , time_unit::SECONDS));
123
- REQUIRE (1000000000.0 == conf->get_duration_as_double (" durations.secondAsNumber" , time_unit::NANOSECONDS));
122
+ REQUIRE (1 == conf->get_duration (" durations.secondAsNumber" , time_unit::SECONDS));
124
123
}
125
124
126
125
SECTION (" should be able to get durations in specific units" , " [config]" ) {
127
126
// Get as a long
128
- REQUIRE (1 == conf->get_duration_as_long (" durations.second" , time_unit::SECONDS));
129
- REQUIRE (500 == conf->get_duration_as_long (" durations.halfSecond" , time_unit::MILLISECONDS));
130
- REQUIRE (1 == conf->get_duration_as_long (" durations.millis" , time_unit::MILLISECONDS));
131
- REQUIRE (1000 == conf->get_duration_as_long (" durations.second" , time_unit::MILLISECONDS));
132
- REQUIRE (60 == conf->get_duration_as_long (" durations.minute" , time_unit::SECONDS));
133
- REQUIRE (60 == conf->get_duration_as_long (" durations.hour" , time_unit::MINUTES));
134
- REQUIRE (24 == conf->get_duration_as_long (" durations.day" , time_unit::HOURS));
135
- REQUIRE (-4 == conf->get_duration_as_long (" durations.minusSeconds" , time_unit::SECONDS));
136
- REQUIRE (43 == conf->get_duration_as_long (" durations.secondWithFractional" , time_unit::SECONDS));
137
- REQUIRE (43200 == conf->get_duration_as_long (" durations.secondWithFractional" , time_unit::MILLISECONDS));
138
- REQUIRE (9223372036854775807 == conf->get_duration_as_long (" durations.largeNanos" , time_unit::NANOSECONDS));
139
- REQUIRE (-9223372036854775807 == conf->get_duration_as_long (" durations.minusLargeNanos" , time_unit::NANOSECONDS));
127
+ REQUIRE (1 == conf->get_duration (" durations.second" , time_unit::SECONDS));
128
+ REQUIRE (500 == conf->get_duration (" durations.halfSecond" , time_unit::MILLISECONDS));
129
+ REQUIRE (1 == conf->get_duration (" durations.millis" , time_unit::MILLISECONDS));
130
+ REQUIRE (1000 == conf->get_duration (" durations.second" , time_unit::MILLISECONDS));
131
+ REQUIRE (60 == conf->get_duration (" durations.minute" , time_unit::SECONDS));
132
+ REQUIRE (60 == conf->get_duration (" durations.hour" , time_unit::MINUTES));
133
+ REQUIRE (24 == conf->get_duration (" durations.day" , time_unit::HOURS));
134
+ REQUIRE (-4 == conf->get_duration (" durations.minusSeconds" , time_unit::SECONDS));
135
+ REQUIRE (43 == conf->get_duration (" durations.secondWithFractional" , time_unit::SECONDS));
136
+ REQUIRE (43200 == conf->get_duration (" durations.secondWithFractional" , time_unit::MILLISECONDS));
137
+ REQUIRE (9223372036854775807 == conf->get_duration (" durations.largeNanos" , time_unit::NANOSECONDS));
138
+ REQUIRE (-9223372036854775807 == conf->get_duration (" durations.minusLargeNanos" , time_unit::NANOSECONDS));
140
139
// getting as a long truncates when casting to a larger value
141
- REQUIRE (0 == conf->get_duration_as_long (" durations.minute" , time_unit::HOURS));
142
- REQUIRE (9223372036 == conf->get_duration_as_long (" durations.largeNanos" , time_unit::SECONDS));
143
- REQUIRE (153722867 == conf->get_duration_as_long (" durations.largeNanos" , time_unit::MINUTES));
144
- REQUIRE (2562047 == conf->get_duration_as_long (" durations.largeNanos" , time_unit::HOURS));
145
- REQUIRE (106751 == conf->get_duration_as_long (" durations.largeNanos" , time_unit::DAYS));
146
-
147
- // Get as a double
148
- REQUIRE (43.2 == conf->get_duration_as_double (" durations.secondWithFractional" , time_unit::SECONDS));
149
- REQUIRE (43200.0 == conf->get_duration_as_double (" durations.secondWithFractional" , time_unit::MILLISECONDS));
150
- REQUIRE (-4.0 == conf->get_duration_as_double (" durations.minusSeconds" , time_unit::SECONDS));
151
- REQUIRE (0.5 == conf->get_duration_as_double (" durations.halfSecond" , time_unit::SECONDS));
152
- REQUIRE (1000.0 == conf->get_duration_as_double (" durations.second" , time_unit::MILLISECONDS));
153
- // getting as a double retains fractional part
154
- REQUIRE ((1.0 / 60.0 ) == conf->get_duration_as_double (" durations.minute" , time_unit::HOURS));
140
+ REQUIRE (0 == conf->get_duration (" durations.minute" , time_unit::HOURS));
141
+ REQUIRE (9223372036 == conf->get_duration (" durations.largeNanos" , time_unit::SECONDS));
142
+ REQUIRE (153722867 == conf->get_duration (" durations.largeNanos" , time_unit::MINUTES));
143
+ REQUIRE (2562047 == conf->get_duration (" durations.largeNanos" , time_unit::HOURS));
144
+ REQUIRE (106751 == conf->get_duration (" durations.largeNanos" , time_unit::DAYS));
155
145
}
156
146
157
147
SECTION (" should throw an exception when overflow occurs" , " [config]" ) {
158
- REQUIRE_THROWS (conf->get_duration_as_long (" durations.largeDays" , time_unit::DAYS));
159
- REQUIRE_THROWS (conf->get_duration_as_double (" durations.largeDays" , time_unit::NANOSECONDS));
160
- REQUIRE_THROWS (conf->get_duration_as_long (" durations.largeDays" , time_unit::NANOSECONDS));
148
+ REQUIRE_THROWS (conf->get_duration (" durations.largeDays" , time_unit::DAYS));
149
+ REQUIRE_THROWS (conf->get_duration (" durations.largeDays" , time_unit::NANOSECONDS));
161
150
}
162
151
}
0 commit comments