348 lines
11 KiB
TypeScript
348 lines
11 KiB
TypeScript
![]() |
/**
|
||
|
* Copyright (c) Meta Platforms, Inc. and affiliates.
|
||
|
*
|
||
|
* This source code is licensed under the MIT license found in the
|
||
|
* LICENSE file in the root directory of this source tree.
|
||
|
*
|
||
|
* @generated SignedSource<<234cdb7f76ac586e034a5b6ca2033fa4>>
|
||
|
* generated by gentest/gentest-driver.ts from gentest/fixtures/YGAutoTest.html
|
||
|
*/
|
||
|
|
||
|
import { instrinsicSizeMeasureFunc } from '../tools/utils.ts'
|
||
|
import Yoga from 'yoga-layout';
|
||
|
import {
|
||
|
Align,
|
||
|
BoxSizing,
|
||
|
Direction,
|
||
|
Display,
|
||
|
Edge,
|
||
|
Errata,
|
||
|
ExperimentalFeature,
|
||
|
FlexDirection,
|
||
|
Gutter,
|
||
|
Justify,
|
||
|
MeasureMode,
|
||
|
Overflow,
|
||
|
PositionType,
|
||
|
Unit,
|
||
|
Wrap,
|
||
|
} from 'yoga-layout';
|
||
|
|
||
|
test('auto_width', () => {
|
||
|
const config = Yoga.Config.create();
|
||
|
let root;
|
||
|
|
||
|
try {
|
||
|
root = Yoga.Node.create(config);
|
||
|
root.setFlexDirection(FlexDirection.Row);
|
||
|
root.setPositionType(PositionType.Absolute);
|
||
|
root.setWidth('auto');
|
||
|
root.setHeight(50);
|
||
|
|
||
|
const root_child0 = Yoga.Node.create(config);
|
||
|
root_child0.setWidth(50);
|
||
|
root_child0.setHeight(50);
|
||
|
root.insertChild(root_child0, 0);
|
||
|
|
||
|
const root_child1 = Yoga.Node.create(config);
|
||
|
root_child1.setWidth(50);
|
||
|
root_child1.setHeight(50);
|
||
|
root.insertChild(root_child1, 1);
|
||
|
|
||
|
const root_child2 = Yoga.Node.create(config);
|
||
|
root_child2.setWidth(50);
|
||
|
root_child2.setHeight(50);
|
||
|
root.insertChild(root_child2, 2);
|
||
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
||
|
|
||
|
expect(root.getComputedLeft()).toBe(0);
|
||
|
expect(root.getComputedTop()).toBe(0);
|
||
|
expect(root.getComputedWidth()).toBe(150);
|
||
|
expect(root.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child1.getComputedLeft()).toBe(50);
|
||
|
expect(root_child1.getComputedTop()).toBe(0);
|
||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child2.getComputedLeft()).toBe(100);
|
||
|
expect(root_child2.getComputedTop()).toBe(0);
|
||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||
|
|
||
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
||
|
|
||
|
expect(root.getComputedLeft()).toBe(0);
|
||
|
expect(root.getComputedTop()).toBe(0);
|
||
|
expect(root.getComputedWidth()).toBe(150);
|
||
|
expect(root.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child0.getComputedLeft()).toBe(100);
|
||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child1.getComputedLeft()).toBe(50);
|
||
|
expect(root_child1.getComputedTop()).toBe(0);
|
||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child2.getComputedLeft()).toBe(0);
|
||
|
expect(root_child2.getComputedTop()).toBe(0);
|
||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||
|
} finally {
|
||
|
if (typeof root !== 'undefined') {
|
||
|
root.freeRecursive();
|
||
|
}
|
||
|
|
||
|
config.free();
|
||
|
}
|
||
|
});
|
||
|
test('auto_height', () => {
|
||
|
const config = Yoga.Config.create();
|
||
|
let root;
|
||
|
|
||
|
try {
|
||
|
root = Yoga.Node.create(config);
|
||
|
root.setPositionType(PositionType.Absolute);
|
||
|
root.setWidth(50);
|
||
|
root.setHeight('auto');
|
||
|
|
||
|
const root_child0 = Yoga.Node.create(config);
|
||
|
root_child0.setWidth(50);
|
||
|
root_child0.setHeight(50);
|
||
|
root.insertChild(root_child0, 0);
|
||
|
|
||
|
const root_child1 = Yoga.Node.create(config);
|
||
|
root_child1.setWidth(50);
|
||
|
root_child1.setHeight(50);
|
||
|
root.insertChild(root_child1, 1);
|
||
|
|
||
|
const root_child2 = Yoga.Node.create(config);
|
||
|
root_child2.setWidth(50);
|
||
|
root_child2.setHeight(50);
|
||
|
root.insertChild(root_child2, 2);
|
||
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
||
|
|
||
|
expect(root.getComputedLeft()).toBe(0);
|
||
|
expect(root.getComputedTop()).toBe(0);
|
||
|
expect(root.getComputedWidth()).toBe(50);
|
||
|
expect(root.getComputedHeight()).toBe(150);
|
||
|
|
||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child1.getComputedLeft()).toBe(0);
|
||
|
expect(root_child1.getComputedTop()).toBe(50);
|
||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child2.getComputedLeft()).toBe(0);
|
||
|
expect(root_child2.getComputedTop()).toBe(100);
|
||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||
|
|
||
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
||
|
|
||
|
expect(root.getComputedLeft()).toBe(0);
|
||
|
expect(root.getComputedTop()).toBe(0);
|
||
|
expect(root.getComputedWidth()).toBe(50);
|
||
|
expect(root.getComputedHeight()).toBe(150);
|
||
|
|
||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child1.getComputedLeft()).toBe(0);
|
||
|
expect(root_child1.getComputedTop()).toBe(50);
|
||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child2.getComputedLeft()).toBe(0);
|
||
|
expect(root_child2.getComputedTop()).toBe(100);
|
||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||
|
} finally {
|
||
|
if (typeof root !== 'undefined') {
|
||
|
root.freeRecursive();
|
||
|
}
|
||
|
|
||
|
config.free();
|
||
|
}
|
||
|
});
|
||
|
test('auto_flex_basis', () => {
|
||
|
const config = Yoga.Config.create();
|
||
|
let root;
|
||
|
|
||
|
try {
|
||
|
root = Yoga.Node.create(config);
|
||
|
root.setPositionType(PositionType.Absolute);
|
||
|
root.setWidth(50);
|
||
|
|
||
|
const root_child0 = Yoga.Node.create(config);
|
||
|
root_child0.setWidth(50);
|
||
|
root_child0.setHeight(50);
|
||
|
root.insertChild(root_child0, 0);
|
||
|
|
||
|
const root_child1 = Yoga.Node.create(config);
|
||
|
root_child1.setWidth(50);
|
||
|
root_child1.setHeight(50);
|
||
|
root.insertChild(root_child1, 1);
|
||
|
|
||
|
const root_child2 = Yoga.Node.create(config);
|
||
|
root_child2.setWidth(50);
|
||
|
root_child2.setHeight(50);
|
||
|
root.insertChild(root_child2, 2);
|
||
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
||
|
|
||
|
expect(root.getComputedLeft()).toBe(0);
|
||
|
expect(root.getComputedTop()).toBe(0);
|
||
|
expect(root.getComputedWidth()).toBe(50);
|
||
|
expect(root.getComputedHeight()).toBe(150);
|
||
|
|
||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child1.getComputedLeft()).toBe(0);
|
||
|
expect(root_child1.getComputedTop()).toBe(50);
|
||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child2.getComputedLeft()).toBe(0);
|
||
|
expect(root_child2.getComputedTop()).toBe(100);
|
||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||
|
|
||
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
||
|
|
||
|
expect(root.getComputedLeft()).toBe(0);
|
||
|
expect(root.getComputedTop()).toBe(0);
|
||
|
expect(root.getComputedWidth()).toBe(50);
|
||
|
expect(root.getComputedHeight()).toBe(150);
|
||
|
|
||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||
|
expect(root_child0.getComputedWidth()).toBe(50);
|
||
|
expect(root_child0.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child1.getComputedLeft()).toBe(0);
|
||
|
expect(root_child1.getComputedTop()).toBe(50);
|
||
|
expect(root_child1.getComputedWidth()).toBe(50);
|
||
|
expect(root_child1.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child2.getComputedLeft()).toBe(0);
|
||
|
expect(root_child2.getComputedTop()).toBe(100);
|
||
|
expect(root_child2.getComputedWidth()).toBe(50);
|
||
|
expect(root_child2.getComputedHeight()).toBe(50);
|
||
|
} finally {
|
||
|
if (typeof root !== 'undefined') {
|
||
|
root.freeRecursive();
|
||
|
}
|
||
|
|
||
|
config.free();
|
||
|
}
|
||
|
});
|
||
|
test('auto_position', () => {
|
||
|
const config = Yoga.Config.create();
|
||
|
let root;
|
||
|
|
||
|
try {
|
||
|
root = Yoga.Node.create(config);
|
||
|
root.setPositionType(PositionType.Absolute);
|
||
|
root.setWidth(50);
|
||
|
root.setHeight(50);
|
||
|
|
||
|
const root_child0 = Yoga.Node.create(config);
|
||
|
root_child0.setPositionAuto(Edge.Right);
|
||
|
root_child0.setWidth(25);
|
||
|
root_child0.setHeight(25);
|
||
|
root.insertChild(root_child0, 0);
|
||
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
||
|
|
||
|
expect(root.getComputedLeft()).toBe(0);
|
||
|
expect(root.getComputedTop()).toBe(0);
|
||
|
expect(root.getComputedWidth()).toBe(50);
|
||
|
expect(root.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child0.getComputedLeft()).toBe(0);
|
||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||
|
expect(root_child0.getComputedWidth()).toBe(25);
|
||
|
expect(root_child0.getComputedHeight()).toBe(25);
|
||
|
|
||
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
||
|
|
||
|
expect(root.getComputedLeft()).toBe(0);
|
||
|
expect(root.getComputedTop()).toBe(0);
|
||
|
expect(root.getComputedWidth()).toBe(50);
|
||
|
expect(root.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child0.getComputedLeft()).toBe(25);
|
||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||
|
expect(root_child0.getComputedWidth()).toBe(25);
|
||
|
expect(root_child0.getComputedHeight()).toBe(25);
|
||
|
} finally {
|
||
|
if (typeof root !== 'undefined') {
|
||
|
root.freeRecursive();
|
||
|
}
|
||
|
|
||
|
config.free();
|
||
|
}
|
||
|
});
|
||
|
test('auto_margin', () => {
|
||
|
const config = Yoga.Config.create();
|
||
|
let root;
|
||
|
|
||
|
try {
|
||
|
root = Yoga.Node.create(config);
|
||
|
root.setPositionType(PositionType.Absolute);
|
||
|
root.setWidth(50);
|
||
|
root.setHeight(50);
|
||
|
|
||
|
const root_child0 = Yoga.Node.create(config);
|
||
|
root_child0.setMargin(Edge.Left, 'auto');
|
||
|
root_child0.setWidth(25);
|
||
|
root_child0.setHeight(25);
|
||
|
root.insertChild(root_child0, 0);
|
||
|
root.calculateLayout(undefined, undefined, Direction.LTR);
|
||
|
|
||
|
expect(root.getComputedLeft()).toBe(0);
|
||
|
expect(root.getComputedTop()).toBe(0);
|
||
|
expect(root.getComputedWidth()).toBe(50);
|
||
|
expect(root.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child0.getComputedLeft()).toBe(25);
|
||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||
|
expect(root_child0.getComputedWidth()).toBe(25);
|
||
|
expect(root_child0.getComputedHeight()).toBe(25);
|
||
|
|
||
|
root.calculateLayout(undefined, undefined, Direction.RTL);
|
||
|
|
||
|
expect(root.getComputedLeft()).toBe(0);
|
||
|
expect(root.getComputedTop()).toBe(0);
|
||
|
expect(root.getComputedWidth()).toBe(50);
|
||
|
expect(root.getComputedHeight()).toBe(50);
|
||
|
|
||
|
expect(root_child0.getComputedLeft()).toBe(25);
|
||
|
expect(root_child0.getComputedTop()).toBe(0);
|
||
|
expect(root_child0.getComputedWidth()).toBe(25);
|
||
|
expect(root_child0.getComputedHeight()).toBe(25);
|
||
|
} finally {
|
||
|
if (typeof root !== 'undefined') {
|
||
|
root.freeRecursive();
|
||
|
}
|
||
|
|
||
|
config.free();
|
||
|
}
|
||
|
});
|