Skip to content

Commit

Permalink
Added tests for the offset operator
Browse files Browse the repository at this point in the history
  • Loading branch information
jayrhynas committed Apr 27, 2023
1 parent 37b0862 commit 350b673
Show file tree
Hide file tree
Showing 2 changed files with 216 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Cartography.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
9AE90A0829FAF36E00944F10 /* AnchorSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AE90A0729FAF36E00944F10 /* AnchorSupport.swift */; };
9AE90A0929FAF36E00944F10 /* AnchorSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AE90A0729FAF36E00944F10 /* AnchorSupport.swift */; };
9AE90A0A29FAF36E00944F10 /* AnchorSupport.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AE90A0729FAF36E00944F10 /* AnchorSupport.swift */; };
9AE90A0C29FB03DC00944F10 /* OffsetDimensionSpec.swift in Sources */ = {isa = PBXBuildFile; fileRef = 9AE90A0B29FB03DC00944F10 /* OffsetDimensionSpec.swift */; };
A75B6143FF12C54FF3223B47 /* Pods_TestPods_Cartography_tvOS_tests.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 0827A83361EACF1E6062607E /* Pods_TestPods_Cartography_tvOS_tests.framework */; };
D63BD7B82089B6FA00061239 /* LayoutItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE85314F1F9363DC003EC021 /* LayoutItem.swift */; };
EE8531501F936462003EC021 /* LayoutItem.swift in Sources */ = {isa = PBXBuildFile; fileRef = EE85314F1F9363DC003EC021 /* LayoutItem.swift */; };
Expand Down Expand Up @@ -280,6 +281,7 @@
97F50E531F9633AA00C6DCF5 /* ViewLayoutGuideSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ViewLayoutGuideSpec.swift; sourceTree = "<group>"; };
9AE90A0329FAF2D700944F10 /* Edge+OffsetOperator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Edge+OffsetOperator.swift"; sourceTree = "<group>"; };
9AE90A0729FAF36E00944F10 /* AnchorSupport.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AnchorSupport.swift; sourceTree = "<group>"; };
9AE90A0B29FB03DC00944F10 /* OffsetDimensionSpec.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = OffsetDimensionSpec.swift; sourceTree = "<group>"; };
EE85314F1F9363DC003EC021 /* LayoutItem.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LayoutItem.swift; sourceTree = "<group>"; };
EEDD4098FF7503B1F9188F10 /* Pods_Cartography_iOS_Tests.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = Pods_Cartography_iOS_Tests.framework; sourceTree = BUILT_PRODUCTS_DIR; };
/* End PBXFileReference section */
Expand Down Expand Up @@ -476,6 +478,7 @@
979F29C91F94DC6B00257363 /* LayoutGuideSpec.swift */,
97D17C9D1F8E774700C57CE1 /* PrioritySpec.swift */,
54C96A23195063CD000CDD27 /* DimensionSpec.swift */,
9AE90A0B29FB03DC00944F10 /* OffsetDimensionSpec.swift */,
97D17C9E1F8E774700C57CE1 /* TestView.swift */,
97D17C9F1F8E774700C57CE1 /* Matchers.swift */,
97D17CA01F8E774700C57CE1 /* DistributeSpec.swift */,
Expand Down Expand Up @@ -906,6 +909,7 @@
97F50E541F9633AA00C6DCF5 /* ViewLayoutGuideSpec.swift in Sources */,
1B319C622162740100DD91D4 /* ViewProxyTests.swift in Sources */,
9795590B1F9701CD0096BBEA /* ConstraintGroupSpec.swift in Sources */,
9AE90A0C29FB03DC00944F10 /* OffsetDimensionSpec.swift in Sources */,
979559081F9701C90096BBEA /* MemoryLeakSpec.swift in Sources */,
979558FC1F97019E0096BBEA /* Matchers.swift in Sources */,
979559021F9701B10096BBEA /* PointSpec.swift in Sources */,
Expand Down
212 changes: 212 additions & 0 deletions CartographyTests/OffsetDimensionSpec.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,212 @@
import Cartography

import Nimble
import Quick

class OffsetDimensionSpec: QuickSpec {
override func spec() {
var window: TestWindow!
var view: TestView!

beforeEach {
window = TestWindow(frame: CGRect(x: 0, y: 0, width: 600, height: 600))

view = TestView(frame: CGRect.zero)

constrain(view) { view in
view.height == 200
view.width == 200
}

window.addSubview(view)
}

describe("X-Axis Offset") {
it("should support relative equalities to other offsets") {
constrain(view) { view in
view.superview!.left |-| view.left == view.right |-| view.superview!.right
}

window.layoutIfNeeded()

expect(view.frame.minX).to(equal(200))
}

it("should support relative equalities to real dimensions") {
constrain(view) { view in
view.superview!.left |-| view.left == view.width
view.width == view.right |-| view.superview!.right
}

window.layoutIfNeeded()

expect(view.frame.minX).to(equal(200))
}

it("should support relative inequalities") {
constrain(view) { view in
view.superview!.left |-| view.left >= view.width
view.superview!.left |-| view.left <= view.width
}

window.layoutIfNeeded()

expect(view.frame.minX).to(equal(200))
}

it("should support addition") {
constrain(view) { view in
view.superview!.left |-| view.left == view.width + 100
}

window.layoutIfNeeded()

expect(view.frame.minX).to(equal(300))
}

it("should support subtraction") {
constrain(view) { view in
view.superview!.left |-| view.left == view.width - 100
}

window.layoutIfNeeded()

expect(view.frame.minX).to(equal(100))
}

it("should support multiplication") {
constrain(view) { view in
view.superview!.left |-| view.left == view.width * 2
}

window.layoutIfNeeded()

expect(view.frame.minX).to(equal(400))
}

it("should support division") {
constrain(view) { view in
view.superview!.left |-| view.left == view.width / 2
}

window.layoutIfNeeded()

expect(view.frame.minX).to(equal(100))
}

it("should support complex expressions") {
constrain(view) { view in
view.superview!.left |-| view.left == view.width / 2 + 100
}

window.layoutIfNeeded()

expect(view.frame.minX).to(equal(200))
}

it("should support numerical equalities") {
constrain(view) { view in
view.superview!.left |-| view.left == 200
}

window.layoutIfNeeded()

expect(view.frame.minX).to(equal(200))
}
}

describe("Y-Axis Offset") {
it("should support relative equalities to other offsets") {
constrain(view) { view in
view.superview!.top |-| view.top == view.bottom |-| view.superview!.bottom
}

window.layoutIfNeeded()

expect(view.frame.minY).to(equal(200))
}

it("should support relative equalities to real dimensions") {
constrain(view) { view in
view.superview!.top |-| view.top == view.height
view.height == view.bottom |-| view.superview!.bottom
}

window.layoutIfNeeded()

expect(view.frame.minY).to(equal(200))
}

it("should support relative inequalities") {
constrain(view) { view in
view.superview!.top |-| view.top >= view.width
view.superview!.top |-| view.top <= view.width
}

window.layoutIfNeeded()

expect(view.frame.minY).to(equal(200))
}

it("should support addition") {
constrain(view) { view in
view.superview!.top |-| view.top == view.height + 100
}

window.layoutIfNeeded()

expect(view.frame.minY).to(equal(300))
}

it("should support subtraction") {
constrain(view) { view in
view.superview!.top |-| view.top == view.height - 100
}

window.layoutIfNeeded()

expect(view.frame.minY).to(equal(100))
}

it("should support multiplication") {
constrain(view) { view in
view.superview!.top |-| view.top == view.height * 2
}

window.layoutIfNeeded()

expect(view.frame.minY).to(equal(400))
}

it("should support division") {
constrain(view) { view in
view.superview!.top |-| view.top == view.height / 2
}

window.layoutIfNeeded()

expect(view.frame.minY).to(equal(100))
}

it("should support complex expressions") {
constrain(view) { view in
view.superview!.top |-| view.top == view.height / 2 + 100
}

window.layoutIfNeeded()

expect(view.frame.minY).to(equal(200))
}

it("should support numerical equalities") {
constrain(view) { view in
view.superview!.top |-| view.top == 200
}

window.layoutIfNeeded()

expect(view.frame.minY).to(equal(200))
}
}
}
}

0 comments on commit 350b673

Please sign in to comment.