Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
L
libsonata
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Model registry
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
BlueBrain
libsonata
Commits
03394020
Unverified
Commit
03394020
authored
Sep 22, 2023
by
Michael Emiel Gevaert
Committed by
GitHub
Sep 22, 2023
Browse files
Options
Downloads
Patches
Plain Diff
Fix toJSON incorrect empty, node_id and compound problems (#289)
parent
c04ed235
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/node_sets.cpp
+21
-7
21 additions, 7 deletions
src/node_sets.cpp
tests/test_node_sets.cpp
+21
-6
21 additions, 6 deletions
tests/test_node_sets.cpp
with
42 additions
and
13 deletions
src/node_sets.cpp
+
21
−
7
View file @
03394020
...
...
@@ -28,7 +28,9 @@ using json = nlohmann::json;
void
replace_trailing_coma
(
std
::
string
&
s
,
char
c
)
{
s
.
pop_back
();
if
(
s
.
back
()
==
','
)
{
s
.
pop_back
();
}
s
.
push_back
(
c
);
}
...
...
@@ -119,10 +121,18 @@ class NodeSets
std
::
string
toJSON
()
const
{
std
::
string
ret
{
"{
\n
"
};
for
(
const
auto
&
pair
:
node_sets_
)
{
if
(
pair
.
second
->
is_compound
())
{
ret
+=
fmt
::
format
(
" {},
\n
"
,
pair
.
second
->
toJSON
());
}
else
{
std
::
string
contents
=
pair
.
second
->
toJSON
();
if
(
contents
.
empty
())
{
continue
;
}
ret
+=
fmt
::
format
(
R"( "{}": {{)"
,
pair
.
first
);
ret
+=
pair
.
second
->
toJSON
()
;
ret
+=
contents
;
ret
+=
"},
\n
"
;
}
}
replace_trailing_coma
(
ret
,
'\n'
);
ret
+=
"}"
;
...
...
@@ -221,7 +231,7 @@ class NodeSetBasicNodeIds: public NodeSetRule
}
std
::
string
toJSON
()
const
final
{
return
toString
(
"node_id
s
"
,
values_
);
return
toString
(
"node_id"
,
values_
);
}
std
::
unique_ptr
<
NodeSetRule
>
clone
()
const
final
{
...
...
@@ -254,7 +264,11 @@ class NodeSetBasicMultiClause: public NodeSetRule
std
::
string
toJSON
()
const
final
{
std
::
string
ret
;
for
(
const
auto
&
clause
:
clauses_
)
{
ret
+=
clause
->
toJSON
();
std
::
string
contents
=
clause
->
toJSON
();
if
(
contents
.
empty
())
{
continue
;
}
ret
+=
contents
;
ret
+=
", "
;
}
replace_trailing_coma
(
ret
,
' '
);
...
...
@@ -422,7 +436,7 @@ class NodeSetCompoundRule: public NodeSetRule
}
std
::
string
toJSON
()
const
final
{
return
toString
(
"node_ids"
,
targets_
);
return
toString
(
name_
,
targets_
);
}
bool
is_compound
()
const
override
{
...
...
This diff is collapsed.
Click to expand it.
tests/test_node_sets.cpp
+
21
−
6
View file @
03394020
...
...
@@ -293,6 +293,7 @@ TEST_CASE("NodeSet") {
})"
;
SECTION
(
"toJSON"
)
{
{
NodeSets
ns0
(
node_sets
);
std
::
string
j
=
ns0
.
toJSON
();
NodeSets
ns1
(
j
);
...
...
@@ -302,6 +303,20 @@ TEST_CASE("NodeSet") {
CHECK
(
ns
.
toJSON
()
==
ns1
.
toJSON
());
}
{
NodeSets
ns0
(
R"({"AND": {"node_id": [], "mtype": "L6_Y"}})"
);
CHECK
(
ns0
.
toJSON
()
==
"{
\n
\"
AND
\"
: {
\"
mtype
\"
: [
\"
L6_Y
\"
] }
\n
}"
);
}
{
NodeSets
ns0
(
R"({"NAME": {"node_id": []}})"
);
CHECK
(
ns0
.
toJSON
()
==
"{
\n
}"
);
NodeSets
ns1
(
R"({})"
);
CHECK
(
ns1
.
toJSON
()
==
"{
\n
}"
);
}
}
SECTION
(
"names"
)
{
NodeSets
ns
(
node_sets
);
std
::
set
<
std
::
string
>
expected
=
{
"bio_layer45"
,
"V1_point_prime"
,
"combined"
,
"power_number_test"
,
"power_regex_test"
};
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
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!
Save comment
Cancel
Please
sign in
to comment