diff --git a/Tests/TPPDFTests/Table/PDFTableCellAlignmentTests.swift b/Tests/TPPDFTests/Table/PDFTableCellAlignmentTests.swift new file mode 100644 index 00000000..4c5198fe --- /dev/null +++ b/Tests/TPPDFTests/Table/PDFTableCellAlignmentTests.swift @@ -0,0 +1,45 @@ +// +// PDFTableCellAlignmentTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.12.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import Testing +@testable import TPPDF + +struct PDFTableCellAlignmentTests { + @Test(arguments: [ + (0, true, false, true, false), + (1, true, false, false, false), + (2, true, false, false, true), + (3, false, false, true, false), + (4, false, false, false, false), + (5, false, false, false, true), + (6, false, true, true, false), + (7, false, true, false, false), + (8, false, true, false, true), + ]) + func alignmentIdentifiesItsVerticalAndHorizontalEdges( + index: Int, expectedTop: Bool, expectedBottom: Bool, expectedLeft: Bool, expectedRight: Bool + ) { + // Arrange + let alignments: [PDFTableCellAlignment] = [ + .topLeft, .top, .topRight, .left, .center, .right, .bottomLeft, .bottom, .bottomRight, + ] + let alignment = alignments[index] + + // Act + let isTop = alignment.isTop + let isBottom = alignment.isBottom + let isLeft = alignment.isLeft + let isRight = alignment.isRight + + // Assert + #expect(isTop == expectedTop) + #expect(isBottom == expectedBottom) + #expect(isLeft == expectedLeft) + #expect(isRight == expectedRight) + } +} diff --git a/Tests/TPPDFTests/Table/PDFTableCellAlignment_Spec.swift b/Tests/TPPDFTests/Table/PDFTableCellAlignment_Spec.swift deleted file mode 100644 index c71157c6..00000000 --- a/Tests/TPPDFTests/Table/PDFTableCellAlignment_Spec.swift +++ /dev/null @@ -1,113 +0,0 @@ -// -// PDFTableCellAlignment_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.12.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFTableCellAlignment_Spec: QuickSpec { - // swiftlint:disable closure_body_length function_body_length - override func spec() { - describe("PDFTableCellAlignment") { - context("enum values") { - it("has topLeft") { - expect(PDFTableCellAlignment.topLeft).toNot(beNil()) - } - - it("has top") { - expect(PDFTableCellAlignment.top).toNot(beNil()) - } - - it("has topRight") { - expect(PDFTableCellAlignment.topRight).toNot(beNil()) - } - - it("has left") { - expect(PDFTableCellAlignment.left).toNot(beNil()) - } - - it("has center") { - expect(PDFTableCellAlignment.center).toNot(beNil()) - } - - it("has right") { - expect(PDFTableCellAlignment.right).toNot(beNil()) - } - - it("has bottomLeft") { - expect(PDFTableCellAlignment.bottomLeft).toNot(beNil()) - } - - it("has bottom") { - expect(PDFTableCellAlignment.bottom).toNot(beNil()) - } - - it("has bottomRight") { - expect(PDFTableCellAlignment.bottomRight).toNot(beNil()) - } - } - - it("has a method to check if it is at top") { - expect(PDFTableCellAlignment.topLeft.isTop).to(beTrue()) - expect(PDFTableCellAlignment.top.isTop).to(beTrue()) - expect(PDFTableCellAlignment.topRight.isTop).to(beTrue()) - - expect(PDFTableCellAlignment.left.isTop).to(beFalse()) - expect(PDFTableCellAlignment.center.isTop).to(beFalse()) - expect(PDFTableCellAlignment.right.isTop).to(beFalse()) - - expect(PDFTableCellAlignment.bottomLeft.isTop).to(beFalse()) - expect(PDFTableCellAlignment.bottom.isTop).to(beFalse()) - expect(PDFTableCellAlignment.bottomRight.isTop).to(beFalse()) - } - - it("has a method to check if it is at bottom") { - expect(PDFTableCellAlignment.topLeft.isBottom).to(beFalse()) - expect(PDFTableCellAlignment.top.isBottom).to(beFalse()) - expect(PDFTableCellAlignment.topRight.isBottom).to(beFalse()) - - expect(PDFTableCellAlignment.left.isBottom).to(beFalse()) - expect(PDFTableCellAlignment.center.isBottom).to(beFalse()) - expect(PDFTableCellAlignment.right.isBottom).to(beFalse()) - - expect(PDFTableCellAlignment.bottomLeft.isBottom).to(beTrue()) - expect(PDFTableCellAlignment.bottom.isBottom).to(beTrue()) - expect(PDFTableCellAlignment.bottomRight.isBottom).to(beTrue()) - } - - it("has a method to check if it is at left") { - expect(PDFTableCellAlignment.topLeft.isLeft).to(beTrue()) - expect(PDFTableCellAlignment.top.isLeft).to(beFalse()) - expect(PDFTableCellAlignment.topRight.isLeft).to(beFalse()) - - expect(PDFTableCellAlignment.left.isLeft).to(beTrue()) - expect(PDFTableCellAlignment.center.isLeft).to(beFalse()) - expect(PDFTableCellAlignment.right.isLeft).to(beFalse()) - - expect(PDFTableCellAlignment.bottomLeft.isLeft).to(beTrue()) - expect(PDFTableCellAlignment.bottom.isLeft).to(beFalse()) - expect(PDFTableCellAlignment.bottomRight.isLeft).to(beFalse()) - } - - it("has a method to check if it is at right") { - expect(PDFTableCellAlignment.topLeft.isRight).to(beFalse()) - expect(PDFTableCellAlignment.top.isRight).to(beFalse()) - expect(PDFTableCellAlignment.topRight.isRight).to(beTrue()) - - expect(PDFTableCellAlignment.left.isRight).to(beFalse()) - expect(PDFTableCellAlignment.center.isRight).to(beFalse()) - expect(PDFTableCellAlignment.right.isRight).to(beTrue()) - - expect(PDFTableCellAlignment.bottomLeft.isRight).to(beFalse()) - expect(PDFTableCellAlignment.bottom.isRight).to(beFalse()) - expect(PDFTableCellAlignment.bottomRight.isRight).to(beTrue()) - } - } - } - // swiftlint:enable closure_body_length function_body_length -} diff --git a/Tests/TPPDFTests/Table/PDFTableCellBorders+Equatable_Spec.swift b/Tests/TPPDFTests/Table/PDFTableCellBorders+Equatable_Spec.swift deleted file mode 100644 index 2d73e3d8..00000000 --- a/Tests/TPPDFTests/Table/PDFTableCellBorders+Equatable_Spec.swift +++ /dev/null @@ -1,47 +0,0 @@ -// -// PDFTableCellBorders+Equatable_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.16.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFTableCellBorders_Equatable_Spec: QuickSpec { - override func spec() { - describe("PDFTableCellBorders") { - context("Equatable") { - let style = PDFLineStyle(type: .dotted, color: .orange, width: 10) - let borders = PDFTableCellBorders() - - it("is equal") { - let otherBorders = PDFTableCellBorders() - expect(borders) == otherBorders - } - - it("is not equal with different left") { - let otherBorders = PDFTableCellBorders(left: style) - expect(borders) != otherBorders - } - - it("is not equal with different top") { - let otherBorders = PDFTableCellBorders(top: style) - expect(borders) != otherBorders - } - - it("is not equal with different right") { - let otherBorders = PDFTableCellBorders(right: style) - expect(borders) != otherBorders - } - - it("is not equal with different bottom") { - let otherBorders = PDFTableCellBorders(bottom: style) - expect(borders) != otherBorders - } - } - } - } -} diff --git a/Tests/TPPDFTests/Table/PDFTableCellBordersEquatableTests.swift b/Tests/TPPDFTests/Table/PDFTableCellBordersEquatableTests.swift new file mode 100644 index 00000000..9695e7a6 --- /dev/null +++ b/Tests/TPPDFTests/Table/PDFTableCellBordersEquatableTests.swift @@ -0,0 +1,44 @@ +// +// PDFTableCellBordersEquatableTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.16.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import Testing +@testable import TPPDF + +struct PDFTableCellBordersEquatableTests { + @Test func defaultBordersAreEqual() { + // Arrange + let borders = PDFTableCellBorders() + let otherBorders = PDFTableCellBorders() + + // Act + let isEqual = borders == otherBorders + + // Assert + #expect(isEqual) + } + + @Test(arguments: ["left", "top", "right", "bottom"]) + func changingAnyBorderMakesBordersUnequal(edge: String) { + // Arrange + let borders = PDFTableCellBorders() + let style = PDFLineStyle(type: .dotted, color: .orange, width: 10) + var otherBorders = PDFTableCellBorders() + switch edge { + case "left": otherBorders.left = style + case "top": otherBorders.top = style + case "right": otherBorders.right = style + default: otherBorders.bottom = style + } + + // Act + let isEqual = borders == otherBorders + + // Assert + #expect(!isEqual) + } +} diff --git a/Tests/TPPDFTests/Table/PDFTableCellBordersTests.swift b/Tests/TPPDFTests/Table/PDFTableCellBordersTests.swift new file mode 100644 index 00000000..4b998130 --- /dev/null +++ b/Tests/TPPDFTests/Table/PDFTableCellBordersTests.swift @@ -0,0 +1,53 @@ +// +// PDFTableCellBordersTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.16.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import Testing +@testable import TPPDF + +struct PDFTableCellBordersTests { + @Test func initializingWithoutBordersUsesNoLineOnEveryEdge() { + // Arrange + let expectedStyle = PDFLineStyle.none + + // Act + let borders = PDFTableCellBorders() + + // Assert + #expect(borders.left == expectedStyle) + #expect(borders.top == expectedStyle) + #expect(borders.right == expectedStyle) + #expect(borders.bottom == expectedStyle) + } + + @Test(arguments: ["left", "top", "right", "bottom"]) + func initializingOneBorderPreservesItsStyle(edge: String) { + // Arrange + let style = PDFLineStyle(type: .dotted, color: .orange, width: 10) + + // Act + let borders: PDFTableCellBorders + let actualStyle: PDFLineStyle + switch edge { + case "left": + borders = PDFTableCellBorders(left: style) + actualStyle = borders.left + case "top": + borders = PDFTableCellBorders(top: style) + actualStyle = borders.top + case "right": + borders = PDFTableCellBorders(right: style) + actualStyle = borders.right + default: + borders = PDFTableCellBorders(bottom: style) + actualStyle = borders.bottom + } + + // Assert + #expect(actualStyle == style) + } +} diff --git a/Tests/TPPDFTests/Table/PDFTableCellBorders_Spec.swift b/Tests/TPPDFTests/Table/PDFTableCellBorders_Spec.swift deleted file mode 100644 index 96bcd5f2..00000000 --- a/Tests/TPPDFTests/Table/PDFTableCellBorders_Spec.swift +++ /dev/null @@ -1,69 +0,0 @@ -// -// PDFTableCellBorders_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.16.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFTableCellBorders_Spec: QuickSpec { - // swiftlint:disable closure_body_length - override func spec() { - describe("PDFTableCellBorders") { - context("variables") { - let borders = PDFTableCellBorders() - - it("has default left border") { - expect(borders.left) == PDFLineStyle.none - } - - it("has default top border") { - expect(borders.top) == PDFLineStyle.none - } - - it("has a default right border") { - expect(borders.right) == PDFLineStyle.none - } - - it("has a default bottom border") { - expect(borders.bottom) == PDFLineStyle.none - } - } - - context("initializer") { - it("can be initialized with a left border") { - let style = PDFLineStyle(type: .dotted, color: .orange, width: 10) - let borders = PDFTableCellBorders(left: style) - - expect(borders.left) == style - } - - it("can be initialized with a top border") { - let style = PDFLineStyle(type: .dotted, color: .orange, width: 10) - let borders = PDFTableCellBorders(top: style) - - expect(borders.top) == style - } - - it("can be initialized with a right border") { - let style = PDFLineStyle(type: .dotted, color: .orange, width: 10) - let borders = PDFTableCellBorders(right: style) - - expect(borders.right) == style - } - - it("can be initialized with a bottom border") { - let style = PDFLineStyle(type: .dotted, color: .orange, width: 10) - let borders = PDFTableCellBorders(bottom: style) - - expect(borders.bottom) == style - } - } - } - } - // swiftlint:enable closure_body_length -} diff --git a/Tests/TPPDFTests/Table/PDFTableCellStyle+Equatable_Spec.swift b/Tests/TPPDFTests/Table/PDFTableCellStyle+Equatable_Spec.swift deleted file mode 100644 index 877fbd0e..00000000 --- a/Tests/TPPDFTests/Table/PDFTableCellStyle+Equatable_Spec.swift +++ /dev/null @@ -1,44 +0,0 @@ -// -// PDFTableCellStyle+Equatable_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.16.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFTableCellStyle_Equatable_Spec: QuickSpec { - override func spec() { - describe("PDFTableCellStyle") { - context("Equatable") { - let style = PDFTableCellStyle() - - it("is equal") { - let otherStyle = PDFTableCellStyle() - expect(style) == otherStyle - } - - it("is not equal with different colors") { - let colors = (fill: Color.red, text: Color.blue) - let otherStyle = PDFTableCellStyle(colors: colors) - expect(style) != otherStyle - } - - it("is not equal with different borders") { - let borders = PDFTableCellBorders(left: PDFLineStyle(type: .dotted)) - let otherStyle = PDFTableCellStyle(borders: borders) - expect(style) != otherStyle - } - - it("is not equal with different font") { - let font = Font.boldSystemFont(ofSize: 10.0) - let otherStyle = PDFTableCellStyle(font: font) - expect(style) != otherStyle - } - } - } - } -} diff --git a/Tests/TPPDFTests/Table/PDFTableCellStyleEquatableTests.swift b/Tests/TPPDFTests/Table/PDFTableCellStyleEquatableTests.swift new file mode 100644 index 00000000..cfb80fa1 --- /dev/null +++ b/Tests/TPPDFTests/Table/PDFTableCellStyleEquatableTests.swift @@ -0,0 +1,42 @@ +// +// PDFTableCellStyleEquatableTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.16.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import Testing +@testable import TPPDF + +struct PDFTableCellStyleEquatableTests { + @Test func defaultCellStylesAreEqual() { + // Arrange + let style = PDFTableCellStyle() + let otherStyle = PDFTableCellStyle() + + // Act + let isEqual = style == otherStyle + + // Assert + #expect(isEqual) + } + + @Test(arguments: ["colors", "borders", "font"]) + func changingCellStyleValuesMakesStylesUnequal(property: String) { + // Arrange + let style = PDFTableCellStyle() + let otherStyle: PDFTableCellStyle + switch property { + case "colors": otherStyle = PDFTableCellStyle(colors: (fill: .red, text: .blue)) + case "borders": otherStyle = PDFTableCellStyle(borders: PDFTableCellBorders(left: PDFLineStyle(type: .dotted))) + default: otherStyle = PDFTableCellStyle(font: Font.boldSystemFont(ofSize: 10)) + } + + // Act + let isEqual = style == otherStyle + + // Assert + #expect(!isEqual) + } +} diff --git a/Tests/TPPDFTests/Table/PDFTableCellStyleTests.swift b/Tests/TPPDFTests/Table/PDFTableCellStyleTests.swift new file mode 100644 index 00000000..a548fe05 --- /dev/null +++ b/Tests/TPPDFTests/Table/PDFTableCellStyleTests.swift @@ -0,0 +1,61 @@ +// +// PDFTableCellStyleTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.16.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import Testing +@testable import TPPDF + +struct PDFTableCellStyleTests { + @Test func initializingWithoutArgumentsUsesDefaultColorsBordersAndFont() { + // Arrange + let expectedBorders = PDFTableCellBorders() + let expectedFont = Font.systemFont(ofSize: PDFConstants.defaultFontSize) + + // Act + let style = PDFTableCellStyle() + + // Assert + #expect(style.colors.fill == .clear) + #expect(style.colors.text == .black) + #expect(style.borders == expectedBorders) + #expect(style.font == expectedFont) + } + + @Test func initializingWithColorsPreservesFillAndTextColors() { + // Arrange + let colors = (fill: Color.orange, text: Color.green) + + // Act + let style = PDFTableCellStyle(colors: colors) + + // Assert + #expect(style.colors.fill == colors.fill) + #expect(style.colors.text == colors.text) + } + + @Test func initializingWithBordersPreservesBorders() { + // Arrange + let borders = PDFTableCellBorders(left: PDFLineStyle(type: .dotted, color: .purple, width: 15)) + + // Act + let style = PDFTableCellStyle(borders: borders) + + // Assert + #expect(style.borders == borders) + } + + @Test func initializingWithFontPreservesFont() { + // Arrange + let font = Font.systemFont(ofSize: 25) + + // Act + let style = PDFTableCellStyle(font: font) + + // Assert + #expect(style.font == font) + } +} diff --git a/Tests/TPPDFTests/Table/PDFTableCellStyle_Spec.swift b/Tests/TPPDFTests/Table/PDFTableCellStyle_Spec.swift deleted file mode 100644 index 0f473a89..00000000 --- a/Tests/TPPDFTests/Table/PDFTableCellStyle_Spec.swift +++ /dev/null @@ -1,60 +0,0 @@ -// -// PDFTableCellStyle_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.16.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFTableCellStyle_Spec: QuickSpec { - // swiftlint:disable closure_body_length - override func spec() { - describe("PDFTableCellStyle") { - context("variables") { - let style = PDFTableCellStyle() - - it("has default colors") { - expect(style.colors.fill) == Color.clear - expect(style.colors.text) == Color.black - } - - it("has default borders") { - expect(style.borders) == PDFTableCellBorders() - } - - it("has a default font") { - expect(style.font) == Font.systemFont(ofSize: PDFConstants.defaultFontSize) - } - } - - context("initializer") { - it("can be initialized with colors") { - let colors = (fill: Color.orange, text: Color.green) - let cell = PDFTableCellStyle(colors: colors) - - expect(cell.colors.fill) == Color.orange - expect(cell.colors.text) == Color.green - } - - it("can be initialized with borders") { - let borders = PDFTableCellBorders(left: PDFLineStyle(type: .dotted, color: .purple, width: 15)) - let cell = PDFTableCellStyle(borders: borders) - - expect(cell.borders) == borders - } - - it("can be initialized with a font") { - let font = Font.systemFont(ofSize: 25) - let cell = PDFTableCellStyle(font: font) - - expect(cell.font) == font - } - } - } - } - // swiftlint:enable closure_body_length -} diff --git a/Tests/TPPDFTests/Table/PDFTableStyle+Defaults_Spec.swift b/Tests/TPPDFTests/Table/PDFTableStyle+Defaults_Spec.swift deleted file mode 100644 index cc2ff401..00000000 --- a/Tests/TPPDFTests/Table/PDFTableStyle+Defaults_Spec.swift +++ /dev/null @@ -1,66 +0,0 @@ -// -// PDFTableStyle+Defaults_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.13.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFTableStyle_Defaults_Spec: QuickSpec { - // swiftlint:disable closure_body_length - override func spec() { - describe("PDFTableStyle") { - context("Defaults") { - it("has a simple style") { - let darkGray = Color(red: 59.0 / 255.0, green: 59.0 / 255.0, blue: 59.0 / 255.0, alpha: 1.0) - - let simple = PDFTableStyleDefaults.simple - - expect(simple.rowHeaderCount) == 1 - expect(simple.columnHeaderCount) == 1 - expect(simple.footerCount) == 0 - - expect(simple.outline) == PDFLineStyle(type: .full, color: Color.darkGray, width: 1.0) - expect(simple.rowHeaderStyle) == PDFTableCellStyle( - colors: (fill: Color.white, text: darkGray), - borders: PDFTableCellBorders(bottom: PDFLineStyle( - type: .full, - color: Color.lightGray, - width: 0.5 - )), - font: Font.boldSystemFont(ofSize: 12.0) - ) - expect(simple.columnHeaderStyle) == PDFTableCellStyle( - colors: ( - fill: Color(red: 83.0 / 255.0, green: 171.0 / 255.0, blue: 104.0 / 255.0, alpha: 1.0), - text: Color.white - ), - borders: PDFTableCellBorders(), - font: Font.boldSystemFont(ofSize: 14) - ) - expect(simple.contentStyle) == PDFTableCellStyle( - colors: ( - fill: Color(red: 246.0 / 255.0, green: 246.0 / 255.0, blue: 246.0 / 255.0, alpha: 1.0), - text: darkGray - ), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 14) - ) - expect(simple.alternatingContentStyle) == PDFTableCellStyle( - colors: ( - fill: Color(red: 233.0 / 255.0, green: 233.0 / 255.0, blue: 233.0 / 255.0, alpha: 1.0), - text: darkGray - ), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 14) - ) - } - } - } - } - // swiftlint:enable closure_body_length -} diff --git a/Tests/TPPDFTests/Table/PDFTableStyle+Equatable_Spec.swift b/Tests/TPPDFTests/Table/PDFTableStyle+Equatable_Spec.swift deleted file mode 100644 index 95d751f0..00000000 --- a/Tests/TPPDFTests/Table/PDFTableStyle+Equatable_Spec.swift +++ /dev/null @@ -1,179 +0,0 @@ -// -// PDFTableStyle+Equatable_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.13.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFTableStyle_Equatable_Spec: QuickSpec { - // swiftlint:disable closure_body_length function_body_length - override func spec() { - describe("PDFTableStyle") { - context("Equatable") { - let style = PDFTableStyle(rowHeaderCount: 1, - columnHeaderCount: 2, - footerCount: 3, - outline: PDFLineStyle.none, - rowHeaderStyle: PDFTableCellStyle(), - columnHeaderStyle: PDFTableCellStyle(), - footerStyle: PDFTableCellStyle(), - contentStyle: PDFTableCellStyle(), - alternatingContentStyle: PDFTableCellStyle()) - - it("is equal") { - let otherStyle = PDFTableStyle(rowHeaderCount: 1, - columnHeaderCount: 2, - footerCount: 3, - outline: PDFLineStyle.none, - rowHeaderStyle: PDFTableCellStyle(), - columnHeaderStyle: PDFTableCellStyle(), - footerStyle: PDFTableCellStyle(), - contentStyle: PDFTableCellStyle(), - alternatingContentStyle: PDFTableCellStyle()) - - expect(style) == otherStyle - } - - it("is not equal with different row header count") { - let otherStyle = PDFTableStyle(rowHeaderCount: 1000, - columnHeaderCount: 2, - footerCount: 3, - outline: PDFLineStyle.none, - rowHeaderStyle: PDFTableCellStyle(), - columnHeaderStyle: PDFTableCellStyle(), - footerStyle: PDFTableCellStyle(), - contentStyle: PDFTableCellStyle(), - alternatingContentStyle: PDFTableCellStyle()) - - expect(style) != otherStyle - } - - it("is not equal with different column header count") { - let otherStyle = PDFTableStyle(rowHeaderCount: 1, - columnHeaderCount: 1000, - footerCount: 3, - outline: PDFLineStyle.none, - rowHeaderStyle: PDFTableCellStyle(), - columnHeaderStyle: PDFTableCellStyle(), - footerStyle: PDFTableCellStyle(), - contentStyle: PDFTableCellStyle(), - alternatingContentStyle: PDFTableCellStyle()) - - expect(style) != otherStyle - } - - it("is not equal with different footer count") { - let otherStyle = PDFTableStyle(rowHeaderCount: 1, - columnHeaderCount: 2, - footerCount: 1000, - outline: PDFLineStyle.none, - rowHeaderStyle: PDFTableCellStyle(), - columnHeaderStyle: PDFTableCellStyle(), - footerStyle: PDFTableCellStyle(), - contentStyle: PDFTableCellStyle(), - alternatingContentStyle: PDFTableCellStyle()) - - expect(style) != otherStyle - } - - it("is not equal with different outline") { - let otherStyle = PDFTableStyle(rowHeaderCount: 1, - columnHeaderCount: 2, - footerCount: 3, - outline: PDFLineStyle(type: .dotted, color: .orange, width: 1.0), - rowHeaderStyle: PDFTableCellStyle(), - columnHeaderStyle: PDFTableCellStyle(), - footerStyle: PDFTableCellStyle(), - contentStyle: PDFTableCellStyle(), - alternatingContentStyle: PDFTableCellStyle()) - - expect(style) != otherStyle - } - - it("is not equal with different row header style") { - let otherStyle = PDFTableStyle(rowHeaderCount: 1, - columnHeaderCount: 2, - footerCount: 3, - outline: PDFLineStyle.none, - rowHeaderStyle: PDFTableCellStyle(colors: (fill: Color.red, text: Color.blue), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 20)), - columnHeaderStyle: PDFTableCellStyle(), - footerStyle: PDFTableCellStyle(), - contentStyle: PDFTableCellStyle(), - alternatingContentStyle: PDFTableCellStyle()) - - expect(style) != otherStyle - } - - it("is not equal with different column header style") { - let otherStyle = PDFTableStyle(rowHeaderCount: 1, - columnHeaderCount: 2, - footerCount: 3, - outline: PDFLineStyle.none, - rowHeaderStyle: PDFTableCellStyle(), - columnHeaderStyle: PDFTableCellStyle(colors: (fill: Color.red, text: Color.blue), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 20)), - footerStyle: PDFTableCellStyle(), - contentStyle: PDFTableCellStyle(), - alternatingContentStyle: PDFTableCellStyle()) - - expect(style) != otherStyle - } - - it("is not equal with different footer style") { - let otherStyle = PDFTableStyle(rowHeaderCount: 1, - columnHeaderCount: 2, - footerCount: 3, - outline: PDFLineStyle.none, - rowHeaderStyle: PDFTableCellStyle(), - columnHeaderStyle: PDFTableCellStyle(), - footerStyle: PDFTableCellStyle(colors: (fill: Color.red, text: Color.blue), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 20)), - contentStyle: PDFTableCellStyle(), - alternatingContentStyle: PDFTableCellStyle()) - - expect(style) != otherStyle - } - - it("is not equal with different content style") { - let otherStyle = PDFTableStyle(rowHeaderCount: 1, - columnHeaderCount: 2, - footerCount: 3, - outline: PDFLineStyle.none, - rowHeaderStyle: PDFTableCellStyle(), - columnHeaderStyle: PDFTableCellStyle(), - footerStyle: PDFTableCellStyle(), - contentStyle: PDFTableCellStyle(colors: (fill: Color.red, text: Color.blue), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 20)), - alternatingContentStyle: PDFTableCellStyle()) - - expect(style) != otherStyle - } - - it("is not equal with different alternatingContentStyle") { - let otherStyle = PDFTableStyle(rowHeaderCount: 1, - columnHeaderCount: 2, - footerCount: 3, - outline: PDFLineStyle.none, - rowHeaderStyle: PDFTableCellStyle(), - columnHeaderStyle: PDFTableCellStyle(), - footerStyle: PDFTableCellStyle(), - contentStyle: PDFTableCellStyle(), - alternatingContentStyle: nil) - - expect(style) != otherStyle - } - } - } - } - // swiftlint:enable closure_body_length function_body_length -} diff --git a/Tests/TPPDFTests/Table/PDFTableStyleDefaultsTests.swift b/Tests/TPPDFTests/Table/PDFTableStyleDefaultsTests.swift new file mode 100644 index 00000000..e1a1b2de --- /dev/null +++ b/Tests/TPPDFTests/Table/PDFTableStyleDefaultsTests.swift @@ -0,0 +1,48 @@ +// +// PDFTableStyleDefaultsTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.13.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import Testing +@testable import TPPDF + +struct PDFTableStyleDefaultsTests { + @Test func simpleStyleUsesExpectedHeadersOutlineAndAlternatingContent() { + // Arrange + let darkGray = Color(red: 59.0 / 255, green: 59.0 / 255, blue: 59.0 / 255, alpha: 1) + let outline = PDFLineStyle(type: .full, color: .darkGray, width: 1) + let rowHeader = PDFTableCellStyle( + colors: (fill: .white, text: darkGray), + borders: PDFTableCellBorders(bottom: PDFLineStyle(type: .full, color: .lightGray, width: 0.5)), + font: Font.boldSystemFont(ofSize: 12) + ) + let columnHeader = PDFTableCellStyle( + colors: (fill: Color(red: 83.0 / 255, green: 171.0 / 255, blue: 104.0 / 255, alpha: 1), text: .white), + font: Font.boldSystemFont(ofSize: 14) + ) + let content = PDFTableCellStyle( + colors: (fill: Color(red: 246.0 / 255, green: 246.0 / 255, blue: 246.0 / 255, alpha: 1), text: darkGray), + font: Font.systemFont(ofSize: 14) + ) + let alternatingContent = PDFTableCellStyle( + colors: (fill: Color(red: 233.0 / 255, green: 233.0 / 255, blue: 233.0 / 255, alpha: 1), text: darkGray), + font: Font.systemFont(ofSize: 14) + ) + + // Act + let style = PDFTableStyleDefaults.simple + + // Assert + #expect(style.rowHeaderCount == 1) + #expect(style.columnHeaderCount == 1) + #expect(style.footerCount == 0) + #expect(style.outline == outline) + #expect(style.rowHeaderStyle == rowHeader) + #expect(style.columnHeaderStyle == columnHeader) + #expect(style.contentStyle == content) + #expect(style.alternatingContentStyle == alternatingContent) + } +} diff --git a/Tests/TPPDFTests/Table/PDFTableStyleEquatableTests.swift b/Tests/TPPDFTests/Table/PDFTableStyleEquatableTests.swift new file mode 100644 index 00000000..243ef16d --- /dev/null +++ b/Tests/TPPDFTests/Table/PDFTableStyleEquatableTests.swift @@ -0,0 +1,61 @@ +// +// PDFTableStyleEquatableTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.13.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import Testing +@testable import TPPDF + +struct PDFTableStyleEquatableTests { + @Test func stylesWithSameValuesAreEqual() { + // Arrange + let style = makeStyle() + let otherStyle = makeStyle() + + // Act + let isEqual = style == otherStyle + + // Assert + #expect(isEqual) + } + + @Test(arguments: [ + "rowHeaderCount", "columnHeaderCount", "footerCount", "outline", "rowHeaderStyle", + "columnHeaderStyle", "footerStyle", "contentStyle", "alternatingContentStyle", + ]) + func changingAnyTableStyleValueMakesStylesUnequal(property: String) { + // Arrange + let style = makeStyle() + let otherStyle = makeStyle() + let cellStyle = PDFTableCellStyle(colors: (fill: .red, text: .blue), font: Font.systemFont(ofSize: 20)) + switch property { + case "rowHeaderCount": otherStyle.rowHeaderCount = 1000 + case "columnHeaderCount": otherStyle.columnHeaderCount = 1000 + case "footerCount": otherStyle.footerCount = 1000 + case "outline": otherStyle.outline = PDFLineStyle(type: .dotted, color: .orange, width: 1) + case "rowHeaderStyle": otherStyle.rowHeaderStyle = cellStyle + case "columnHeaderStyle": otherStyle.columnHeaderStyle = cellStyle + case "footerStyle": otherStyle.footerStyle = cellStyle + case "contentStyle": otherStyle.contentStyle = cellStyle + default: otherStyle.alternatingContentStyle = nil + } + + // Act + let isEqual = style == otherStyle + + // Assert + #expect(!isEqual) + } + + private func makeStyle() -> PDFTableStyle { + PDFTableStyle( + rowHeaderCount: 1, columnHeaderCount: 2, footerCount: 3, outline: .none, + rowHeaderStyle: PDFTableCellStyle(), columnHeaderStyle: PDFTableCellStyle(), + footerStyle: PDFTableCellStyle(), contentStyle: PDFTableCellStyle(), + alternatingContentStyle: PDFTableCellStyle() + ) + } +} diff --git a/Tests/TPPDFTests/Table/PDFTableStyleTests.swift b/Tests/TPPDFTests/Table/PDFTableStyleTests.swift new file mode 100644 index 00000000..3a180a70 --- /dev/null +++ b/Tests/TPPDFTests/Table/PDFTableStyleTests.swift @@ -0,0 +1,88 @@ +// +// PDFTableStyleTests.swift +// TPPDF +// +// Created by Philip Niedertscheider on 11.13.2017. +// Copyright © 2016-2026 techprimate GmbH. All rights reserved. +// + +import Testing +@testable import TPPDF + +struct PDFTableStyleTests { + @Test func initializingWithoutArgumentsUsesDefaultCountsAndStyles() { + // Arrange + let expectedOutline = PDFLineStyle() + let expectedCellStyle = PDFTableCellStyle() + + // Act + let style = PDFTableStyle() + + // Assert + #expect(style.rowHeaderCount == 1) + #expect(style.columnHeaderCount == 1) + #expect(style.footerCount == 1) + #expect(style.outline == expectedOutline) + #expect(style.rowHeaderStyle == expectedCellStyle) + #expect(style.columnHeaderStyle == expectedCellStyle) + #expect(style.footerStyle == expectedCellStyle) + #expect(style.contentStyle == expectedCellStyle) + #expect(style.alternatingContentStyle == nil) + } + + @Test func initializingWithValuesPreservesCountsAndEachCellStyle() { + // Arrange + let outline = PDFLineStyle(type: .dashed, color: .orange, width: 1.25) + let rowHeader = PDFTableCellStyle(colors: (fill: .blue, text: .green), font: Font.systemFont(ofSize: 10)) + let columnHeader = PDFTableCellStyle(colors: (fill: .black, text: .green), font: Font.systemFont(ofSize: 12)) + let footer = PDFTableCellStyle(colors: (fill: .purple, text: .green), font: Font.systemFont(ofSize: 15)) + let content = PDFTableCellStyle(colors: (fill: .blue, text: .orange), font: Font.systemFont(ofSize: 10)) + let alternatingContent = PDFTableCellStyle(colors: (fill: .red, text: .green), font: Font.systemFont(ofSize: 15)) + + // Act + let style = PDFTableStyle( + rowHeaderCount: 4, columnHeaderCount: 4, footerCount: 4, outline: outline, + rowHeaderStyle: rowHeader, columnHeaderStyle: columnHeader, footerStyle: footer, + contentStyle: content, alternatingContentStyle: alternatingContent + ) + + // Assert + #expect(style.rowHeaderCount == 4) + #expect(style.columnHeaderCount == 4) + #expect(style.footerCount == 4) + #expect(style.outline == outline) + #expect(style.rowHeaderStyle == rowHeader) + #expect(style.columnHeaderStyle == columnHeader) + #expect(style.footerStyle == footer) + #expect(style.contentStyle == content) + #expect(style.alternatingContentStyle == alternatingContent) + } + + @Test func copyingCreatesDistinctStyleWithAllValuesPreserved() { + // Arrange + let style = PDFTableStyle( + rowHeaderCount: 4, columnHeaderCount: 4, footerCount: 4, + outline: PDFLineStyle(type: .dashed, color: .orange, width: 1.25), + rowHeaderStyle: PDFTableCellStyle(colors: (fill: .blue, text: .green), font: Font.systemFont(ofSize: 10)), + columnHeaderStyle: PDFTableCellStyle(colors: (fill: .black, text: .green), font: Font.systemFont(ofSize: 12)), + footerStyle: PDFTableCellStyle(colors: (fill: .purple, text: .green), font: Font.systemFont(ofSize: 15)), + contentStyle: PDFTableCellStyle(colors: (fill: .blue, text: .orange), font: Font.systemFont(ofSize: 10)), + alternatingContentStyle: PDFTableCellStyle(colors: (fill: .red, text: .green), font: Font.systemFont(ofSize: 15)) + ) + + // Act + let copy = style.copy() + + // Assert + #expect(copy !== style) + #expect(copy.rowHeaderCount == style.rowHeaderCount) + #expect(copy.columnHeaderCount == style.columnHeaderCount) + #expect(copy.footerCount == style.footerCount) + #expect(copy.outline == style.outline) + #expect(copy.rowHeaderStyle == style.rowHeaderStyle) + #expect(copy.columnHeaderStyle == style.columnHeaderStyle) + #expect(copy.footerStyle == style.footerStyle) + #expect(copy.contentStyle == style.contentStyle) + #expect(copy.alternatingContentStyle == style.alternatingContentStyle) + } +} diff --git a/Tests/TPPDFTests/Table/PDFTableStyle_Spec.swift b/Tests/TPPDFTests/Table/PDFTableStyle_Spec.swift deleted file mode 100644 index bf816cf5..00000000 --- a/Tests/TPPDFTests/Table/PDFTableStyle_Spec.swift +++ /dev/null @@ -1,168 +0,0 @@ -// -// PDFTableStyle_Spec.swift -// TPPDF -// -// Created by Philip Niedertscheider on 11.13.2017. -// Copyright © 2016-2026 techprimate GmbH. All rights reserved. -// - -import Nimble -import Quick -@testable import TPPDF - -class PDFTableStyle_Spec: QuickSpec { - // swiftlint:disable closure_body_length function_body_length - override func spec() { - describe("PDFTableStyle") { - context("variables") { - let style = PDFTableStyle() - - it("has a row header count") { - expect(style.rowHeaderCount).toNot(beNil()) - } - - it("has a column header count") { - expect(style.columnHeaderCount).toNot(beNil()) - } - - it("has a footer count") { - expect(style.footerCount).toNot(beNil()) - } - - it("has a outline") { - expect(style.outline).toNot(beNil()) - } - - it("has a row header style") { - expect(style.rowHeaderStyle).toNot(beNil()) - } - - it("has a column header style") { - expect(style.columnHeaderStyle).toNot(beNil()) - } - - it("has a footer style") { - expect(style.footerStyle).toNot(beNil()) - } - - it("has a content style") { - expect(style.contentStyle).toNot(beNil()) - } - - it("has an alternating content style") { - expect(style.alternatingContentStyle).to(beNil()) - } - } - - context("initializer") { - it("can be initialized with default values") { - let style = PDFTableStyle() - - expect(style.rowHeaderCount) == 1 - expect(style.columnHeaderCount) == 1 - expect(style.footerCount) == 1 - expect(style.outline) == PDFLineStyle() - expect(style.rowHeaderStyle) == PDFTableCellStyle() - expect(style.columnHeaderStyle) == PDFTableCellStyle() - expect(style.footerStyle) == PDFTableCellStyle() - expect(style.contentStyle) == PDFTableCellStyle() - expect(style.alternatingContentStyle).to(beNil()) - } - - it("can be initialized with values") { - let rowHeaderCount = 4 - let columnHeaderCount = 4 - let footerCount = 4 - - let outline = PDFLineStyle(type: .dashed, color: .orange, width: 1.25) - let rowHeaderStyle = PDFTableCellStyle(colors: (fill: Color.blue, text: Color.green), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 10)) - let columnHeaderStyle = PDFTableCellStyle(colors: (fill: Color.black, text: Color.green), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 12)) - let footerStyle = PDFTableCellStyle(colors: (fill: Color.purple, text: Color.green), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 15)) - let contentStyle = PDFTableCellStyle(colors: (fill: Color.blue, text: Color.orange), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 10)) - let alternatingContentStyle = PDFTableCellStyle(colors: (fill: Color.red, text: Color.green), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 15)) - - let style = PDFTableStyle( - rowHeaderCount: rowHeaderCount, - columnHeaderCount: columnHeaderCount, - footerCount: footerCount, - outline: outline, - rowHeaderStyle: rowHeaderStyle, - columnHeaderStyle: columnHeaderStyle, - footerStyle: footerStyle, - contentStyle: contentStyle, - alternatingContentStyle: alternatingContentStyle - ) - - expect(style.rowHeaderCount) == rowHeaderCount - expect(style.columnHeaderCount) == columnHeaderCount - expect(style.footerCount) == footerCount - expect(style.outline) == outline - expect(style.rowHeaderStyle) == rowHeaderStyle - expect(style.columnHeaderStyle) == columnHeaderStyle - expect(style.footerStyle) == footerStyle - expect(style.contentStyle) == contentStyle - expect(style.alternatingContentStyle) == alternatingContentStyle - } - } - - it("can be copied") { - let rowHeaderCount = 4 - let columnHeaderCount = 4 - let footerCount = 4 - - let outline = PDFLineStyle(type: .dashed, color: .orange, width: 1.25) - let rowHeaderStyle = PDFTableCellStyle(colors: (fill: Color.blue, text: Color.green), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 10)) - let columnHeaderStyle = PDFTableCellStyle(colors: (fill: Color.black, text: Color.green), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 12)) - let footerStyle = PDFTableCellStyle(colors: (fill: Color.purple, text: Color.green), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 15)) - let contentStyle = PDFTableCellStyle(colors: (fill: Color.blue, text: Color.orange), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 10)) - let alternatingContentStyle = PDFTableCellStyle(colors: (fill: Color.red, text: Color.green), - borders: PDFTableCellBorders(), - font: Font.systemFont(ofSize: 15)) - - let style = PDFTableStyle( - rowHeaderCount: rowHeaderCount, - columnHeaderCount: columnHeaderCount, - footerCount: footerCount, - outline: outline, - rowHeaderStyle: rowHeaderStyle, - columnHeaderStyle: columnHeaderStyle, - footerStyle: footerStyle, - contentStyle: contentStyle, - alternatingContentStyle: alternatingContentStyle - ) - let copy = style.copy() - - expect(copy).toNot(be(style)) - - expect(copy.rowHeaderCount) == rowHeaderCount - expect(copy.columnHeaderCount) == columnHeaderCount - expect(copy.footerCount) == footerCount - expect(copy.outline) == outline - expect(copy.rowHeaderStyle) == rowHeaderStyle - expect(copy.columnHeaderStyle) == columnHeaderStyle - expect(copy.footerStyle) == footerStyle - expect(copy.contentStyle) == contentStyle - expect(copy.alternatingContentStyle) == alternatingContentStyle - } - } - } - // swiftlint:enable closure_body_length function_body_length -}