2 * Copyright 2000-2014 JetBrains s.r.o.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
16 package com.intellij.util.text;
18 import junit.framework.TestCase;
19 import org.jetbrains.annotations.NotNull;
21 public class SemVerTest extends TestCase {
22 public void testParsing() throws Exception {
23 String version = "0.9.2";
24 assertEquals(new SemVer(version, 0, 9, 2), parseNotNull(version));
27 public void testExtendedVersion() throws Exception {
28 String version = "0.9.2-dart";
29 assertEquals(new SemVer(version, 0, 9, 2), parseNotNull(version));
32 public void testGulp4Alpha() throws Exception {
33 String version = "4.0.0-alpha.1";
34 assertEquals(new SemVer(version, 4, 0, 0), parseNotNull(version));
37 public void testCompare() throws Exception {
38 assertTrue(parseNotNull("1.0.0").compareTo(parseNotNull("0.10.0")) > 0);
39 assertTrue(parseNotNull("1.0.0").compareTo(parseNotNull("2.10.0")) < 0);
41 assertTrue(parseNotNull("0.30.0").compareTo(parseNotNull("0.5.1000")) > 0);
42 assertTrue(parseNotNull("0.30.10").compareTo(parseNotNull("0.100.0")) < 0);
44 assertTrue(parseNotNull("2.9.123-test").compareTo(parseNotNull("2.9.100")) > 0);
45 assertTrue(parseNotNull("2.9.123-test").compareTo(parseNotNull("2.9.124")) < 0);
47 assertTrue(parseNotNull("11.123.0").compareTo(parseNotNull("11.123.0")) == 0);
51 private static SemVer parseNotNull(@NotNull String text) {
52 SemVer semVer = SemVer.parseFromText(text);
53 assertNotNull(semVer);