Skip to content

Commit

Permalink
Add tests for centering documentation examples (#276)
Browse files Browse the repository at this point in the history
  • Loading branch information
tinder-cfuller authored Jan 19, 2024
1 parent 0452c36 commit e5c5098
Show file tree
Hide file tree
Showing 41 changed files with 172 additions and 0 deletions.
112 changes: 112 additions & 0 deletions Tests/LayoutTests/LayoutExampleTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,118 @@ final class LayoutExampleTests: XCTestCase {
}
}

func testHorizontallyCenteringDocumentationExample() {

// GIVEN

let siblingView: UIView = pinkView

let label: UILabel = {
let label: UILabel = .init()
label.text = "Layout"
return label
}()

// THEN

assertLayout { view in
view
.layout {
siblingView
.size(width: 100, height: 100)
.center()
label
.center(.vertical)
}
.center(label, between: siblingView.trailing, and: view.trailing)
.activate()
}
}

func testVerticallyCenteringDocumentationExample() {

// GIVEN

let siblingView: UIView = pinkView

let label: UILabel = {
let label: UILabel = .init()
label.text = "Layout"
return label
}()

// THEN

assertLayout { view in
view
.layout {
siblingView
.size(width: 100, height: 100)
.center()
label
.center(.horizontal)
}
.center(label, between: siblingView.bottom, and: view.bottom)
.activate()
}
}

func testHorizontallyCenteringLayoutItemDocumentationExample() {

// GIVEN

let siblingView: UIView = pinkView

let label: UILabel = {
let label: UILabel = .init()
label.text = "Layout"
return label
}()

// THEN

assertLayout { view in
view
.layout {
siblingView
.size(width: 100, height: 100)
.center()
label
.center(.vertical)
.center(between: siblingView.trailing, and: view.trailing)
}
.activate()
}
}

func testVerticallyCenteringLayoutItemDocumentationExample() {

// GIVEN

let siblingView: UIView = pinkView

let label: UILabel = {
let label: UILabel = .init()
label.text = "Layout"
return label
}()

// THEN

assertLayout { view in
view
.layout {
siblingView
.size(width: 100, height: 100)
.center()
label
.center(.horizontal)
.center(between: siblingView.bottom, and: view.bottom)
}
.activate()
}
}

func testReadmeExample() {

// GIVEN
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 812)>
| <View; name = Pink; frame = (x: 137.666667, y: 356, width: 100, height: 100)>
| <UILabel; frame = (280.667 396; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 390, height: 844)>
| <View; name = Pink; frame = (x: 145, y: 372, width: 100, height: 100)>
| <UILabel; frame = (292 412; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 667)>
| <View; name = Pink; frame = (x: 137.666667, y: 283.666667, width: 100, height: 100)>
| <UILabel; frame = (280.667 323.333; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 320, height: 568)>
| <View; name = Pink; frame = (x: 110, y: 234, width: 100, height: 100)>
| <UILabel; frame = (239.333 274; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 812)>
| <View; name = Pink; frame = (x: 137.666667, y: 356, width: 100, height: 100)>
| <UILabel; frame = (280.667 396; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 812)>
| <View; name = Pink; frame = (x: 137.666667, y: 356, width: 100, height: 100)>
| <UILabel; frame = (280.667 396; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 390, height: 844)>
| <View; name = Pink; frame = (x: 145, y: 372, width: 100, height: 100)>
| <UILabel; frame = (292 412; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 667)>
| <View; name = Pink; frame = (x: 137.666667, y: 283.666667, width: 100, height: 100)>
| <UILabel; frame = (280.667 323.333; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 320, height: 568)>
| <View; name = Pink; frame = (x: 110, y: 234, width: 100, height: 100)>
| <UILabel; frame = (239.333 274; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 812)>
| <View; name = Pink; frame = (x: 137.666667, y: 356, width: 100, height: 100)>
| <UILabel; frame = (280.667 396; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 812)>
| <View; name = Pink; frame = (x: 137.666667, y: 356, width: 100, height: 100)>
| <UILabel; frame = (162 624; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 390, height: 844)>
| <View; name = Pink; frame = (x: 145, y: 372, width: 100, height: 100)>
| <UILabel; frame = (169.333 648; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 667)>
| <View; name = Pink; frame = (x: 137.666667, y: 283.666667, width: 100, height: 100)>
| <UILabel; frame = (162 515; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 320, height: 568)>
| <View; name = Pink; frame = (x: 110, y: 234, width: 100, height: 100)>
| <UILabel; frame = (134.333 441; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 812)>
| <View; name = Pink; frame = (x: 137.666667, y: 356, width: 100, height: 100)>
| <UILabel; frame = (162 624; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 812)>
| <View; name = Pink; frame = (x: 137.666667, y: 356, width: 100, height: 100)>
| <UILabel; frame = (162 624; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 390, height: 844)>
| <View; name = Pink; frame = (x: 145, y: 372, width: 100, height: 100)>
| <UILabel; frame = (169.333 648; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 667)>
| <View; name = Pink; frame = (x: 137.666667, y: 283.666667, width: 100, height: 100)>
| <UILabel; frame = (162 515; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 320, height: 568)>
| <View; name = Pink; frame = (x: 110, y: 234, width: 100, height: 100)>
| <UILabel; frame = (134.333 441; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
<View; frame = (x: 0, y: 0, width: 375, height: 812)>
| <View; name = Pink; frame = (x: 137.666667, y: 356, width: 100, height: 100)>
| <UILabel; frame = (162 624; 51.3333 20.3333); text = 'Layout'; userInteractionEnabled = NO; backgroundColor = UIExtendedGrayColorSpace 0 0; layer = <_UILabelLayer>>

0 comments on commit e5c5098

Please sign in to comment.