-
Notifications
You must be signed in to change notification settings - Fork 23
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
17 changed files
with
231 additions
and
149 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
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,46 @@ | ||
// Copyright (c) 2024 Dr. Colin Hirsch and Daniel Frey | ||
// Please see LICENSE for license or visit https://github.com/taocpp/config/ | ||
|
||
#include <sstream> | ||
#include <string> | ||
|
||
#include "test.hpp" | ||
|
||
#include <tao/config/key.hpp> | ||
|
||
namespace tao::config | ||
{ | ||
void unit_test() | ||
{ | ||
const std::string s0 = "foo.bar.42.\" \""; | ||
const std::vector< key_part > kpv = { key_part( "foo" ), key_part( "bar" ), key_part( 42 ), key_part( " " ) }; | ||
const key k1( kpv.begin(), kpv.end() ); | ||
const key k2( "foo.bar.42.' '" ); | ||
const key k3 = { key_part( "foo" ), key_part( "bar" ), key_part( 42 ), key_part( " " ) }; | ||
key k4 = k3; | ||
TAO_CONFIG_TEST_ASSERT( k1.size() == 4 ); | ||
TAO_CONFIG_TEST_ASSERT( k1 == k2 ); | ||
TAO_CONFIG_TEST_ASSERT( k1 == k3 ); | ||
TAO_CONFIG_TEST_ASSERT( k1.vector() == k2.vector() ); | ||
TAO_CONFIG_TEST_ASSERT( k1.vector() == k4.vector() ); | ||
const auto k5 = pop_front( k1 ); | ||
const auto k6 = pop_back( k1 ); | ||
TAO_CONFIG_TEST_ASSERT( k5.size() == 3 ); | ||
TAO_CONFIG_TEST_ASSERT( k6.size() == 3 ); | ||
TAO_CONFIG_TEST_ASSERT( k5 == key( "bar.42.' '" ) ); | ||
TAO_CONFIG_TEST_ASSERT( k6 == key( "foo.bar.42" ) ); | ||
const std::string s1 = to_string( k1 ); | ||
TAO_CONFIG_TEST_ASSERT( s1 == s0 ); | ||
std::ostringstream oss; | ||
to_stream( oss, k1 ); | ||
TAO_CONFIG_TEST_ASSERT( oss.str() == s0 ); | ||
k4 = pop_back( k1 ); | ||
TAO_CONFIG_TEST_ASSERT( k4 + " " == k1 ); | ||
TAO_CONFIG_TEST_ASSERT( k4 + key_part( " " ) == k1 ); | ||
TAO_CONFIG_TEST_ASSERT( k4 + key( "\" \"" ) == k1 ); | ||
TAO_CONFIG_TEST_ASSERT( k1 + 123 == key( s0 + ".123" ) ); | ||
} | ||
|
||
} // namespace tao::config | ||
|
||
#include "main.hpp" |
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,58 @@ | ||
// Copyright (c) 2024 Dr. Colin Hirsch and Daniel Frey | ||
// Please see LICENSE for license or visit https://github.com/taocpp/config/ | ||
|
||
#include <sstream> | ||
#include <string> | ||
|
||
#include "test.hpp" | ||
|
||
#include <tao/config/key_part.hpp> | ||
|
||
namespace tao::config | ||
{ | ||
void test_name1() | ||
{ | ||
const std::string str = "foo"; | ||
const key_part p( str ); | ||
TAO_CONFIG_TEST_ASSERT( p.kind() == key_kind::name ); | ||
TAO_CONFIG_TEST_ASSERT( p.get_name() == str ); | ||
TAO_CONFIG_TEST_ASSERT( to_string( p ) == str ); | ||
std::ostringstream oss; | ||
to_stream( oss, p ); | ||
TAO_CONFIG_TEST_ASSERT( oss.str() == str ); | ||
} | ||
|
||
void test_name2() | ||
{ | ||
const std::string str = "+- "; | ||
const key_part p( str ); | ||
TAO_CONFIG_TEST_ASSERT( p.kind() == key_kind::name ); | ||
TAO_CONFIG_TEST_ASSERT( p.get_name() == str ); | ||
TAO_CONFIG_TEST_ASSERT( to_string( p ) == '"' + str + '"' ); | ||
std::ostringstream oss; | ||
to_stream( oss, p ); | ||
TAO_CONFIG_TEST_ASSERT( oss.str() == '"' + str + '"' ); | ||
} | ||
|
||
void test_index() | ||
{ | ||
const std::size_t ind = 42; | ||
const key_part p( ind ); | ||
TAO_CONFIG_TEST_ASSERT( p.kind() == key_kind::index ); | ||
TAO_CONFIG_TEST_ASSERT( p.get_index() == ind ); | ||
TAO_CONFIG_TEST_ASSERT( to_string( p ) == "42" ); | ||
std::ostringstream oss; | ||
to_stream( oss, p ); | ||
TAO_CONFIG_TEST_ASSERT( oss.str() == "42" ); | ||
} | ||
|
||
void unit_test() | ||
{ | ||
test_name1(); | ||
test_name2(); | ||
test_index(); | ||
} | ||
|
||
} // namespace tao::config | ||
|
||
#include "main.hpp" |
Oops, something went wrong.