• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // Protocol Buffers - Google's data interchange format
2 // Copyright 2008 Google Inc.  All rights reserved.
3 //
4 // Use of this source code is governed by a BSD-style
5 // license that can be found in the LICENSE file or at
6 // https://developers.google.com/open-source/licenses/bsd
7 
8 #include "google/protobuf/compiler/versions.h"
9 
10 #include <gmock/gmock.h>
11 #include <gtest/gtest.h>
12 #include "google/protobuf/test_textproto.h"
13 
14 namespace google {
15 namespace protobuf {
16 namespace compiler {
17 namespace internal {
18 namespace {
TEST(ParseProtobufVersionTest,EmptyVersionString)19 TEST(ParseProtobufVersionTest, EmptyVersionString) {
20   EXPECT_DEATH({ ParseProtobufVersion(""); }, "version cannot be empty.");
21 }
22 
TEST(ParseProtobufVersionTest,MissingVersionSegment)23 TEST(ParseProtobufVersionTest, MissingVersionSegment) {
24   EXPECT_DEATH({ ParseProtobufVersion("3.26-dev"); },
25                "version string must provide major, minor and micro numbers.");
26 }
27 
TEST(ParseProtobufVersionTest,RedundantVersionSuffix)28 TEST(ParseProtobufVersionTest, RedundantVersionSuffix) {
29   EXPECT_DEATH({ ParseProtobufVersion("3.26-dev-rc1"); },
30                "version cannot have more than one suffix annotated by \"-\".");
31 }
32 
TEST(ParseProtobufVersionTest,FullVersionWithRCSuffix)33 TEST(ParseProtobufVersionTest, FullVersionWithRCSuffix) {
34   EXPECT_THAT(ParseProtobufVersion("3.26.2-rc1"),
35               EqualsProto(R"pb(major: 3 minor: 26 patch: 2 suffix: "-rc1")pb"));
36 }
37 
TEST(ParseProtobufVersionTest,FullVersionWithoutSuffix)38 TEST(ParseProtobufVersionTest, FullVersionWithoutSuffix) {
39   EXPECT_THAT(ParseProtobufVersion("3.26.2"),
40               EqualsProto(R"pb(major: 3 minor: 26 patch: 2)pb"));
41 }
42 
TEST(ParseProtobufVersionTest,VersionWithDevSuffix)43 TEST(ParseProtobufVersionTest, VersionWithDevSuffix) {
44   EXPECT_THAT(ParseProtobufVersion("3.26.0-dev"),
45               EqualsProto(R"pb(major: 3 minor: 26 patch: 0 suffix: "-dev")pb"));
46 }
47 }  // namespace
48 }  // namespace internal
49 }  // namespace compiler
50 }  // namespace protobuf
51 }  // namespace google
52