Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Utils
KWSys
Commits
09942f51
Commit
09942f51
authored
Apr 08, 2020
by
Ben Boeckel
⛰
Committed by
Brad King
Apr 09, 2020
Browse files
testSystemTools: add tests for SplitString
parent
95a97253
Changes
1
Hide whitespace changes
Inline
Side-by-side
testSystemTools.cxx
View file @
09942f51
...
...
@@ -1120,6 +1120,42 @@ static bool CheckURLParsing()
return
ret
;
}
static
bool
CheckSplitString
()
{
bool
ret
=
true
;
auto
check_split
=
[](
std
::
string
const
&
input
,
std
::
initializer_list
<
const
char
*>
expected
)
->
bool
{
auto
const
components
=
kwsys
::
SystemTools
::
SplitString
(
input
,
'/'
);
if
(
components
.
size
()
!=
expected
.
size
())
{
std
::
cerr
<<
"Incorrect split count for "
<<
input
<<
": "
<<
components
.
size
()
<<
std
::
endl
;
return
false
;
}
size_t
i
=
0
;
for
(
auto
&
part
:
expected
)
{
if
(
components
[
i
]
!=
part
)
{
std
::
cerr
<<
"Incorrect split component "
<<
i
<<
" for "
<<
input
<<
": "
<<
components
[
i
]
<<
std
::
endl
;
return
false
;
}
++
i
;
}
return
true
;
};
// No separators
ret
&=
check_split
(
"nosep"
,
{
"nosep"
});
// Simple
ret
&=
check_split
(
"first/second"
,
{
"first"
,
"second"
});
// Separator at beginning
ret
&=
check_split
(
"/starts/sep"
,
{
""
,
"starts"
,
"sep"
});
// Separator at end
ret
&=
check_split
(
"ends/sep/"
,
{
"ends"
,
"sep"
,
""
});
return
ret
;
}
int
testSystemTools
(
int
,
char
*
[])
{
bool
res
=
true
;
...
...
@@ -1169,5 +1205,7 @@ int testSystemTools(int, char* [])
res
&=
CheckURLParsing
();
res
&=
CheckSplitString
();
return
res
?
0
:
1
;
}
Brad King
@brad.king
mentioned in commit
b62956f5
·
Apr 10, 2020
mentioned in commit
b62956f5
mentioned in commit b62956f5d70fef750e8414342f1566a29e8e7899
Toggle commit list
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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