Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Source/API/Utils/CrossPlattformGraphics.swift
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@
public static var topRight: RectCorner = .init(rawValue: 1 << 1)
public static var bottomLeft: RectCorner = .init(rawValue: 1 << 2)
public static var bottomRight: RectCorner = .init(rawValue: 1 << 3)
public static var allCorners: RectCorner = .init(rawValue: 1 << 4 - 1)
public static var allCorners: RectCorner = .init(rawValue: (1 << 4) - 1)

let value: Int

Expand Down
70 changes: 70 additions & 0 deletions Tests/TPPDFTests/Utils/RectCornerTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
//
// RectCornerTests.swift
// TPPDF_Tests
//
// Created by Philip Niedertscheider on 2025-12-29.
// Copyright © 2016-2025 techprimate GmbH. All rights reserved.
//

#if !os(iOS) && !os(tvOS) && !os(watchOS) && !os(visionOS)
import Testing
@testable import TPPDF

@Suite("RectCorner Tests")
struct RectCornerTests {
@Test("Individual corner raw values are correct")
func testIndividualCornerRawValues() {
#expect(RectCorner.topLeft.rawValue == 1) // 1 << 0 = 0b0001
#expect(RectCorner.topRight.rawValue == 2) // 1 << 1 = 0b0010
#expect(RectCorner.bottomLeft.rawValue == 4) // 1 << 2 = 0b0100
#expect(RectCorner.bottomRight.rawValue == 8) // 1 << 3 = 0b1000
}

@Test("allCorners raw value is correct")
func testAllCornersRawValue() {
// allCorners should be (1 << 4) - 1 = 16 - 1 = 15 = 0b1111
#expect(RectCorner.allCorners.rawValue == 15)
}

@Test("allCorners contains all individual corners")
func testAllCornersContainsAllCorners() {
#expect(RectCorner.allCorners.contains(.topLeft))
#expect(RectCorner.allCorners.contains(.topRight))
#expect(RectCorner.allCorners.contains(.bottomLeft))
#expect(RectCorner.allCorners.contains(.bottomRight))
}

@Test("Can combine corners using OptionSet operations")
func testCombineCorners() {
let topCorners: RectCorner = [.topLeft, .topRight]
#expect(topCorners.contains(.topLeft))
#expect(topCorners.contains(.topRight))
#expect(!topCorners.contains(.bottomLeft))
#expect(!topCorners.contains(.bottomRight))

let bottomCorners: RectCorner = [.bottomLeft, .bottomRight]
#expect(bottomCorners.contains(.bottomLeft))
#expect(bottomCorners.contains(.bottomRight))
#expect(!bottomCorners.contains(.topLeft))
#expect(!bottomCorners.contains(.topRight))
}

@Test("Can create RectCorner from raw value")
func testInitFromRawValue() {
let corner = RectCorner(rawValue: 1)
#expect(corner.rawValue == 1)
#expect(corner == .topLeft)

let allCornersFromRaw = RectCorner(rawValue: 15)
#expect(allCornersFromRaw.rawValue == 15)
#expect(allCornersFromRaw == .allCorners)
}

@Test("Union of all individual corners equals allCorners")
func testUnionEqualsAllCorners() {
let combined: RectCorner = [.topLeft, .topRight, .bottomLeft, .bottomRight]
#expect(combined.rawValue == RectCorner.allCorners.rawValue)
#expect(combined == .allCorners)
}
}
#endif
Loading