-
Notifications
You must be signed in to change notification settings - Fork 11
Fix parsing bug and implement categories #8
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
AdrianBinDC
wants to merge
6
commits into
dmail-me:main
Choose a base branch
from
AdrianBinDC:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
b774cc5
Fix parsing bug
AdrianBinDC baf5565
Update Package.swift
AdrianBinDC b91137f
Implement categories
AdrianBinDC 5b18b22
Merge branch 'implement-categories'
AdrianBinDC 56292e8
Update Sources/iCalendarParser/Models/ICEvent.swift
AdrianBinDC 176795b
Update access modifier
AdrianBinDC File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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
36 changes: 36 additions & 0 deletions
36
Tests/iCalendarParserTests/Extensions/XCTestCase+Extension.swift
This file contains hidden or 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,36 @@ | ||
| // | ||
| // XCTestCase+Extension.swift | ||
| // | ||
| // | ||
| // Created by Adrian Bolinger on 7/28/24. | ||
| // | ||
|
|
||
| import XCTest | ||
|
|
||
| extension XCTestCase { | ||
| /// Reads the contents of a file located in the test directory's "Resources" folder. | ||
| /// | ||
| /// - Parameters: | ||
| /// - filename: The name of the file (without extension). | ||
| /// - ext: The extension of the file. | ||
| /// - Returns: The contents of the file as a String. | ||
| /// - Throws: An error if the file cannot be read. | ||
| func getContents(of filename: String, ext: String, file: StaticString = #filePath) throws -> String { | ||
| // Get the directory of the current file | ||
| let currentFilePath = String(describing: file) | ||
| let currentDirectoryPath = URL(fileURLWithPath: currentFilePath).deletingLastPathComponent() | ||
|
|
||
| // Construct the full file path | ||
| let fileURL = currentDirectoryPath.appendingPathComponent("Resources/\(filename).\(ext)") | ||
|
|
||
| // Ensure the file exists | ||
| guard FileManager.default.fileExists(atPath: fileURL.path) else { | ||
| throw NSError(domain: "FileNotFoundError", code: 1, userInfo: [NSLocalizedDescriptionKey: "File \(filename).\(ext) not found at path \(fileURL.path)."]) | ||
| } | ||
|
|
||
| // Read the contents of the file | ||
| let fileContents = try String(contentsOf: fileURL, encoding: .utf8) | ||
|
|
||
| return fileContents | ||
| } | ||
| } |
This file contains hidden or 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,50 @@ | ||
| // | ||
| // ICParserTests.swift | ||
| // | ||
| // | ||
| // Created by Adrian Bolinger on 7/28/24. | ||
| // | ||
|
|
||
| import XCTest | ||
|
|
||
| @testable import iCalendarParser | ||
|
|
||
| final class ICParserTests: XCTestCase { | ||
|
|
||
| var sut: ICParser! | ||
|
|
||
| override func setUpWithError() throws { | ||
| try super.setUpWithError() | ||
| sut = ICParser() | ||
| } | ||
|
|
||
| override func tearDownWithError() throws { | ||
| sut = nil | ||
| try super.tearDownWithError() | ||
| } | ||
|
|
||
| func testICParser() throws { | ||
| let iCalString = try getContents(of: "uf-full-calendar", ext: "txt") | ||
| let calendar = sut.calendar(from: iCalString) | ||
| XCTAssertEqual(calendar?.events.count, 295) | ||
| } | ||
|
|
||
| func testICParserCategories() throws { | ||
| let iCalString = try getContents(of: "ufl-all-events", ext: "txt") | ||
| guard let calendar = sut.calendar(from: iCalString) else { | ||
| XCTFail("could not create calendar") | ||
| return | ||
| } | ||
|
|
||
| let uniqueCategories = calendar.events | ||
| .compactMap { $0.categories } | ||
| .flatMap { $0 } | ||
| .reduce(into: [String]()) { result, category in | ||
| if !result.contains(category) { | ||
| result.append(category) | ||
| } | ||
| } | ||
|
|
||
| XCTAssertEqual(uniqueCategories.count, 19) | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.