Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Clean up how const types are handled and fix C-style arrays. Fixes #19,
- Loading branch information
1 parent
dae6eda
commit 207e0e6
Showing
8 changed files
with
194 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
#include "arraylike.h" | ||
#include "hippo/hippo.h" | ||
|
||
TEST_CASE("native array") { | ||
hippo::configuration config; | ||
config.indent = 2; | ||
int val[]{0, 1, 2}; | ||
SECTION("expanded") { | ||
config.width = 0; | ||
std::vector<std::string> expected_string{"native array [", " 0,", " 1,", | ||
" 2", "]"}; | ||
REQUIRE(hippo::print(val, config) == expected_string); | ||
} | ||
SECTION("compressed") { | ||
config.width = 100; | ||
std::vector<std::string> expected_string{"native array [ 0, 1, 2 ]"}; | ||
REQUIRE(hippo::print(val, config) == expected_string); | ||
} | ||
SECTION("formatted") { | ||
config.width = 100; | ||
hippo::integer_format fmt; | ||
fmt.base = hippo::integer_format::base_type::hex; | ||
std::vector<std::string> expected_string{"native array [ 0x0, 0x1, 0x2 ]"}; | ||
REQUIRE(hippo::print(hippo::formatter(val, fmt), config) == | ||
expected_string); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#include "catch.hpp" | ||
#include "hippo/hippo.h" | ||
|
||
struct Foo {}; | ||
|
||
HIPPO_CLASS_BEGIN(Foo); | ||
HIPPO_CLASS_END(); | ||
|
||
TEST_CASE("const volatile type") { | ||
hippo::configuration config; | ||
config.indent = 2; | ||
Foo foo; | ||
std::string expected("Foo { }"); | ||
REQUIRE( | ||
std::get<hippo::line>(hippo::printer<const Foo>::print(foo, 0, config)) | ||
.string == expected); | ||
REQUIRE( | ||
std::get<hippo::line>(hippo::printer<volatile Foo>::print(foo, 0, config)) | ||
.string == expected); | ||
REQUIRE(std::get<hippo::line>( | ||
hippo::printer<const volatile Foo>::print(foo, 0, config)) | ||
.string == expected); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
#include "catch.hpp" | ||
#include "hippo/hippo.h" | ||
|
||
TEMPLATE_TEST_CASE("integer", "[builtin]", std::uint8_t, std::uint16_t, | ||
std::uint32_t, std::uint64_t, std::int8_t, std::int16_t, | ||
std::int32_t, std::int64_t) { | ||
TestType value = 2; | ||
hippo::configuration config; | ||
SECTION("decimal") { | ||
std::vector<std::string> expected{"2"}; | ||
REQUIRE(hippo::print(value, config) == expected); | ||
} | ||
SECTION("octal") { | ||
hippo::integer_format fmt; | ||
fmt.base = hippo::integer_format::base_type::oct; | ||
std::vector<std::string> expected{"02"}; | ||
REQUIRE(hippo::print(hippo::formatter(value, fmt), config) == expected); | ||
} | ||
SECTION("hexadecimal") { | ||
hippo::integer_format fmt; | ||
fmt.base = hippo::integer_format::base_type::hex; | ||
std::vector<std::string> expected{"0x2"}; | ||
REQUIRE(hippo::print(hippo::formatter(value, fmt), config) == expected); | ||
} | ||
} | ||
|
||
TEMPLATE_TEST_CASE("float", "[builtin]", float, double, long double) { | ||
TestType value = 0.5; | ||
hippo::configuration config; | ||
SECTION("default") { | ||
std::vector<std::string> expected{"0.5"}; | ||
REQUIRE(hippo::print(value, config) == expected); | ||
} | ||
SECTION("scientific") { | ||
hippo::float_format fmt; | ||
fmt.notation = hippo::float_format::notation_type::scientific; | ||
fmt.precision = 2; | ||
std::vector<std::string> expected{"5.00e-01"}; | ||
REQUIRE(hippo::print(hippo::formatter(value, fmt), config) == expected); | ||
} | ||
SECTION("fixed") { | ||
hippo::float_format fmt; | ||
fmt.notation = hippo::float_format::notation_type::fixed; | ||
fmt.precision = 2; | ||
std::vector<std::string> expected{"0.50"}; | ||
REQUIRE(hippo::print(hippo::formatter(value, fmt), config) == expected); | ||
} | ||
} | ||
|
||
TEST_CASE("bool") { | ||
hippo::configuration config; | ||
std::vector<std::string> expected_false{"false"}; | ||
std::vector<std::string> expected_true{"true"}; | ||
REQUIRE(hippo::print(false, config) == expected_false); | ||
REQUIRE(hippo::print(true, config) == expected_true); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters