-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #10 from thejohnlima/fix/parse_json_functions
Fix functions used to parse data from local files
- Loading branch information
Showing
7 changed files
with
157 additions
and
9 deletions.
There are no files selected for viewing
This file contains 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 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 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 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,72 @@ | ||
// MIT License | ||
// | ||
// Copyright (c) 2020 John Lima | ||
// | ||
// 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 | ||
// 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 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. | ||
|
||
@testable | ||
import LMStorage | ||
import XCTest | ||
|
||
final class LMCodableTests: XCTestCase { | ||
|
||
// MARK: - Properties | ||
private var sign: Sign? | ||
private var signs: [Sign] = [] | ||
|
||
static var allTests = [ | ||
("testSuccessItemLocalParse", testSuccessItemLocalParse) | ||
] | ||
|
||
// MARK: - Overrides | ||
override func setUp() { | ||
super.setUp() | ||
sign = Sign.getItem(from: "sign", bundle: .module) | ||
signs = Sign.getItems(from: "signs", bundle: .module) | ||
} | ||
|
||
override func tearDown() { | ||
sign = nil | ||
signs = [] | ||
super.tearDown() | ||
} | ||
|
||
// MARK: - Test Methods | ||
func testSuccessItemLocalParse() { | ||
XCTAssertEqual(sign?.dateRange, "Aug 23 - Sep 22") | ||
XCTAssertEqual(sign?.currentDate, "July 11, 2021") | ||
XCTAssertEqual(sign?.description, "You reach a milestone of some kind today, and should be able to build on it without too much trouble. In fact, now is a really good time for you to step back and reconsider your goals and ambitions.") | ||
XCTAssertEqual(sign?.compatibility, "Cancer") | ||
XCTAssertEqual(sign?.mood, "Serious") | ||
XCTAssertEqual(sign?.color, "Orchid") | ||
XCTAssertEqual(sign?.luckyNumber, "93") | ||
XCTAssertEqual(sign?.luckyTime, "4pm") | ||
} | ||
|
||
func testSuccessItemsLocalParse() { | ||
XCTAssertEqual(signs.last?.dateRange, "Mar 21 - Apr 20") | ||
XCTAssertEqual(signs.last?.currentDate, "July 11, 2021") | ||
XCTAssertEqual(signs.last?.description, "Your social energy is potent today -- but it's best spent on those you already know fairly well. Friends and family need your attention more than strangers, anyway, so hole up at home for now.") | ||
XCTAssertEqual(signs.last?.compatibility, "Sagittarius") | ||
XCTAssertEqual(signs.last?.mood, "Thoughtful") | ||
XCTAssertEqual(signs.last?.color, "Teal") | ||
XCTAssertEqual(signs.last?.luckyNumber, "42") | ||
XCTAssertEqual(signs.last?.luckyTime, "4pm") | ||
} | ||
} |
This file contains 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,28 @@ | ||
// | ||
// File.swift | ||
// | ||
// | ||
// Created by John Lima on 7/11/21. | ||
// | ||
|
||
@testable | ||
import LMStorage | ||
|
||
struct Sign: LMCodable { | ||
let dateRange: String? | ||
let currentDate: String? | ||
let description: String? | ||
let compatibility: String? | ||
let mood: String? | ||
let color: String? | ||
let luckyNumber: String? | ||
let luckyTime: String? | ||
|
||
enum CodingKeys: String, CodingKey { | ||
case description, compatibility, mood, color | ||
case dateRange = "date_range" | ||
case currentDate = "current_date" | ||
case luckyNumber = "lucky_number" | ||
case luckyTime = "lucky_time" | ||
} | ||
} |
This file contains 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,10 @@ | ||
{ | ||
"date_range": "Aug 23 - Sep 22", | ||
"current_date": "July 11, 2021", | ||
"description": "You reach a milestone of some kind today, and should be able to build on it without too much trouble. In fact, now is a really good time for you to step back and reconsider your goals and ambitions.", | ||
"compatibility": "Cancer", | ||
"mood": "Serious", | ||
"color": "Orchid", | ||
"lucky_number": "93", | ||
"lucky_time": "4pm" | ||
} |
This file contains 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,22 @@ | ||
[ | ||
{ | ||
"date_range": "Aug 23 - Sep 22", | ||
"current_date": "July 11, 2021", | ||
"description": "You reach a milestone of some kind today, and should be able to build on it without too much trouble. In fact, now is a really good time for you to step back and reconsider your goals and ambitions.", | ||
"compatibility": "Cancer", | ||
"mood": "Serious", | ||
"color": "Orchid", | ||
"lucky_number": "93", | ||
"lucky_time": "4pm" | ||
}, | ||
{ | ||
"date_range": "Mar 21 - Apr 20", | ||
"current_date": "July 11, 2021", | ||
"description": "Your social energy is potent today -- but it's best spent on those you already know fairly well. Friends and family need your attention more than strangers, anyway, so hole up at home for now.", | ||
"compatibility": "Sagittarius", | ||
"mood": "Thoughtful", | ||
"color": "Teal", | ||
"lucky_number": "42", | ||
"lucky_time": "4pm" | ||
} | ||
] |