Skip to content
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

Handle binary and int values in ValueSlot::copyValue #172

Merged
merged 1 commit into from
Jul 19, 2023
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
7 changes: 7 additions & 0 deletions Fleece/Mutable/ValueSlot.cc
Original file line number Diff line number Diff line change
Expand Up @@ -256,6 +256,13 @@ namespace fleece { namespace impl {
case kStringTag:
set(value->asString());
break;
case kBinaryTag:
setData(value->asData());
break;
case kIntTag:
if (value->isUnsigned()) set(value->asUnsigned());
else set(value->asInt());
break;
case kFloatTag:
set(value->asDouble());
break;
Expand Down
29 changes: 29 additions & 0 deletions Tests/API_ValueTests.cc
Original file line number Diff line number Diff line change
Expand Up @@ -366,3 +366,32 @@ TEST_CASE("API MutableDict item bool conversion", "[API]") {
}
CHECK(dict.toJSONString() == "{\"a_key\":6}");
}


TEST_CASE("API Mutable copy of Dict with int", "[API]") {
auto enc = fleece::Encoder();
enc.beginDict();
enc.writeKey("a");
enc.writeInt(0xFFFFFFFFFFFFFF);
enc.endDict();
auto data = enc.finish();
auto doc = Doc(data);
auto copy = doc.root().asDict().mutableCopy(kFLCopyImmutables);
CHECK(copy.count() == 1);
CHECK(copy["a"].type() == kFLNumber);
CHECK(copy["a"].asInt() == 0xFFFFFFFFFFFFFF);
}

TEST_CASE("API Mutable copy of Dict with data", "[API]") {
auto enc = fleece::Encoder();
enc.beginDict();
enc.writeKey("a");
enc.writeData("aaaaaaaaaaaaaaaa"_sl);
enc.endDict();
auto data = enc.finish();
auto doc = Doc(data);
auto copy = doc.root().asDict().mutableCopy(kFLCopyImmutables);
CHECK(copy.count() == 1);
CHECK(copy["a"].type() == kFLData);
CHECK(copy["a"].asData() == "aaaaaaaaaaaaaaaa"_sl);
}