diff --git a/CDCodabarEncoder.swift b/CDCodabarEncoder.swift index 417f7fb..54e27cb 100644 --- a/CDCodabarEncoder.swift +++ b/CDCodabarEncoder.swift @@ -43,12 +43,14 @@ import Foundation *********************************************************************/ -public struct CDCodabarEncoder { +struct CDCodabarEncoder { - private struct Constants { + private enum Constants { - static let minLength = 3 - static let maxLength = 16 + enum Length { + static let min = 3 + static let max = 16 + } static let encodings: [Character: [Int]] = [ "0": [1, 0, 1, 0, 1, 0, 0, 1, 1], @@ -75,11 +77,10 @@ public struct CDCodabarEncoder { } enum Error: Swift.Error { - - case invalidLength - case invalidStartCharacter - case invalidEndCharacter - case invalidIntermediateCharacter + case length + case startCharacter + case endCharacter + case intermediateCharacter } private let code: String @@ -87,20 +88,20 @@ public struct CDCodabarEncoder { public init(code: String) throws { let code = code.uppercased() - guard (Constants.minLength ... Constants.maxLength) ~= code.characters.count else { - throw Error.invalidLength + guard (Constants.Length.min ... Constants.Length.max) ~= code.count else { + throw Error.length } - guard let startChar = code.characters.first, ("A" ... "D") ~= startChar else { - throw Error.invalidStartCharacter + guard let startChar = code.first, ("A" ... "D") ~= startChar else { + throw Error.startCharacter } - guard let stopChar = code.characters.last, ("A" ... "D") ~= stopChar else { - throw Error.invalidEndCharacter + guard let stopChar = code.last, ("A" ... "D") ~= stopChar else { + throw Error.endCharacter } - guard code.characters.filter({ !Constants.encodings.keys.contains($0) }).isEmpty else { - throw Error.invalidIntermediateCharacter + guard code.filter({ !Constants.encodings.keys.contains($0) }).isEmpty else { + throw Error.intermediateCharacter } self.code = code @@ -111,9 +112,9 @@ public struct CDCodabarEncoder { /// /// - Returns: Returns array of integer representing bits public func sequence() -> [Int] { - return code.characters + return code .map { Constants.encodings[$0]! } .joined(separator: [0]) - .flatMap { $0 } + .compactMap { $0 } } } diff --git a/CDCodabarView.podspec b/CDCodabarView.podspec index ec87336..2231e16 100644 --- a/CDCodabarView.podspec +++ b/CDCodabarView.podspec @@ -1,6 +1,6 @@ Pod::Spec.new do |s| s.name = "CDCodabarView" - s.version = "1.0.0" + s.version = "1.1.0" s.summary = "Codabar Barcode Generator for iOS." s.homepage = "https://github.com/Coledunsby/CDCodabarView" s.authors = { "Cole Dunsby" => "coledunsby@gmail.com" } diff --git a/CDCodabarView.swift b/CDCodabarView.swift index 0c278e1..0f476c8 100755 --- a/CDCodabarView.swift +++ b/CDCodabarView.swift @@ -9,12 +9,15 @@ import UIKit @IBDesignable -public final class CDCodabarView: UIView { +open class CDCodabarView: UIView { + // MARK: - Inspectable Properties + @IBInspectable public var barColor: UIColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) { didSet { setNeedsDisplay() }} @IBInspectable public var textColor: UIColor = #colorLiteral(red: 0, green: 0, blue: 0, alpha: 1) { didSet { setNeedsDisplay() }} @IBInspectable public var padding: CGFloat = 2.0 { didSet { setNeedsDisplay() }} @IBInspectable public var hideCode: Bool = false { didSet { setNeedsDisplay() }} + @IBInspectable public var invalidText: String = "Invalid Code" { didSet { setNeedsDisplay() }} @IBInspectable public var code: String = "A123456789B" { didSet { @@ -23,10 +26,16 @@ public final class CDCodabarView: UIView { } } + // MARK: - Public Properties + public var font = UIFont.systemFont(ofSize: 15.0) { didSet { setNeedsDisplay() }} + // MARK: - Private Properties + private var encoder: CDCodabarEncoder? + // MARK: - Lifecycle + override init(frame: CGRect) { super.init(frame: frame) } @@ -35,27 +44,25 @@ public final class CDCodabarView: UIView { super.init(coder: aDecoder) } - override public func draw(_ rect: CGRect) { + override open func draw(_ rect: CGRect) { let paragraphStyle = NSMutableParagraphStyle() paragraphStyle.alignment = .center let attributes: [NSAttributedStringKey: Any] = [ - NSAttributedStringKey.font: font, - NSAttributedStringKey.foregroundColor: textColor, - NSAttributedStringKey.paragraphStyle: paragraphStyle, + .font: font, + .foregroundColor: textColor, + .paragraphStyle: paragraphStyle ] guard let encoder = encoder else { - let text = "Invalid Code" - - let textSize = text.boundingRect( + let textSize = invalidText.boundingRect( with: CGSize(width: bounds.size.width, height: CGFloat.greatestFiniteMagnitude), options: [.truncatesLastVisibleLine, .usesLineFragmentOrigin], - attributes: [NSAttributedStringKey.font: font], + attributes: [.font: font], context: nil ) - text.draw( + invalidText.draw( at: CGPoint(x: bounds.size.width / 2 - textSize.width / 2, y: bounds.size.height / 2 - textSize.height / 2), withAttributes: attributes ) diff --git a/CDCodabarViewExample.xcodeproj/project.pbxproj b/CDCodabarViewExample.xcodeproj/project.pbxproj index 8301426..05b279e 100644 --- a/CDCodabarViewExample.xcodeproj/project.pbxproj +++ b/CDCodabarViewExample.xcodeproj/project.pbxproj @@ -8,7 +8,7 @@ /* Begin PBXBuildFile section */ 2092DBCB1E9BC13000B735A5 /* CDCodabarEncoder.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2092DBCA1E9BC13000B735A5 /* CDCodabarEncoder.swift */; }; - 2092DBD31E9BC1B300B735A5 /* EncoderSpecs.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2092DBD21E9BC1B300B735A5 /* EncoderSpecs.swift */; }; + 2092DBD31E9BC1B300B735A5 /* CDCodabarViewTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 2092DBD21E9BC1B300B735A5 /* CDCodabarViewTests.swift */; }; 252518E51DD3BB9B00F770A3 /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 252518DF1DD3BB9B00F770A3 /* AppDelegate.swift */; }; 252518E61DD3BB9B00F770A3 /* Images.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 252518E01DD3BB9B00F770A3 /* Images.xcassets */; }; 252518E81DD3BB9B00F770A3 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 252518E21DD3BB9B00F770A3 /* LaunchScreen.storyboard */; }; @@ -30,7 +30,7 @@ /* Begin PBXFileReference section */ 2092DBCA1E9BC13000B735A5 /* CDCodabarEncoder.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDCodabarEncoder.swift; sourceTree = ""; }; 2092DBD01E9BC1B300B735A5 /* CDCodabarViewTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = CDCodabarViewTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; }; - 2092DBD21E9BC1B300B735A5 /* EncoderSpecs.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EncoderSpecs.swift; sourceTree = ""; }; + 2092DBD21E9BC1B300B735A5 /* CDCodabarViewTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = CDCodabarViewTests.swift; sourceTree = ""; }; 2092DBD41E9BC1B300B735A5 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = ""; }; 252518DF1DD3BB9B00F770A3 /* AppDelegate.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = ""; }; 252518E01DD3BB9B00F770A3 /* Images.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Images.xcassets; sourceTree = ""; }; @@ -39,7 +39,8 @@ 252518E31DD3BB9B00F770A3 /* Main.storyboard */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = file.storyboard; path = Main.storyboard; sourceTree = ""; }; 252518E41DD3BB9B00F770A3 /* ViewController.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = ViewController.swift; sourceTree = ""; }; 252518ED1DD3BDDB00F770A3 /* CDCodabarView.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = CDCodabarView.swift; sourceTree = ""; }; - 607FACD01AFB9204008FA782 /* CDCodabarView_Example.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CDCodabarView_Example.app; sourceTree = BUILT_PRODUCTS_DIR; }; + 607FACD01AFB9204008FA782 /* CDCodabarViewExample.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = CDCodabarViewExample.app; sourceTree = BUILT_PRODUCTS_DIR; }; + EDEF7BA721014883002D4DCB /* CDCodabarView.podspec */ = {isa = PBXFileReference; explicitFileType = text.script.ruby; path = CDCodabarView.podspec; sourceTree = ""; }; /* End PBXFileReference section */ /* Begin PBXFrameworksBuildPhase section */ @@ -63,7 +64,7 @@ 2092DBD11E9BC1B300B735A5 /* CDCodabarViewTests */ = { isa = PBXGroup; children = ( - 2092DBD21E9BC1B300B735A5 /* EncoderSpecs.swift */, + 2092DBD21E9BC1B300B735A5 /* CDCodabarViewTests.swift */, 2092DBD41E9BC1B300B735A5 /* Info.plist */, ); path = CDCodabarViewTests; @@ -85,6 +86,7 @@ 607FACC71AFB9204008FA782 = { isa = PBXGroup; children = ( + EDEF7BA721014883002D4DCB /* CDCodabarView.podspec */, 252518ED1DD3BDDB00F770A3 /* CDCodabarView.swift */, 2092DBCA1E9BC13000B735A5 /* CDCodabarEncoder.swift */, 252518DE1DD3BB9B00F770A3 /* CDCodabarViewExample */, @@ -96,7 +98,7 @@ 607FACD11AFB9204008FA782 /* Products */ = { isa = PBXGroup; children = ( - 607FACD01AFB9204008FA782 /* CDCodabarView_Example.app */, + 607FACD01AFB9204008FA782 /* CDCodabarViewExample.app */, 2092DBD01E9BC1B300B735A5 /* CDCodabarViewTests.xctest */, ); name = Products; @@ -123,9 +125,9 @@ productReference = 2092DBD01E9BC1B300B735A5 /* CDCodabarViewTests.xctest */; productType = "com.apple.product-type.bundle.unit-test"; }; - 607FACCF1AFB9204008FA782 /* CDCodabarView_Example */ = { + 607FACCF1AFB9204008FA782 /* CDCodabarViewExample */ = { isa = PBXNativeTarget; - buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "CDCodabarView_Example" */; + buildConfigurationList = 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "CDCodabarViewExample" */; buildPhases = ( 607FACCC1AFB9204008FA782 /* Sources */, 607FACCD1AFB9204008FA782 /* Frameworks */, @@ -135,9 +137,9 @@ ); dependencies = ( ); - name = CDCodabarView_Example; + name = CDCodabarViewExample; productName = CDCodabarView; - productReference = 607FACD01AFB9204008FA782 /* CDCodabarView_Example.app */; + productReference = 607FACD01AFB9204008FA782 /* CDCodabarViewExample.app */; productType = "com.apple.product-type.application"; }; /* End PBXNativeTarget section */ @@ -147,19 +149,19 @@ isa = PBXProject; attributes = { LastSwiftUpdateCheck = 0830; - LastUpgradeCheck = 0810; + LastUpgradeCheck = 1000; ORGANIZATIONNAME = CocoaPods; TargetAttributes = { 2092DBCF1E9BC1B300B735A5 = { CreatedOnToolsVersion = 8.3; - DevelopmentTeam = B3YTJ78KXJ; + DevelopmentTeam = W8W9HUZP5Z; LastSwiftMigration = 0940; ProvisioningStyle = Automatic; TestTargetID = 607FACCF1AFB9204008FA782; }; 607FACCF1AFB9204008FA782 = { CreatedOnToolsVersion = 6.3.1; - DevelopmentTeam = JU6JS2KXPW; + DevelopmentTeam = W8W9HUZP5Z; LastSwiftMigration = 0940; }; }; @@ -177,7 +179,7 @@ projectDirPath = ""; projectRoot = ""; targets = ( - 607FACCF1AFB9204008FA782 /* CDCodabarView_Example */, + 607FACCF1AFB9204008FA782 /* CDCodabarViewExample */, 2092DBCF1E9BC1B300B735A5 /* CDCodabarViewTests */, ); }; @@ -208,7 +210,7 @@ isa = PBXSourcesBuildPhase; buildActionMask = 2147483647; files = ( - 2092DBD31E9BC1B300B735A5 /* EncoderSpecs.swift in Sources */, + 2092DBD31E9BC1B300B735A5 /* CDCodabarViewTests.swift in Sources */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -228,7 +230,7 @@ /* Begin PBXTargetDependency section */ 2092DBD61E9BC1B300B735A5 /* PBXTargetDependency */ = { isa = PBXTargetDependency; - target = 607FACCF1AFB9204008FA782 /* CDCodabarView_Example */; + target = 607FACCF1AFB9204008FA782 /* CDCodabarViewExample */; targetProxy = 2092DBD51E9BC1B300B735A5 /* PBXContainerItemProxy */; }; /* End PBXTargetDependency section */ @@ -242,7 +244,7 @@ CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; DEBUG_INFORMATION_FORMAT = dwarf; - DEVELOPMENT_TEAM = B3YTJ78KXJ; + DEVELOPMENT_TEAM = W8W9HUZP5Z; INFOPLIST_FILE = CDCodabarViewTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -251,7 +253,7 @@ SWIFT_ACTIVE_COMPILATION_CONDITIONS = DEBUG; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CDCodabarView_Example.app/CDCodabarView_Example"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CDCodabarViewExample.app/CDCodabarViewExample"; }; name = Debug; }; @@ -262,7 +264,7 @@ CLANG_ANALYZER_NONNULL = YES; CLANG_ANALYZER_NUMBER_OBJECT_CONVERSION = YES_AGGRESSIVE; CLANG_WARN_DOCUMENTATION_COMMENTS = YES; - DEVELOPMENT_TEAM = B3YTJ78KXJ; + DEVELOPMENT_TEAM = W8W9HUZP5Z; INFOPLIST_FILE = CDCodabarViewTests/Info.plist; IPHONEOS_DEPLOYMENT_TARGET = 10.3; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks @loader_path/Frameworks"; @@ -270,7 +272,7 @@ PRODUCT_NAME = "$(TARGET_NAME)"; SWIFT_SWIFT3_OBJC_INFERENCE = Default; SWIFT_VERSION = 4.0; - TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CDCodabarView_Example.app/CDCodabarView_Example"; + TEST_HOST = "$(BUILT_PRODUCTS_DIR)/CDCodabarViewExample.app/CDCodabarViewExample"; }; name = Release; }; @@ -282,14 +284,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -329,14 +339,22 @@ CLANG_CXX_LIBRARY = "libc++"; CLANG_ENABLE_MODULES = YES; CLANG_ENABLE_OBJC_ARC = YES; + CLANG_WARN_BLOCK_CAPTURE_AUTORELEASING = YES; CLANG_WARN_BOOL_CONVERSION = YES; + CLANG_WARN_COMMA = YES; CLANG_WARN_CONSTANT_CONVERSION = YES; + CLANG_WARN_DEPRECATED_OBJC_IMPLEMENTATIONS = YES; CLANG_WARN_DIRECT_OBJC_ISA_USAGE = YES_ERROR; CLANG_WARN_EMPTY_BODY = YES; CLANG_WARN_ENUM_CONVERSION = YES; CLANG_WARN_INFINITE_RECURSION = YES; CLANG_WARN_INT_CONVERSION = YES; + CLANG_WARN_NON_LITERAL_NULL_CONVERSION = YES; + CLANG_WARN_OBJC_IMPLICIT_RETAIN_SELF = YES; + CLANG_WARN_OBJC_LITERAL_CONVERSION = YES; CLANG_WARN_OBJC_ROOT_CLASS = YES_ERROR; + CLANG_WARN_RANGE_LOOP_ANALYSIS = YES; + CLANG_WARN_STRICT_PROTOTYPES = YES; CLANG_WARN_SUSPICIOUS_MOVE = YES; CLANG_WARN_UNREACHABLE_CODE = YES; CLANG_WARN__DUPLICATE_METHOD_MATCH = YES; @@ -365,7 +383,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; - DEVELOPMENT_TEAM = JU6JS2KXPW; + DEVELOPMENT_TEAM = W8W9HUZP5Z; INFOPLIST_FILE = "$(SRCROOT)/CDCodabarViewExample/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -382,7 +400,7 @@ isa = XCBuildConfiguration; buildSettings = { CLANG_ENABLE_MODULES = YES; - DEVELOPMENT_TEAM = JU6JS2KXPW; + DEVELOPMENT_TEAM = W8W9HUZP5Z; INFOPLIST_FILE = "$(SRCROOT)/CDCodabarViewExample/Info.plist"; IPHONEOS_DEPLOYMENT_TARGET = 9.0; LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks"; @@ -415,7 +433,7 @@ defaultConfigurationIsVisible = 0; defaultConfigurationName = Release; }; - 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "CDCodabarView_Example" */ = { + 607FACEF1AFB9204008FA782 /* Build configuration list for PBXNativeTarget "CDCodabarViewExample" */ = { isa = XCConfigurationList; buildConfigurations = ( 607FACF01AFB9204008FA782 /* Debug */, diff --git a/CDCodabarViewExample/AppDelegate.swift b/CDCodabarViewExample/AppDelegate.swift index f56648f..7f3d196 100644 --- a/CDCodabarViewExample/AppDelegate.swift +++ b/CDCodabarViewExample/AppDelegate.swift @@ -1,11 +1,3 @@ -// -// AppDelegate.swift -// CDCodabarViewSample -// -// Created by Cole Dunsby on 2015-12-21. -// Copyright © 2016 Cole Dunsby. All rights reserved. -// - import UIKit @UIApplicationMain @@ -17,4 +9,3 @@ final class AppDelegate: UIResponder, UIApplicationDelegate { return true } } - diff --git a/CDCodabarViewExample/Info.plist b/CDCodabarViewExample/Info.plist index e3d55d0..0b9567e 100644 --- a/CDCodabarViewExample/Info.plist +++ b/CDCodabarViewExample/Info.plist @@ -17,7 +17,7 @@ CFBundlePackageType APPL CFBundleShortVersionString - 1.0 + 1.1.0 CFBundleSignature ???? CFBundleVersion diff --git a/CDCodabarViewExample/ViewController.swift b/CDCodabarViewExample/ViewController.swift index 6987405..26a007e 100644 --- a/CDCodabarViewExample/ViewController.swift +++ b/CDCodabarViewExample/ViewController.swift @@ -1,11 +1,3 @@ -// -// ViewController.swift -// CDCodabarViewSample -// -// Created by Cole Dunsby on 2015-12-21. -// Copyright © 2016 Cole Dunsby. All rights reserved. -// - import UIKit final class ViewController: UIViewController { diff --git a/CDCodabarViewTests/EncoderSpecs.swift b/CDCodabarViewTests/CDCodabarViewTests.swift similarity index 55% rename from CDCodabarViewTests/EncoderSpecs.swift rename to CDCodabarViewTests/CDCodabarViewTests.swift index 415ea85..5920bc9 100644 --- a/CDCodabarViewTests/EncoderSpecs.swift +++ b/CDCodabarViewTests/CDCodabarViewTests.swift @@ -1,61 +1,51 @@ -// -// CDCodabarViewTests.swift -// CDCodabarViewTests -// -// Created by Emil Wojtaszek on 10/04/2017. -// Copyright © 2017 CocoaPods. All rights reserved. -// - +@testable import CDCodabarViewExample import XCTest -@testable import CDCodabarView_Example - -class CDCodabarViewTests: XCTestCase { +final class CDCodabarViewTests: XCTestCase { - func testThatZeroLetterCodeIsInvalid() { + func testEmptyCodeInvalid() { let encoder = try? CDCodabarEncoder(code: "") XCTAssertNil(encoder) } - func testThat1LetterCodeIsInvalid() { + func test1LetterCodeInvalid() { let encoder = try? CDCodabarEncoder(code: "A") XCTAssertNil(encoder) } - func testThat2LettersCodeIsInvalid() { + func test2LetterCodeInvalid() { let encoder = try? CDCodabarEncoder(code: "A0") XCTAssertNil(encoder) } - func testThat3LettersCodeIsValid() { + func test3LetterCodeValid() { let encoder = try? CDCodabarEncoder(code: "A0B") XCTAssertNotNil(encoder) } - func testThat17LettersCodeIsInvalid() { + func test17LetterCodeInvalid() { let encoder = try? CDCodabarEncoder(code: "A000000000000000B") XCTAssertNil(encoder) } - func testThatCodeWithWrongStartLetterIsInvalid() { + func testStartLetterInvalid() { let encoder = try? CDCodabarEncoder(code: "E00000000000B") XCTAssertNil(encoder) } - func testThatCodeWithWrongStopLetterIsInvalid() { + func testStopLetterInvalid() { let encoder = try? CDCodabarEncoder(code: "A00000000000E") XCTAssertNil(encoder) } - func testThreeCodeWithUnsupportedCharacterIsInvalid() { + func testUnsupportedCharacterInvalid() { let encoder = try? CDCodabarEncoder(code: "A!B") XCTAssertNil(encoder) } - func testExampleSequance() { - let encoder = try? CDCodabarEncoder(code: "A012B") - XCTAssertNotNil(encoder) - XCTAssertEqual(encoder!.sequence(), [ + func testExampleSequence() throws { + let encoder = try CDCodabarEncoder(code: "A012B") + let expected = [ 1, 0, 1, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 0, 1, 0, 0, 1, 1, @@ -64,6 +54,8 @@ class CDCodabarViewTests: XCTestCase { 0, 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, - 1, 0, 1, 0, 0, 1, 0, 0, 1, 1]) + 1, 0, 1, 0, 0, 1, 0, 0, 1, 1 + ] + XCTAssertEqual(encoder.sequence(), expected) } }