Skip to content

Commit

Permalink
Add default test for box sizing (#1716)
Browse files Browse the repository at this point in the history
Summary:
X-link: facebook/react-native#46800

Pull Request resolved: #1716

Had a mini heart attack thinking I set the default to content box. Wrote this to double check and it passed. Might as well check it in

Technically the default to BoxSizing.h is ContentBox, but in the style we override that. Regardless I switched that around so border box was the default.

Changelog: [Internal]

Reviewed By: NickGerleman

Differential Revision: D63802722

fbshipit-source-id: 49ed29657c964bc12a2bf70988061ab4599267ec
  • Loading branch information
joevilches authored and facebook-github-bot committed Oct 3, 2024
1 parent 3351e8e commit 990ec92
Show file tree
Hide file tree
Showing 7 changed files with 24 additions and 13 deletions.
2 changes: 1 addition & 1 deletion enums.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
"PositionType": ["Static", "Relative", "Absolute"],
"Display": ["Flex", "None"],
"Wrap": ["NoWrap", "Wrap", "WrapReverse"],
"BoxSizing": ["ContentBox", "BorderBox"],
"BoxSizing": ["BorderBox", "ContentBox"],
"MeasureMode": ["Undefined", "Exactly", "AtMost"],
"Dimension": ["Width", "Height"],
"Edge": [
Expand Down
8 changes: 4 additions & 4 deletions java/com/facebook/yoga/YogaBoxSizing.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@
package com.facebook.yoga;

public enum YogaBoxSizing {
CONTENT_BOX(0),
BORDER_BOX(1);
BORDER_BOX(0),
CONTENT_BOX(1);

private final int mIntValue;

Expand All @@ -25,8 +25,8 @@ public int intValue() {

public static YogaBoxSizing fromInt(int value) {
switch (value) {
case 0: return CONTENT_BOX;
case 1: return BORDER_BOX;
case 0: return BORDER_BOX;
case 1: return CONTENT_BOX;
default: throw new IllegalArgumentException("Unknown enum value: " + value);
}
}
Expand Down
6 changes: 3 additions & 3 deletions javascript/src/generated/YGEnums.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,8 @@ export enum Align {
}

export enum BoxSizing {
ContentBox = 0,
BorderBox = 1,
BorderBox = 0,
ContentBox = 1,
}

export enum Dimension {
Expand Down Expand Up @@ -142,8 +142,8 @@ const constants = {
ALIGN_SPACE_BETWEEN: Align.SpaceBetween,
ALIGN_SPACE_AROUND: Align.SpaceAround,
ALIGN_SPACE_EVENLY: Align.SpaceEvenly,
BOX_SIZING_CONTENT_BOX: BoxSizing.ContentBox,
BOX_SIZING_BORDER_BOX: BoxSizing.BorderBox,
BOX_SIZING_CONTENT_BOX: BoxSizing.ContentBox,
DIMENSION_WIDTH: Dimension.Width,
DIMENSION_HEIGHT: Dimension.Height,
DIRECTION_INHERIT: Direction.Inherit,
Expand Down
11 changes: 11 additions & 0 deletions tests/YGDefaultValuesTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -162,3 +162,14 @@ TEST(YogaTest, assert_legacy_stretch_behaviour) {

YGConfigFree(config);
}

TEST(YogaTest, assert_box_sizing_border_box) {
YGConfig* config = YGConfigNew();
YGNodeRef root = YGNodeNewWithConfig(config);

ASSERT_EQ(YGBoxSizingBorderBox, YGNodeStyleGetBoxSizing(root));

YGNodeFreeRecursive(root);

YGConfigFree(config);
}
4 changes: 2 additions & 2 deletions yoga/YGEnums.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ const char* YGAlignToString(const YGAlign value) {

const char* YGBoxSizingToString(const YGBoxSizing value) {
switch (value) {
case YGBoxSizingContentBox:
return "content-box";
case YGBoxSizingBorderBox:
return "border-box";
case YGBoxSizingContentBox:
return "content-box";
}
return "unknown";
}
Expand Down
4 changes: 2 additions & 2 deletions yoga/YGEnums.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ YG_ENUM_DECL(

YG_ENUM_DECL(
YGBoxSizing,
YGBoxSizingContentBox,
YGBoxSizingBorderBox)
YGBoxSizingBorderBox,
YGBoxSizingContentBox)

YG_ENUM_DECL(
YGDimension,
Expand Down
2 changes: 1 addition & 1 deletion yoga/enums/BoxSizing.h
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
namespace facebook::yoga {

enum class BoxSizing : uint8_t {
ContentBox = YGBoxSizingContentBox,
BorderBox = YGBoxSizingBorderBox,
ContentBox = YGBoxSizingContentBox,
};

template <>
Expand Down

0 comments on commit 990ec92

Please sign in to comment.