Update tests.

This commit is contained in:
Huy Nguyen 2015-06-23 18:47:50 +07:00
parent 64e2323a4e
commit 4ad64b2841
9 changed files with 205 additions and 196 deletions

View File

@ -330,7 +330,6 @@
ACF6ED5C1B178DC700DA7C62 /* ASCenterLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED531B178DC700DA7C62 /* ASCenterLayoutNodeSnapshotTests.mm */; }; ACF6ED5C1B178DC700DA7C62 /* ASCenterLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED531B178DC700DA7C62 /* ASCenterLayoutNodeSnapshotTests.mm */; };
ACF6ED5D1B178DC700DA7C62 /* ASDimensionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED541B178DC700DA7C62 /* ASDimensionTests.mm */; }; ACF6ED5D1B178DC700DA7C62 /* ASDimensionTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED541B178DC700DA7C62 /* ASDimensionTests.mm */; };
ACF6ED5E1B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED551B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm */; }; ACF6ED5E1B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED551B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm */; };
ACF6ED5F1B178DC700DA7C62 /* ASLayoutNodeSizeTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED561B178DC700DA7C62 /* ASLayoutNodeSizeTests.mm */; };
ACF6ED601B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED581B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.m */; }; ACF6ED601B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.m in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED581B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.m */; };
ACF6ED611B178DC700DA7C62 /* ASOverlayLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED591B178DC700DA7C62 /* ASOverlayLayoutNodeSnapshotTests.mm */; }; ACF6ED611B178DC700DA7C62 /* ASOverlayLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED591B178DC700DA7C62 /* ASOverlayLayoutNodeSnapshotTests.mm */; };
ACF6ED621B178DC700DA7C62 /* ASRatioLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED5A1B178DC700DA7C62 /* ASRatioLayoutNodeSnapshotTests.mm */; }; ACF6ED621B178DC700DA7C62 /* ASRatioLayoutNodeSnapshotTests.mm in Sources */ = {isa = PBXBuildFile; fileRef = ACF6ED5A1B178DC700DA7C62 /* ASRatioLayoutNodeSnapshotTests.mm */; };
@ -558,7 +557,6 @@
ACF6ED531B178DC700DA7C62 /* ASCenterLayoutNodeSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASCenterLayoutNodeSnapshotTests.mm; sourceTree = "<group>"; }; ACF6ED531B178DC700DA7C62 /* ASCenterLayoutNodeSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASCenterLayoutNodeSnapshotTests.mm; sourceTree = "<group>"; };
ACF6ED541B178DC700DA7C62 /* ASDimensionTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASDimensionTests.mm; sourceTree = "<group>"; }; ACF6ED541B178DC700DA7C62 /* ASDimensionTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASDimensionTests.mm; sourceTree = "<group>"; };
ACF6ED551B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASInsetLayoutNodeSnapshotTests.mm; sourceTree = "<group>"; }; ACF6ED551B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASInsetLayoutNodeSnapshotTests.mm; sourceTree = "<group>"; };
ACF6ED561B178DC700DA7C62 /* ASLayoutNodeSizeTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASLayoutNodeSizeTests.mm; sourceTree = "<group>"; };
ACF6ED571B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASLayoutNodeSnapshotTestsHelper.h; sourceTree = "<group>"; }; ACF6ED571B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = ASLayoutNodeSnapshotTestsHelper.h; sourceTree = "<group>"; };
ACF6ED581B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ASLayoutNodeSnapshotTestsHelper.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; }; ACF6ED581B178DC700DA7C62 /* ASLayoutNodeSnapshotTestsHelper.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = ASLayoutNodeSnapshotTestsHelper.m; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
ACF6ED591B178DC700DA7C62 /* ASOverlayLayoutNodeSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASOverlayLayoutNodeSnapshotTests.mm; sourceTree = "<group>"; }; ACF6ED591B178DC700DA7C62 /* ASOverlayLayoutNodeSnapshotTests.mm */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.objcpp; path = ASOverlayLayoutNodeSnapshotTests.mm; sourceTree = "<group>"; };
@ -746,7 +744,6 @@
058D0A2F195D057000B7D73C /* ASDisplayNodeTests.m */, 058D0A2F195D057000B7D73C /* ASDisplayNodeTests.m */,
058D0A30195D057000B7D73C /* ASDisplayNodeTestsHelper.h */, 058D0A30195D057000B7D73C /* ASDisplayNodeTestsHelper.h */,
058D0A31195D057000B7D73C /* ASDisplayNodeTestsHelper.m */, 058D0A31195D057000B7D73C /* ASDisplayNodeTestsHelper.m */,
ACF6ED561B178DC700DA7C62 /* ASLayoutNodeSizeTests.mm */,
052EE0651A159FEF002C6279 /* ASMultiplexImageNodeTests.m */, 052EE0651A159FEF002C6279 /* ASMultiplexImageNodeTests.m */,
058D0A32195D057000B7D73C /* ASMutableAttributedStringBuilderTests.m */, 058D0A32195D057000B7D73C /* ASMutableAttributedStringBuilderTests.m */,
3C9C128419E616EF00E942A0 /* ASTableViewTests.m */, 3C9C128419E616EF00E942A0 /* ASTableViewTests.m */,
@ -1420,7 +1417,6 @@
058D0A3F195D057000B7D73C /* ASTextNodeShadowerTests.m in Sources */, 058D0A3F195D057000B7D73C /* ASTextNodeShadowerTests.m in Sources */,
ACF6ED631B178DC700DA7C62 /* ASStackLayoutNodeSnapshotTests.mm in Sources */, ACF6ED631B178DC700DA7C62 /* ASStackLayoutNodeSnapshotTests.mm in Sources */,
29CDC2E21AAE70D000833CA4 /* ASBasicImageDownloaderContextTests.m in Sources */, 29CDC2E21AAE70D000833CA4 /* ASBasicImageDownloaderContextTests.m in Sources */,
ACF6ED5F1B178DC700DA7C62 /* ASLayoutNodeSizeTests.mm in Sources */,
056D21551ABCEF50001107EF /* ASImageNodeSnapshotTests.m in Sources */, 056D21551ABCEF50001107EF /* ASImageNodeSnapshotTests.m in Sources */,
05EA6FE71AC0966E00E35788 /* ASSnapshotTestCase.mm in Sources */, 05EA6FE71AC0966E00E35788 /* ASSnapshotTestCase.mm in Sources */,
ACF6ED5E1B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm in Sources */, ACF6ED5E1B178DC700DA7C62 /* ASInsetLayoutNodeSnapshotTests.mm in Sources */,

View File

@ -47,7 +47,9 @@ static const ASSizeRange kSize = {{100, 120}, {320, 160}};
sizingOptions:(ASCenterLayoutNodeSizingOptions)sizingOptions sizingOptions:(ASCenterLayoutNodeSizingOptions)sizingOptions
{ {
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor redColor]); ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]); ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
foregroundNode.staticSize = {70, 100};
ASLayoutNode *layoutNode = ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode [ASBackgroundLayoutNode
@ -55,8 +57,7 @@ static const ASSizeRange kSize = {{100, 120}, {320, 160}};
[ASCenterLayoutNode [ASCenterLayoutNode
newWithCenteringOptions:options newWithCenteringOptions:options
sizingOptions:sizingOptions sizingOptions:sizingOptions
child:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(70.0, 100.0) displayNode:foregroundNode] child:[ASCompositeNode newWithDisplayNode:foregroundNode]]
size:{}]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]]; background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
[self testLayoutNode:layoutNode [self testLayoutNode:layoutNode
@ -92,7 +93,8 @@ static NSString *suffixForCenteringOptions(ASCenterLayoutNodeCenteringOptions ce
- (void)testMinimumSizeRangeIsGivenToChildWhenNotCentering - (void)testMinimumSizeRangeIsGivenToChildWhenNotCentering
{ {
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor redColor]); ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor redColor]); ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor redColor]);
foregroundNode.staticSize = {10, 10};
ASCenterLayoutNode *layoutNode = ASCenterLayoutNode *layoutNode =
[ASCenterLayoutNode [ASCenterLayoutNode
@ -102,14 +104,12 @@ static NSString *suffixForCenteringOptions(ASCenterLayoutNodeCenteringOptions ce
[ASBackgroundLayoutNode [ASBackgroundLayoutNode
newWithNode: newWithNode:
[ASStackLayoutNode [ASStackLayoutNode
newWithSize:{} newWithStyle:{}
style:{}
children:@[[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { children:@[[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(10, 10) displayNode:foregroundNode]; mutableChild.node = [ASCompositeNode newWithDisplayNode:foregroundNode];
mutableChild.flexGrow = YES; mutableChild.flexGrow = YES;
}]]] }]]]
background: [ASCompositeNode newWithDisplayNode:backgroundNode]] background: [ASCompositeNode newWithDisplayNode:backgroundNode]]];
size:{}];
[self testLayoutNode:layoutNode sizeRange:kSize subnodes:@[backgroundNode, foregroundNode] identifier:nil]; [self testLayoutNode:layoutNode sizeRange:kSize subnodes:@[backgroundNode, foregroundNode] identifier:nil];
} }

View File

@ -58,14 +58,15 @@ static NSString *nameForInsets(UIEdgeInsets insets)
for (NSUInteger combination = 0; combination < 16; combination++) { for (NSUInteger combination = 0; combination < 16; combination++) {
UIEdgeInsets insets = insetsForCombination(combination, 10); UIEdgeInsets insets = insetsForCombination(combination, 10);
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor grayColor]); ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor grayColor]);
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]); ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
foregroundNode.staticSize = {10, 10};
ASLayoutNode *layoutNode = ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode [ASBackgroundLayoutNode
newWithNode: newWithNode:
[ASInsetLayoutNode [ASInsetLayoutNode
newWithInsets:insets newWithInsets:insets
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(10, 10) displayNode:foregroundNode]] node:[ASCompositeNode newWithDisplayNode:foregroundNode]]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]]; background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
static ASSizeRange kVariableSize = {{0, 0}, {300, 300}}; static ASSizeRange kVariableSize = {{0, 0}, {300, 300}};
@ -81,14 +82,15 @@ static NSString *nameForInsets(UIEdgeInsets insets)
for (NSUInteger combination = 0; combination < 16; combination++) { for (NSUInteger combination = 0; combination < 16; combination++) {
UIEdgeInsets insets = insetsForCombination(combination, 10); UIEdgeInsets insets = insetsForCombination(combination, 10);
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor grayColor]); ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor grayColor]);
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]); ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
foregroundNode.staticSize = {10, 10};
ASLayoutNode *layoutNode = ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode [ASBackgroundLayoutNode
newWithNode: newWithNode:
[ASInsetLayoutNode [ASInsetLayoutNode
newWithInsets:insets newWithInsets:insets
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(10, 10) displayNode:foregroundNode]] node:[ASCompositeNode newWithDisplayNode:foregroundNode]]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]]; background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
static ASSizeRange kFixedSize = {{300, 300}, {300, 300}}; static ASSizeRange kFixedSize = {{300, 300}, {300, 300}};
@ -105,14 +107,15 @@ static NSString *nameForInsets(UIEdgeInsets insets)
for (NSUInteger combination = 0; combination < 16; combination++) { for (NSUInteger combination = 0; combination < 16; combination++) {
UIEdgeInsets insets = insetsForCombination(combination, 0); UIEdgeInsets insets = insetsForCombination(combination, 0);
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor grayColor]); ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor grayColor]);
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]); ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
foregroundNode.staticSize = {10, 10};
ASLayoutNode *layoutNode = ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode [ASBackgroundLayoutNode
newWithNode: newWithNode:
[ASInsetLayoutNode [ASInsetLayoutNode
newWithInsets:insets newWithInsets:insets
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(10, 10) displayNode:foregroundNode]] node:[ASCompositeNode newWithDisplayNode:foregroundNode]]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]]; background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
static ASSizeRange kFixedSize = {{300, 300}, {300, 300}}; static ASSizeRange kFixedSize = {{300, 300}, {300, 300}};

View File

@ -1,88 +0,0 @@
/*
* Copyright (c) 2014-present, Facebook, Inc.
* All rights reserved.
*
* This source code is licensed under the BSD-style license found in the
* LICENSE file in the root directory of this source tree. An additional grant
* of patent rights can be found in the PATENTS file in the same directory.
*
*/
#import <XCTest/XCTest.h>
#import "ASLayoutNode.h"
@interface ASLayoutNodeSizeTests : XCTestCase
@end
@implementation ASLayoutNodeSizeTests
- (void)testResolvingSizeWithAutoInAllFieldsReturnsUnconstrainedRange
{
ASLayoutNodeSize s;
ASSizeRange r = ASLayoutNodeSizeResolve(s, {500, 300});
XCTAssertEqual(r.min.width, 0.f, @"Expected no min width");
XCTAssertEqual(r.max.width, INFINITY, @"Expected no max width");
XCTAssertEqual(r.min.height, 0.f, @"Expected no min height");
XCTAssertEqual(r.max.height, INFINITY, @"Expected no max height");
}
- (void)testPercentageWidthIsResolvedAgainstParentDimension
{
ASLayoutNodeSize s = {.width = ASRelativeDimensionMakeWithPercent(1.0)};
ASSizeRange r = ASLayoutNodeSizeResolve(s, {500, 300});
XCTAssertEqual(r.min.width, 500.0f, @"Expected min of resolved range to match");
XCTAssertEqual(r.max.width, 500.0f, @"Expected max of resolved range to match");
}
- (void)testMaxSizeClampsLayoutNodeSize
{
ASLayoutNodeSize s = {.width = ASRelativeDimensionMakeWithPercent(1.0), .maxWidth = ASRelativeDimensionMakeWithPoints(300)};
ASSizeRange r = ASLayoutNodeSizeResolve(s, {500, 300});
XCTAssertEqual(r.min.width, 300.0f, @"Expected max-size to clamp the width to exactly 300 pts");
XCTAssertEqual(r.max.width, 300.0f, @"Expected max-size to clamp the width to exactly 300 pts");
}
- (void)testMinSizeOverridesMaxSizeWhenTheyConflict
{
// Min-size overriding max-size matches CSS.
ASLayoutNodeSize s = {.minWidth = ASRelativeDimensionMakeWithPercent(0.5), .maxWidth = ASRelativeDimensionMakeWithPoints(300)};
ASSizeRange r = ASLayoutNodeSizeResolve(s, {800, 300});
XCTAssertEqual(r.min.width, 400.0f, @"Expected min-size to override max-size");
XCTAssertEqual(r.max.width, 400.0f, @"Expected min-size to override max-size");
}
- (void)testMinSizeAloneResultsInRangeUnconstrainedToInfinity
{
ASLayoutNodeSize s = {.minWidth = ASRelativeDimensionMakeWithPoints(100)};
ASSizeRange r = ASLayoutNodeSizeResolve(s, {800, 300});
XCTAssertEqual(r.min.width, 100.0f, @"Expected min width to be passed through");
XCTAssertEqual(r.max.width, INFINITY, @"Expected max width to be infinity since no maxWidth was specified");
}
- (void)testMaxSizeAloneResultsInRangeUnconstrainedFromZero
{
ASLayoutNodeSize s = {.maxWidth = ASRelativeDimensionMakeWithPoints(100)};
ASSizeRange r = ASLayoutNodeSizeResolve(s, {800, 300});
XCTAssertEqual(r.min.width, 0.0f, @"Expected min width to be zero");
XCTAssertEqual(r.max.width, 100.0f, @"Expected max width to be passed through");
}
- (void)testMinSizeAndMaxSizeResolveToARangeWhenTheyAreNotInConflict
{
ASLayoutNodeSize s = {.minWidth = ASRelativeDimensionMakeWithPoints(100), .maxWidth = ASRelativeDimensionMakeWithPoints(300)};
ASSizeRange r = ASLayoutNodeSizeResolve(s, {800, 300});
XCTAssertEqual(r.min.width, 100.0f, @"Expected min-size to be passed to size range");
XCTAssertEqual(r.max.width, 300.0f, @"Expected max-size to be passed to size range");
}
- (void)testWhenWidthFallsBetweenMinAndMaxWidthsItReturnsARangeWithExactlyThatWidth
{
ASLayoutNodeSize s = {.minWidth = ASRelativeDimensionMakeWithPoints(100), .width = ASRelativeDimensionMakeWithPoints(200), .maxWidth = ASRelativeDimensionMakeWithPoints(300)};
ASSizeRange r = ASLayoutNodeSizeResolve(s, {800, 300});
XCTAssertEqual(r.min.width, 200.0f, @"Expected min-size to be width");
XCTAssertEqual(r.max.width, 200.0f, @"Expected max-size to be width");
}
@end

View File

@ -27,10 +27,17 @@
identifier:(NSString *)identifier; identifier:(NSString *)identifier;
@end @end
static inline ASDisplayNode *ASDisplayNodeWithBackgroundColor(UIColor *backgroundColor) @interface ASStaticSizeDisplayNode : ASDisplayNode
@property (nonatomic) CGSize staticSize;
@end
static inline ASStaticSizeDisplayNode *ASDisplayNodeWithBackgroundColor(UIColor *backgroundColor)
{ {
ASDisplayNode *node = [[ASDisplayNode alloc] init]; ASStaticSizeDisplayNode *node = [[ASStaticSizeDisplayNode alloc] init];
node.layerBacked = YES; node.layerBacked = YES;
node.backgroundColor = backgroundColor; node.backgroundColor = backgroundColor;
node.staticSize = CGSizeZero;
return node; return node;
} }

View File

@ -50,7 +50,7 @@
- (void)setLayoutNodeUnderTest:(ASLayoutNode *)layoutNodeUnderTest sizeRange:(ASSizeRange)sizeRange - (void)setLayoutNodeUnderTest:(ASLayoutNode *)layoutNodeUnderTest sizeRange:(ASSizeRange)sizeRange
{ {
_layoutUnderTest = [layoutNodeUnderTest calculateLayoutThatFits:sizeRange]; _layoutUnderTest = [layoutNodeUnderTest computeLayoutThatFits:sizeRange];
self.frame = CGRectMake(0, 0, _layoutUnderTest.size.width, _layoutUnderTest.size.height); self.frame = CGRectMake(0, 0, _layoutUnderTest.size.width, _layoutUnderTest.size.height);
[self measure:_layoutUnderTest.size]; [self measure:_layoutUnderTest.size];
} }
@ -61,3 +61,14 @@
} }
@end @end
@implementation ASStaticSizeDisplayNode
- (ASLayout *)calculateLayoutThatFits:(CGSize)constrainedSize
{
return CGSizeEqualToSize(_staticSize, CGSizeZero)
? [super calculateLayoutThatFits:constrainedSize]
: [ASLayout newWithNode:[ASLayoutNode new] size:_staticSize];
}
@end

View File

@ -29,7 +29,8 @@ static const ASSizeRange kSize = {{320, 320}, {320, 320}};
- (void)testOverlay - (void)testOverlay
{ {
ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor blueColor]); ASDisplayNode *backgroundNode = ASDisplayNodeWithBackgroundColor([UIColor blueColor]);
ASDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor blackColor]); ASStaticSizeDisplayNode *foregroundNode = ASDisplayNodeWithBackgroundColor([UIColor blackColor]);
foregroundNode.staticSize = {20, 20};
ASLayoutNode *layoutNode = ASLayoutNode *layoutNode =
[ASOverlayLayoutNode [ASOverlayLayoutNode
@ -38,8 +39,7 @@ static const ASSizeRange kSize = {{320, 320}, {320, 320}};
[ASCenterLayoutNode [ASCenterLayoutNode
newWithCenteringOptions:ASCenterLayoutNodeCenteringXY newWithCenteringOptions:ASCenterLayoutNodeCenteringXY
sizingOptions:{} sizingOptions:{}
child:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(20, 20) displayNode:foregroundNode] child:[ASCompositeNode newWithDisplayNode:foregroundNode]]];
size:{}]];
[self testLayoutNode:layoutNode sizeRange:kSize subnodes:@[backgroundNode, foregroundNode] identifier: nil]; [self testLayoutNode:layoutNode sizeRange:kSize subnodes:@[backgroundNode, foregroundNode] identifier: nil];
} }

View File

@ -27,12 +27,12 @@ static const ASSizeRange kFixedSize = {{0, 0}, {100, 100}};
- (void)testRatioLayoutNodeWithRatio:(CGFloat)ratio childNodeSize:(CGSize)childNodeSize identifier:(NSString *)identifier - (void)testRatioLayoutNodeWithRatio:(CGFloat)ratio childNodeSize:(CGSize)childNodeSize identifier:(NSString *)identifier
{ {
ASDisplayNode *subnode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]); ASStaticSizeDisplayNode *subnode = ASDisplayNodeWithBackgroundColor([UIColor greenColor]);
subnode.staticSize = childNodeSize;
ASLayoutNode *layoutNode = [ASRatioLayoutNode ASLayoutNode *layoutNode = [ASRatioLayoutNode
newWithRatio:ratio newWithRatio:ratio
size:{} node:[ASCompositeNode newWithDisplayNode:subnode]];
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMakeWithCGSize(childNodeSize) displayNode:subnode]];
[self testLayoutNode:layoutNode sizeRange:kFixedSize subnodes:@[subnode] identifier:identifier]; [self testLayoutNode:layoutNode sizeRange:kFixedSize subnodes:@[subnode] identifier:identifier];
} }

View File

@ -37,11 +37,20 @@ static ASStackLayoutNodeChild *flexChild(ASLayoutNode *n, BOOL flex)
static NSArray *defaultSubnodes() static NSArray *defaultSubnodes()
{ {
return @[ return defaultSubnodesWithSameSize(CGSizeZero);
}
static NSArray *defaultSubnodesWithSameSize(CGSize subnodeSize)
{
NSArray *subnodes = @[
ASDisplayNodeWithBackgroundColor([UIColor redColor]), ASDisplayNodeWithBackgroundColor([UIColor redColor]),
ASDisplayNodeWithBackgroundColor([UIColor blueColor]), ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
ASDisplayNodeWithBackgroundColor([UIColor greenColor]) ASDisplayNodeWithBackgroundColor([UIColor greenColor])
]; ];
for (ASStaticSizeDisplayNode *subnode in subnodes) {
subnode.staticSize = subnodeSize;
}
return subnodes;
} }
- (void)testStackLayoutNodeWithJustify:(ASStackLayoutJustifyContent)justify - (void)testStackLayoutNodeWithJustify:(ASStackLayoutJustifyContent)justify
@ -53,12 +62,11 @@ static NSArray *defaultSubnodes()
.direction = ASStackLayoutDirectionHorizontal, .direction = ASStackLayoutDirectionHorizontal,
.justifyContent = justify .justifyContent = justify
}; };
ASLayoutNodeSize subnodeSize = ASLayoutNodeSizeMake(50, 50); NSArray *subnodes = defaultSubnodesWithSameSize({50, 50});
NSArray *subnodes = defaultSubnodes();
NSArray *children = @[ NSArray *children = @[
flexChild([ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[0]], flex), flexChild([ASCompositeNode newWithDisplayNode:subnodes[0]], flex),
flexChild([ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[1]], flex), flexChild([ASCompositeNode newWithDisplayNode:subnodes[1]], flex),
flexChild([ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[2]], flex) flexChild([ASCompositeNode newWithDisplayNode:subnodes[2]], flex)
]; ];
[self testStackLayoutNodeWithStyle:style children:children sizeRange:sizeRange subnodes:subnodes identifier:identifier]; [self testStackLayoutNodeWithStyle:style children:children sizeRange:sizeRange subnodes:subnodes identifier:identifier];
@ -74,7 +82,7 @@ static NSArray *defaultSubnodes()
ASLayoutNode *layoutNode = ASLayoutNode *layoutNode =
[ASBackgroundLayoutNode [ASBackgroundLayoutNode
newWithNode:[ASStackLayoutNode newWithSize:{} style:style children:children] newWithNode:[ASStackLayoutNode newWithStyle:style children:children]
background:[ASCompositeNode newWithDisplayNode:backgroundNode]]; background:[ASCompositeNode newWithDisplayNode:backgroundNode]];
NSMutableArray *newSubnodes = [NSMutableArray arrayWithObject:backgroundNode]; NSMutableArray *newSubnodes = [NSMutableArray arrayWithObject:backgroundNode];
@ -106,20 +114,19 @@ static NSArray *defaultSubnodes()
- (void)testOverflowBehaviorsWhenAllFlexShrinkNodesHaveBeenClampedToZeroButViolationStillExists - (void)testOverflowBehaviorsWhenAllFlexShrinkNodesHaveBeenClampedToZeroButViolationStillExists
{ {
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal}; ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
ASLayoutNodeSize subnodeSize = ASLayoutNodeSizeMake(50, 50); NSArray *subnodes = defaultSubnodesWithSameSize({50, 50});
NSArray *subnodes = defaultSubnodes();
NSArray *children = @[ NSArray *children = @[
// After flexShrink-able children are all clamped to zero, the sum of their widths is 100px. // After flexShrink-able children are all clamped to zero, the sum of their widths is 100px.
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.flexShrink = NO; mutableChild.flexShrink = NO;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.flexShrink = YES; mutableChild.flexShrink = YES;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:subnodeSize displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.flexShrink = NO; mutableChild.flexShrink = NO;
}] }]
]; ];
@ -131,11 +138,16 @@ static NSArray *defaultSubnodes()
- (void)testFlexWithUnequalIntrinsicSizes - (void)testFlexWithUnequalIntrinsicSizes
{ {
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal}; ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {150, 150};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {50, 50};
NSArray *children = @[ NSArray *children = @[
flexChild([ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]], YES), flexChild([ASCompositeNode newWithDisplayNode:subnodes[0]], YES),
flexChild([ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 150) displayNode:subnodes[1]], YES), flexChild([ASCompositeNode newWithDisplayNode:subnodes[1]], YES),
flexChild([ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[2]], YES) flexChild([ASCompositeNode newWithDisplayNode:subnodes[2]], YES)
]; ];
// width 300px; height 0-150px. // width 300px; height 0-150px.
@ -150,16 +162,21 @@ static NSArray *defaultSubnodes()
- (void)testCrossAxisSizeBehaviors - (void)testCrossAxisSizeBehaviors
{ {
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionVertical}; ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionVertical};
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 50};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 50) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 50) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
}] }]
]; ];
@ -178,16 +195,21 @@ static NSArray *defaultSubnodes()
.direction = ASStackLayoutDirectionVertical, .direction = ASStackLayoutDirectionVertical,
.spacing = 10 .spacing = 10
}; };
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 50};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 50) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 50) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
}] }]
]; ];
// width 0-300px; height 300px // width 0-300px; height 300px
@ -208,8 +230,7 @@ static NSArray *defaultSubnodes()
[ASBackgroundLayoutNode [ASBackgroundLayoutNode
newWithNode: newWithNode:
[ASStackLayoutNode [ASStackLayoutNode
newWithSize:{} newWithStyle:{
style:{
.direction = ASStackLayoutDirectionVertical, .direction = ASStackLayoutDirectionVertical,
.spacing = 10, .spacing = 10,
.alignItems = ASStackLayoutAlignItemsStretch .alignItems = ASStackLayoutAlignItemsStretch
@ -229,19 +250,23 @@ static NSArray *defaultSubnodes()
{ {
// width 0-INF; height 0-INF // width 0-INF; height 0-INF
static ASSizeRange kAnySize = {{0, 0}, {INFINITY, INFINITY}}; static ASSizeRange kAnySize = {{0, 0}, {INFINITY, INFINITY}};
NSArray *subnodes = defaultSubnodes();
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionVertical}; ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionVertical};
NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.spacingBefore = 10; mutableChild.spacingBefore = 10;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.spacingBefore = 20; mutableChild.spacingBefore = 20;
}] }]
]; ];
@ -249,14 +274,14 @@ static NSArray *defaultSubnodes()
children = @[ children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.spacingAfter = 10; mutableChild.spacingAfter = 10;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.spacingAfter = 20; mutableChild.spacingAfter = 20;
}] }]
]; ];
@ -265,15 +290,15 @@ static NSArray *defaultSubnodes()
style.spacing = 10; style.spacing = 10;
children = @[ children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.spacingBefore = -10; mutableChild.spacingBefore = -10;
mutableChild.spacingAfter = -10; mutableChild.spacingAfter = -10;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
}] }]
]; ];
[self testStackLayoutNodeWithStyle:style children:children sizeRange:kAnySize subnodes:subnodes identifier:@"spacingBalancedOut"]; [self testStackLayoutNodeWithStyle:style children:children sizeRange:kAnySize subnodes:subnodes identifier:@"spacingBalancedOut"];
@ -285,18 +310,23 @@ static NSArray *defaultSubnodes()
.direction = ASStackLayoutDirectionVertical, .direction = ASStackLayoutDirectionVertical,
.justifyContent = ASStackLayoutJustifyContentCenter .justifyContent = ASStackLayoutJustifyContentCenter
}; };
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.spacingBefore = 0; mutableChild.spacingBefore = 0;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.spacingBefore = 20; mutableChild.spacingBefore = 20;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.spacingBefore = 30; mutableChild.spacingBefore = 30;
}] }]
]; ];
@ -309,22 +339,24 @@ static NSArray *defaultSubnodes()
- (void)testNodeThatChangesCrossSizeWhenMainSizeIsFlexed - (void)testNodeThatChangesCrossSizeWhenMainSizeIsFlexed
{ {
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal}; ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
NSArray *subnodes = @[ NSArray *subnodes = @[
ASDisplayNodeWithBackgroundColor([UIColor blueColor]), ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
ASDisplayNodeWithBackgroundColor([UIColor redColor]) ASDisplayNodeWithBackgroundColor([UIColor redColor])
]; ];
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {50, 50};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASRatioLayoutNode mutableChild.node = [ASRatioLayoutNode
newWithRatio:1.5 newWithRatio:1.5
size:{} node:[ASCompositeNode newWithDisplayNode:subnodes[0]]];
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(00, 150) displayNode:subnodes[0]]];;
mutableChild.flexBasis = ASRelativeDimensionMakeWithPercent(1); mutableChild.flexBasis = ASRelativeDimensionMakeWithPercent(1);
mutableChild.flexGrow = YES; mutableChild.flexGrow = YES;
mutableChild.flexShrink = YES; mutableChild.flexShrink = YES;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
}] }]
]; ];
static ASSizeRange kFixedWidth = {{150, 0}, {150, INFINITY}}; static ASSizeRange kFixedWidth = {{150, 0}, {150, INFINITY}};
@ -337,17 +369,21 @@ static NSArray *defaultSubnodes()
.direction = ASStackLayoutDirectionVertical, .direction = ASStackLayoutDirectionVertical,
.alignItems = ASStackLayoutAlignItemsCenter .alignItems = ASStackLayoutAlignItemsCenter
}; };
NSArray *subnodes = @[ NSArray *subnodes = @[
ASDisplayNodeWithBackgroundColor([UIColor redColor]), ASDisplayNodeWithBackgroundColor([UIColor redColor]),
ASDisplayNodeWithBackgroundColor([UIColor blueColor]) ASDisplayNodeWithBackgroundColor([UIColor blueColor])
]; ];
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {100, 100};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {50, 50};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 100) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.flexShrink = YES; mutableChild.flexShrink = YES;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.flexShrink = YES; mutableChild.flexShrink = YES;
}], }],
]; ];
@ -358,16 +394,20 @@ static NSArray *defaultSubnodes()
- (void)testAlignCenterWithIndefiniteCrossDimension - (void)testAlignCenterWithIndefiniteCrossDimension
{ {
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal}; ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
NSArray *subnodes = @[ NSArray *subnodes = @[
ASDisplayNodeWithBackgroundColor([UIColor redColor]), ASDisplayNodeWithBackgroundColor([UIColor redColor]),
ASDisplayNodeWithBackgroundColor([UIColor blueColor]) ASDisplayNodeWithBackgroundColor([UIColor blueColor])
]; ];
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {100, 100};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {50, 50};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 100) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.alignSelf = ASStackLayoutAlignSelfCenter; mutableChild.alignSelf = ASStackLayoutAlignSelfCenter;
}], }],
]; ];
@ -382,18 +422,23 @@ static NSArray *defaultSubnodes()
.justifyContent = ASStackLayoutJustifyContentCenter, .justifyContent = ASStackLayoutJustifyContentCenter,
.alignItems = ASStackLayoutAlignItemsStart .alignItems = ASStackLayoutAlignItemsStart
}; };
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.spacingBefore = 0; mutableChild.spacingBefore = 0;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.spacingBefore = 20; mutableChild.spacingBefore = 20;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.spacingBefore = 30; mutableChild.spacingBefore = 30;
}] }]
]; ];
@ -408,18 +453,23 @@ static NSArray *defaultSubnodes()
.justifyContent = ASStackLayoutJustifyContentCenter, .justifyContent = ASStackLayoutJustifyContentCenter,
.alignItems = ASStackLayoutAlignItemsEnd .alignItems = ASStackLayoutAlignItemsEnd
}; };
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.spacingBefore = 0; mutableChild.spacingBefore = 0;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.spacingBefore = 20; mutableChild.spacingBefore = 20;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.spacingBefore = 30; mutableChild.spacingBefore = 30;
}] }]
]; ];
@ -434,18 +484,23 @@ static NSArray *defaultSubnodes()
.justifyContent = ASStackLayoutJustifyContentCenter, .justifyContent = ASStackLayoutJustifyContentCenter,
.alignItems = ASStackLayoutAlignItemsCenter .alignItems = ASStackLayoutAlignItemsCenter
}; };
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.spacingBefore = 0; mutableChild.spacingBefore = 0;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.spacingBefore = 20; mutableChild.spacingBefore = 20;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.spacingBefore = 30; mutableChild.spacingBefore = 30;
}] }]
]; ];
@ -460,18 +515,23 @@ static NSArray *defaultSubnodes()
.justifyContent = ASStackLayoutJustifyContentCenter, .justifyContent = ASStackLayoutJustifyContentCenter,
.alignItems = ASStackLayoutAlignItemsStretch .alignItems = ASStackLayoutAlignItemsStretch
}; };
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.spacingBefore = 0; mutableChild.spacingBefore = 0;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.spacingBefore = 20; mutableChild.spacingBefore = 20;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.spacingBefore = 30; mutableChild.spacingBefore = 30;
}] }]
]; ];
@ -487,18 +547,23 @@ static NSArray *defaultSubnodes()
.justifyContent = ASStackLayoutJustifyContentCenter, .justifyContent = ASStackLayoutJustifyContentCenter,
.alignItems = ASStackLayoutAlignItemsStretch .alignItems = ASStackLayoutAlignItemsStretch
}; };
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 70};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {150, 90};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.spacingBefore = 0; mutableChild.spacingBefore = 0;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 70) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.spacingBefore = 20; mutableChild.spacingBefore = 20;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 90) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.spacingBefore = 30; mutableChild.spacingBefore = 30;
}] }]
]; ];
@ -516,20 +581,25 @@ static NSArray *defaultSubnodes()
- (void)testFixedFlexBasisAppliedWhenFlexingItems - (void)testFixedFlexBasisAppliedWhenFlexingItems
{ {
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal}; ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {150, 150};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {50, 50};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.flexGrow = YES; mutableChild.flexGrow = YES;
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10); mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10);
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 150) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.flexGrow = YES; mutableChild.flexGrow = YES;
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10); mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10);
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.flexGrow = YES; mutableChild.flexGrow = YES;
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10); mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(10);
}] }]
@ -546,21 +616,21 @@ static NSArray *defaultSubnodes()
- (void)testPercentageFlexBasisResolvesAgainstParentSize - (void)testPercentageFlexBasisResolvesAgainstParentSize
{ {
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal}; ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodesWithSameSize({50, 50});
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.flexGrow = YES; mutableChild.flexGrow = YES;
// This should override the intrinsic size of 50pts and instead compute to 50% = 100pts. // This should override the intrinsic size of 50pts and instead compute to 50% = 100pts.
// The result should be that the red box is twice as wide as the blue and gree boxes after flexing. // The result should be that the red box is twice as wide as the blue and gree boxes after flexing.
mutableChild.flexBasis = ASRelativeDimensionMakeWithPercent(0.5); mutableChild.flexBasis = ASRelativeDimensionMakeWithPercent(0.5);
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.flexGrow = YES; mutableChild.flexGrow = YES;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.flexGrow = YES; mutableChild.flexGrow = YES;
}] }]
]; ];
@ -571,18 +641,23 @@ static NSArray *defaultSubnodes()
- (void)testFixedFlexBasisOverridesIntrinsicSizeForNonFlexingChildren - (void)testFixedFlexBasisOverridesIntrinsicSizeForNonFlexingChildren
{ {
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal}; ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {50, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {150, 150};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {50, 50};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20); mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20);
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(150, 150) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20); mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20);
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(50, 50) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20); mutableChild.flexBasis = ASRelativeDimensionMakeWithPoints(20);
}] }]
]; ];
@ -597,6 +672,8 @@ static NSArray *defaultSubnodes()
ASDisplayNodeWithBackgroundColor([UIColor blueColor]), ASDisplayNodeWithBackgroundColor([UIColor blueColor]),
ASDisplayNodeWithBackgroundColor([UIColor redColor]) ASDisplayNodeWithBackgroundColor([UIColor redColor])
]; ];
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {10, 0};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {3000, 3000};
// If cross axis stretching occurred *before* flexing, then the blue child would be stretched to 3000 points tall. // If cross axis stretching occurred *before* flexing, then the blue child would be stretched to 3000 points tall.
// Instead it should be stretched to 300 points tall, matching the red child and not overlapping the green inset. // Instead it should be stretched to 300 points tall, matching the red child and not overlapping the green inset.
@ -607,20 +684,18 @@ static NSArray *defaultSubnodes()
newWithInsets:UIEdgeInsetsMake(10, 10, 10, 10) newWithInsets:UIEdgeInsetsMake(10, 10, 10, 10)
node: node:
[ASStackLayoutNode [ASStackLayoutNode
newWithSize:{} newWithStyle:{
style:{
.direction = ASStackLayoutDirectionHorizontal, .direction = ASStackLayoutDirectionHorizontal,
.alignItems = ASStackLayoutAlignItemsStretch, .alignItems = ASStackLayoutAlignItemsStretch,
} }
children: children:
@[ @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(10, 00) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
}], }],
flexChild([ASRatioLayoutNode flexChild([ASRatioLayoutNode
newWithRatio:1.0 newWithRatio:1.0
size:{} node:[ASCompositeNode newWithDisplayNode:subnodes[2]]],
node:[ASCompositeNode newWithSize:ASLayoutNodeSizeMake(3000, 3000) displayNode:subnodes[2]]],
YES), YES),
]]] ]]]
background:[ASCompositeNode newWithDisplayNode:subnodes[0]]]; background:[ASCompositeNode newWithDisplayNode:subnodes[0]]];
@ -632,18 +707,23 @@ static NSArray *defaultSubnodes()
- (void)testViolationIsDistributedEquallyAmongFlexibleChildNodes - (void)testViolationIsDistributedEquallyAmongFlexibleChildNodes
{ {
ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal}; ASStackLayoutNodeStyle style = {.direction = ASStackLayoutDirectionHorizontal};
NSArray *subnodes = defaultSubnodes(); NSArray *subnodes = defaultSubnodes();
((ASStaticSizeDisplayNode *)subnodes[0]).staticSize = {300, 50};
((ASStaticSizeDisplayNode *)subnodes[1]).staticSize = {100, 50};
((ASStaticSizeDisplayNode *)subnodes[2]).staticSize = {200, 50};
NSArray *children = @[ NSArray *children = @[
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(300, 50) displayNode:subnodes[0]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[0]];
mutableChild.flexShrink = YES; mutableChild.flexShrink = YES;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(100, 50) displayNode:subnodes[1]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[1]];
mutableChild.flexShrink = NO; mutableChild.flexShrink = NO;
}], }],
[ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) { [ASStackLayoutNodeChild newWithInitializer:^(ASMutableStackLayoutNodeChild *mutableChild) {
mutableChild.node = [ASCompositeNode newWithSize:ASLayoutNodeSizeMake(200, 50) displayNode:subnodes[2]]; mutableChild.node = [ASCompositeNode newWithDisplayNode:subnodes[2]];
mutableChild.flexShrink = YES; mutableChild.flexShrink = YES;
}] }]
]; ];