• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 //===- VersionTupleTests.cpp - Version Number Handling Tests --------------===//
2 //
3 //                     The LLVM Compiler Infrastructure
4 //
5 // This file is distributed under the University of Illinois Open Source
6 // License. See LICENSE.TXT for details.
7 //
8 //===----------------------------------------------------------------------===//
9 
10 #include "llvm/Support/VersionTuple.h"
11 #include "gtest/gtest.h"
12 
13 using namespace llvm;
14 
TEST(VersionTuple,getAsString)15 TEST(VersionTuple, getAsString) {
16   EXPECT_EQ("0", VersionTuple().getAsString());
17   EXPECT_EQ("1", VersionTuple(1).getAsString());
18   EXPECT_EQ("1.2", VersionTuple(1, 2).getAsString());
19   EXPECT_EQ("1.2.3", VersionTuple(1, 2, 3).getAsString());
20   EXPECT_EQ("1.2.3.4", VersionTuple(1, 2, 3, 4).getAsString());
21 }
22 
TEST(VersionTuple,tryParse)23 TEST(VersionTuple, tryParse) {
24   VersionTuple VT;
25 
26   EXPECT_FALSE(VT.tryParse("1"));
27   EXPECT_EQ("1", VT.getAsString());
28 
29   EXPECT_FALSE(VT.tryParse("1.2"));
30   EXPECT_EQ("1.2", VT.getAsString());
31 
32   EXPECT_FALSE(VT.tryParse("1.2.3"));
33   EXPECT_EQ("1.2.3", VT.getAsString());
34 
35   EXPECT_FALSE(VT.tryParse("1.2.3.4"));
36   EXPECT_EQ("1.2.3.4", VT.getAsString());
37 
38   EXPECT_TRUE(VT.tryParse(""));
39   EXPECT_TRUE(VT.tryParse("1."));
40   EXPECT_TRUE(VT.tryParse("1.2."));
41   EXPECT_TRUE(VT.tryParse("1.2.3."));
42   EXPECT_TRUE(VT.tryParse("1.2.3.4."));
43   EXPECT_TRUE(VT.tryParse("1.2.3.4.5"));
44   EXPECT_TRUE(VT.tryParse("1-2"));
45   EXPECT_TRUE(VT.tryParse("1+2"));
46   EXPECT_TRUE(VT.tryParse(".1"));
47   EXPECT_TRUE(VT.tryParse(" 1"));
48   EXPECT_TRUE(VT.tryParse("1 "));
49   EXPECT_TRUE(VT.tryParse("."));
50 }
51