Skip to content

CXX-3082 Rename ASSERT to EXPECT in API examples #1230

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Oct 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ namespace {
// [Example]
// [1, 2.0, "three"]
void example(bsoncxx::array::view arr) {
ASSERT(std::distance(arr.begin(), arr.end()) == 3);
EXPECT(std::distance(arr.begin(), arr.end()) == 3);

std::vector<bsoncxx::array::element> elements;

Expand All @@ -37,9 +37,9 @@ void example(bsoncxx::array::view arr) {
return e.key().compare("0") == 0 || e.type() == bsoncxx::type::k_string;
});

ASSERT(elements.size() == 2u);
ASSERT(elements[0].key().compare("0") == 0);
ASSERT(elements[1].key().compare("2") == 0);
EXPECT(elements.size() == 2u);
EXPECT(elements[0].key().compare("0") == 0);
EXPECT(elements[1].key().compare("2") == 0);
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ void example(bsoncxx::array::view arr) {
for (bsoncxx::array::element e : arr) {
switch (e.type()) {
case bsoncxx::type::k_int32:
ASSERT(e.key().compare("0") == 0);
ASSERT(e.get_int32().value == 1);
EXPECT(e.key().compare("0") == 0);
EXPECT(e.get_int32().value == 1);
break;
case bsoncxx::type::k_double:
ASSERT(e.key().compare("1") == 0);
ASSERT(e.get_double().value == 2.0);
EXPECT(e.key().compare("1") == 0);
EXPECT(e.get_double().value == 2.0);
break;
case bsoncxx::type::k_string:
ASSERT(e.key().compare("2") == 0);
ASSERT(e.get_string().value.compare("three") == 0);
EXPECT(e.key().compare("2") == 0);
EXPECT(e.get_string().value.compare("three") == 0);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ namespace {
// [Example]
// [1, 2]
void example(bsoncxx::array::view arr) {
ASSERT(arr.find(0) == arr.begin());
EXPECT(arr.find(0) == arr.begin());

{
auto iter = arr.find(1);

ASSERT(iter != arr.end());
ASSERT(iter->key().compare("1") == 0);
ASSERT(iter->get_int32().value == 2);
EXPECT(iter != arr.end());
EXPECT(iter->key().compare("1") == 0);
EXPECT(iter->get_int32().value == 2);
}

ASSERT(arr.find(2) == arr.end());
EXPECT(arr.find(2) == arr.end());
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ namespace {
// [Example]
// [1, 2]
void example(bsoncxx::array::view arr) {
ASSERT(arr.begin() != arr.end());
EXPECT(arr.begin() != arr.end());

auto iter = arr.begin();
ASSERT(iter == arr.begin());
EXPECT(iter == arr.begin());

{
bsoncxx::array::element e = *iter;

ASSERT(e.key().compare("0") == 0);
ASSERT(e.get_int32().value == 1);
EXPECT(e.key().compare("0") == 0);
EXPECT(e.get_int32().value == 1);
}

++iter;

ASSERT(iter->key().compare("1") == 0);
ASSERT(iter->get_int32().value == 2);
EXPECT(iter->key().compare("1") == 0);
EXPECT(iter->get_int32().value == 2);

{
auto iter_copy = iter++;

ASSERT(iter_copy != iter);
ASSERT(iter_copy->key().compare("1") == 0);
ASSERT(iter_copy->get_int32() == 2);
EXPECT(iter_copy != iter);
EXPECT(iter_copy->key().compare("1") == 0);
EXPECT(iter_copy->get_int32() == 2);
}

ASSERT(iter == arr.end());
EXPECT(iter == arr.end());
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ namespace {
// [Example]
// [1, 2]
void example(bsoncxx::array::view arr) {
ASSERT(arr[0]);
EXPECT(arr[0]);

{
bsoncxx::array::element e = arr[1];

ASSERT(e.key().compare("1") == 0);
ASSERT(e.get_int32().value == 2);
EXPECT(e.key().compare("1") == 0);
EXPECT(e.get_int32().value == 2);
}

ASSERT(!arr[2]); // Invalid element.
EXPECT(!arr[2]); // Invalid element.
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ namespace {
// [Example]
// {"a": 1, "b": 2.0, "c": "three"}
void example(bsoncxx::document::view doc) {
ASSERT(std::distance(doc.begin(), doc.end()) == 3);
EXPECT(std::distance(doc.begin(), doc.end()) == 3);

std::vector<bsoncxx::document::element> elements;

Expand All @@ -40,9 +40,9 @@ void example(bsoncxx::document::view doc) {
return e.key().compare("a") == 0 || e.type() == bsoncxx::type::k_string;
});

ASSERT(elements.size() == 2u);
ASSERT(elements[0].key().compare("a") == 0);
ASSERT(elements[1].key().compare("c") == 0);
EXPECT(elements.size() == 2u);
EXPECT(elements[0].key().compare("a") == 0);
EXPECT(elements[1].key().compare("c") == 0);
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,16 +28,16 @@ void example(bsoncxx::document::view doc) {
for (bsoncxx::document::element e : doc) {
switch (e.type()) {
case bsoncxx::type::k_int32:
ASSERT(e.key().compare("a") == 0);
ASSERT(e.get_int32().value == 1);
EXPECT(e.key().compare("a") == 0);
EXPECT(e.get_int32().value == 1);
break;
case bsoncxx::type::k_double:
ASSERT(e.key().compare("b") == 0);
ASSERT(e.get_double().value == 2.0);
EXPECT(e.key().compare("b") == 0);
EXPECT(e.get_double().value == 2.0);
break;
case bsoncxx::type::k_string:
ASSERT(e.key().compare("c") == 0);
ASSERT(e.get_string().value.compare("three") == 0);
EXPECT(e.key().compare("c") == 0);
EXPECT(e.get_string().value.compare("three") == 0);
break;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,17 +24,17 @@ namespace {
// [Example]
// {"a": 1, "b": 2}
void example(bsoncxx::document::view doc) {
ASSERT(doc.find("a") == doc.begin());
EXPECT(doc.find("a") == doc.begin());

{
auto iter = doc.find("b");

ASSERT(iter != doc.end());
ASSERT(iter->key().compare("b") == 0);
ASSERT(iter->get_int32().value == 2);
EXPECT(iter != doc.end());
EXPECT(iter->key().compare("b") == 0);
EXPECT(iter->get_int32().value == 2);
}

ASSERT(doc.find("x") == doc.end());
EXPECT(doc.find("x") == doc.end());
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,32 +25,32 @@ namespace {
// [Example]
// {"a": 1, "b": 2}
void example(bsoncxx::document::view doc) {
ASSERT(doc.begin() != doc.end());
EXPECT(doc.begin() != doc.end());

auto iter = doc.begin();
ASSERT(iter == doc.begin());
EXPECT(iter == doc.begin());

{
bsoncxx::document::element e = *iter;

ASSERT(e.key().compare("a") == 0);
ASSERT(e.get_int32().value == 1);
EXPECT(e.key().compare("a") == 0);
EXPECT(e.get_int32().value == 1);
}

++iter;

ASSERT(iter->key().compare("b") == 0);
ASSERT(iter->get_int32().value == 2);
EXPECT(iter->key().compare("b") == 0);
EXPECT(iter->get_int32().value == 2);

{
auto iter_copy = iter++;

ASSERT(iter_copy != iter);
ASSERT(iter_copy->key().compare("b") == 0);
ASSERT(iter_copy->get_int32() == 2);
EXPECT(iter_copy != iter);
EXPECT(iter_copy->key().compare("b") == 0);
EXPECT(iter_copy->get_int32() == 2);
}

ASSERT(iter == doc.end());
EXPECT(iter == doc.end());
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,16 @@ namespace {
// [Example]
// {"a": 1, "b": 2}
void example(bsoncxx::document::view doc) {
ASSERT(doc["a"]);
EXPECT(doc["a"]);

{
bsoncxx::document::element e = doc["b"];

ASSERT(e.key().compare("b") == 0);
ASSERT(e.get_int32().value == 2);
EXPECT(e.key().compare("b") == 0);
EXPECT(e.get_int32().value == 2);
}

ASSERT(!doc["c"]); // Invalid element.
EXPECT(!doc["c"]); // Invalid element.
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,9 @@ void example() {
bsoncxx::array::value owner = builder.extract();
bsoncxx::array::view arr = owner.view();

ASSERT(arr[0].get_int32().value == 1);
ASSERT(arr[1].get_double().value == 2.0);
ASSERT(arr[2].get_string().value.compare("three") == 0);
EXPECT(arr[0].get_int32().value == 1);
EXPECT(arr[1].get_double().value == 2.0);
EXPECT(arr[2].get_string().value.compare("three") == 0);
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ void example() {
bsoncxx::array::value owner = builder.extract();
bsoncxx::array::view arr = owner.view();

ASSERT(arr[0].get_int32().value == 1);
ASSERT(arr[1].get_double().value == 2.0);
ASSERT(arr[2].get_string().value.compare("three") == 0);
EXPECT(arr[0].get_int32().value == 1);
EXPECT(arr[1].get_double().value == 2.0);
EXPECT(arr[2].get_string().value.compare("three") == 0);
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,13 @@ void example() {
bsoncxx::array::value owner = bsoncxx::builder::basic::make_array(a, b, c);
bsoncxx::array::view arr = owner.view();

ASSERT(arr[0].type() == bsoncxx::type::k_int32);
ASSERT(arr[1].type() == bsoncxx::type::k_double);
ASSERT(arr[2].type() == bsoncxx::type::k_string);
EXPECT(arr[0].type() == bsoncxx::type::k_int32);
EXPECT(arr[1].type() == bsoncxx::type::k_double);
EXPECT(arr[2].type() == bsoncxx::type::k_string);

ASSERT(arr[0].get_int32().value == 1);
ASSERT(arr[1].get_double().value == 2.0);
ASSERT(arr[2].get_string().value.compare("three") == 0);
EXPECT(arr[0].get_int32().value == 1);
EXPECT(arr[1].get_double().value == 2.0);
EXPECT(arr[2].get_string().value.compare("three") == 0);
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,13 +40,13 @@ void example() {
bsoncxx::builder::basic::make_array(values[0], values[1], values[2]);
bsoncxx::array::view arr = owner.view();

ASSERT(arr[0].type() == bsoncxx::type::k_int32);
ASSERT(arr[1].type() == bsoncxx::type::k_double);
ASSERT(arr[2].type() == bsoncxx::type::k_string);
EXPECT(arr[0].type() == bsoncxx::type::k_int32);
EXPECT(arr[1].type() == bsoncxx::type::k_double);
EXPECT(arr[2].type() == bsoncxx::type::k_string);

ASSERT(arr[0].get_value() == values[0]);
ASSERT(arr[1].get_value() == values[1]);
ASSERT(arr[2].get_value() == values[2]);
EXPECT(arr[0].get_value() == values[0]);
EXPECT(arr[1].get_value() == values[1]);
EXPECT(arr[2].get_value() == values[2]);
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ void example(bsoncxx::array::view a, bsoncxx::array::view b) {
builder.append(bsoncxx::builder::concatenate(a));
builder.append(bsoncxx::builder::concatenate(b));

ASSERT(builder.view() == bsoncxx::builder::basic::make_array(1, 2));
EXPECT(builder.view() == bsoncxx::builder::basic::make_array(1, 2));
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,9 @@ void example() {
bsoncxx::builder::basic::make_array(std::int32_t{1}, 2.0, "three");
bsoncxx::array::view arr = owner.view();

ASSERT(arr[0].get_int32().value == 1);
ASSERT(arr[1].get_double().value == 2.0);
ASSERT(arr[2].get_string().value.compare("three") == 0);
EXPECT(arr[0].get_int32().value == 1);
EXPECT(arr[1].get_double().value == 2.0);
EXPECT(arr[2].get_string().value.compare("three") == 0);
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@ void example(const std::uint8_t* data, std::size_t length) {
bsoncxx::array::value owner{raw, length, deleter};
bsoncxx::array::view arr = owner.view();

ASSERT(arr[0].get_int32().value == 1);
ASSERT(arr[1].get_int32().value == 2);
EXPECT(arr[0].get_int32().value == 1);
EXPECT(arr[1].get_int32().value == 2);
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,8 @@ namespace {
void example(const std::uint8_t* data, std::size_t length) {
bsoncxx::array::view arr{data, length};

ASSERT(arr[0].get_int32().value == 1);
ASSERT(arr[1].get_int32().value == 2);
EXPECT(arr[0].get_int32().value == 1);
EXPECT(arr[1].get_int32().value == 2);
}
// [Example]

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,11 @@ void example() {
bsoncxx::array::view a = a_owner.view();
bsoncxx::array::view b = b_owner.view();

ASSERT(a[0].type() == bsoncxx::type::k_int32);
ASSERT(b[0].type() == bsoncxx::type::k_int64);
EXPECT(a[0].type() == bsoncxx::type::k_int32);
EXPECT(b[0].type() == bsoncxx::type::k_int64);

ASSERT(a[0].get_int32().value == 1);
ASSERT(b[0].get_int64().value == 2);
EXPECT(a[0].get_int32().value == 1);
EXPECT(b[0].get_int64().value == 2);
}
// [Example]

Expand Down
Loading