1 /*
2  * Copyright 2018 The Android Open Source Project
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 package androidx.build
18 
19 import org.junit.Assert.assertEquals
20 import org.junit.Test
21 import org.junit.runner.RunWith
22 import org.junit.runners.JUnit4
23 
24 @RunWith(JUnit4::class)
25 class VersionTest {
26     @Test
testComparisonsnull27     fun testComparisons() {
28         val version2600 = Version("26.0.0")
29         val version2610 = Version("26.1.0")
30         val version2611 = Version("26.1.1")
31         val version2620 = Version("26.2.0")
32         val version2621 = Version("26.2.1")
33         val version2700 = Version("27.0.0")
34         val version2700SNAPSHOT = Version("27.0.0-SNAPSHOT")
35         val version2700TNAPSHOT = Version("27.0.0-TNAPSHOT")
36 
37         assertEquals(version2600, version2600)
38 
39         assert(version2600 < version2700)
40 
41         assert(version2600 < version2700)
42 
43         assert(version2610 < version2611)
44         assert(version2610 < version2620)
45         assert(version2610 < version2621)
46         assert(version2610 < version2700)
47 
48         assert(version2611 < version2620)
49         assert(version2611 < version2621)
50         assert(version2611 < version2700)
51 
52         assert(version2700 > version2600)
53         assert(version2700 > version2700SNAPSHOT)
54         assert(version2700SNAPSHOT < version2700)
55 
56         assert(version2700TNAPSHOT > version2700SNAPSHOT)
57         assert(version2700SNAPSHOT < version2700TNAPSHOT)
58     }
59 
60     @Test
testParsingDependencyRangesnull61     fun testParsingDependencyRanges() {
62         assert(Version.isDependencyRange("[1.0.0]") == false)
63         assert(Version.isDependencyRange("[1.0.0,2.0.0]") == true)
64         assert(Version.isDependencyRange("1.0.0+") == true)
65         assert(Version.isDependencyRange("1.0.0") == false)
66         assert(Version.isDependencyRange("") == false)
67         assert(Version.isDependencyRange("(1.0.0)") == false)
68         assert(Version.isDependencyRange("(1.0.0,2.0.0)") == true)
69         assert(Version.isDependencyRange("(1.0.0-beta01,2.0.0)") == true)
70     }
71 }
72