Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #9 from jrsaruo/test/increase-coverage
Increase coverage
- Loading branch information
Showing
16 changed files
with
277 additions
and
65 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,70 @@ | ||
// | ||
// LayoutConstraintsBuilderTests.swift | ||
// | ||
// | ||
// Created by Yusaku Nishi on 2022/01/09. | ||
// | ||
|
||
import XCTest | ||
import AceLayout | ||
|
||
final class LayoutConstraintsBuilderTests: XCTestCase { | ||
|
||
private var view: AL.View! | ||
private let conditionTrue = true | ||
|
||
override func setUp() { | ||
super.setUp() | ||
view = AL.View() | ||
} | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
view = nil | ||
} | ||
|
||
func testVoidExpression() { | ||
func doNothing() {} | ||
let constraints = view.autoLayout { item in | ||
doNothing() | ||
} | ||
XCTAssert(constraints.isEmpty) | ||
} | ||
|
||
func testIfStatement() { | ||
let constraints = view.autoLayout { item in | ||
if conditionTrue { | ||
item.width.equal(to: 100) | ||
} | ||
if !conditionTrue { | ||
item.height.equal(to: 50) | ||
} | ||
} | ||
let expectedConstraints = [ | ||
view.widthAnchor.constraint(equalToConstant: 100) | ||
] | ||
NSLayoutConstraint.activate(expectedConstraints) | ||
assertEqual(constraints, expectedConstraints) | ||
} | ||
|
||
func testIfElseStatement() { | ||
let constraints = view.autoLayout { item in | ||
if conditionTrue { | ||
item.width.equal(to: 100) | ||
} else { | ||
item.height.equal(to: 100) | ||
} | ||
if !conditionTrue { | ||
item.width.equal(to: 50) | ||
} else { | ||
item.height.equal(to: 50) | ||
} | ||
} | ||
let expectedConstraints = [ | ||
view.widthAnchor.constraint(equalToConstant: 100), | ||
view.heightAnchor.constraint(equalToConstant: 50) | ||
] | ||
NSLayoutConstraint.activate(expectedConstraints) | ||
assertEqual(constraints, expectedConstraints) | ||
} | ||
} |
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,38 @@ | ||
// | ||
// LayoutTargetTests.swift | ||
// | ||
// | ||
// Created by Yusaku Nishi on 2022/01/10. | ||
// | ||
|
||
import XCTest | ||
import AceLayout | ||
|
||
final class LayoutTargetTests: XCTestCase { | ||
|
||
func testAutoLayout() { | ||
XCTContext.runActivity(named: "translatesAutoresizingMaskIntoConstraints should become false") { _ in | ||
let view = AL.View() | ||
XCTAssert(view.translatesAutoresizingMaskIntoConstraints) | ||
view.autoLayout { item in | ||
item.width.equal(to: 100) | ||
} | ||
XCTAssertFalse(view.translatesAutoresizingMaskIntoConstraints) | ||
} | ||
XCTContext.runActivity(named: "isActive control") { _ in | ||
let view = AL.View() | ||
XCTContext.runActivity(named: "All isActive should become true by default") { _ in | ||
let constraints = view.autoLayout { item in | ||
item.size.equal(toSquare: 100) | ||
} | ||
XCTAssert(constraints.allSatisfy { $0.isActive }) | ||
} | ||
XCTContext.runActivity(named: "All isActive should be false when activates: false") { _ in | ||
let constraints = view.autoLayout(activates: false) { item in | ||
item.size.equal(toSquare: 100) | ||
} | ||
XCTAssert(constraints.allSatisfy { !$0.isActive }) | ||
} | ||
} | ||
} | ||
} |
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
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
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
41 changes: 41 additions & 0 deletions
41
Tests/AceLayoutTests/NSLayoutConstraintExtensionTests.swift
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,41 @@ | ||
// | ||
// NSLayoutConstraintExtensionTests.swift | ||
// | ||
// | ||
// Created by Yusaku Nishi on 2021/12/16. | ||
// | ||
|
||
import XCTest | ||
import AceLayout | ||
|
||
final class NSLayoutConstraintExtensionTests: XCTestCase { | ||
|
||
private var superview: AL.View! | ||
private var subview: AL.View! | ||
|
||
override func setUp() { | ||
super.setUp() | ||
|
||
superview = AL.View() | ||
subview = AL.View() | ||
superview.addSubview(subview) | ||
} | ||
|
||
override func tearDown() { | ||
super.tearDown() | ||
|
||
subview.removeFromSuperview() | ||
subview = nil | ||
superview = nil | ||
} | ||
|
||
func testPriority() { | ||
let constraints = subview.autoLayout { item in | ||
item.width.equal(to: 100) | ||
item.height.equal(to: 100).priority(.defaultLow) | ||
item.center.equal(to: superview).priority(.defaultHigh) | ||
} | ||
XCTAssertEqual(constraints.map { $0.priority }, | ||
[.required, .defaultLow, .defaultHigh, .defaultHigh]) | ||
} | ||
} |