-
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
18 changed files
with
143 additions
and
32 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
ignore: | ||
- src/example/**/* |
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,29 @@ | ||
// Copyright (c) 2021-2024 Dr. Colin Hirsch and Daniel Frey | ||
// Please see LICENSE for license or visit https://github.com/taocpp/config/ | ||
|
||
#include <sstream> | ||
#include <string> | ||
#include <string_view> | ||
|
||
#include "test.hpp" | ||
|
||
#include <tao/config.hpp> | ||
#include <tao/config/internal/to_stream.hpp> | ||
|
||
namespace tao::config | ||
{ | ||
void unit_test() | ||
{ | ||
const std::string input = "a = 1 b { c = 42 d = [ null, true ] }"; | ||
internal::config_parser cp; | ||
cp.parse( std::string_view( input ), __FUNCTION__ ); | ||
std::ostringstream oss; | ||
internal::to_stream( oss, cp.st.root ); | ||
const std::string output = oss.str(); | ||
const std::string reference = "{position:\"(root):1:1\",object_data:{a:{remove:true,implicit:false,temporary:false,position:\"unit_test:1:1\",concat_list:[{type:\"unsigned\",data:1}]},b:{remove:false,implicit:false,temporary:false,position:\"unit_test:1:7\",concat_list:[{type:\"object\",data:{position:\"unit_test:1:9\",object_data:{c:{remove:true,implicit:false,temporary:false,position:\"unit_test:1:11\",concat_list:[{type:\"unsigned\",data:42}]},d:{remove:true,implicit:false,temporary:false,position:\"unit_test:1:18\",concat_list:[{type:\"array\",data:{position:\"unit_test:1:22\",function:\"\",array_data:[{remove:false,implicit:false,temporary:false,position:\"unit_test:1:24\",concat_list:[{type:\"null\"}]},{remove:false,implicit:false,temporary:false,position:\"unit_test:1:24\",concat_list:[{type:\"boolean\",data:true}]}]}}]}}}}]}}}"; | ||
TAO_CONFIG_TEST_ASSERT( output == reference ); | ||
} | ||
|
||
} // 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
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 <iostream> | ||
#include <sstream> | ||
#include <string> | ||
|
||
#include "test.hpp" | ||
|
||
#include <tao/config.hpp> | ||
|
||
namespace tao::config | ||
{ | ||
void unit_test() | ||
{ | ||
const std::string input = "a = 1 b { c = 42 d = [ null, true ] }"; | ||
const tao::config::value parsed = tao::config::from_string( input, "main" ); | ||
{ | ||
std::ostringstream oss; | ||
tao::config::to_stream( oss, parsed ); | ||
const std::string string1 = oss.str(); | ||
const std::string reference1 = "{meta:{key:[],position:\"(root):1:1\"},data:{a:{meta:{key:[{key_kind:\"name\",key_data:{index:0,value:\"a\"}}],position:\"main:1:6\"},data:1},b:{meta:{key:[{key_kind:\"name\",key_data:{index:0,value:\"b\"}}],position:\"main:1:9\"},data:{c:{meta:{key:[{key_kind:\"name\",key_data:{index:0,value:\"b\"}},{key_kind:\"name\",key_data:{index:0,value:\"c\"}}],position:\"main:1:17\"},data:42},d:{meta:{key:[{key_kind:\"name\",key_data:{index:0,value:\"b\"}},{key_kind:\"name\",key_data:{index:0,value:\"d\"}}],position:\"main:1:22\"},data:[{meta:{key:[{key_kind:\"name\",key_data:{index:0,value:\"b\"}},{key_kind:\"name\",key_data:{index:0,value:\"d\"}},{key_kind:\"index\",key_data:{index:1,value:0}}],position:\"main:1:24\"},data:null},{meta:{key:[{key_kind:\"name\",key_data:{index:0,value:\"b\"}},{key_kind:\"name\",key_data:{index:0,value:\"d\"}},{key_kind:\"index\",key_data:{index:1,value:1}}],position:\"main:1:30\"},data:true}]}}}}}"; | ||
if( string1 != reference1 ) { | ||
std::cerr << string1 << std::endl; | ||
std::cerr << reference1 << std::endl; | ||
std::cerr << "Config to_stream test 1 failed!" << std::endl; | ||
++failed; | ||
} | ||
} { | ||
std::ostringstream oss; | ||
tao::config::to_stream( oss, parsed, 3 ); | ||
const std::string string2 = oss.str(); | ||
const std::string reference2 = "{\n meta: {\n key: [],\n position: \"(root):1:1\"\n },\n data: {\n a: {\n meta: {\n key: [\n {\n key_kind: \"name\",\n key_data: {\n index: 0,\n value: \"a\"\n }\n }\n ],\n position: \"main:1:6\"\n },\n data: 1\n },\n b: {\n meta: {\n key: [\n {\n key_kind: \"name\",\n key_data: {\n index: 0,\n value: \"b\"\n }\n }\n ],\n position: \"main:1:9\"\n },\n data: {\n c: {\n meta: {\n key: [\n {\n key_kind: \"name\",\n key_data: {\n index: 0,\n value: \"b\"\n }\n },\n {\n key_kind: \"name\",\n key_data: {\n index: 0,\n value: \"c\"\n }\n }\n ],\n position: \"main:1:17\"\n },\n data: 42\n },\n d: {\n meta: {\n key: [\n {\n key_kind: \"name\",\n key_data: {\n index: 0,\n value: \"b\"\n }\n },\n {\n key_kind: \"name\",\n key_data: {\n index: 0,\n value: \"d\"\n }\n }\n ],\n position: \"main:1:22\"\n },\n data: [\n {\n meta: {\n key: [\n {\n key_kind: \"name\",\n key_data: {\n index: 0,\n value: \"b\"\n }\n },\n {\n key_kind: \"name\",\n key_data: {\n index: 0,\n value: \"d\"\n }\n },\n {\n key_kind: \"index\",\n key_data: {\n index: 1,\n value: 0\n }\n }\n ],\n position: \"main:1:24\"\n },\n data: null\n },\n {\n meta: {\n key: [\n {\n key_kind: \"name\",\n key_data: {\n index: 0,\n value: \"b\"\n }\n },\n {\n key_kind: \"name\",\n key_data: {\n index: 0,\n value: \"d\"\n }\n },\n {\n key_kind: \"index\",\n key_data: {\n index: 1,\n value: 1\n }\n }\n ],\n position: \"main:1:30\"\n },\n data: true\n }\n ]\n }\n }\n }\n }\n}"; | ||
if( string2 != reference2 ) { | ||
std:: cerr << string2.size() << " " << reference2.size() << std::endl; | ||
std::cerr << string2 << std::endl; | ||
std::cerr << reference2 << std::endl; | ||
std::cerr << "Config to_stream test 2 failed!" << std::endl; | ||
++failed; | ||
} | ||
} | ||
} | ||
|
||
} // 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,5 @@ | ||
{ | ||
a : $3031, | ||
b : $3031, | ||
c : $3031 | ||
} |
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,3 @@ | ||
a = $3031 | ||
b = $30 + $31 | ||
c = $"\x30\x31" |
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,2 @@ | ||
a = (default (b) "foo") | ||
b = (default (a) "bar") |
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,4 @@ | ||
a = {} | ||
a.* = 42 | ||
a.a.b = (default (a.a.c) "foo") | ||
a.a.c = (default (a.a.b) "bar") |
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,2 @@ | ||
a.b.c = (b.x) | ||
a.b.x = (b.c) |
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,2 @@ | ||
a = ((y)) | ||
y = ((a)) |