Move tests to commonTest; convert some classes from Swift to Kotlin

This commit is contained in:
2019-04-13 22:28:05 -05:00
parent d463bb55d7
commit fe4139e268
20 changed files with 248 additions and 248 deletions

View File

@@ -32,7 +32,7 @@ import UIKit
backend = Backend(databaseName: "uhabits.db",
databaseOpener: IosDatabaseOpener(withLog: log),
fileOpener: IosFileOpener(),
localeHelper: IosLocaleHelper(NSLocale.preferredLanguages),
localeHelper: IosLocaleHelper(log: log),
log: log,
scope: UIDispatcher())

View File

@@ -19,6 +19,19 @@
import UIKit
extension Color {
var uicolor: UIColor {
return UIColor(red: CGFloat(self.red),
green: CGFloat(self.green),
blue: CGFloat(self.blue),
alpha: CGFloat(self.alpha))
}
var cgcolor : CGColor {
return uicolor.cgColor
}
}
class ComponentView : UIView {
var component: Component?

View File

@@ -1,60 +0,0 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import Foundation
extension LocalDate {
var iosDate : Date {
let calendar = Calendar(identifier: .gregorian)
var dc = DateComponents()
dc.year = Int(self.year)
dc.month = Int(self.month)
dc.day = Int(self.day)
dc.hour = 13
dc.minute = 0
return calendar.date(from: dc)!
}
}
extension Date {
var localDate : LocalDate {
let calendar = Calendar(identifier: .gregorian)
return LocalDate(year: Int32(calendar.component(.year, from: self)),
month: Int32(calendar.component(.month, from: self)),
day: Int32(calendar.component(.day, from: self)))
}
}
class IosLocalDateFormatter : NSObject, LocalDateFormatter {
let fmt = DateFormatter()
override init() {
fmt.locale = Locale(identifier: NSLocale.preferredLanguages.first!)
}
func shortMonthName(date: LocalDate) -> String {
fmt.dateFormat = "MMM"
return fmt.string(from: date.iosDate)
}
func shortWeekdayName(date: LocalDate) -> String {
fmt.dateFormat = "EEE"
return fmt.string(from: date.iosDate)
}
}

View File

@@ -1,33 +0,0 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import UIKit
extension Color {
var uicolor: UIColor {
return UIColor(red: CGFloat(self.red),
green: CGFloat(self.green),
blue: CGFloat(self.blue),
alpha: CGFloat(self.alpha))
}
var cgcolor : CGColor {
return uicolor.cgColor
}
}

View File

@@ -1,64 +0,0 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import Foundation
class IosLocaleHelper : NSObject, LocaleHelper {
var preferredLanguages: [String]
init(_ preferredLanguages: [String]) {
self.preferredLanguages = preferredLanguages
}
func getStringsForCurrentLocale() -> Strings {
let lang = preferredLanguages.first ?? "en-US"
StandardLog().debug(tag: "IosLocale", msg: lang)
if lang.hasPrefix("ar") { return StringsArabic() }
if lang.hasPrefix("fr") { return StringsFrench() }
if lang.hasPrefix("es") { return StringsSpanish() }
if lang.hasPrefix("pt-BR") { return StringsPortugueseBR() }
if lang.hasPrefix("pt") { return StringsPortuguesePT() }
if lang.hasPrefix("it") { return StringsItalian() }
if lang.hasPrefix("de") { return StringsGerman() }
if lang.hasPrefix("zh-Hans") { return StringsChineseCN() }
if lang.hasPrefix("zh-Hant") { return StringsChineseTW() }
if lang.hasPrefix("nl") { return StringsDutch() }
if lang.hasPrefix("ja") { return StringsJapanese() }
if lang.hasPrefix("ko") { return StringsKorean() }
if lang.hasPrefix("vi") { return StringsVietnamese() }
if lang.hasPrefix("ru") { return StringsRussian() }
if lang.hasPrefix("sv") { return StringsSwedish() }
if lang.hasPrefix("da") { return StringsDanish() }
if lang.hasPrefix("fi") { return StringsFinnish() }
if lang.hasPrefix("nb") { return StringsNorwegian() }
if lang.hasPrefix("tr") { return StringsTurkish() }
if lang.hasPrefix("el") { return StringsGreek() }
if lang.hasPrefix("id") { return StringsIndonesian() }
if lang.hasPrefix("hi") { return StringsHindi() }
if lang.hasPrefix("hu") { return StringsHungarian() }
if lang.hasPrefix("pl") { return StringsPolish() }
if lang.hasPrefix("cs") { return StringsCzech() }
if lang.hasPrefix("sk") { return StringsSlovak() }
if lang.hasPrefix("ca") { return StringsCatalan() }
if lang.hasPrefix("ro") { return StringsRomanian() }
if lang.hasPrefix("hr") { return StringsCroatian() }
if lang.hasPrefix("he") { return StringsHebrew() }
return Strings()
}
}

View File

@@ -1,35 +0,0 @@
/*
* Copyright (C) 2016-2019 Álinson Santos Xavier <isoron@gmail.com>
*
* This file is part of Loop Habit Tracker.
*
* Loop Habit Tracker is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation, either version 3 of the License, or (at your
* option) any later version.
*
* Loop Habit Tracker is distributed in the hope that it will be useful, but
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
import XCTest
import UIKit
@testable import uhabits
class IosDateFormatterTest : XCTestCase {
func testShortMonthName() {
let fmt = IosLocalDateFormatter()
let d1 = LocalDate(year: 2019, month: 3, day: 25)
let d2 = LocalDate(year: 2019, month: 4, day: 4)
let d3 = LocalDate(year: 2019, month: 5, day: 12)
XCTAssertEqual(fmt.shortWeekdayName(date: d1), "Mon")
XCTAssertEqual(fmt.shortWeekdayName(date: d2), "Thu")
XCTAssertEqual(fmt.shortWeekdayName(date: d3), "Sun")
}
}

View File

@@ -8,7 +8,6 @@
/* Begin PBXBuildFile section */
001592642260AE0F00D2814F /* main.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C0C6C92246E543003D8AF0 /* main.framework */; };
006EFE4E2252EA2B008464E0 /* IosLocale.swift in Sources */ = {isa = PBXBuildFile; fileRef = 006EFE4D2252EA2B008464E0 /* IosLocale.swift */; };
006EFE50225432B8008464E0 /* AboutScreenController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 006EFE4F225432B8008464E0 /* AboutScreenController.swift */; };
00A5B42822009F590024E00C /* AppDelegate.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42722009F590024E00C /* AppDelegate.swift */; };
00A5B42A22009F590024E00C /* MainScreenController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00A5B42922009F590024E00C /* MainScreenController.swift */; };
@@ -20,11 +19,8 @@
00C0C6BF22465F65003D8AF0 /* migrations in Resources */ = {isa = PBXBuildFile; fileRef = 00C0C6BC22465F65003D8AF0 /* migrations */; };
00C0C6CA2246E543003D8AF0 /* main.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 00C0C6C92246E543003D8AF0 /* main.framework */; };
00C0C6CC2246E550003D8AF0 /* main.framework in Embed Frameworks */ = {isa = PBXBuildFile; fileRef = 00C0C6C92246E543003D8AF0 /* main.framework */; settings = {ATTRIBUTES = (CodeSignOnCopy, RemoveHeadersOnCopy, ); }; };
00C0C6CE2246EFB3003D8AF0 /* IosExtensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00C0C6CD2246EFB3003D8AF0 /* IosExtensions.swift */; };
00C0C6D122470705003D8AF0 /* IosCanvas.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00C0C6D022470705003D8AF0 /* IosCanvas.swift */; };
00C0C6D92247DC13003D8AF0 /* IosCanvasTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00C0C6D82247DC13003D8AF0 /* IosCanvasTest.swift */; };
00C0C6DB2247E6B0003D8AF0 /* IosDates.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00C0C6DA2247E6B0003D8AF0 /* IosDates.swift */; };
00C0C6DD2247E6C4003D8AF0 /* IosDatesTest.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00C0C6DC2247E6C4003D8AF0 /* IosDatesTest.swift */; };
00C0C6E0224A3602003D8AF0 /* DetailScreenController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00C0C6DE224A35FC003D8AF0 /* DetailScreenController.swift */; };
00D48BD12200A31300CC4527 /* Launch.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 00D48BD02200A31300CC4527 /* Launch.storyboard */; };
00D48BD32200AC1600CC4527 /* EditHabitController.swift in Sources */ = {isa = PBXBuildFile; fileRef = 00D48BD22200AC1600CC4527 /* EditHabitController.swift */; };
@@ -55,7 +51,6 @@
/* End PBXCopyFilesBuildPhase section */
/* Begin PBXFileReference section */
006EFE4D2252EA2B008464E0 /* IosLocale.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosLocale.swift; sourceTree = "<group>"; };
006EFE4F225432B8008464E0 /* AboutScreenController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AboutScreenController.swift; sourceTree = "<group>"; };
00A5B42422009F590024E00C /* uhabits.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = uhabits.app; sourceTree = BUILT_PRODUCTS_DIR; };
00A5B42722009F590024E00C /* AppDelegate.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = AppDelegate.swift; sourceTree = "<group>"; };
@@ -71,11 +66,8 @@
00C0C6BB22465F65003D8AF0 /* databases */ = {isa = PBXFileReference; lastKnownFileType = folder; path = databases; sourceTree = "<group>"; };
00C0C6BC22465F65003D8AF0 /* migrations */ = {isa = PBXFileReference; lastKnownFileType = folder; path = migrations; sourceTree = "<group>"; };
00C0C6C92246E543003D8AF0 /* main.framework */ = {isa = PBXFileReference; lastKnownFileType = wrapper.framework; name = main.framework; path = ../core/build/bin/ios/mainDebugFramework/main.framework; sourceTree = "<group>"; };
00C0C6CD2246EFB3003D8AF0 /* IosExtensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosExtensions.swift; sourceTree = "<group>"; };
00C0C6D022470705003D8AF0 /* IosCanvas.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosCanvas.swift; sourceTree = "<group>"; };
00C0C6D82247DC13003D8AF0 /* IosCanvasTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosCanvasTest.swift; sourceTree = "<group>"; };
00C0C6DA2247E6B0003D8AF0 /* IosDates.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosDates.swift; sourceTree = "<group>"; };
00C0C6DC2247E6C4003D8AF0 /* IosDatesTest.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = IosDatesTest.swift; sourceTree = "<group>"; };
00C0C6DE224A35FC003D8AF0 /* DetailScreenController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DetailScreenController.swift; sourceTree = "<group>"; };
00D48BD02200A31300CC4527 /* Launch.storyboard */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; path = Launch.storyboard; sourceTree = "<group>"; };
00D48BD22200AC1600CC4527 /* EditHabitController.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = EditHabitController.swift; sourceTree = "<group>"; };
@@ -179,9 +171,6 @@
children = (
00C0C6D022470705003D8AF0 /* IosCanvas.swift */,
00C0C6A7224654A2003D8AF0 /* IosDatabase.swift */,
00C0C6DA2247E6B0003D8AF0 /* IosDates.swift */,
00C0C6CD2246EFB3003D8AF0 /* IosExtensions.swift */,
006EFE4D2252EA2B008464E0 /* IosLocale.swift */,
);
path = Platform;
sourceTree = "<group>";
@@ -191,7 +180,6 @@
children = (
00C0C6D82247DC13003D8AF0 /* IosCanvasTest.swift */,
00C0C6A222465365003D8AF0 /* IosDatabaseTest.swift */,
00C0C6DC2247E6C4003D8AF0 /* IosDatesTest.swift */,
);
path = Platform;
sourceTree = "<group>";
@@ -323,11 +311,8 @@
buildActionMask = 2147483647;
files = (
00C0C6D122470705003D8AF0 /* IosCanvas.swift in Sources */,
00C0C6CE2246EFB3003D8AF0 /* IosExtensions.swift in Sources */,
00C0C6E0224A3602003D8AF0 /* DetailScreenController.swift in Sources */,
00C0C6A8224654A2003D8AF0 /* IosDatabase.swift in Sources */,
006EFE4E2252EA2B008464E0 /* IosLocale.swift in Sources */,
00C0C6DB2247E6B0003D8AF0 /* IosDates.swift in Sources */,
00A5B42A22009F590024E00C /* MainScreenController.swift in Sources */,
00A5B42822009F590024E00C /* AppDelegate.swift in Sources */,
00D48BD32200AC1600CC4527 /* EditHabitController.swift in Sources */,
@@ -339,7 +324,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
00C0C6DD2247E6C4003D8AF0 /* IosDatesTest.swift in Sources */,
00C0C6D92247DC13003D8AF0 /* IosCanvasTest.swift in Sources */,
00C0C6A62246537E003D8AF0 /* IosDatabaseTest.swift in Sources */,
);