Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
89 changes: 89 additions & 0 deletions tests/YGDefaultValuesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -173,3 +173,92 @@ TEST(YogaTest, assert_box_sizing_border_box) {

YGConfigFree(config);
}

TEST(YogaTest, width_keyword_replaces_pooled_number) {
const YGNodeRef node = YGNodeNew();
YGNodeStyleSetHeight(node, 0.5f);
YGNodeStyleSetWidth(node, 0.25f);
YGNodeStyleSetWidthMaxContent(node);
ASSERT_EQ(YGNodeStyleGetWidth(node).unit, YGUnitMaxContent);
YGNodeFree(node);
}

TEST(YogaTest, height_max_content_replaces_pooled_number) {
const YGNodeRef node = YGNodeNew();
YGNodeStyleSetWidth(node, 0.5f);
YGNodeStyleSetHeight(node, 0.25f);
YGNodeStyleSetHeightMaxContent(node);
ASSERT_EQ(YGNodeStyleGetHeight(node).unit, YGUnitMaxContent);
YGNodeFree(node);
}

TEST(YogaTest, width_fit_content_replaces_pooled_number) {
const YGNodeRef node = YGNodeNew();
YGNodeStyleSetWidth(node, 0.5f);
YGNodeStyleSetWidthFitContent(node);
ASSERT_EQ(YGNodeStyleGetWidth(node).unit, YGUnitFitContent);
YGNodeFree(node);
}

TEST(YogaTest, width_stretch_replaces_pooled_number) {
const YGNodeRef node = YGNodeNew();
YGNodeStyleSetWidth(node, 0.5f);
YGNodeStyleSetWidthStretch(node);
ASSERT_EQ(YGNodeStyleGetWidth(node).unit, YGUnitStretch);
YGNodeFree(node);
}

TEST(YogaTest, min_width_max_content_replaces_pooled_number) {
const YGNodeRef node = YGNodeNew();
YGNodeStyleSetHeight(node, 0.5f);
YGNodeStyleSetMinWidth(node, 0.25f);
YGNodeStyleSetMinWidthMaxContent(node);
ASSERT_EQ(YGNodeStyleGetMinWidth(node).unit, YGUnitMaxContent);
YGNodeFree(node);
}

TEST(YogaTest, max_width_stretch_replaces_pooled_number) {
const YGNodeRef node = YGNodeNew();
YGNodeStyleSetMaxWidth(node, 0.5f);
YGNodeStyleSetMaxWidthStretch(node);
ASSERT_EQ(YGNodeStyleGetMaxWidth(node).unit, YGUnitStretch);
YGNodeFree(node);
}

TEST(YogaTest, min_height_stretch_replaces_pooled_number) {
const YGNodeRef node = YGNodeNew();
YGNodeStyleSetWidth(node, 0.5f);
YGNodeStyleSetMinHeight(node, 0.25f);
YGNodeStyleSetMinHeightStretch(node);
ASSERT_EQ(YGNodeStyleGetMinHeight(node).unit, YGUnitStretch);
YGNodeFree(node);
}

TEST(YogaTest, max_height_max_content_replaces_pooled_number) {
const YGNodeRef node = YGNodeNew();
YGNodeStyleSetWidth(node, 0.5f);
YGNodeStyleSetMaxHeight(node, 0.25f);
YGNodeStyleSetMaxHeightMaxContent(node);
ASSERT_EQ(YGNodeStyleGetMaxHeight(node).unit, YGUnitMaxContent);
YGNodeFree(node);
}

TEST(YogaTest, flex_basis_max_content_replaces_pooled_number) {
const YGNodeRef node = YGNodeNew();
YGNodeStyleSetWidth(node, 0.5f);
YGNodeStyleSetFlexBasis(node, 0.25f);
YGNodeStyleSetFlexBasisMaxContent(node);
ASSERT_EQ(YGNodeStyleGetFlexBasis(node).unit, YGUnitMaxContent);
YGNodeFree(node);
}

TEST(YogaTest, flex_basis_max_content_replaces_unmatched_pool_index) {
const YGNodeRef node = YGNodeNew();
YGNodeStyleSetWidth(node, 0.5f);
YGNodeStyleSetHeight(node, 0.25f);
YGNodeStyleSetMinWidth(node, 0.75f);
YGNodeStyleSetFlexBasis(node, 1.5f);
YGNodeStyleSetFlexBasisMaxContent(node);
ASSERT_EQ(YGNodeStyleGetFlexBasis(node).unit, YGUnitMaxContent);
YGNodeFree(node);
}
4 changes: 4 additions & 0 deletions yoga/style/StyleValueHandle.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ class StyleValueHandle {
repr_ |= kHandleIndexedMask;
}

constexpr void setValueIsNotIndexed() {
repr_ &= (~kHandleIndexedMask);
}

uint16_t repr_{0};
};

Expand Down
12 changes: 4 additions & 8 deletions yoga/style/StyleValuePool.h
Original file line number Diff line number Diff line change
Expand Up @@ -155,14 +155,10 @@ class StyleValuePool {
StyleValueHandle& handle,
StyleValueHandle::Keyword keyword) {
handle.setType(StyleValueHandle::Type::Keyword);

if (handle.isValueIndexed()) {
auto newIndex =
buffer_.replace(handle.value(), static_cast<uint32_t>(keyword));
handle.setValue(newIndex);
} else {
handle.setValue(static_cast<uint16_t>(keyword));
}
// A keyword always fits in the handle. setValue keeps bit 3, so an
// existing pool index would be read back as Keyword's enum value.
handle.setValue(static_cast<uint16_t>(keyword));
handle.setValueIsNotIndexed();
}

static constexpr bool isIntegerPackable(float f) {
Expand Down