Skip to content

Commit

Permalink
make classes public, started writing tests
Browse files Browse the repository at this point in the history
  • Loading branch information
xremix committed Jun 26, 2017
1 parent 59f9456 commit 4e10db7
Show file tree
Hide file tree
Showing 11 changed files with 225 additions and 17 deletions.
14 changes: 12 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,19 @@ A GS1 Barcode Library and Parser for Swift Edit
## CocoaPod
https://github.com/xremix/SwiftGS1Barcode

## Deployment Steps:
## Deployment Steps
- Update Version
- Push Code to Git
- Create Release on Git
- `pod lib lint`
- `pod trunk push SwiftGS1Barcode.podspec`
- `pod trunk push SwiftGS1Barcode.podspec`

## Resources
A couple of resources, used for this project.

#### GS1 parsing
https://www.activebarcode.de/codes/ean128_ucc128_ai.html
https://www.gs1.at/fileadmin/user_upload/Liste_GS1_Austria_Application_Identifier.pdf

#### CocoaPod
https://www.appcoda.com/cocoapods-making-guide/
2 changes: 1 addition & 1 deletion SwiftGS1Barcode.podspec
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Pod::Spec.new do |s|
s.name = 'SwiftGS1Barcode'
s.version = '0.1.0'
s.version = '0.1.1'
s.summary = 'A GS1 Barcode Library and Parser for Swift'

s.description = <<-DESC
Expand Down
24 changes: 20 additions & 4 deletions SwiftGS1Barcode.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
64754D061F010EBB00B22B62 /* StringExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64754D051F010EBB00B22B62 /* StringExtension.swift */; };
64754D081F010ECA00B22B62 /* DateExtension.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64754D071F010ECA00B22B62 /* DateExtension.swift */; };
64754D0A1F010EFA00B22B62 /* SwiftGS1Barcode.podspec in Resources */ = {isa = PBXBuildFile; fileRef = 64754D091F010EFA00B22B62 /* SwiftGS1Barcode.podspec */; };
64754D0C1F01103C00B22B62 /* BarcodeParserTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64754D0B1F01103C00B22B62 /* BarcodeParserTests.swift */; };
64754D101F01106500B22B62 /* SimpleBarcodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64754D0F1F01106500B22B62 /* SimpleBarcodeTests.swift */; };
64754D121F01106D00B22B62 /* GS1BarcodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64754D111F01106D00B22B62 /* GS1BarcodeTests.swift */; };
64754D141F01107500B22B62 /* StringTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64754D131F01107500B22B62 /* StringTests.swift */; };
64754D161F01107B00B22B62 /* DateTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64754D151F01107B00B22B62 /* DateTests.swift */; };
64AE611D1F01081800F3B9C0 /* SwiftGS1Barcode.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 64AE61131F01081800F3B9C0 /* SwiftGS1Barcode.framework */; };
64AE61221F01081800F3B9C0 /* SwiftGS1BarcodeTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64AE61211F01081800F3B9C0 /* SwiftGS1BarcodeTests.swift */; };
64AE61241F01081800F3B9C0 /* SwiftGS1Barcode.h in Headers */ = {isa = PBXBuildFile; fileRef = 64AE61161F01081800F3B9C0 /* SwiftGS1Barcode.h */; settings = {ATTRIBUTES = (Public, ); }; };
/* End PBXBuildFile section */

Expand All @@ -37,11 +41,15 @@
64754D051F010EBB00B22B62 /* StringExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringExtension.swift; sourceTree = "<group>"; };
64754D071F010ECA00B22B62 /* DateExtension.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateExtension.swift; sourceTree = "<group>"; };
64754D091F010EFA00B22B62 /* SwiftGS1Barcode.podspec */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text; path = SwiftGS1Barcode.podspec; sourceTree = "<group>"; };
64754D0B1F01103C00B22B62 /* BarcodeParserTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = BarcodeParserTests.swift; sourceTree = "<group>"; };
64754D0F1F01106500B22B62 /* SimpleBarcodeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = SimpleBarcodeTests.swift; sourceTree = "<group>"; };
64754D111F01106D00B22B62 /* GS1BarcodeTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = GS1BarcodeTests.swift; sourceTree = "<group>"; };
64754D131F01107500B22B62 /* StringTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = StringTests.swift; sourceTree = "<group>"; };
64754D151F01107B00B22B62 /* DateTests.swift */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.swift; path = DateTests.swift; sourceTree = "<group>"; };
64AE61131F01081800F3B9C0 /* SwiftGS1Barcode.framework */ = {isa = PBXFileReference; explicitFileType = wrapper.framework; includeInIndex = 0; path = SwiftGS1Barcode.framework; sourceTree = BUILT_PRODUCTS_DIR; };
64AE61161F01081800F3B9C0 /* SwiftGS1Barcode.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = SwiftGS1Barcode.h; sourceTree = "<group>"; };
64AE61171F01081800F3B9C0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
64AE611C1F01081800F3B9C0 /* SwiftGS1BarcodeTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = SwiftGS1BarcodeTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
64AE61211F01081800F3B9C0 /* SwiftGS1BarcodeTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = SwiftGS1BarcodeTests.swift; sourceTree = "<group>"; };
64AE61231F01081800F3B9C0 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
/* End PBXFileReference section */

Expand Down Expand Up @@ -101,8 +109,12 @@
64AE61201F01081800F3B9C0 /* SwiftGS1BarcodeTests */ = {
isa = PBXGroup;
children = (
64AE61211F01081800F3B9C0 /* SwiftGS1BarcodeTests.swift */,
64AE61231F01081800F3B9C0 /* Info.plist */,
64754D0B1F01103C00B22B62 /* BarcodeParserTests.swift */,
64754D0F1F01106500B22B62 /* SimpleBarcodeTests.swift */,
64754D111F01106D00B22B62 /* GS1BarcodeTests.swift */,
64754D131F01107500B22B62 /* StringTests.swift */,
64754D151F01107B00B22B62 /* DateTests.swift */,
);
path = SwiftGS1BarcodeTests;
sourceTree = "<group>";
Expand Down Expand Up @@ -234,7 +246,11 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
64AE61221F01081800F3B9C0 /* SwiftGS1BarcodeTests.swift in Sources */,
64754D161F01107B00B22B62 /* DateTests.swift in Sources */,
64754D141F01107500B22B62 /* StringTests.swift in Sources */,
64754D0C1F01103C00B22B62 /* BarcodeParserTests.swift in Sources */,
64754D121F01106D00B22B62 /* GS1BarcodeTests.swift in Sources */,
64754D101F01106500B22B62 /* SimpleBarcodeTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down
2 changes: 1 addition & 1 deletion SwiftGS1Barcode/BarcodeParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@

import UIKit

class GS1BarcodeParser: NSObject {
public class GS1BarcodeParser: NSObject {
static func reduce(data: String?, by node: GS1Node)->String?{
if data == nil{
return data
Expand Down
6 changes: 1 addition & 5 deletions SwiftGS1Barcode/GS1Barcode.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,6 @@

import UIKit

class GS1BarcodePretty: GS1Barcode{

}

enum GS1Type: String{
case GTIN
case GroupSeperatorBased
Expand Down Expand Up @@ -50,7 +46,7 @@ struct GS1Nodes{
var amountNode = GS1Node(identifier: "30", type: .GroupSeperatorBasedInt)
}

class GS1Barcode: NSObject, Barcode {
public class GS1Barcode: NSObject, Barcode {
var raw: String?
var nodes = GS1Nodes()

Expand Down
2 changes: 1 addition & 1 deletion SwiftGS1Barcode/Info.plist
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
<key>CFBundlePackageType</key>
<string>FMWK</string>
<key>CFBundleShortVersionString</key>
<string>0.1.0</string>
<string>0.1.1</string>
<key>CFBundleVersion</key>
<string>$(CURRENT_PROJECT_VERSION)</string>
<key>NSPrincipalClass</key>
Expand Down
56 changes: 56 additions & 0 deletions SwiftGS1BarcodeTests/BarcodeParserTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
//
// BarcodeParserTests.swift
// SwiftGS1Barcode
//
// Created by Toni Hoffmann on 26.06.17.
// Copyright © 2017 Toni Hoffmann. All rights reserved.
//

import XCTest
@testable import SwiftGS1Barcode

class BarcodeParserTests: XCTestCase {

override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}

func testGtinPraser(){
var node = GS1Node(identifier: "01", type: .GTIN)
node = GS1BarcodeParser.parseGS1Node(node: node, data: "010012349993333001")
XCTAssertEqual(node.value, "00123499933330")
}
func testDatePraser(){
var node = GS1Node(identifier: "01", type: .Date)
node = GS1BarcodeParser.parseGS1Node(node: node, data: "17210228")
XCTAssertEqual(node.dateValue, NSDate.from(year: 2021, month: 2, day: 28)) // 17
}
func testGroupSeperatorBasedInt(){
var node = GS1Node(identifier: "03", type: .GroupSeperatorBasedInt)
node = GS1BarcodeParser.parseGS1Node(node: node, data: "3001\u{1D}12341234")
XCTAssertEqual(node.value, "01")
XCTAssertEqual(node.intValue, 1)
XCTAssertEqual(node.dateValue, nil)
}
func testGroupSeperatorBased(){
var node = GS1Node(identifier: "03", type: .GroupSeperatorBased)
node = GS1BarcodeParser.parseGS1Node(node: node, data: "3001\u{1D}12341234")
XCTAssertEqual(node.value, "01")
XCTAssertEqual(node.intValue, nil)
XCTAssertEqual(node.dateValue, nil)
}
func testGroupSeperatorBasedEndOfString(){
var node = GS1Node(identifier: "03", type: .GroupSeperatorBased)
node = GS1BarcodeParser.parseGS1Node(node: node, data: "3001")
XCTAssertEqual(node.value, "01")
XCTAssertEqual(node.intValue, nil)
XCTAssertEqual(node.dateValue, nil)
}

}
30 changes: 30 additions & 0 deletions SwiftGS1BarcodeTests/DateTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
//
// DateTests.swift
// SwiftGS1Barcode
//
// Created by Toni Hoffmann on 26.06.17.
// Copyright © 2017 Toni Hoffmann. All rights reserved.
//

import XCTest
@testable import SwiftGS1Barcode

class DateTests: XCTestCase {

override func setUp() {
super.setUp()

}

override func tearDown() {
super.tearDown()
}

func testFrom() {
let date = NSDate.from(year: 2017, month: 12, day: 24)

XCTAssert(NSCalendar.current.component(.year, from: date as Date) == 2017)
XCTAssert(NSCalendar.current.component(.month, from: date as Date) == 12)
XCTAssert(NSCalendar.current.component(.day, from: date as Date) == 24)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
//
// SwiftGS1BarcodeTests.swift
// SwiftGS1BarcodeTests
// GS1BarcodeTests.swift
// SwiftGS1Barcode
//
// Created by Toni Hoffmann on 26.06.17.
// Copyright © 2017 Toni Hoffmann. All rights reserved.
Expand All @@ -9,7 +9,7 @@
import XCTest
@testable import SwiftGS1Barcode

class SwiftGS1BarcodeTests: XCTestCase {
class GS1BarcodeTests: XCTestCase {

override func setUp() {
super.setUp()
Expand Down
37 changes: 37 additions & 0 deletions SwiftGS1BarcodeTests/SimpleBarcodeTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
//
// SimpleBarcodeTests.swift
// SwiftGS1Barcode
//
// Created by Toni Hoffmann on 26.06.17.
// Copyright © 2017 Toni Hoffmann. All rights reserved.
//

import XCTest
@testable import SwiftGS1Barcode

class SimpleBarcodeTests: XCTestCase {
var simpleBarcode: SimpleBarcode?
override func setUp() {
super.setUp()
// Put setup code here. This method is called before the invocation of each test method in the class.
}

override func tearDown() {
// Put teardown code here. This method is called after the invocation of each test method in the class.
super.tearDown()
}

func testRaw(){
simpleBarcode = SimpleBarcode(raw: "0120012345678909")
XCTAssert(simpleBarcode!.raw == "0120012345678909")
}

func testValidate() {
simpleBarcode = SimpleBarcode(raw: "0120012345678909")
XCTAssert(simpleBarcode!.validate())
simpleBarcode?.raw = ""
XCTAssert(!simpleBarcode!.validate())
simpleBarcode?.raw = nil
XCTAssert(!simpleBarcode!.validate())
}
}
63 changes: 63 additions & 0 deletions SwiftGS1BarcodeTests/StringTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
//
// StringTests.swift
// SwiftGS1Barcode
//
// Created by Toni Hoffmann on 26.06.17.
// Copyright © 2017 Toni Hoffmann. All rights reserved.
//

import XCTest
@testable import SwiftGS1Barcode

class StringTests: XCTestCase {
var testString: String = ""
override func setUp() {
super.setUp()
testString = "Hallo Welt"
}

override func tearDown() {
super.tearDown()
}

func testLength(){
XCTAssertEqual(testString.length, 10)
}

func testSubstringFromLength() {
XCTAssertEqual(testString.substring(0, length: 5), "Hallo")
XCTAssertEqual(testString.substring(1, length: 5), "allo ")
}
func testSubstringFromTo() {
XCTAssertEqual(testString.substring(0, to: 5), "Hallo")
XCTAssertEqual(testString.substring(1, to: 5), "allo")
}
func testSubstringFrom() {
XCTAssertEqual(testString.substring(from: 0), "Hallo Welt")
XCTAssertEqual(testString.substring(from: 1), "allo Welt")
}
func testSubstringTo() {
XCTAssertEqual(testString.substring(from: 0), testString)
XCTAssertEqual(testString.substring(from: 6), "Welt")
XCTAssertEqual(testString.substring(from: testString.length), "")
}
func testSubstringToString() {
XCTAssertEqual(testString.substring(to: "Welt"), "Hallo ")
XCTAssertEqual(testString.substring(to: "Hallo Welt"), "")
}
func testStartsWith(){
XCTAssert(testString.startsWith("Hallo"))
XCTAssert(!testString.startsWith("Welt"))
}

func testIndexOfOptions(){
// testString.index(of: "Welt", options: co)
}

func testPerformanceExample() {
// This is an example of a performance test case.
self.measure {
_ = self.testString.substring(0, to: 5)
}
}
}

0 comments on commit 4e10db7

Please sign in to comment.