-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move extension to NSLayoutXAxisAnchor.swift (#174)
* Move extension to NSLayoutXAxisAnchor.swift * Move tests
- Loading branch information
1 parent
4ee4721
commit de98e3c
Showing
4 changed files
with
134 additions
and
104 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
// | ||
// All Contributions by Match Group | ||
// | ||
// Copyright © 2023 Tinder (Match Group, LLC) | ||
// | ||
// Licensed under the Match Group Modified 3-Clause BSD License. | ||
// See https://github.com/Tinder/Layout/blob/main/LICENSE for license information. | ||
// | ||
|
||
import UIKit | ||
|
||
extension NSLayoutXAxisAnchor { | ||
|
||
// swiftlint:disable function_default_parameter_at_end | ||
|
||
public func constraint( | ||
is relation: NSLayoutConstraint.Relation = .equal, | ||
to anchor: NSLayoutXAxisAnchor, | ||
constant: CGFloat = 0 | ||
) -> NSLayoutConstraint { | ||
switch relation { | ||
case .equal: | ||
return constraint(equalTo: anchor, constant: constant) | ||
case .greaterThanOrEqual: | ||
return constraint(greaterThanOrEqualTo: anchor, constant: constant) | ||
case .lessThanOrEqual: | ||
return constraint(lessThanOrEqualTo: anchor, constant: constant) | ||
@unknown default: | ||
return constraint(equalTo: anchor, constant: constant) | ||
} | ||
} | ||
|
||
// swiftlint:enable function_default_parameter_at_end | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,100 @@ | ||
// | ||
// All Contributions by Match Group | ||
// | ||
// Copyright © 2023 Tinder (Match Group, LLC) | ||
// | ||
// Licensed under the Match Group Modified 3-Clause BSD License. | ||
// See https://github.com/Tinder/Layout/blob/main/LICENSE for license information. | ||
// | ||
|
||
@testable import Layout | ||
import Nimble | ||
import XCTest | ||
|
||
@MainActor | ||
final class NSLayoutXAxisAnchorTests: XCTestCase { | ||
|
||
func testConstraintToXAnchor_withDefaults() { | ||
|
||
// GIVEN | ||
|
||
let viewA: UIView = .init() | ||
let viewB: UIView = .init() | ||
let expected: NSLayoutConstraint = viewA | ||
.centerX | ||
.constraint(equalTo: viewB.centerX) | ||
|
||
// WHEN | ||
|
||
let constraint: NSLayoutConstraint = viewA | ||
.centerX | ||
.constraint(to: viewB.centerX) | ||
|
||
// THEN | ||
|
||
expect(constraint).to(match(expected)) | ||
} | ||
|
||
func testConstraintToXAnchor_withConstant() { | ||
|
||
// GIVEN | ||
|
||
let viewA: UIView = .init() | ||
let viewB: UIView = .init() | ||
let expected: NSLayoutConstraint = viewA | ||
.centerX | ||
.constraint(equalTo: viewB.centerX, constant: 50) | ||
|
||
// WHEN | ||
|
||
let constraint: NSLayoutConstraint = viewA | ||
.centerX | ||
.constraint(is: .equal, to: viewB.centerX, constant: 50) | ||
|
||
// THEN | ||
|
||
expect(constraint).to(match(expected)) | ||
} | ||
|
||
func testConstraintToXAnchor_withGreaterThanOrEqualRelation() { | ||
|
||
// GIVEN | ||
|
||
let viewA: UIView = .init() | ||
let viewB: UIView = .init() | ||
let expected: NSLayoutConstraint = viewA | ||
.centerX | ||
.constraint(greaterThanOrEqualTo: viewB.centerX) | ||
|
||
// WHEN | ||
|
||
let constraint: NSLayoutConstraint = viewA | ||
.centerX | ||
.constraint(is: .greaterThanOrEqual, to: viewB.centerX) | ||
|
||
// THEN | ||
|
||
expect(constraint).to(match(expected)) | ||
} | ||
|
||
func testConstraintToXAnchor_withLessThanOrEqualRelation() { | ||
|
||
// GIVEN | ||
|
||
let viewA: UIView = .init() | ||
let viewB: UIView = .init() | ||
let expected: NSLayoutConstraint = viewA | ||
.centerX | ||
.constraint(lessThanOrEqualTo: viewB.centerX) | ||
|
||
// WHEN | ||
|
||
let constraint: NSLayoutConstraint = viewA | ||
.centerX | ||
.constraint(is: .lessThanOrEqual, to: viewB.centerX) | ||
|
||
// THEN | ||
|
||
expect(constraint).to(match(expected)) | ||
} | ||
} |