gentest: allow for different default values

Summary:
@public

We use Chrome for generating test cases, which since v67 (or so) for `min-width` and `min-height` has a default value of either `0px` (CSS 2) or `auto` (CSS 3), depending on style properties.

Our setup only allowed for a single default value, and our test cases produce *both.*
This changes the test gen logic to allow for more than one value.

Reviewed By: SidharthGuglani

Differential Revision: D14682387

fbshipit-source-id: e76361f5cc0b88f9c2d74a5f3248c66abd6907a7
This commit is contained in:
David Aurelio
2019-03-29 06:26:59 -07:00
committed by Facebook Github Bot
parent c235301b52
commit 1fc8472d35
5 changed files with 36 additions and 25 deletions

View File

@@ -213,8 +213,6 @@ namespace Facebook.Yoga
root_child1_child0.FlexShrink = 1; root_child1_child0.FlexShrink = 1;
root_child1_child0.FlexBasis = 0.Percent(); root_child1_child0.FlexBasis = 0.Percent();
root_child1_child0.Width = 20; root_child1_child0.Width = 20;
root_child1_child0.MinWidth = 0;
root_child1_child0.MinHeight = 0;
root_child1.Insert(0, root_child1_child0); root_child1.Insert(0, root_child1_child0);
YogaNode root_child2 = new YogaNode(config); YogaNode root_child2 = new YogaNode(config);

View File

@@ -137,7 +137,7 @@ function checkDefaultValues() {
{style:'bottom', value:'undefined'}, {style:'bottom', value:'undefined'},
{style:'display', value:'flex'}, {style:'display', value:'flex'},
].forEach(function(item) { ].forEach(function(item) {
assert(item.value === getDefaultStyleValue(item.style), assert(isDefaultStyleValue(item.style, item.value),
item.style + ' should be ' + item.value); item.style + ' should be ' + item.value);
}); });
} }
@@ -156,9 +156,11 @@ function setupTestTree(e, parent, node, genericNode, nodeName, parentName, index
style == 'width' || style == 'width' ||
style == 'height')) { style == 'height')) {
continue; continue;
}
if (node.style[style] !== getDefaultStyleValue(style)) {
var DEFAULT_STYLES = Object.create }
if (!isDefaultStyleValue(style, node.style[style])) {
switch (style) { switch (style) {
case 'direction': case 'direction':
e.YGNodeStyleSetDirection(nodeName, directionValue(e, node.style[style])); e.YGNodeStyleSetDirection(nodeName, directionValue(e, node.style[style]));
@@ -399,21 +401,38 @@ function displayValue(e, value){
} }
} }
function getDefaultStyleValue(style) { var DEFAULT_STYLES = new Map();
if (style == 'position') {
return 'relative'; function isDefaultStyleValue(style, value) {
let defaultStyle = DEFAULT_STYLES.get(style);
if (defaultStyle == null) {
switch (style) {
case 'position':
defaultStyle = new Set(['relative']);;
break;
case 'left':
case 'top':
case 'right':
case 'bottom':
case 'start':
case 'end':
defaultStyle = new Set(['undefined']);
break;
case 'min-height':
case 'min-width':
defaultStyle = new Set(['0', '0px', 'auto']);
break;
default:
var node = document.getElementById('default');
defaultStyle = new Set([getComputedStyle(node, null)[style]]);
break;
}
DEFAULT_STYLES.set(style, defaultStyle);
} }
switch (style) { return DEFAULT_STYLES.get(style).has(value);
case 'left':
case 'top':
case 'right':
case 'bottom':
case 'start':
case 'end':
return 'undefined';
}
var node = document.getElementById('default');
return getComputedStyle(node, null).getPropertyValue(style);
} }
function getRoundedSize(node) { function getRoundedSize(node) {

View File

@@ -218,8 +218,6 @@ public class YGDisplayTest {
root_child1_child0.setFlexShrink(1f); root_child1_child0.setFlexShrink(1f);
root_child1_child0.setFlexBasisPercent(0f); root_child1_child0.setFlexBasisPercent(0f);
root_child1_child0.setWidth(20f); root_child1_child0.setWidth(20f);
root_child1_child0.setMinWidth(0f);
root_child1_child0.setMinHeight(0f);
root_child1.addChildAt(root_child1_child0, 0); root_child1.addChildAt(root_child1_child0, 0);
final YogaNode root_child2 = createNode(config); final YogaNode root_child2 = createNode(config);

View File

@@ -215,8 +215,6 @@ it("display_none_with_child", function () {
root_child1_child0.setFlexShrink(1); root_child1_child0.setFlexShrink(1);
root_child1_child0.setFlexBasis("0%"); root_child1_child0.setFlexBasis("0%");
root_child1_child0.setWidth(20); root_child1_child0.setWidth(20);
root_child1_child0.setMinWidth(0);
root_child1_child0.setMinHeight(0);
root_child1.insertChild(root_child1_child0, 0); root_child1.insertChild(root_child1_child0, 0);
var root_child2 = Yoga.Node.create(config); var root_child2 = Yoga.Node.create(config);

View File

@@ -206,8 +206,6 @@ TEST(YogaTest, display_none_with_child) {
YGNodeStyleSetFlexShrink(root_child1_child0, 1); YGNodeStyleSetFlexShrink(root_child1_child0, 1);
YGNodeStyleSetFlexBasisPercent(root_child1_child0, 0); YGNodeStyleSetFlexBasisPercent(root_child1_child0, 0);
YGNodeStyleSetWidth(root_child1_child0, 20); YGNodeStyleSetWidth(root_child1_child0, 20);
YGNodeStyleSetMinWidth(root_child1_child0, 0);
YGNodeStyleSetMinHeight(root_child1_child0, 0);
YGNodeInsertChild(root_child1, root_child1_child0, 0); YGNodeInsertChild(root_child1, root_child1_child0, 0);
const YGNodeRef root_child2 = YGNodeNewWithConfig(config); const YGNodeRef root_child2 = YGNodeNewWithConfig(config);