Skip to content

Commit c8c2396

Browse files
committed
Add unit test for single member struct encoding
Because this was previously broken and is now fixed.
1 parent 6e6babd commit c8c2396

File tree

1 file changed

+32
-0
lines changed

1 file changed

+32
-0
lines changed

unit/solvers/smt2_incremental/struct_encoding.cpp

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,35 @@ TEST_CASE("struct encoding of expressions", "[core][smt2_incremental]")
105105
REQUIRE(test.struct_encoding.encode(struct_expr) == expected_result);
106106
}
107107
}
108+
109+
TEST_CASE(
110+
"encoding of single member struct expressions",
111+
"[core][smt2_incremental]")
112+
{
113+
const struct_union_typet::componentst component_types{
114+
{"eggs", signedbv_typet{32}}};
115+
const type_symbolt type_symbol{"foot", struct_typet{component_types}, ID_C};
116+
auto test = struct_encoding_test_environmentt::make();
117+
test.symbol_table.insert(type_symbol);
118+
const struct_tag_typet struct_tag{type_symbol.name};
119+
const symbolt struct_value_symbol{"foo", struct_tag, ID_C};
120+
test.symbol_table.insert(struct_value_symbol);
121+
const auto symbol_expr = struct_value_symbol.symbol_expr();
122+
const auto symbol_expr_as_bv = symbol_exprt{"foo", bv_typet{32}};
123+
SECTION("struct typed symbol expression")
124+
{
125+
REQUIRE(test.struct_encoding.encode(symbol_expr) == symbol_expr_as_bv);
126+
}
127+
SECTION("struct equality expression")
128+
{
129+
const auto struct_equal = equal_exprt{symbol_expr, symbol_expr};
130+
const auto bv_equal = equal_exprt{symbol_expr_as_bv, symbol_expr_as_bv};
131+
REQUIRE(test.struct_encoding.encode(struct_equal) == bv_equal);
132+
}
133+
SECTION("expression for a struct from (single item) list of components")
134+
{
135+
const auto dozen = from_integer(12, signedbv_typet{32});
136+
const struct_exprt struct_expr{{dozen}, struct_tag};
137+
REQUIRE(test.struct_encoding.encode(struct_expr) == dozen);
138+
}
139+
}

0 commit comments

Comments
 (0)