Skip to content

Commit

Permalink
better empty tests
Browse files Browse the repository at this point in the history
  • Loading branch information
grencez committed May 21, 2024
1 parent 5125ea1 commit 846dc00
Show file tree
Hide file tree
Showing 11 changed files with 56 additions and 30 deletions.
14 changes: 9 additions & 5 deletions src/sxproto/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -97,12 +97,16 @@ write_json_FildeshO(
putc_FildeshO(out, '{');
NEWLINE_INDENT(indent_level+1);
if (e->field_kind == FildeshSxprotoFieldKind_MESSAGE) {
assert(!fildesh_nullid(e->elem) && "Manyof cannot hold nameless message values.");
print_quoted_sxpb_str_FildeshO(out, e->text);
putstrlit_FildeshO(out, ": {");
write_json_FildeshO(out, sxpb, sub_it, indent_level+2);
NEWLINE_INDENT(indent_level+1);
putc_FildeshO(out, '}');
if (fildesh_nullid(e->elem)) {
putstrlit_FildeshO(out, ": {}");
}
else {
putstrlit_FildeshO(out, ": {");
write_json_FildeshO(out, sxpb, sub_it, indent_level+2);
NEWLINE_INDENT(indent_level+1);
putc_FildeshO(out, '}');
}
}
else if (e->field_kind == FildeshSxprotoFieldKind_ARRAY ||
e->field_kind == FildeshSxprotoFieldKind_MANYOF)
Expand Down
14 changes: 9 additions & 5 deletions src/sxproto/txtpb.c
Original file line number Diff line number Diff line change
Expand Up @@ -82,12 +82,16 @@ write_txtpb_FildeshO(
if (e->field_kind == FildeshSxprotoFieldKind_MESSAGE ||
e->field_kind == FildeshSxprotoFieldKind_LONEOF)
{
assert(!fildesh_nullid(e->elem) && "Manyof cannot hold nameless message values.");
putstr_FildeshO(out, e->text);
putstrlit_FildeshO(out, " {");
write_txtpb_FildeshO(out, sxpb, sub_it, indent_level+2);
NEWLINE_INDENT(indent_level+1);
putc_FildeshO(out, '}');
if (fildesh_nullid(e->elem)) {
putstrlit_FildeshO(out, " {}");
}
else {
putstrlit_FildeshO(out, " {");
write_txtpb_FildeshO(out, sxpb, sub_it, indent_level+2);
NEWLINE_INDENT(indent_level+1);
putc_FildeshO(out, '}');
}
}
else if (e->field_kind == FildeshSxprotoFieldKind_ARRAY ||
e->field_kind == FildeshSxprotoFieldKind_MANYOF)
Expand Down
8 changes: 6 additions & 2 deletions src/sxproto/yaml.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,13 @@ write_yaml_FildeshO(
NEWLINE_INDENT(indent_level, on_indented_line);
putstrlit_FildeshO(out, "- ");
if (e->field_kind == FildeshSxprotoFieldKind_MESSAGE) {
assert(!fildesh_nullid(e->elem) && "Manyof cannot hold nameless message values.");
print_yaml_key_FildeshO(out, e);
write_yaml_FildeshO(out, sxpb, sub_it, indent_level+1, false);
if (fildesh_nullid(e->elem)) {
putstrlit_FildeshO(out, " {}");
}
else {
write_yaml_FildeshO(out, sxpb, sub_it, indent_level+1, false);
}
}
else if (e->field_kind == FildeshSxprotoFieldKind_ARRAY ||
e->field_kind == FildeshSxprotoFieldKind_MANYOF)
Expand Down
2 changes: 1 addition & 1 deletion test/sxproto/content/array.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,5 +10,5 @@
"i": 5,
"s": "hello"
}],
"maybe_elements": []
"my_empty_array": []
}
2 changes: 1 addition & 1 deletion test/sxproto/content/array.sxpb
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@
(() (i 5) (f 5.5) (s "hello")))

; An empty array.
((maybe_elements))
((my_empty_array))
2 changes: 1 addition & 1 deletion test/sxproto/content/array.txtpb
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ my_messages: [{
i: 5
s: "hello"
}]
maybe_elements: []
my_empty_array: []
2 changes: 1 addition & 1 deletion test/sxproto/content/array.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@ my_messages:
- f: 5.5e+0
i: 5
s: "hello"
maybe_elements: []
my_empty_array: []
12 changes: 7 additions & 5 deletions test/sxproto/content/manyof.json
Original file line number Diff line number Diff line change
Expand Up @@ -41,11 +41,13 @@
"value": true
}]
}]
}],
"maybe_manyof": [],
"maybe_manyof_elements": [{
"maybe_array": []
}, {
"or": [{
"or": []
}, {
"and": []
}]
"maybe_manyof": []
}, {
"maybe_message": {}
}]
}
10 changes: 9 additions & 1 deletion test/sxproto/content/manyof.sxpb
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,14 @@
false
(((and)) true false)
(((or)) false false true))
)

; An empty manyof.
(((maybe_manyof)))

((or) ((or)) ((and)))
; A manyof with empty elements.
((maybe_manyof_elements)
((maybe_array))
(((maybe_manyof)))
(maybe_message)
)
12 changes: 7 additions & 5 deletions test/sxproto/content/manyof.txtpb
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,12 @@ expressions: [{
value: true
}]
}]
}]
maybe_manyof: []
maybe_manyof_elements: [{
maybe_array: []
}, {
or: [{
or: []
}, {
and: []
}]
maybe_manyof: []
}, {
maybe_message {}
}]
8 changes: 5 additions & 3 deletions test/sxproto/content/manyof.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ expressions:
- value: false
- value: false
- value: true
- or:
- or: []
- and: []
maybe_manyof: []
maybe_manyof_elements:
- maybe_array: []
- maybe_manyof: []
- maybe_message: {}

0 comments on commit 846dc00

Please sign in to comment.