Skip to content

Commit

Permalink
added unicode + basic tests
Browse files Browse the repository at this point in the history
  • Loading branch information
adriencanterot committed Sep 29, 2016
1 parent de7be4c commit a983f79
Show file tree
Hide file tree
Showing 2 changed files with 79 additions and 5 deletions.
69 changes: 64 additions & 5 deletions Tests/SQLiteTests/SQLite3Tests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,70 @@ import XCTest
@testable import SQLite

class SQLite3Tests: XCTestCase {
static let allTests = [
("testReality", testReality)
]
static let allTests = [""]

func testReality() {
XCTAssert(2 + 2 == 4, "Something is seriously wrong.")
var database:SQLite!

override func setUp() {
self.database = SQLite.makeTestConnection()
}

func testTables() {
do {
try _ = database.execute("DROP TABLE IF EXISTS foo")
try _ = database.execute("CREATE TABLE foo (bar INT(4), baz VARCHAR(16))")
try _ = database.execute("INSERT INTO foo VALUES (42, 'Life')")
try _ = database.execute("INSERT INTO foo VALUES (1337, 'Elite')")
try _ = database.execute("INSERT INTO foo VALUES (9, NULL)")

if let resultBar = try database.execute("SELECT * FROM foo WHERE bar = 42").first {
XCTAssertEqual(resultBar.data["bar"], "42")
XCTAssertEqual(resultBar.data["baz"], "Life")
} else {
XCTFail("Could not get bar result")
}


if let resultBaz = try database.execute("SELECT * FROM foo where baz = 'Elite'").first {
XCTAssertEqual(resultBaz.data["bar"], "1337")
XCTAssertEqual(resultBaz.data["baz"], "Elite")
} else {
XCTFail("Could not get baz result")
}

if let resultBaz = try database.execute("SELECT * FROM foo where bar = 9").first {
XCTAssertEqual(resultBaz.data["bar"], "9")
XCTAssertEqual(resultBaz.data["baz"], nil)
} else {
XCTFail("Could not get null result")
}
} catch {
XCTFail("Testing tables failed: \(error)")
}
}

func testUnicodeStrings() {

do {

/**
This string includes characters from most Unicode categories
such as Latin, Latin-Extended-A/B, Cyrrilic, Greek etc.
*/
let unicode = "®¿ÐØ×ĞƋƢǂNJǕǮȐȘȢȱȵẀˍΔῴЖ♆"
try _ = database.execute("DROP TABLE IF EXISTS `foo`")
try _ = database.execute("CREATE TABLE `foo` (bar TEXT)")
try _ = database.execute("INSERT INTO `foo` VALUES(?)") { statement in
try statement.bind(unicode)
}

if let results = try database.execute("SELECT * FROM `foo`").first {
XCTAssertEqual(results.data["bar"], unicode)
}
} catch {
XCTFail(error.localizedDescription)
}

}

}
15 changes: 15 additions & 0 deletions Tests/SQLiteTests/Utilities.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import XCTest
@testable import SQLite

extension SQLite {
static func makeTestConnection() -> SQLite? {
do {
let sqlite = try SQLite(path:"test_database.sqlite")
return sqlite

} catch {
XCTFail()
}
return nil
}
}

0 comments on commit a983f79

Please sign in to comment.