-
Notifications
You must be signed in to change notification settings - Fork 14
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make classes public, started writing tests
- Loading branch information
Showing
11 changed files
with
225 additions
and
17 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} | ||
} | ||
} |