Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
A
Actor Framework
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Metrics
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
cpp-libs
Actor Framework
Commits
13e78371
Commit
13e78371
authored
May 04, 2020
by
Dominik Charousset
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix CLI parsing of nested strings and lists
(cherry picked from commit
ed22184f
)
parent
390195a4
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
198 additions
and
30 deletions
+198
-30
libcaf_core/caf/config_value.hpp
libcaf_core/caf/config_value.hpp
+102
-17
libcaf_core/caf/config_value_adaptor_access.hpp
libcaf_core/caf/config_value_adaptor_access.hpp
+3
-2
libcaf_core/caf/config_value_field.hpp
libcaf_core/caf/config_value_field.hpp
+1
-1
libcaf_core/caf/config_value_object_access.hpp
libcaf_core/caf/config_value_object_access.hpp
+4
-3
libcaf_core/caf/detail/config_value_adaptor_field_impl.hpp
libcaf_core/caf/detail/config_value_adaptor_field_impl.hpp
+0
-1
libcaf_core/caf/detail/config_value_field_base.hpp
libcaf_core/caf/detail/config_value_field_base.hpp
+6
-3
libcaf_core/caf/detail/config_value_field_impl.hpp
libcaf_core/caf/detail/config_value_field_impl.hpp
+0
-1
libcaf_core/caf/make_config_option.hpp
libcaf_core/caf/make_config_option.hpp
+1
-1
libcaf_core/test/config_value.cpp
libcaf_core/test/config_value.cpp
+80
-0
libcaf_core/test/make_config_value_field.cpp
libcaf_core/test/make_config_value_field.cpp
+1
-1
No files found.
libcaf_core/caf/config_value.hpp
View file @
13e78371
...
@@ -214,6 +214,22 @@ private:
...
@@ -214,6 +214,22 @@ private:
variant_type
data_
;
variant_type
data_
;
};
};
// -- convenience constants ----------------------------------------------------
/// Type of the `top_level_cli_parsing` constant.
using
top_level_cli_parsing_t
=
std
::
false_type
;
/// Signals parsing of top-level config values when used as third argument to
/// `parse_cli`.
constexpr
auto
top_level_cli_parsing
=
top_level_cli_parsing_t
{};
/// Type of the `top_level_cli_parsing` constant.
using
nested_cli_parsing_t
=
std
::
true_type
;
/// Signals parsing of nested config values when used as third argument to
/// `parse_cli`.
constexpr
auto
nested_cli_parsing
=
nested_cli_parsing_t
{};
// -- SumType-like access ------------------------------------------------------
// -- SumType-like access ------------------------------------------------------
template
<
class
T
>
template
<
class
T
>
...
@@ -234,7 +250,8 @@ struct default_config_value_access {
...
@@ -234,7 +250,8 @@ struct default_config_value_access {
return
x
;
return
x
;
}
}
static
void
parse_cli
(
string_parser_state
&
ps
,
T
&
x
)
{
template
<
class
Nested
>
static
void
parse_cli
(
string_parser_state
&
ps
,
T
&
x
,
Nested
)
{
detail
::
parse
(
ps
,
x
);
detail
::
parse
(
ps
,
x
);
}
}
};
};
...
@@ -262,19 +279,36 @@ CAF_DEFAULT_CONFIG_VALUE_ACCESS(uri, "uri");
...
@@ -262,19 +279,36 @@ CAF_DEFAULT_CONFIG_VALUE_ACCESS(uri, "uri");
#undef CAF_DEFAULT_CONFIG_VALUE_ACCESS
#undef CAF_DEFAULT_CONFIG_VALUE_ACCESS
template
<
>
template
<
>
struct
CAF_CORE_EXPORT
config_value_access
<
std
::
string
>
struct
CAF_CORE_EXPORT
config_value_access
<
std
::
string
>
{
:
default_config_value_access
<
std
::
string
>
{
using
super
=
default_config_value_access
<
std
::
string
>
;
using
super
=
default_config_value_access
<
std
::
string
>
;
static
std
::
string
type_name
()
{
static
std
::
string
type_name
()
{
return
"string"
;
return
"string"
;
}
}
using
super
::
parse_cli
;
static
bool
is
(
const
config_value
&
x
)
{
return
holds_alternative
<
std
::
string
>
(
x
.
get_data
());
}
static
const
std
::
string
*
get_if
(
const
config_value
*
x
)
{
return
caf
::
get_if
<
std
::
string
>
(
&
(
x
->
get_data
()));
}
static
std
::
string
get
(
const
config_value
&
x
)
{
return
caf
::
get
<
std
::
string
>
(
x
.
get_data
());
}
static
std
::
string
convert
(
std
::
string
x
)
{
return
x
;
}
template
<
bool
IsNested
>
static
void
parse_cli
(
string_parser_state
&
ps
,
std
::
string
&
x
,
static
void
parse_cli
(
string_parser_state
&
ps
,
std
::
string
&
x
,
const
char
*
char_blacklist
)
{
std
::
integral_constant
<
bool
,
IsNested
>
)
{
detail
::
parse_element
(
ps
,
x
,
char_blacklist
);
if
(
IsNested
)
detail
::
parse_element
(
ps
,
x
,
",={}[]"
);
else
detail
::
parse
(
ps
,
x
);
}
}
};
};
...
@@ -422,7 +456,8 @@ struct select_config_value_access<T, select_config_value_hint::is_integral> {
...
@@ -422,7 +456,8 @@ struct select_config_value_access<T, select_config_value_hint::is_integral> {
return
x
;
return
x
;
}
}
static
void
parse_cli
(
string_parser_state
&
ps
,
T
&
x
)
{
template
<
class
Nested
>
static
void
parse_cli
(
string_parser_state
&
ps
,
T
&
x
,
Nested
)
{
detail
::
parse
(
ps
,
x
);
detail
::
parse
(
ps
,
x
);
}
}
};
};
...
@@ -482,23 +517,70 @@ struct select_config_value_access<T, select_config_value_hint::is_list> {
...
@@ -482,23 +517,70 @@ struct select_config_value_access<T, select_config_value_hint::is_list> {
return
result
;
return
result
;
}
}
static
void
parse_cli
(
string_parser_state
&
ps
,
T
&
xs
)
{
static
void
parse_cli
(
string_parser_state
&
ps
,
T
&
xs
,
config_value
::
dictionary
result
;
top_level_cli_parsing_t
)
{
bool
has_open_token
=
ps
.
consume
(
'['
);
bool
has_open_token
;
auto
subtype
=
select_config_value_oracle
<
value_type
>
();
if
(
subtype
==
select_config_value_hint
::
is_list
)
{
// The outer square brackets are optional in nested lists. This means we
// need to check for "[[" at the beginning and otherwise we assume the
// leading '[' was omitted.
string_parser_state
tmp
{
ps
.
i
,
ps
.
e
};
has_open_token
=
tmp
.
consume
(
'['
)
&&
tmp
.
consume
(
'['
);
if
(
has_open_token
)
ps
.
consume
(
'['
);
}
else
{
has_open_token
=
ps
.
consume
(
'['
);
}
do
{
do
{
if
(
has_open_token
&&
ps
.
consume
(
']'
))
{
ps
.
skip_whitespaces
();
if
(
has_open_token
)
{
if
(
ps
.
consume
(
']'
))
{
ps
.
skip_whitespaces
();
ps
.
skip_whitespaces
();
ps
.
code
=
ps
.
at_end
()
?
pec
::
success
:
pec
::
trailing_character
;
ps
.
code
=
ps
.
at_end
()
?
pec
::
success
:
pec
::
trailing_character
;
return
;
return
;
}
}
}
else
if
(
ps
.
at_end
())
{
// Allow trailing commas and empty strings.
ps
.
code
=
pec
::
success
;
return
;
}
value_type
tmp
;
value_type
tmp
;
value_trait
::
parse_cli
(
ps
,
tmp
);
value_trait
::
parse_cli
(
ps
,
tmp
,
nested_cli_parsing
);
if
(
ps
.
code
>
pec
::
trailing_character
)
if
(
ps
.
code
>
pec
::
trailing_character
)
return
;
return
;
xs
.
insert
(
xs
.
end
(),
std
::
move
(
tmp
));
xs
.
insert
(
xs
.
end
(),
std
::
move
(
tmp
));
}
while
(
ps
.
consume
(
','
));
}
while
(
ps
.
consume
(
','
));
if
(
has_open_token
&&
!
ps
.
consume
(
']'
))
if
(
has_open_token
&&
!
ps
.
consume
(
']'
))
{
ps
.
code
=
ps
.
at_end
()
?
pec
::
unexpected_eof
:
pec
::
unexpected_character
;
ps
.
code
=
ps
.
at_end
()
?
pec
::
unexpected_eof
:
pec
::
unexpected_character
;
return
;
}
ps
.
skip_whitespaces
();
ps
.
code
=
ps
.
at_end
()
?
pec
::
success
:
pec
::
trailing_character
;
}
static
void
parse_cli
(
string_parser_state
&
ps
,
T
&
xs
,
nested_cli_parsing_t
)
{
if
(
!
ps
.
consume
(
'['
))
{
ps
.
code
=
ps
.
at_end
()
?
pec
::
unexpected_eof
:
pec
::
unexpected_character
;
return
;
}
do
{
if
(
ps
.
consume
(
']'
))
{
ps
.
skip_whitespaces
();
ps
.
code
=
ps
.
at_end
()
?
pec
::
success
:
pec
::
trailing_character
;
return
;
}
value_type
tmp
;
value_trait
::
parse_cli
(
ps
,
tmp
,
nested_cli_parsing
);
if
(
ps
.
code
>
pec
::
trailing_character
)
return
;
xs
.
insert
(
xs
.
end
(),
std
::
move
(
tmp
));
}
while
(
ps
.
consume
(
','
));
if
(
!
ps
.
consume
(
']'
))
{
ps
.
code
=
ps
.
at_end
()
?
pec
::
unexpected_eof
:
pec
::
unexpected_character
;
return
;
}
ps
.
skip_whitespaces
();
ps
.
skip_whitespaces
();
ps
.
code
=
ps
.
at_end
()
?
pec
::
success
:
pec
::
trailing_character
;
ps
.
code
=
ps
.
at_end
()
?
pec
::
success
:
pec
::
trailing_character
;
}
}
...
@@ -555,7 +637,8 @@ struct select_config_value_access<T, select_config_value_hint::is_map> {
...
@@ -555,7 +637,8 @@ struct select_config_value_access<T, select_config_value_hint::is_map> {
return
std
::
move
(
*
result
);
return
std
::
move
(
*
result
);
}
}
static
void
parse_cli
(
string_parser_state
&
ps
,
map_type
&
xs
)
{
template
<
class
Nested
>
static
void
parse_cli
(
string_parser_state
&
ps
,
map_type
&
xs
,
Nested
)
{
detail
::
parse
(
ps
,
xs
);
detail
::
parse
(
ps
,
xs
);
}
}
...
@@ -592,7 +675,8 @@ struct config_value_access<float> {
...
@@ -592,7 +675,8 @@ struct config_value_access<float> {
return
x
;
return
x
;
}
}
static
void
parse_cli
(
string_parser_state
&
ps
,
float
&
x
)
{
template
<
class
Nested
>
static
void
parse_cli
(
string_parser_state
&
ps
,
float
&
x
,
Nested
)
{
detail
::
parse
(
ps
,
x
);
detail
::
parse
(
ps
,
x
);
}
}
};
};
...
@@ -644,7 +728,8 @@ struct config_value_access<std::tuple<Ts...>> {
...
@@ -644,7 +728,8 @@ struct config_value_access<std::tuple<Ts...>> {
return
result
;
return
result
;
}
}
static
void
parse_cli
(
string_parser_state
&
ps
,
tuple_type
&
xs
)
{
template
<
class
Nested
>
static
void
parse_cli
(
string_parser_state
&
ps
,
tuple_type
&
xs
,
Nested
)
{
rec_parse
(
ps
,
xs
,
detail
::
int_token
<
0
>
(),
detail
::
type_list
<
Ts
...
>
());
rec_parse
(
ps
,
xs
,
detail
::
int_token
<
0
>
(),
detail
::
type_list
<
Ts
...
>
());
}
}
...
@@ -723,7 +808,7 @@ private:
...
@@ -723,7 +808,7 @@ private:
static
void
rec_parse
(
string_parser_state
&
ps
,
tuple_type
&
xs
,
static
void
rec_parse
(
string_parser_state
&
ps
,
tuple_type
&
xs
,
detail
::
int_token
<
Pos
>
,
detail
::
type_list
<
U
,
Us
...
>
)
{
detail
::
int_token
<
Pos
>
,
detail
::
type_list
<
U
,
Us
...
>
)
{
using
trait
=
select_config_value_access_t
<
U
>
;
using
trait
=
select_config_value_access_t
<
U
>
;
trait
::
parse_cli
(
std
::
get
<
Pos
>
(
xs
));
trait
::
parse_cli
(
std
::
get
<
Pos
>
(
xs
)
,
nested_cli_parsing
);
if
(
ps
.
code
>
pec
::
trailing_character
)
if
(
ps
.
code
>
pec
::
trailing_character
)
return
;
return
;
if
(
sizeof
...(
Us
)
>
0
&&
!
ps
.
consume
(
','
))
if
(
sizeof
...(
Us
)
>
0
&&
!
ps
.
consume
(
','
))
...
...
libcaf_core/caf/config_value_adaptor_access.hpp
View file @
13e78371
...
@@ -90,9 +90,10 @@ struct config_value_adaptor_access {
...
@@ -90,9 +90,10 @@ struct config_value_adaptor_access {
return
result
;
return
result
;
}
}
static
void
parse_cli
(
string_parser_state
&
ps
,
value_type
&
x
)
{
template
<
class
Nested
>
static
void
parse_cli
(
string_parser_state
&
ps
,
value_type
&
x
,
Nested
nested
)
{
tuple_type
tmp
;
tuple_type
tmp
;
tuple_access
::
parse_cli
(
ps
,
tmp
);
tuple_access
::
parse_cli
(
ps
,
tmp
,
nested
);
if
(
ps
.
code
<=
pec
::
trailing_character
)
if
(
ps
.
code
<=
pec
::
trailing_character
)
convert
(
tmp
,
x
);
convert
(
tmp
,
x
);
}
}
...
...
libcaf_core/caf/config_value_field.hpp
View file @
13e78371
...
@@ -57,7 +57,7 @@ public:
...
@@ -57,7 +57,7 @@ public:
/// Parses the content for this field in `object` from `ps`.
/// Parses the content for this field in `object` from `ps`.
virtual
void
parse_cli
(
string_parser_state
&
ps
,
Object
&
object
,
virtual
void
parse_cli
(
string_parser_state
&
ps
,
Object
&
object
,
const
char
*
char_blacklist
=
""
)
const
=
0
;
bool
is_nested
)
const
=
0
;
};
};
}
// namespace caf
}
// namespace caf
libcaf_core/caf/config_value_object_access.hpp
View file @
13e78371
...
@@ -91,7 +91,8 @@ struct config_value_object_access {
...
@@ -91,7 +91,8 @@ struct config_value_object_access {
return
result
;
return
result
;
}
}
static
void
parse_cli
(
string_parser_state
&
ps
,
object_type
&
x
)
{
template
<
class
Nested
>
static
void
parse_cli
(
string_parser_state
&
ps
,
object_type
&
x
,
Nested
)
{
using
field_type
=
config_value_field
<
object_type
>
;
using
field_type
=
config_value_field
<
object_type
>
;
std
::
vector
<
field_type
*>
parsed_fields
;
std
::
vector
<
field_type
*>
parsed_fields
;
auto
got
=
[
&
](
field_type
*
f
)
{
auto
got
=
[
&
](
field_type
*
f
)
{
...
@@ -131,7 +132,7 @@ struct config_value_object_access {
...
@@ -131,7 +132,7 @@ struct config_value_object_access {
return
;
return
;
}
}
std
::
string
field_name
;
std
::
string
field_name
;
string_access
::
parse_cli
(
ps
,
field_name
,
"=}"
);
string_access
::
parse_cli
(
ps
,
field_name
,
nested_cli_parsing
);
if
(
ps
.
code
>
pec
::
trailing_character
)
if
(
ps
.
code
>
pec
::
trailing_character
)
return
;
return
;
if
(
!
ps
.
consume
(
'='
))
{
if
(
!
ps
.
consume
(
'='
))
{
...
@@ -151,7 +152,7 @@ struct config_value_object_access {
...
@@ -151,7 +152,7 @@ struct config_value_object_access {
ps
.
code
=
pec
::
repeated_field_name
;
ps
.
code
=
pec
::
repeated_field_name
;
return
;
return
;
}
}
fptr
->
parse_cli
(
ps
,
x
,
",}"
);
fptr
->
parse_cli
(
ps
,
x
,
true
);
if
(
ps
.
code
>
pec
::
trailing_character
)
if
(
ps
.
code
>
pec
::
trailing_character
)
return
;
return
;
if
(
ps
.
at_end
())
{
if
(
ps
.
at_end
())
{
...
...
libcaf_core/caf/detail/config_value_adaptor_field_impl.hpp
View file @
13e78371
...
@@ -25,7 +25,6 @@
...
@@ -25,7 +25,6 @@
#include "caf/config_value_adaptor_field.hpp"
#include "caf/config_value_adaptor_field.hpp"
#include "caf/config_value_field.hpp"
#include "caf/config_value_field.hpp"
#include "caf/detail/config_value_field_base.hpp"
#include "caf/detail/config_value_field_base.hpp"
#include "caf/detail/dispatch_parse_cli.hpp"
#include "caf/string_view.hpp"
#include "caf/string_view.hpp"
namespace
caf
::
detail
{
namespace
caf
::
detail
{
...
...
libcaf_core/caf/detail/config_value_field_base.hpp
View file @
13e78371
...
@@ -20,7 +20,6 @@
...
@@ -20,7 +20,6 @@
#include "caf/config_value.hpp"
#include "caf/config_value.hpp"
#include "caf/config_value_field.hpp"
#include "caf/config_value_field.hpp"
#include "caf/detail/dispatch_parse_cli.hpp"
#include "caf/optional.hpp"
#include "caf/optional.hpp"
namespace
caf
::
detail
{
namespace
caf
::
detail
{
...
@@ -82,9 +81,13 @@ public:
...
@@ -82,9 +81,13 @@ public:
}
}
void
parse_cli
(
string_parser_state
&
ps
,
object_type
&
x
,
void
parse_cli
(
string_parser_state
&
ps
,
object_type
&
x
,
const
char
*
char_blacklist
)
const
override
{
bool
nested
)
const
override
{
using
access
=
caf
::
select_config_value_access_t
<
value_type
>
;
value_type
tmp
;
value_type
tmp
;
dispatch_parse_cli
(
ps
,
tmp
,
char_blacklist
);
if
(
nested
)
access
::
parse_cli
(
ps
,
tmp
,
nested_cli_parsing
);
else
access
::
parse_cli
(
ps
,
tmp
,
top_level_cli_parsing
);
if
(
ps
.
code
<=
pec
::
trailing_character
)
{
if
(
ps
.
code
<=
pec
::
trailing_character
)
{
if
(
predicate_
&&
!
predicate_
(
tmp
))
if
(
predicate_
&&
!
predicate_
(
tmp
))
ps
.
code
=
pec
::
invalid_argument
;
ps
.
code
=
pec
::
invalid_argument
;
...
...
libcaf_core/caf/detail/config_value_field_impl.hpp
View file @
13e78371
...
@@ -24,7 +24,6 @@
...
@@ -24,7 +24,6 @@
#include "caf/config_value.hpp"
#include "caf/config_value.hpp"
#include "caf/config_value_field.hpp"
#include "caf/config_value_field.hpp"
#include "caf/detail/config_value_field_base.hpp"
#include "caf/detail/config_value_field_base.hpp"
#include "caf/detail/dispatch_parse_cli.hpp"
#include "caf/detail/parse.hpp"
#include "caf/detail/parse.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/detail/type_traits.hpp"
#include "caf/optional.hpp"
#include "caf/optional.hpp"
...
...
libcaf_core/caf/make_config_option.hpp
View file @
13e78371
...
@@ -60,7 +60,7 @@ expected<config_value> parse_impl(T* ptr, string_view str) {
...
@@ -60,7 +60,7 @@ expected<config_value> parse_impl(T* ptr, string_view str) {
}
}
using
trait
=
select_config_value_access_t
<
T
>
;
using
trait
=
select_config_value_access_t
<
T
>
;
string_parser_state
ps
{
str
.
begin
(),
str
.
end
()};
string_parser_state
ps
{
str
.
begin
(),
str
.
end
()};
trait
::
parse_cli
(
ps
,
*
ptr
);
trait
::
parse_cli
(
ps
,
*
ptr
,
top_level_cli_parsing
);
if
(
ps
.
code
!=
pec
::
success
)
if
(
ps
.
code
!=
pec
::
success
)
return
make_error
(
ps
);
return
make_error
(
ps
);
return
config_value
{
trait
::
convert
(
*
ptr
)};
return
config_value
{
trait
::
convert
(
*
ptr
)};
...
...
libcaf_core/test/config_value.cpp
View file @
13e78371
...
@@ -18,6 +18,8 @@
...
@@ -18,6 +18,8 @@
#define CAF_SUITE config_value
#define CAF_SUITE config_value
#include "caf/config_value.hpp"
#include "core-test.hpp"
#include "core-test.hpp"
#include <list>
#include <list>
...
@@ -32,6 +34,7 @@
...
@@ -32,6 +34,7 @@
#include "caf/actor_system_config.hpp"
#include "caf/actor_system_config.hpp"
#include "caf/deep_to_string.hpp"
#include "caf/deep_to_string.hpp"
#include "caf/detail/bounds_checker.hpp"
#include "caf/detail/bounds_checker.hpp"
#include "caf/make_config_option.hpp"
#include "caf/none.hpp"
#include "caf/none.hpp"
#include "caf/pec.hpp"
#include "caf/pec.hpp"
#include "caf/string_view.hpp"
#include "caf/string_view.hpp"
...
@@ -252,6 +255,83 @@ CAF_TEST(successful parsing) {
...
@@ -252,6 +255,83 @@ CAF_TEST(successful parsing) {
CAF_CHECK_EQUAL
(
get
<
di
>
(
parse
(
"{a=1,b=2}"
)),
di
({{
"a"
,
1
},
{
"b"
,
2
}}));
CAF_CHECK_EQUAL
(
get
<
di
>
(
parse
(
"{a=1,b=2}"
)),
di
({{
"a"
,
1
},
{
"b"
,
2
}}));
}
}
#define CHECK_CLI_PARSE(type, str, ...) \
do { \
/* Note: parse_impl from make_config_option.hpp internally dispatches */
\
/* to parse_cli. No need to replicate that wrapping code here. */
\
if (auto res = caf::detail::parse_impl<type>(nullptr, str)) { \
type expected_res{__VA_ARGS__}; \
if (auto unboxed = ::caf::get_if<type>(std::addressof(*res))) { \
if (*unboxed == expected_res) \
CAF_CHECK_PASSED("parse(" << str << ") == " << expected_res); \
else \
CAF_CHECK_FAILED(*unboxed << " != " << expected_res); \
} else { \
CAF_CHECK_FAILED(*res << " != " << expected_res); \
} \
} else { \
CAF_CHECK_FAILED("parse(" << str << ") -> " << res.error()); \
} \
} while (false)
#define CHECK_CLI_PARSE_FAILS(type, str) \
do { \
if (auto res = caf::detail::parse_impl<type>(nullptr, str)) { \
CAF_CHECK_FAILED("unexpected parser result: " << *res); \
} else { \
CAF_CHECK_PASSED("parse(" << str << ") == " << res.error()); \
} \
} while (false)
CAF_TEST
(
parsing
via
parse_cli
enables
shortcut
syntax
for
some
types
)
{
using
ls
=
std
::
vector
<
string
>
;
// List-of-strings.
using
li
=
std
::
vector
<
int
>
;
// List-of-integers.
using
lli
=
std
::
vector
<
li
>
;
// List-of-list-of-integers.
CAF_MESSAGE
(
"lists can omit square brackets"
);
CHECK_CLI_PARSE
(
int
,
"123"
,
123
);
CHECK_CLI_PARSE
(
li
,
"[ 1,2 , 3 ,]"
,
1
,
2
,
3
);
CHECK_CLI_PARSE
(
li
,
"[ 1,2 , 3 ]"
,
1
,
2
,
3
);
CHECK_CLI_PARSE
(
li
,
" 1,2 , 3 ,"
,
1
,
2
,
3
);
CHECK_CLI_PARSE
(
li
,
" 1,2 , 3 "
,
1
,
2
,
3
);
CHECK_CLI_PARSE
(
li
,
" [ ] "
,
li
{});
CHECK_CLI_PARSE
(
li
,
" "
,
li
{});
CHECK_CLI_PARSE
(
li
,
""
,
li
{});
CHECK_CLI_PARSE
(
li
,
"[123]"
,
123
);
CHECK_CLI_PARSE
(
li
,
"123"
,
123
);
CAF_MESSAGE
(
"brackets must have matching opening/closing brackets"
);
CHECK_CLI_PARSE_FAILS
(
li
,
" 1,2 , 3 ,]"
);
CHECK_CLI_PARSE_FAILS
(
li
,
" 1,2 , 3 ]"
);
CHECK_CLI_PARSE_FAILS
(
li
,
"123]"
);
CHECK_CLI_PARSE_FAILS
(
li
,
"[ 1,2 , 3 ,"
);
CHECK_CLI_PARSE_FAILS
(
li
,
"[ 1,2 , 3 "
);
CHECK_CLI_PARSE_FAILS
(
li
,
"[123"
);
CAF_MESSAGE
(
"string lists can omit quotation marks"
);
CHECK_CLI_PARSE
(
string
,
R"_("123")_"
,
"123"
);
CHECK_CLI_PARSE
(
string
,
R"_(123)_"
,
"123"
);
CHECK_CLI_PARSE
(
ls
,
R"_([ "1 ","2" , "3" ,])_"
,
"1 "
,
"2"
,
"3"
);
CHECK_CLI_PARSE
(
ls
,
R"_([ 1,2 , 3 ,])_"
,
"1"
,
"2"
,
"3"
);
CHECK_CLI_PARSE
(
ls
,
R"_([ 1,2 , 3 ])_"
,
"1"
,
"2"
,
"3"
);
CHECK_CLI_PARSE
(
ls
,
R"_( 1,2 , 3 ,)_"
,
"1"
,
"2"
,
"3"
);
CHECK_CLI_PARSE
(
ls
,
R"_( 1,2 , 3 )_"
,
"1"
,
"2"
,
"3"
);
CHECK_CLI_PARSE
(
ls
,
R"_( [ ] )_"
,
ls
{});
CHECK_CLI_PARSE
(
ls
,
R"_( )_"
,
ls
{});
CHECK_CLI_PARSE
(
ls
,
R"_(["abc"])_"
,
"abc"
);
CHECK_CLI_PARSE
(
ls
,
R"_([abc])_"
,
"abc"
);
CHECK_CLI_PARSE
(
ls
,
R"_("abc")_"
,
"abc"
);
CHECK_CLI_PARSE
(
ls
,
R"_(abc)_"
,
"abc"
);
CAF_MESSAGE
(
"nested lists can omit the outer square brackets"
);
CHECK_CLI_PARSE
(
lli
,
"[[1, 2, 3, ], ]"
,
li
({
1
,
2
,
3
}));
CHECK_CLI_PARSE
(
lli
,
"[[1, 2, 3]]"
,
li
({
1
,
2
,
3
}));
CHECK_CLI_PARSE
(
lli
,
"[1, 2, 3, ]"
,
li
({
1
,
2
,
3
}));
CHECK_CLI_PARSE
(
lli
,
"[1, 2, 3]"
,
li
({
1
,
2
,
3
}));
CHECK_CLI_PARSE
(
lli
,
"[[1], [2]]"
,
li
({
1
}),
li
({
2
}));
CHECK_CLI_PARSE
(
lli
,
"[1], [2]"
,
li
({
1
}),
li
({
2
}));
CHECK_CLI_PARSE_FAILS
(
lli
,
"1"
);
CHECK_CLI_PARSE_FAILS
(
lli
,
"1, 2"
);
CHECK_CLI_PARSE_FAILS
(
lli
,
"[1, 2]]"
);
CHECK_CLI_PARSE_FAILS
(
lli
,
"[[1, 2]"
);
}
CAF_TEST
(
unsuccessful
parsing
)
{
CAF_TEST
(
unsuccessful
parsing
)
{
auto
parse
=
[](
const
string
&
str
)
{
auto
parse
=
[](
const
string
&
str
)
{
auto
x
=
config_value
::
parse
(
str
);
auto
x
=
config_value
::
parse
(
str
);
...
...
libcaf_core/test/make_config_value_field.cpp
View file @
13e78371
...
@@ -139,7 +139,7 @@ struct fixture {
...
@@ -139,7 +139,7 @@ struct fixture {
CAF_CHECK
(
!
foo_field
.
set
(
x
,
config_value
(
-
1
)));
CAF_CHECK
(
!
foo_field
.
set
(
x
,
config_value
(
-
1
)));
string_view
input
=
"123"
;
string_view
input
=
"123"
;
string_parser_state
ps
{
input
.
begin
(),
input
.
end
()};
string_parser_state
ps
{
input
.
begin
(),
input
.
end
()};
foo_field
.
parse_cli
(
ps
,
x
);
foo_field
.
parse_cli
(
ps
,
x
,
false
);
CAF_CHECK_EQUAL
(
ps
.
code
,
pec
::
success
);
CAF_CHECK_EQUAL
(
ps
.
code
,
pec
::
success
);
CAF_CHECK_EQUAL
(
foo_field
.
get
(
x
),
config_value
(
123
));
CAF_CHECK_EQUAL
(
foo_field
.
get
(
x
),
config_value
(
123
));
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment