Skip to content

Commit 12d6370

Browse files
authored
Merge pull request #98 from novi/update-decimal-tests
Fix decimal type tests
2 parents 02d3c93 + c5e3773 commit 12d6370

14 files changed

+147
-144
lines changed

.circleci/config.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ jobs:
2424
DATABASE_HOST: "%"
2525
steps:
2626
- checkout
27+
- run: sleep 5 #wait for mysql
2728
- run: swift build
2829
- run: swift test
2930
linux-swift4.2:
@@ -38,6 +39,7 @@ jobs:
3839
DATABASE_HOST: "%"
3940
steps:
4041
- checkout
42+
- run: sleep 5 #wait for mysql
4143
- run: swift build
4244
- run: swift test
4345

Tests/LinuxMain.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import XCTest
2+
23
import MySQLTests
34
import SQLFormatterTests
45

56
var tests = [XCTestCaseEntry]()
6-
7-
tests += MySQLTests.allTests()
8-
tests += SQLFormatterTests.allTests()
7+
tests += MySQLTests.__allTests()
8+
tests += SQLFormatterTests.__allTests()
99

1010
XCTMain(tests)

Tests/MySQLTests/BlobTests.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ import XCTest
1010
@testable import MySQL
1111
import Foundation
1212

13-
extension BlobQueryTests {
14-
static var allTests : [(String, (BlobQueryTests) -> () throws -> Void)] {
15-
return [
16-
("testInsertForCombinedUnicodeCharacter", testInsertForCombinedUnicodeCharacter),
17-
("testBlobAndTextOnBinCollation", testBlobAndTextOnBinCollation),
18-
("testEscapeBlob", testEscapeBlob),
19-
("testJSONColumnValue", testJSONColumnValue)
20-
]
21-
}
22-
}
23-
24-
2513
extension Row {
2614

2715
fileprivate struct BlobTextRow: Codable, QueryParameter {

Tests/MySQLTests/ConnectionPoolTests.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ import Dispatch
1111
import XCTest
1212
@testable import MySQL
1313

14-
extension ConnectionPoolTests {
15-
static var allTests : [(String, (ConnectionPoolTests) -> () throws -> Void)] {
16-
return [
17-
("testGetConnection", testGetConnection),
18-
("testExecutionBlock", testExecutionBlock),
19-
("testThreadingConnectionPool", testThreadingConnectionPool)
20-
]
21-
}
22-
}
23-
2414
final class ConnectionPoolTests: XCTestCase, MySQLTestType {
2515

2616

Tests/MySQLTests/ConnectionTests.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,6 @@
99
import XCTest
1010
@testable import MySQL
1111

12-
extension ConnectionTests {
13-
static var allTests : [(String, (ConnectionTests) -> () throws -> Void)] {
14-
return [
15-
("testConnect", testConnect),
16-
("testConnect2", testConnect2),
17-
("testDefaultConnectionOption", testDefaultConnectionOption)
18-
]
19-
}
20-
}
21-
2212
final class ConnectionTests: XCTestCase, MySQLTestType {
2313

2414
var constants: TestConstantsType!

Tests/MySQLTests/DateTests.swift

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,6 @@ import CoreFoundation
1111
import Foundation
1212
@testable import MySQL
1313

14-
extension DateTests {
15-
static var allTests : [(String, (DateTests) -> () throws -> Void)] {
16-
return [
17-
("testSQLDate", testSQLDate),
18-
("testSQLCalendar", testSQLCalendar),
19-
("testDateComponents", testDateComponents),
20-
]
21-
}
22-
}
23-
2414
struct QueryParameterTestOption: QueryParameterOption {
2515
let timeZone: TimeZone
2616
}

Tests/MySQLTests/EscapeTests.swift

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,6 @@ import XCTest
1010
@testable import MySQL
1111
import SQLFormatter
1212

13-
14-
extension EscapeTests {
15-
static var allTests : [(String, (EscapeTests) -> () throws -> Void)] {
16-
return [
17-
("testStringEscape", testStringEscape),
18-
("testBasicTypes", testBasicTypes),
19-
("testArrayType", testArrayType),
20-
("testNestedArray", testNestedArray),
21-
("testDictionary", testDictionary),
22-
("testAutoincrement", testAutoincrement)
23-
]
24-
}
25-
}
26-
2713
final class EscapeTests: XCTestCase {
2814

2915
// https://github.com/mysqljs/mysql/blob/master/test/unit/protocol/test-SqlString.js

Tests/MySQLTests/QueryDecimalTypeTests.swift

Lines changed: 23 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,20 +9,13 @@ import XCTest
99
@testable import MySQL
1010
import Foundation
1111

12-
extension QueryDecimalTypeTests {
13-
static var allTests : [(String, (QueryDecimalTypeTests) -> () throws -> Void)] {
14-
return [
15-
]
16-
}
17-
}
18-
1912
extension Row {
2013
fileprivate struct DecimalRow: Codable, QueryParameter, Equatable {
21-
let valueDouble: Decimal
22-
let valueText: Decimal
14+
let valueDoubleColumn: Decimal
15+
let valueTextColumn: Decimal
2316
private enum CodingKeys: String, CodingKey {
24-
case valueDouble = "value_double"
25-
case valueText = "value_text"
17+
case valueDoubleColumn = "value_double_col"
18+
case valueTextColumn = "value_text_col"
2619
}
2720
}
2821
}
@@ -46,8 +39,8 @@ final class QueryDecimalTypeTests: XCTestCase, QueryTestType {
4639
let query = """
4740
CREATE TABLE `\(constants.tableName)` (
4841
`id` int(11) unsigned NOT NULL AUTO_INCREMENT,
49-
`value_double` DOUBLE NOT NULL DEFAULT 0,
50-
`value_text` MEDIUMTEXT,
42+
`value_double_col` DOUBLE NOT NULL DEFAULT 0,
43+
`value_text_col` MEDIUMTEXT,
5144
PRIMARY KEY (`id`)
5245
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;
5346
"""
@@ -56,10 +49,24 @@ final class QueryDecimalTypeTests: XCTestCase, QueryTestType {
5649
}
5750

5851

52+
func testDecimalType() throws {
53+
let value = Decimal(string: "1.549")!
54+
let row = Row.DecimalRow(valueDoubleColumn: value, valueTextColumn: value)
55+
56+
try pool.execute { conn in
57+
_ = try conn.query("INSERT INTO ?? SET ? ", [constants.tableName, row])
58+
}
59+
60+
let rows: [Row.DecimalRow] = try pool.execute {
61+
try $0.query("SELECT * FROM ?? ORDER BY id ASC", [constants.tableName])
62+
}
63+
64+
XCTAssertEqual(rows[0], row)
65+
}
5966

60-
func disabled_testDecimalType() throws {
61-
let value = Decimal(1.23e100)
62-
let row = Row.DecimalRow(valueDouble: value, valueText: value)
67+
func testDecimalType_largerValue() throws {
68+
let value = Decimal(string: "1.23e100")!
69+
let row = Row.DecimalRow(valueDoubleColumn: value, valueTextColumn: value)
6370

6471
try pool.execute { conn in
6572
_ = try conn.query("INSERT INTO ?? SET ? ", [constants.tableName, row])

Tests/MySQLTests/QueryFormatterTests.swift

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,6 @@ import XCTest
1010
@testable import MySQL
1111
import SQLFormatter
1212

13-
extension QueryFormatterTests {
14-
static var allTests : [(String, (QueryFormatterTests) -> () throws -> Void)] {
15-
return [
16-
("testBasicFormatting", testBasicFormatting),
17-
("testLikeEscape", testLikeEscape),
18-
("testPlaceholder", testPlaceholder),
19-
("testStringUtil", testStringUtil)
20-
]
21-
}
22-
}
23-
2413

2514
final class QueryFormatterTests: XCTestCase {
2615

Tests/MySQLTests/QueryTests.swift

Lines changed: 0 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,18 +10,6 @@ import XCTest
1010
@testable import MySQL
1111
import Foundation
1212

13-
extension QueryTests {
14-
static var allTests : [(String, (QueryTests) -> () throws -> Void)] {
15-
return [
16-
("testInsertRowCodable", testInsertRowCodable),
17-
("testTransaction", testTransaction),
18-
("testEmojiInserting", testEmojiInserting),
19-
("testBulkInsert", testBulkInsert)
20-
]
21-
}
22-
}
23-
24-
2513
protocol QueryTestType: MySQLTestType {
2614
func dropTestTable() throws
2715
}

0 commit comments

Comments
 (0)