Skip to content

Commit

Permalink
Merge pull request #26 from corujautx/master
Browse files Browse the repository at this point in the history
Moving version handling from shadowed `SwiftLMDB` struct to `LMDBVersion.current`
  • Loading branch information
agisboye authored Jul 10, 2024
2 parents 23d4d91 + 97afa7a commit a933e01
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 50 deletions.
31 changes: 31 additions & 0 deletions Sources/LMDBVersion.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
//
// LMDBVersion.swift
//
//
// Created by Vitor Travain on 2/7/2024.
//

import Foundation
import LMDB

struct LMDBVersion {
var major: Int
var minor: Int
var patch: Int

private init(major: Int, minor: Int, patch: Int) {
self.major = major
self.minor = minor
self.patch = patch
}

static let current: LMDBVersion = {
var major: Int32 = 0
var minor: Int32 = 0
var patch: Int32 = 0

_ = mdb_version(&major, &minor, &patch)

return LMDBVersion(major: Int(major), minor: Int(minor), patch: Int(patch))
}()
}
17 changes: 0 additions & 17 deletions Sources/SwiftLMDB.h

This file was deleted.

30 changes: 0 additions & 30 deletions Sources/SwiftLMDB.swift

This file was deleted.

9 changes: 6 additions & 3 deletions Tests/SwiftLMDBTests/SwiftLMDBTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,10 @@ class SwiftLMDBTests: XCTestCase {
// MARK: - Tests

func testGetLMDBVersion() {
XCTAssert(SwiftLMDB.version != (0, 0, 0), "Unable to get LMDB major version.")
XCTAssertNotEqual(
[LMDBVersion.current.major, LMDBVersion.current.minor, LMDBVersion.current.patch],
[0, 0, 0]
)
}

func testCreateEnvironment() {
Expand Down Expand Up @@ -197,13 +200,13 @@ class SwiftLMDBTests: XCTestCase {
}

func testStats() {

let database = createDatabase(named: #function)

do {
try database.put(value: "value", forKey: "key")
let stats = database.stats
XCTAssertEqual(stats.pageSize, 4096)
XCTAssertEqual(stats.pageSize, UInt32(sysconf(_SC_PAGESIZE)))
XCTAssertEqual(stats.depth, 1)
XCTAssertEqual(stats.branchPageCount, 0)
XCTAssertEqual(stats.leafPageCount, 1)
Expand Down

0 comments on commit a933e01

Please sign in to comment.