Skip to content

Commit

Permalink
Update for 1.0.5 release
Browse files Browse the repository at this point in the history
  • Loading branch information
nicklockwood committed Jan 20, 2024
1 parent 184afdd commit db98270
Show file tree
Hide file tree
Showing 6 changed files with 145 additions and 21 deletions.
32 changes: 26 additions & 6 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,18 @@ on:
pull_request:
jobs:
macos:
runs-on: macos-latest
strategy:
fail-fast: false
matrix:
macos:
- 11
- 14
xcode:
- latest-stable
runs-on: macos-${{ matrix.macos }}
steps:
- name: Checkout
uses: actions/checkout@v1
uses: actions/checkout@v2
- name: Build and Test
run: |
xcodebuild -scheme "LRUCache" -sdk macosx clean build test -enableCodeCoverage YES -derivedDataPath Build/
Expand All @@ -18,13 +26,25 @@ jobs:
pathCoverage=Build/Build/ProfileData/${directory}/Coverage.profdata
cd ../../../../
xcrun llvm-cov export -format="lcov" -instr-profile $pathCoverage Build/Build/Products/Debug/LRUCache.framework/LRUCache > info.lcov
bash <(curl https://codecov.io/bash) -t 5bfd6ece-264f-4cef-8dbf-4c5cfa0f87aa
env:
DEVELOPER_DIR: /Applications/Xcode_11.7.app/Contents/Developer
- name: Codecov
uses: codecov/codecov-action@v2
with:
# the token is optional for a public repo, but including it anyway
token: 5bfd6ece-264f-4cef-8dbf-4c5cfa0f87aa
env_vars: MD_APPLE_SDK_ROOT,RUNNER_OS,RUNNER_ARCH

linux:
strategy:
fail-fast: false
matrix:
swiftver:
- swift:5.2
- swiftlang/swift:nightly-main
swiftos:
- focal
runs-on: ubuntu-latest
container:
image: swift:5.2
image: ${{ format('{0}-{1}', matrix.swiftver, matrix.swiftos) }}
options: --cap-add=SYS_PTRACE --security-opt seccomp=unconfined --security-opt apparmor=unconfined
steps:
- name: Checkout
Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [1.0.5](https://github.com/nicklockwood/LRUCache/releases/tag/1.0.5) (2024-01-20)

- Added `allKeys` computed property

## [1.0.4](https://github.com/nicklockwood/LRUCache/releases/tag/1.0.4) (2022-09-16)

- Added `allValues` computed property
Expand Down
8 changes: 6 additions & 2 deletions LRUCache.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

/* Begin PBXBuildFile section */
0162A09923795EB30078AE84 /* LRUCache.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 016FAB2921BFE78100AF60DC /* LRUCache.framework */; };
01E6777E2B5BDBE1005594D6 /* MetadataTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01E6777D2B5BDBE1005594D6 /* MetadataTests.swift */; };
01FFF38226BCDCCC004D99ED /* LRUPerformanceTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 01FFF38126BCDCCC004D99ED /* LRUPerformanceTests.swift */; };
0A240137256A64FB00C1535C /* LRUCacheTests.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A240136256A64FB00C1535C /* LRUCacheTests.swift */; };
0A24013F256A671600C1535C /* LRUCache.swift in Sources */ = {isa = PBXBuildFile; fileRef = 0A24013E256A671600C1535C /* LRUCache.swift */; };
Expand All @@ -28,6 +29,7 @@
016FAB2D21BFE78100AF60DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
016FAB3221BFE78100AF60DC /* LRUCacheTests.xctest */ = {isa = PBXFileReference; explicitFileType = wrapper.cfbundle; includeInIndex = 0; path = LRUCacheTests.xctest; sourceTree = BUILT_PRODUCTS_DIR; };
016FAB3921BFE78100AF60DC /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
01E6777D2B5BDBE1005594D6 /* MetadataTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = MetadataTests.swift; sourceTree = "<group>"; };
01FFF38126BCDCCC004D99ED /* LRUPerformanceTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LRUPerformanceTests.swift; sourceTree = "<group>"; };
0A240136256A64FB00C1535C /* LRUCacheTests.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LRUCacheTests.swift; sourceTree = "<group>"; };
0A24013E256A671600C1535C /* LRUCache.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = LRUCache.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -94,6 +96,7 @@
children = (
0A240136256A64FB00C1535C /* LRUCacheTests.swift */,
01FFF38126BCDCCC004D99ED /* LRUPerformanceTests.swift */,
01E6777D2B5BDBE1005594D6 /* MetadataTests.swift */,
016FAB3921BFE78100AF60DC /* Info.plist */,
);
path = Tests;
Expand Down Expand Up @@ -262,6 +265,7 @@
files = (
01FFF38226BCDCCC004D99ED /* LRUPerformanceTests.swift in Sources */,
0A240137256A64FB00C1535C /* LRUCacheTests.swift in Sources */,
01E6777E2B5BDBE1005594D6 /* MetadataTests.swift in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
Expand Down Expand Up @@ -426,7 +430,7 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.0.2;
MARKETING_VERSION = 1.0.5;
OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-expression-type-checking=75";
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.LRUCache;
PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)";
Expand Down Expand Up @@ -460,7 +464,7 @@
"@executable_path/../Frameworks",
"@loader_path/Frameworks",
);
MARKETING_VERSION = 1.0.2;
MARKETING_VERSION = 1.0.5;
OTHER_SWIFT_FLAGS = "-Xfrontend -warn-long-expression-type-checking=75";
PRODUCT_BUNDLE_IDENTIFIER = com.charcoaldesign.LRUCache;
PRODUCT_MODULE_NAME = "$(PRODUCT_NAME:c99extidentifier)";
Expand Down
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
[![Platforms](https://img.shields.io/badge/platforms-iOS%20|%20Mac%20|%20tvOS%20|%20watchOS%20|%20Linux-lightgray.svg)]()
[![Swift 5.1](https://img.shields.io/badge/swift-5.1-red.svg?style=flat)](https://developer.apple.com/swift)
[![License](https://img.shields.io/badge/license-MIT-lightgrey.svg)](https://opensource.org/licenses/MIT)
[![Twitter](https://img.shields.io/badge/twitter-@nicklockwood-blue.svg)](http://twitter.com/nicklockwood)
[![Mastodon](https://img.shields.io/badge/mastodon-@nicklockwood@mastodon.social-636dff.svg)](https://mastodon.social/@nicklockwood)

- [Introduction](#introduction)
- [Installation](#installation)
Expand All @@ -27,7 +27,7 @@ LRUCache is packaged as a dynamic framework that you can import into your Xcode
To install using Swift Package Manage, add this to the `dependencies:` section in your Package.swift file:

```swift
.package(url: "https://github.com/nicklockwood/LRUCache.git", .upToNextMinor(from: "1.0.0")),
.package(url: "https://github.com/nicklockwood/LRUCache.git", .upToNextMinor(from: "1.0.5")),
```


Expand All @@ -51,9 +51,10 @@ To fetch a cached value, use:
let value = cache.value(forKey: "foo") // Returns nil if value not found
```

To fetch *all* the values stored in the cache, use:
To fetch *all* the key or values stored in the cache, use:

```swift
let keys = cache.allKeys // Ordered from oldest to newest
let values = cache.allValues // Ordered from oldest to newest
```

Expand Down
21 changes: 11 additions & 10 deletions Sources/LRUCache.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,22 +13,22 @@
// https://github.com/nicklockwood/LRUCache
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// of this software and associated documentation files (the "Software"), to
// deal in the Software without restriction, including without limitation the
// rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
// sell copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all
// copies or substantial portions of the Software.
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
// SOFTWARE.
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
// IN THE SOFTWARE.
//

import Foundation
Expand Down Expand Up @@ -69,7 +69,8 @@ public final class LRUCache<Key: Hashable, Value> {
didSet { clean() }
}

/// Initialize the cache with the specified `totalCostLimit` and `countLimit`
/// Initialize the cache with the specified `totalCostLimit` and
/// `countLimit`
public init(
totalCostLimit: Int = .max,
countLimit: Int = .max,
Expand Down
94 changes: 94 additions & 0 deletions Tests/MetadataTests.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//
// MetadataTests.swift
// LRUCacheTests
//
// Created by Nick Lockwood on 04/07/2021.
// Copyright © 2019 Nick Lockwood. All rights reserved.
//

@testable import LRUCache
import XCTest

private let projectDirectory = URL(fileURLWithPath: #file)
.deletingLastPathComponent().deletingLastPathComponent()

private let changelogURL = projectDirectory
.appendingPathComponent("CHANGELOG.md")

private let projectURL = projectDirectory
.appendingPathComponent("LRUCache.xcodeproj")
.appendingPathComponent("project.pbxproj")

private let projectVersion: String = {
let string = try! String(contentsOf: projectURL)
let start = string.range(of: "MARKETING_VERSION = ")!.upperBound
let end = string.range(of: ";", range: start ..< string.endIndex)!
.lowerBound
return String(string[start ..< end])
}()

private let changelogTitles: [Substring] = {
let changelog = try! String(contentsOf: changelogURL, encoding: .utf8)
var range = changelog.startIndex ..< changelog.endIndex
var matches = [Substring]()
while let match = changelog.range(
of: "## \\[[^]]+\\]\\([^)]+\\) \\([^)]+\\)",
options: .regularExpression,
range: range
) {
matches.append(changelog[match])
range = match.upperBound ..< changelog.endIndex
}
return matches
}()

class MetadataTests: XCTestCase {
// MARK: releases

func testProjectVersionMatchesChangelog() throws {
let changelog = try String(contentsOf: changelogURL, encoding: .utf8)
let range = try XCTUnwrap(changelog.range(of: "releases/tag/"))
XCTAssertTrue(
changelog[range.upperBound...].hasPrefix(projectVersion),
"Marketing version \(projectVersion) does not match most recent tag in CHANGELOG.md"
)
}

func testLatestVersionInChangelog() throws {
let changelog = try String(contentsOf: changelogURL, encoding: .utf8)
XCTAssertTrue(
changelog.contains("[\(projectVersion)]"),
"CHANGELOG.md does not mention latest release"
)
XCTAssertTrue(
changelog
.contains(
"(https://github.com/nicklockwood/LRUCache/releases/tag/\(projectVersion))"
),
"CHANGELOG.md does not include correct link for latest release"
)
}

func testChangelogDatesAreAscending() throws {
var lastDate: Date?
let dateParser = DateFormatter()
dateParser.timeZone = TimeZone(identifier: "UTC")
dateParser.locale = Locale(identifier: "en_GB")
dateParser.dateFormat = " (yyyy-MM-dd)"
for title in changelogTitles {
let dateRange = try XCTUnwrap(title.range(
of: " \\([^)]+\\)$",
options: .regularExpression
))
let dateString = String(title[dateRange])
let date = try XCTUnwrap(dateParser.date(from: dateString))
if let lastDate = lastDate, date > lastDate {
XCTFail(
"\(title) has newer date than subsequent version (\(date) vs \(lastDate))"
)
return
}
lastDate = date
}
}
}

0 comments on commit db98270

Please sign in to comment.