mirror of https://github.com/tuskyapp/Tusky.git
5 changed files with 2 additions and 85 deletions
@ -1,44 +0,0 @@
|
||||
/* Copyright 2019 kyori19 |
||||
* |
||||
* This file is a part of Tusky. |
||||
* |
||||
* This program 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. |
||||
* |
||||
* Tusky 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 Tusky; if not, |
||||
* see <http://www.gnu.org/licenses>. */
|
||||
|
||||
package com.keylesspalace.tusky.util; |
||||
|
||||
import androidx.annotation.NonNull; |
||||
|
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
public class VersionUtils { |
||||
|
||||
private int major; |
||||
private int minor; |
||||
private int patch; |
||||
|
||||
public VersionUtils(@NonNull String versionString) { |
||||
String regex = "([0-9]+)\\.([0-9]+)\\.([0-9]+).*"; |
||||
Pattern pattern = Pattern.compile(regex); |
||||
Matcher matcher = pattern.matcher(versionString); |
||||
if (matcher.find()) { |
||||
major = Integer.parseInt(matcher.group(1)); |
||||
minor = Integer.parseInt(matcher.group(2)); |
||||
patch = Integer.parseInt(matcher.group(3)); |
||||
} |
||||
} |
||||
|
||||
public boolean supportsScheduledToots() { |
||||
return (major == 2) ? ( (minor == 7) ? (patch >= 0) : (minor > 7) ) : (major > 2); |
||||
} |
||||
|
||||
} |
||||
@ -1,35 +0,0 @@
|
||||
package com.keylesspalace.tusky.util |
||||
|
||||
import org.junit.Assert.assertEquals |
||||
import org.junit.Test |
||||
import org.junit.runner.RunWith |
||||
import org.junit.runners.Parameterized |
||||
|
||||
@RunWith(Parameterized::class) |
||||
class VersionUtilsTest( |
||||
private val versionString: String, |
||||
private val supportsScheduledToots: Boolean |
||||
) { |
||||
|
||||
companion object { |
||||
@JvmStatic |
||||
@Parameterized.Parameters |
||||
fun data() = listOf( |
||||
arrayOf("2.0.0", false), |
||||
arrayOf("2a9a0", false), |
||||
arrayOf("1.0", false), |
||||
arrayOf("error", false), |
||||
arrayOf("", false), |
||||
arrayOf("2.6.9", false), |
||||
arrayOf("2.7.0", true), |
||||
arrayOf("2.00008.0", true), |
||||
arrayOf("2.7.2 (compatible; Pleroma 1.0.0-1168-ge18c7866-pleroma-dot-site)", true), |
||||
arrayOf("3.0.1", true) |
||||
) |
||||
} |
||||
|
||||
@Test |
||||
fun testVersionUtils() { |
||||
assertEquals(VersionUtils(versionString).supportsScheduledToots(), supportsScheduledToots) |
||||
} |
||||
} |
||||
Loading…
Reference in new issue