gentest for Java and C#
Summary: - Revise scripts to generate Java and C# unittests using the same HTML fixtures as well as C for code coverage. - Add wrap_column test workaround in gentest.js. - Add checkDefaultValues for sanity check of the CSSLayout default values by test-template.html - Add `align-content: flex-start;` in default div to align with CSSLayout default $ cd csharp/gentest $ ruby gentest.rb - macOS example for C# $ cd csharp/tests/Facebook.CSSLayout $ clang -DCSS_ASSERT_FAIL_ENABLED -Wall -Wextra -dynamiclib -o libCSSLayout.dylib -g -I../../.. ../../../CSSLayout/*.c ../../CSSLayout/CSSInterop.cpp $ mcs -debug -t:library -r:nunit.framework.dll -out:CSSLayoutTest.dll *.cs ../../../csharp/Facebook.CSSLayout/*cs $ mono64 --debug nunit-console.exe CSSLayoutTest.dll Reviewed By: emilsjolander Differential Revision: D4053777 fbshipit-source-id: 84450208015e65baf604987bd56c6a268598b545
This commit is contained in:
committed by
Facebook Github Bot
parent
1488f822c3
commit
dc5e613285
@@ -8,11 +8,35 @@
|
||||
*/
|
||||
|
||||
window.onload = function() {
|
||||
printTest(document.body.children[0], document.body.children[1], document.body.children[2]);
|
||||
checkDefaultValues();
|
||||
|
||||
printTest(
|
||||
new CPPEmitter(),
|
||||
document.body.children[0],
|
||||
document.body.children[1],
|
||||
document.body.children[2]);
|
||||
|
||||
printTest(
|
||||
new JavaEmitter(),
|
||||
document.body.children[0],
|
||||
document.body.children[1],
|
||||
document.body.children[2]);
|
||||
|
||||
printTest(
|
||||
new CSEmitter(),
|
||||
document.body.children[0],
|
||||
document.body.children[1],
|
||||
document.body.children[2]);
|
||||
}
|
||||
|
||||
function printTest(LTRContainer, RTLContainer, genericContainer) {
|
||||
var lines = [
|
||||
function assert(condition, message) {
|
||||
if (!condition) {
|
||||
throw new Error(message);
|
||||
}
|
||||
}
|
||||
|
||||
function printTest(e, LTRContainer, RTLContainer, genericContainer) {
|
||||
e.push([
|
||||
'/**',
|
||||
' * Copyright (c) 2014-present, Facebook, Inc.',
|
||||
' * All rights reserved.',
|
||||
@@ -22,14 +46,13 @@ function printTest(LTRContainer, RTLContainer, genericContainer) {
|
||||
' * of patent rights can be found in the PATENTS file in the same directory.',
|
||||
' */',
|
||||
'',
|
||||
];
|
||||
|
||||
lines.push('/**');
|
||||
lines.push(' * @Generated by gentest/gentest.sh with the following input');
|
||||
lines.push(' *');
|
||||
'/**',
|
||||
' * @Generated by gentest/gentest.sh with the following input',
|
||||
' *',
|
||||
]);
|
||||
|
||||
var indentation = 0;
|
||||
lines.push(genericContainer.innerHTML.split('\n').map(function(line) {
|
||||
e.push(genericContainer.innerHTML.split('\n').map(function(line) {
|
||||
return line.trim();
|
||||
}).filter(function(line) {
|
||||
return line.length > 0 && line !== '<div id="default"></div>';
|
||||
@@ -50,81 +73,106 @@ function printTest(LTRContainer, RTLContainer, genericContainer) {
|
||||
}
|
||||
return curr + '\n' + prev;
|
||||
}));
|
||||
lines.push(' *');
|
||||
lines.push(' */');
|
||||
lines.push('');
|
||||
|
||||
lines.push([
|
||||
'#include <CSSLayout/CSSLayout.h>',
|
||||
'#include <gtest/gtest.h>',
|
||||
e.push([
|
||||
' *',
|
||||
' */',
|
||||
'',
|
||||
].reduce(function(curr, prev) {
|
||||
return curr + '\n' + prev;
|
||||
}));
|
||||
]);
|
||||
e.emitPrologue();
|
||||
|
||||
var LTRLayoutTree = calculateTree(LTRContainer);
|
||||
var RTLLayoutTree = calculateTree(RTLContainer);
|
||||
var genericLayoutTree = calculateTree(genericContainer);
|
||||
|
||||
for (var i = 0; i < genericLayoutTree.length; i++) {
|
||||
lines.push('TEST(CSSLayoutTest, ' + genericLayoutTree[i].name + ') {');
|
||||
|
||||
lines.push(' ' + setupTestTree(
|
||||
for (var i = 0; i < genericLayoutTree.length; i++) {
|
||||
e.emitTestPrologue(genericLayoutTree[i].name);
|
||||
|
||||
if (genericLayoutTree[i].name == 'wrap_column') {
|
||||
// Modify width and left values due to both safari and chrome not abiding by the
|
||||
// specification. The undefined dimension of a parent should be defined by the total size
|
||||
// of their children in that dimension.
|
||||
// See diagram under flex-wrap header https://www.w3.org/TR/css-flexbox-1/
|
||||
assert(LTRLayoutTree[0].width == 30, 'wrap_column LTR root.width should be 30');
|
||||
LTRLayoutTree[0].width = 60;
|
||||
assert(RTLLayoutTree[0].width == 30, 'wrap_column RTL root.width should be 30');
|
||||
RTLLayoutTree[0].width = 60;
|
||||
var children = RTLLayoutTree[0].children;
|
||||
assert(children[0].left == 0, 'wrap_column RTL root_child0.left should be 0');
|
||||
children[0].left = 30;
|
||||
assert(children[1].left == 0, 'wrap_column RTL root_child0.left should be 0');
|
||||
children[1].left = 30;
|
||||
assert(children[2].left == 0, 'wrap_column RTL root_child2.left should be 0');
|
||||
children[2].left = 30;
|
||||
assert(children[3].left == -30, 'wrap_column RTL root_child3.left should be -30');
|
||||
children[3].left = 0;
|
||||
}
|
||||
|
||||
setupTestTree(
|
||||
e,
|
||||
undefined,
|
||||
LTRLayoutTree[i],
|
||||
genericLayoutTree[i],
|
||||
'root',
|
||||
null).reduce(function(curr, prev) {
|
||||
return curr + '\n ' + prev;
|
||||
}));
|
||||
null);
|
||||
|
||||
lines.push(' CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionLTR);');
|
||||
lines.push('');
|
||||
e.CSSNodeCalculateLayout('root', e.CSSDirectionLTR);
|
||||
e.push('');
|
||||
|
||||
lines.push(' ' + assertTestTree(LTRLayoutTree[i], 'root', null).reduce(function(curr, prev) {
|
||||
return curr + '\n ' + prev;
|
||||
}));
|
||||
lines.push('');
|
||||
assertTestTree(e, LTRLayoutTree[i], 'root', null);
|
||||
e.push('');
|
||||
|
||||
lines.push(' CSSNodeCalculateLayout(root, CSSUndefined, CSSUndefined, CSSDirectionRTL);');
|
||||
lines.push('');
|
||||
e.CSSNodeCalculateLayout('root', e.CSSDirectionRTL);
|
||||
e.push('');
|
||||
|
||||
lines.push(' ' + assertTestTree(RTLLayoutTree[i], 'root', null).reduce(function(curr, prev) {
|
||||
return curr + '\n ' + prev;
|
||||
}));
|
||||
assertTestTree(e, RTLLayoutTree[i], 'root', null);
|
||||
|
||||
lines.push('\n CSSNodeFreeRecursive(root);')
|
||||
lines.push('}');
|
||||
lines.push('');
|
||||
e.emitTestEpilogue();
|
||||
}
|
||||
e.emitEpilogue();
|
||||
|
||||
printLines(lines);
|
||||
e.print();
|
||||
}
|
||||
|
||||
function assertTestTree(node, nodeName, parentName) {
|
||||
var lines = [
|
||||
'ASSERT_EQ(' + node.left + ', CSSNodeLayoutGetLeft(' + nodeName + '));',
|
||||
'ASSERT_EQ(' + node.top + ', CSSNodeLayoutGetTop(' + nodeName + '));',
|
||||
'ASSERT_EQ(' + node.width + ', CSSNodeLayoutGetWidth(' + nodeName + '));',
|
||||
'ASSERT_EQ(' + node.height + ', CSSNodeLayoutGetHeight(' + nodeName + '));',
|
||||
];
|
||||
function assertTestTree(e, node, nodeName, parentName) {
|
||||
e.AssertEQ(node.left, e.CSSNodeLayoutGetLeft(nodeName));
|
||||
e.AssertEQ(node.top, e.CSSNodeLayoutGetTop(nodeName));
|
||||
e.AssertEQ(node.width, e.CSSNodeLayoutGetWidth(nodeName));
|
||||
e.AssertEQ(node.height, e.CSSNodeLayoutGetHeight(nodeName));
|
||||
|
||||
for (var i = 0; i < node.children.length; i++) {
|
||||
lines.push('');
|
||||
e.push('');
|
||||
var childName = nodeName + '_child' + i;
|
||||
lines = lines.concat(assertTestTree(node.children[i], childName, nodeName));
|
||||
assertTestTree(e, node.children[i], childName, nodeName);
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
function setupTestTree(parent, node, genericNode, nodeName, parentName, index) {
|
||||
var lines = [
|
||||
'const CSSNodeRef ' + nodeName + ' = CSSNodeNew();',
|
||||
];
|
||||
function checkDefaultValues() {
|
||||
// Sanity check of the CSSLayout default values by test-template.html
|
||||
[
|
||||
{style:'flex-direction', value:'column'},
|
||||
{style:'justify-content', value:'flex-start'},
|
||||
{style:'align-content', value:'flex-start'},
|
||||
{style:'align-items', value:'stretch'},
|
||||
{style:'position', value:'relative'},
|
||||
{style:'flex-wrap', value:'nowrap'},
|
||||
{style:'overflow', value:'visible'},
|
||||
{style:'flex-grow', value:'0'},
|
||||
{style:'flex-shrink', value:'0'},
|
||||
{style:'left', value:'0px'},
|
||||
{style:'top', value:'0px'},
|
||||
{style:'right', value:'0px'},
|
||||
{style:'bottom', value:'0px'},
|
||||
].forEach(function(item) {
|
||||
assert(item.value === getDefaultStyleValue(item.style),
|
||||
item.style + ' should be ' + item.value);
|
||||
});
|
||||
}
|
||||
|
||||
function setupTestTree(e, parent, node, genericNode, nodeName, parentName, index) {
|
||||
e.emitTestTreePrologue(nodeName);
|
||||
|
||||
for (var style in node.style) {
|
||||
|
||||
// Skip position info for root as it messes up tests
|
||||
if (node.declaredStyle[style] === "" &&
|
||||
(style == 'position' ||
|
||||
@@ -140,267 +188,225 @@ function setupTestTree(parent, node, genericNode, nodeName, parentName, index) {
|
||||
if (node.style[style] !== getDefaultStyleValue(style)) {
|
||||
switch (style) {
|
||||
case 'direction':
|
||||
lines.push('CSSNodeStyleSetDirection(' + nodeName + ', ' +
|
||||
directionValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetDirection(nodeName, directionValue(e, node.style[style]));
|
||||
break;
|
||||
case 'flex-direction':
|
||||
lines.push('CSSNodeStyleSetFlexDirection(' + nodeName + ', ' +
|
||||
flexDirectionValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetFlexDirection(nodeName, flexDirectionValue(e, node.style[style]));
|
||||
break;
|
||||
case 'justify-content':
|
||||
lines.push('CSSNodeStyleSetJustifyContent(' + nodeName + ', ' +
|
||||
justifyValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetJustifyContent(nodeName, justifyValue(e, node.style[style]));
|
||||
break;
|
||||
case 'align-content':
|
||||
lines.push('CSSNodeStyleSetAlignContent(' + nodeName + ', ' +
|
||||
alignValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetAlignContent(nodeName, alignValue(e, node.style[style]));
|
||||
break;
|
||||
case 'align-items':
|
||||
lines.push('CSSNodeStyleSetAlignItems(' + nodeName + ', ' +
|
||||
alignValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetAlignItems(nodeName, alignValue(e, node.style[style]));
|
||||
break;
|
||||
case 'align-self':
|
||||
if (!parent || node.style[style] !== parent.style['align-items']) {
|
||||
lines.push('CSSNodeStyleSetAlignSelf(' + nodeName + ', ' +
|
||||
alignValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetAlignSelf(nodeName, alignValue(e, node.style[style]));
|
||||
}
|
||||
break;
|
||||
case 'position':
|
||||
lines.push('CSSNodeStyleSetPositionType(' + nodeName + ', ' +
|
||||
positionValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPositionType(nodeName, positionValue(e, node.style[style]));
|
||||
break;
|
||||
case 'flex-wrap':
|
||||
lines.push('CSSNodeStyleSetFlexWrap(' + nodeName + ', ' +
|
||||
wrapValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetFlexWrap(nodeName, wrapValue(e, node.style[style]));
|
||||
break;
|
||||
case 'overflow':
|
||||
lines.push('CSSNodeStyleSetOverflow(' + nodeName + ', ' +
|
||||
overflowValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetOverflow(nodeName, overflowValue(e, node.style[style]));
|
||||
break;
|
||||
case 'flex-grow':
|
||||
lines.push('CSSNodeStyleSetFlexGrow(' + nodeName + ', ' + node.style[style] + ');');
|
||||
e.CSSNodeStyleSetFlexGrow(nodeName, node.style[style]);
|
||||
break;
|
||||
case 'flex-shrink':
|
||||
lines.push('CSSNodeStyleSetFlexShrink(' + nodeName + ', ' + node.style[style] + ');');
|
||||
e.CSSNodeStyleSetFlexShrink(nodeName, node.style[style]);
|
||||
break;
|
||||
case 'flex-basis':
|
||||
lines.push('CSSNodeStyleSetFlexBasis(' + nodeName + ', ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetFlexBasis(nodeName, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'left':
|
||||
if (genericNode.rawStyle.indexOf('start:') >= 0) {
|
||||
lines.push('CSSNodeStyleSetPosition(' + nodeName + ', CSSEdgeStart, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeStart, pixelValue(e, node.style[style]));
|
||||
} else {
|
||||
lines.push('CSSNodeStyleSetPosition(' + nodeName + ', CSSEdgeLeft, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeLeft, pixelValue(e, node.style[style]));
|
||||
}
|
||||
break;
|
||||
case 'top':
|
||||
lines.push('CSSNodeStyleSetPosition(' + nodeName + ', CSSEdgeTop, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeTop, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'right':
|
||||
if (genericNode.rawStyle.indexOf('end:') >= 0) {
|
||||
lines.push('CSSNodeStyleSetPosition(' + nodeName + ', CSSEdgeEnd, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeEnd, pixelValue(e, node.style[style]));
|
||||
} else {
|
||||
lines.push('CSSNodeStyleSetPosition(' + nodeName + ', CSSEdgeRight, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeRight, pixelValue(e, node.style[style]));
|
||||
}
|
||||
break;
|
||||
case 'bottom':
|
||||
lines.push('CSSNodeStyleSetPosition(' + nodeName + ', CSSEdgeBottom, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPosition(nodeName, e.CSSEdgeBottom, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'margin-left':
|
||||
if (genericNode.rawStyle.indexOf('margin-start:') >= 0) {
|
||||
lines.push('CSSNodeStyleSetMargin(' + nodeName + ', CSSEdgeStart, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeStart, pixelValue(e, node.style[style]));
|
||||
} else {
|
||||
lines.push('CSSNodeStyleSetMargin(' + nodeName + ', CSSEdgeLeft, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeLeft, pixelValue(e, node.style[style]));
|
||||
}
|
||||
break;
|
||||
case 'margin-top':
|
||||
lines.push('CSSNodeStyleSetMargin(' + nodeName + ', CSSEdgeTop, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeTop, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'margin-right':
|
||||
if (genericNode.rawStyle.indexOf('margin-end:') >= 0) {
|
||||
lines.push('CSSNodeStyleSetMargin(' + nodeName + ', CSSEdgeEnd, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeEnd, pixelValue(e, node.style[style]));
|
||||
} else {
|
||||
lines.push('CSSNodeStyleSetMargin(' + nodeName + ', CSSEdgeRight, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeRight, pixelValue(e, node.style[style]));
|
||||
}
|
||||
break;
|
||||
case 'margin-bottom':
|
||||
lines.push('CSSNodeStyleSetMargin(' + nodeName + ', CSSEdgeBottom, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetMargin(nodeName, e.CSSEdgeBottom, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'padding-left':
|
||||
if (genericNode.rawStyle.indexOf('padding-start:') >= 0) {
|
||||
lines.push('CSSNodeStyleSetPadding(' + nodeName + ', CSSEdgeStart, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeStart, pixelValue(e, node.style[style]));
|
||||
} else {
|
||||
lines.push('CSSNodeStyleSetPadding(' + nodeName + ', CSSEdgeLeft, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeLeft, pixelValue(e, node.style[style]));
|
||||
}
|
||||
break;
|
||||
case 'padding-top':
|
||||
lines.push('CSSNodeStyleSetPadding(' + nodeName + ', CSSEdgeTop, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeTop, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'padding-right':
|
||||
if (genericNode.rawStyle.indexOf('padding-end:') >= 0) {
|
||||
lines.push('CSSNodeStyleSetPadding(' + nodeName + ', CSSEdgeEnd, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeEnd, pixelValue(e, node.style[style]));
|
||||
} else {
|
||||
lines.push('CSSNodeStyleSetPadding(' + nodeName + ', CSSEdgeRight, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeRight, pixelValue(e, node.style[style]));
|
||||
}
|
||||
break;
|
||||
case 'padding-bottom':
|
||||
lines.push('CSSNodeStyleSetPadding(' + nodeName + ', CSSEdgeBottom, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetPadding(nodeName, e.CSSEdgeBottom, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'border-left-width':
|
||||
if (genericNode.rawStyle.indexOf('border-start-width:') >= 0) {
|
||||
lines.push('CSSNodeStyleSetBorder(' + nodeName + ', CSSEdgeStart, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeStart, pixelValue(e, node.style[style]));
|
||||
} else {
|
||||
lines.push('CSSNodeStyleSetBorder(' + nodeName + ', CSSEdgeLeft, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeLeft, pixelValue(e, node.style[style]));
|
||||
}
|
||||
break;
|
||||
case 'border-top-width':
|
||||
lines.push('CSSNodeStyleSetBorder(' + nodeName + ', CSSEdgeTop, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeTop, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'border-right-width':
|
||||
if (genericNode.rawStyle.indexOf('border-end-width:') >= 0) {
|
||||
lines.push('CSSNodeStyleSetBorder(' + nodeName + ', CSSEdgeEnd, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeEnd, pixelValue(e, node.style[style]));
|
||||
} else {
|
||||
lines.push('CSSNodeStyleSetBorder(' + nodeName + ', CSSEdgeRight, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeRight, pixelValue(e, node.style[style]));
|
||||
}
|
||||
break;
|
||||
case 'border-bottom-width':
|
||||
lines.push('CSSNodeStyleSetBorder(' + nodeName + ', CSSEdgeBottom, ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetBorder(nodeName, e.CSSEdgeBottom, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'width':
|
||||
lines.push('CSSNodeStyleSetWidth(' + nodeName + ', ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetWidth(nodeName, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'min-width':
|
||||
lines.push('CSSNodeStyleSetMinWidth(' + nodeName + ', ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetMinWidth(nodeName, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'max-width':
|
||||
lines.push('CSSNodeStyleSetMaxWidth(' + nodeName + ', ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetMaxWidth(nodeName, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'height':
|
||||
lines.push('CSSNodeStyleSetHeight(' + nodeName + ', ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetHeight(nodeName, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'min-height':
|
||||
lines.push('CSSNodeStyleSetMinHeight(' + nodeName + ', ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetMinHeight(nodeName, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
case 'max-height':
|
||||
lines.push('CSSNodeStyleSetMaxHeight(' + nodeName + ', ' +
|
||||
pixelValue(node.style[style]) + ');');
|
||||
e.CSSNodeStyleSetMaxHeight(nodeName, pixelValue(e, node.style[style]));
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (parentName) {
|
||||
lines.push('CSSNodeInsertChild(' + parentName + ', ' + nodeName + ', ' + index + ');');
|
||||
e.CSSNodeInsertChild(parentName, nodeName, index);
|
||||
}
|
||||
|
||||
for (var i = 0; i < node.children.length; i++) {
|
||||
lines.push('');
|
||||
e.push('');
|
||||
var childName = nodeName + '_child' + i;
|
||||
lines = lines.concat(
|
||||
setupTestTree(
|
||||
node,
|
||||
node.children[i],
|
||||
genericNode.children[i],
|
||||
childName,
|
||||
nodeName,
|
||||
i));
|
||||
}
|
||||
|
||||
return lines;
|
||||
}
|
||||
|
||||
function overflowValue(value) {
|
||||
switch (value) {
|
||||
case 'visible': return 'CSSOverflowVisible';
|
||||
case 'hidden': return 'CSSOverflowHidden';
|
||||
setupTestTree(
|
||||
e,
|
||||
node,
|
||||
node.children[i],
|
||||
genericNode.children[i],
|
||||
childName,
|
||||
nodeName,
|
||||
i);
|
||||
}
|
||||
}
|
||||
|
||||
function wrapValue(value) {
|
||||
function overflowValue(e, value) {
|
||||
switch (value) {
|
||||
case 'wrap': return 'CSSWrapTypeWrap';
|
||||
case 'nowrap': return 'CSSWrapTypeNoWrap';
|
||||
case 'visible': return e.CSSOverflowVisible;
|
||||
case 'hidden': return e.CSSOverflowHidden;
|
||||
}
|
||||
}
|
||||
|
||||
function flexDirectionValue(value) {
|
||||
function wrapValue(e, value) {
|
||||
switch (value) {
|
||||
case 'row': return 'CSSFlexDirectionRow';
|
||||
case 'row-reverse': return 'CSSFlexDirectionRowReverse';
|
||||
case 'column': return 'CSSFlexDirectionColumn';
|
||||
case 'column-reverse': return 'CSSFlexDirectionColumnReverse';
|
||||
case 'wrap': return e.CSSWrapTypeWrap;
|
||||
case 'nowrap': return e.CSSWrapTypeNoWrap;
|
||||
}
|
||||
}
|
||||
|
||||
function justifyValue(value) {
|
||||
function flexDirectionValue(e, value) {
|
||||
switch (value) {
|
||||
case 'center': return 'CSSJustifyCenter';
|
||||
case 'space-around': return 'CSSJustifySpaceAround';
|
||||
case 'space-between': return 'CSSJustifySpaceBetween';
|
||||
case 'flex-start': return 'CSSJustifyFlexStart';
|
||||
case 'flex-end': return 'CSSJustifyFlexEnd';
|
||||
case 'row': return e.CSSFlexDirectionRow;
|
||||
case 'row-reverse': return e.CSSFlexDirectionRowReverse;
|
||||
case 'column': return e.CSSFlexDirectionColumn;
|
||||
case 'column-reverse': return e.CSSFlexDirectionColumnReverse;
|
||||
}
|
||||
}
|
||||
|
||||
function positionValue(value) {
|
||||
function justifyValue(e, value) {
|
||||
switch (value) {
|
||||
case 'absolute': return 'CSSPositionTypeAbsolute';
|
||||
default: return 'CSSPositionTypeRelative'
|
||||
case 'center': return e.CSSJustifyCenter;
|
||||
case 'space-around': return e.CSSJustifySpaceAround;
|
||||
case 'space-between': return e.CSSJustifySpaceBetween;
|
||||
case 'flex-start': return e.CSSJustifyFlexStart;
|
||||
case 'flex-end': return e.CSSJustifyFlexEnd;
|
||||
}
|
||||
}
|
||||
|
||||
function directionValue(value) {
|
||||
function positionValue(e, value) {
|
||||
switch (value) {
|
||||
case 'ltr': return 'CSSDirectionLTR';
|
||||
case 'rtl': return 'CSSDirectionRTL';
|
||||
case 'inherit': return 'CSSDirectionInherit';
|
||||
case 'absolute': return e.CSSPositionTypeAbsolute;
|
||||
default: return e.CSSPositionTypeRelative
|
||||
}
|
||||
}
|
||||
|
||||
function alignValue(value) {
|
||||
function directionValue(e, value) {
|
||||
switch (value) {
|
||||
case 'auto': return 'CSSAlignAuto';
|
||||
case 'center': return 'CSSAlignCenter';
|
||||
case 'stretch': return 'CSSAlignStretch';
|
||||
case 'flex-start': return 'CSSAlignFlexStart';
|
||||
case 'flex-end': return 'CSSAlignFlexEnd';
|
||||
case 'ltr': return e.CSSDirectionLTR;
|
||||
case 'rtl': return e.CSSDirectionRTL;
|
||||
case 'inherit': return e.CSSDirectionInherit;
|
||||
}
|
||||
}
|
||||
|
||||
function pixelValue(value) {
|
||||
function alignValue(e, value) {
|
||||
switch (value) {
|
||||
case 'auto': return 'CSSUndefined';
|
||||
case 'undefined': return 'CSSUndefined';
|
||||
case 'auto': return e.CSSAlignAuto;
|
||||
case 'center': return e.CSSAlignCenter;
|
||||
case 'stretch': return e.CSSAlignStretch;
|
||||
case 'flex-start': return e.CSSAlignFlexStart;
|
||||
case 'flex-end': return e.CSSAlignFlexEnd;
|
||||
}
|
||||
}
|
||||
|
||||
function pixelValue(e, value) {
|
||||
switch (value) {
|
||||
case 'auto': return e.CSSUndefined;
|
||||
case 'undefined': return e.CSSUndefined;
|
||||
default: return value.replace('px', '');
|
||||
}
|
||||
}
|
||||
@@ -413,14 +419,6 @@ function getDefaultStyleValue(style) {
|
||||
return getComputedStyle(node, null).getPropertyValue(style);
|
||||
}
|
||||
|
||||
function printLines(lines) {
|
||||
console.log(lines.map(function(value) {
|
||||
return value + '\n';
|
||||
}).reduce(function(prev, curr) {
|
||||
return prev + curr;
|
||||
}, ''));
|
||||
}
|
||||
|
||||
function calculateTree(root) {
|
||||
var rootLayout = [];
|
||||
|
||||
@@ -483,3 +481,38 @@ function getCSSLayoutStyle(node) {
|
||||
return map;
|
||||
}, {});
|
||||
}
|
||||
|
||||
var Emitter = function(lang, indent) {
|
||||
this.lang = lang;
|
||||
this.indent = indent;
|
||||
this.indents = [];
|
||||
this.lines = [];
|
||||
};
|
||||
|
||||
Emitter.prototype = Object.create(Object.prototype, {
|
||||
constructor:{value:Emitter},
|
||||
|
||||
pushIndent:{value:function() {
|
||||
this.indents.push(this.indent);
|
||||
}},
|
||||
|
||||
popIndent:{value:function() {
|
||||
this.indents.pop();
|
||||
}},
|
||||
|
||||
push:{value:function(line) {
|
||||
if (line instanceof Array) {
|
||||
line.forEach(function(element) {
|
||||
this.push(element);
|
||||
}, this);
|
||||
return;
|
||||
} else if (line.length > 0) {
|
||||
line = this.indents.join('') + line;
|
||||
}
|
||||
this.lines.push(line);
|
||||
}},
|
||||
|
||||
print:{value:function() {
|
||||
console.log(this.lines.join('\n'));
|
||||
}},
|
||||
});
|
||||
|
Reference in New Issue
Block a user