Skip to content

Commit 6522782

Browse files
committed
Refactor: adapt tests to optional change
1 parent 814523f commit 6522782

2 files changed

Lines changed: 11 additions & 11 deletions

File tree

code-gen/tests/cpp_gen_test.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,7 @@ def test_render_template_default_member_values() -> None:
404404

405405
result = cpp_gen._render_template(parsed_idl, {"package": "test"})
406406

407-
assert "int foo = 42;".replace(" ", "") in result.replace(" ", "")
407+
assert "std::optional<int> foo = 42;".replace(" ", "") in result.replace(" ", "")
408408
assert "std::optional<int> bar;".replace(" ", "") in result.replace(" ", "")
409409
assert "namespace test" in result
410410

@@ -549,7 +549,7 @@ def test__render_template_string_default_value() -> None:
549549
for match in matches:
550550
struct_body = match[1]
551551
if match[0] == "Foo":
552-
assert 'std::string foo = "bar";'.replace(" ", "") in struct_body.replace(" ", "")
552+
assert 'std::optional<std::string> foo = "bar";'.replace(" ", "") in struct_body.replace(" ", "")
553553

554554

555555
def test__render_template_boolean_default_value() -> None:
@@ -572,8 +572,8 @@ def test__render_template_boolean_default_value() -> None:
572572
for match in matches:
573573
struct_body = match[1]
574574
if match[0] == "Foo":
575-
assert "bool foo = true;".replace(" ", "") in struct_body.replace(" ", "")
576-
assert "bool bar = false;".replace(" ", "") in struct_body.replace(" ", "")
575+
assert "std::optional<bool> foo = true;".replace(" ", "") in struct_body.replace(" ", "")
576+
assert "std::optional<bool> bar = false;".replace(" ", "") in struct_body.replace(" ", "")
577577

578578

579579
def test_render_template_struct_with_multi_inheritance() -> None:
@@ -673,4 +673,4 @@ def test_render_template_struct_with_empty_type_default() -> None:
673673
for match in matches:
674674
struct_body = match[1]
675675
if match[0] == "Data":
676-
assert "Base_t base = Foo{};".replace(" ", "") in struct_body.replace(" ", "")
676+
assert "std::optional<Base_t> base = Foo{};".replace(" ", "") in struct_body.replace(" ", "")

code-gen/tests/py_gen_test.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ def test_render_template_default_member_values() -> None:
285285

286286
result = py_gen._render_template(parsed_idl, {"package": "test"})
287287

288-
assert "foo: int = 42".replace(" ", "") in result.replace(" ", "")
288+
assert "foo: Optional[int] = 42".replace(" ", "") in result.replace(" ", "")
289289
assert "bar: Optional[int] = None".replace(" ", "") in result.replace(" ", "")
290290

291291

@@ -564,7 +564,7 @@ def test__render_template_string_default_value() -> None:
564564
for match in matches:
565565
struct_body = match[2]
566566
if match[0] == "Foo":
567-
assert 'foo: str = "bar"'.replace(" ", "") in struct_body.replace(" ", "")
567+
assert 'foo: Optional[str] = "bar"'.replace(" ", "") in struct_body.replace(" ", "")
568568

569569

570570
def test_render_template_struct_with_empty_type_default() -> None:
@@ -600,7 +600,7 @@ def test_render_template_struct_with_empty_type_default() -> None:
600600
for match in matches:
601601
struct_body = match[2]
602602
if match[0] == "Data":
603-
assert 'base: Annotated[Union["Foo", "Bar", "Base"],Field(discriminator="type")] = Foo()'.replace(
603+
assert 'base: Optional[Annotated[Union["Foo", "Bar", "Base"],Field(discriminator="type")]] = Foo()'.replace(
604604
" ", ""
605605
) in struct_body.replace(" ", "")
606606
elif match[0] == "Base":
@@ -609,7 +609,7 @@ def test_render_template_struct_with_empty_type_default() -> None:
609609
assert 'type: Literal["Foo"] = "Foo"'.replace(" ", "") in struct_body.replace(" ", "")
610610
elif match[0] == "Bar":
611611
assert 'type: Literal["Bar"] = "Bar"'.replace(" ", "") in struct_body.replace(" ", "")
612-
assert "value: int = int()".replace(" ", "") in struct_body.replace(" ", "")
612+
assert "value: Optional[int] = int()".replace(" ", "") in struct_body.replace(" ", "")
613613

614614

615615
def test__render_template_boolean_default_value() -> None:
@@ -630,5 +630,5 @@ def test__render_template_boolean_default_value() -> None:
630630
for match in matches:
631631
struct_body = match[2]
632632
if match[0] == "Foo":
633-
assert "foo: bool = True".replace(" ", "") in struct_body.replace(" ", "")
634-
assert "bar: bool = False".replace(" ", "") in struct_body.replace(" ", "")
633+
assert "foo: Optional[bool] = True".replace(" ", "") in struct_body.replace(" ", "")
634+
assert "bar: Optional[bool] = False".replace(" ", "") in struct_body.replace(" ", "")

0 commit comments

Comments
 (0)