Initial version of semver 2.0.0 parser.
This commit is contained in:
+28
@@ -0,0 +1,28 @@
|
||||
# Compiled Object files
|
||||
*.slo
|
||||
*.lo
|
||||
*.o
|
||||
*.obj
|
||||
|
||||
# Precompiled Headers
|
||||
*.gch
|
||||
*.pch
|
||||
|
||||
# Compiled Dynamic libraries
|
||||
*.so
|
||||
*.dylib
|
||||
*.dll
|
||||
|
||||
# Fortran module files
|
||||
*.mod
|
||||
|
||||
# Compiled Static libraries
|
||||
*.lai
|
||||
*.la
|
||||
*.a
|
||||
*.lib
|
||||
|
||||
# Executables
|
||||
*.exe
|
||||
*.out
|
||||
*.app
|
||||
@@ -0,0 +1,39 @@
|
||||
cmake_minimum_required(VERSION 3.0)
|
||||
project(semver)
|
||||
set(VERSION_MAJOR "0")
|
||||
set(VERSION_MINOR "1")
|
||||
set(VERSION_PATCH "0")
|
||||
set(VERSION_RELEASE "alpha")
|
||||
set(VERSION_BUILD "")
|
||||
|
||||
# Build full version string, including optional components
|
||||
string(COMPARE NOTEQUAL VERSION_RELEASE "" HAVE_RELEASE)
|
||||
string(COMPARE NOTEQUAL VERSION_BUILD "" HAVE_BUILD)
|
||||
set(VERSION_FULL "${VERSION_MAJOR}.${VERSION_MINOR}.${VERSION_PATCH}")
|
||||
if(HAVE_RELEASE)
|
||||
set(VERSION_FULL "${VERSION_FULL}-${VERSION_RELEASE}")
|
||||
endif()
|
||||
if(HAVE_BUILD)
|
||||
set(VERSION_FULL "${VERSION_FULL}-${VERSION_BUILD}")
|
||||
endif()
|
||||
|
||||
if(UNIX)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Werror -Wextra -pedantic")
|
||||
add_definitions(-std=c++14)
|
||||
endif()
|
||||
|
||||
if(WIN32)
|
||||
add_definitions(-DWINVER=0x0601)
|
||||
add_definitions(-D_WIN32_WINNT=0x0601)
|
||||
endif()
|
||||
|
||||
if(MSVC)
|
||||
add_definitions(-D_SCL_SECURE_NO_WARNINGS)
|
||||
endif()
|
||||
|
||||
add_subdirectory(src)
|
||||
add_subdirectory(test)
|
||||
|
||||
enable_testing()
|
||||
add_test(NAME semver200_parser_tests COMMAND semver200_parser_tests)
|
||||
add_test(NAME semver200_comparator_tests COMMAND semver200_comparator_tests)
|
||||
@@ -0,0 +1,22 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Marko Živanović
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
|
||||
@@ -0,0 +1,71 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Marko Zivanovic
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <cstdint>
|
||||
#include <string>
|
||||
|
||||
namespace version {
|
||||
|
||||
struct Version_data {
|
||||
int major;
|
||||
int minor;
|
||||
int patch;
|
||||
std::string release;
|
||||
std::string build;
|
||||
};
|
||||
|
||||
struct Semver200_parser {
|
||||
Version_data parse(const std::string&);
|
||||
};
|
||||
|
||||
struct Semver200_comparator {
|
||||
int compare(const Version_data&, const Version_data&);
|
||||
};
|
||||
|
||||
template<typename Parser, typename Comparator>
|
||||
class Basic_version {
|
||||
public:
|
||||
Basic_version(const std::string&, Parser, Comparator);
|
||||
|
||||
bool operator>(const Basic_version&);
|
||||
bool operator>=(const Basic_version&);
|
||||
bool operator<(const Basic_version&);
|
||||
bool operator<=(const Basic_version&);
|
||||
bool operator==(const Basic_version&);
|
||||
bool operator!=(const Basic_version&);
|
||||
|
||||
private:
|
||||
Parser parser_;
|
||||
Comparator comparator_;
|
||||
const Version_data ver_;
|
||||
};
|
||||
|
||||
class Semver200 : public Basic_version<Semver200_parser, Semver200_comparator> {};
|
||||
|
||||
class Parse_error : public std::runtime_error {
|
||||
using std::runtime_error::runtime_error;
|
||||
};
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
include_directories(
|
||||
../include
|
||||
)
|
||||
|
||||
add_library(semver
|
||||
version.cpp
|
||||
)
|
||||
+158
@@ -0,0 +1,158 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Marko Zivanovic
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
#include "version.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace {
|
||||
enum class Parser_phase {
|
||||
major, minor, patch, release, build
|
||||
};
|
||||
|
||||
using Phase_transition_hook = function<void(const string&)>;
|
||||
using Transition = tuple<const char, Parser_phase, Phase_transition_hook>;
|
||||
using Validator = function<void(const string&, const char)>;
|
||||
|
||||
inline Transition mkx(const char c, Parser_phase p, Phase_transition_hook px) {
|
||||
return make_tuple(c, p, px);
|
||||
}
|
||||
|
||||
inline void process_char(const char c, Parser_phase& phase, const vector<Transition> transitions,
|
||||
string& target, Validator validate) {
|
||||
for (const auto& t : transitions) {
|
||||
if (c == get<0>(t)) {
|
||||
phase = get<1>(t);
|
||||
if (get<2>(t)) get<2>(t)(target);
|
||||
return;
|
||||
}
|
||||
}
|
||||
validate(target, c);
|
||||
target.push_back(c);
|
||||
}
|
||||
|
||||
auto normal_version_validator = [](const string& tgt, const char c) {
|
||||
if (c < '0' || c > '9') throw version::Parse_error("invalid character encountered: " + string(1, c));
|
||||
if (tgt.compare(0, 1, "0") == 0) throw version::Parse_error("leading 0 not allowed");
|
||||
};
|
||||
|
||||
auto release_version_validator = [](const string& tgt, const char c) {
|
||||
if ((c < '0' || c > '9') && (c < 'A' || c > 'Z') && (c < 'a' || c > 'z') && c != '.' && c != '-')
|
||||
throw version::Parse_error("invalid character encountered: " + string(1, c));
|
||||
};
|
||||
|
||||
void validate_release_identifier(const string& id) {
|
||||
if (id.find_first_not_of("0123456789") == string::npos
|
||||
&& id.compare(0, 1, "0") == 0) {
|
||||
throw version::Parse_error("leading 0 not allowed");
|
||||
}
|
||||
}
|
||||
|
||||
void validate_release_identifiers(const string& release) {
|
||||
string id;
|
||||
for (const auto& c : release) {
|
||||
if (c == '.') {
|
||||
validate_release_identifier(id);
|
||||
id.clear();
|
||||
} else {
|
||||
id.push_back(c);
|
||||
}
|
||||
}
|
||||
validate_release_identifier(id);
|
||||
}
|
||||
}
|
||||
|
||||
namespace version {
|
||||
|
||||
Version_data Semver200_parser::parse(const string& s) {
|
||||
string major;
|
||||
string minor;
|
||||
string patch;
|
||||
string release;
|
||||
string build;
|
||||
|
||||
auto process_release_component = [&](const string& t) {
|
||||
if (t.empty()) throw Parse_error("version identifier cannot be empty");
|
||||
if (t.compare(t.length() - 1, 1, ".") == 0) throw Parse_error("version identifier cannot be empty");
|
||||
release.push_back('.');};
|
||||
|
||||
auto process_build_component = [&](const string& t) {
|
||||
if (t.empty()) throw Parse_error("version identifier cannot be empty");
|
||||
if (t.compare(t.length() - 1, 1, ".") == 0) throw Parse_error("version identifier cannot be empty");
|
||||
build.push_back('.');};
|
||||
|
||||
auto major_xs = {
|
||||
mkx('.', Parser_phase::minor, {})
|
||||
};
|
||||
auto minor_xs = {
|
||||
mkx('.', Parser_phase::patch, {})
|
||||
};
|
||||
auto patch_xs = {
|
||||
mkx('-', Parser_phase::release, {}),
|
||||
mkx('+', Parser_phase::build, {})
|
||||
};
|
||||
auto release_xs = {
|
||||
mkx('.', Parser_phase::release, process_release_component),
|
||||
mkx('+', Parser_phase::build, {})
|
||||
};
|
||||
auto build_xs = {
|
||||
mkx('.', Parser_phase::build, process_build_component)
|
||||
};
|
||||
Parser_phase phase = Parser_phase::major;
|
||||
for (const auto& c : s) {
|
||||
switch (phase) {
|
||||
case Parser_phase::major:
|
||||
process_char(c, phase, major_xs, major, normal_version_validator);
|
||||
break;
|
||||
case Parser_phase::minor:
|
||||
process_char(c, phase, minor_xs, minor, normal_version_validator);
|
||||
break;
|
||||
case Parser_phase::patch:
|
||||
process_char(c, phase, patch_xs, patch, normal_version_validator);
|
||||
break;
|
||||
case Parser_phase::release:
|
||||
process_char(c, phase, release_xs, release, release_version_validator);
|
||||
break;
|
||||
case Parser_phase::build:
|
||||
process_char(c, phase, build_xs, build, release_version_validator);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
validate_release_identifiers(release);
|
||||
|
||||
try {
|
||||
return Version_data{ stoi(major), stoi(minor), stoi(patch), release, build };
|
||||
} catch (invalid_argument& ex) {
|
||||
throw Parse_error(ex.what());
|
||||
}
|
||||
}
|
||||
|
||||
int Semver200_comparator::compare(const Version_data& l, const Version_data& r) {
|
||||
throw 1;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
set(Boost_USE_STATIC_LIBS ON)
|
||||
set(Boost_USE_MULTITHREADED ON)
|
||||
|
||||
find_package(Boost COMPONENTS unit_test_framework)
|
||||
#find_package(Threads)
|
||||
|
||||
include_directories(../include)
|
||||
|
||||
include_directories(
|
||||
${Boost_INCLUDE_DIRS}
|
||||
)
|
||||
|
||||
add_executable(semver200_parser_tests semver200_parser_tests.cpp)
|
||||
target_link_libraries(semver200_parser_tests
|
||||
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
|
||||
semver
|
||||
)
|
||||
|
||||
add_executable(semver200_comparator_tests semver200_comparator_tests.cpp)
|
||||
target_link_libraries(semver200_comparator_tests
|
||||
${Boost_UNIT_TEST_FRAMEWORK_LIBRARY}
|
||||
semver
|
||||
)
|
||||
@@ -0,0 +1,127 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Marko Zivanovic
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE semver200_comparator_tests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "version.h"
|
||||
|
||||
using namespace version;
|
||||
|
||||
int compare(const std::string& l, const std::string& r) {
|
||||
Semver200_comparator c;
|
||||
Semver200_parser p;
|
||||
auto lv = p.parse(l);
|
||||
auto rv = p.parse(r);
|
||||
return c.compare(lv, rv);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_eq) {
|
||||
BOOST_CHECK(compare("0.0.0", "0.0.0") == 0);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_major_gt_1) {
|
||||
BOOST_CHECK(compare("1.0.0", "0.0.0") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_major_gt_2) {
|
||||
BOOST_CHECK(compare("1.0.0", "0.0.5") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_major_gt_3) {
|
||||
BOOST_CHECK(compare("1.0.0", "0.17.0") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_minor_gt_1) {
|
||||
BOOST_CHECK(compare("1.1.0", "1.0.0") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_minor_gt_2) {
|
||||
BOOST_CHECK(compare("1.1.0", "1.0.32") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_patch_gt) {
|
||||
BOOST_CHECK(compare("1.1.3", "1.1.0") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_major_lt_1) {
|
||||
BOOST_CHECK(compare("1.0.0", "2.0.0") == -1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_major_lt_2) {
|
||||
BOOST_CHECK(compare("1.0.1", "2.0.0") == -1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_major_lt_3) {
|
||||
BOOST_CHECK(compare("1.3.0", "2.0.0") == -1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_minor_lt_1) {
|
||||
BOOST_CHECK(compare("1.1.0", "1.2.0") == -1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_minor_lt_2) {
|
||||
BOOST_CHECK(compare("1.1.3", "1.2.0") == -1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_normal_patch_lt) {
|
||||
BOOST_CHECK(compare("1.1.3", "1.1.5") == -1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_prerel_single_eq) {
|
||||
BOOST_CHECK(compare("1.1.3-prerel", "1.1.3-prerel") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_prerel_multiple_eq) {
|
||||
BOOST_CHECK(compare("1.1.3-prerel.1.2.3", "1.1.3-prerel.1.2.3") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_prerel_multiple_num_eq) {
|
||||
BOOST_CHECK(compare("1.1.3-prerel.123", "1.1.3-prerel.123") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_prerel_multiple_num_gt) {
|
||||
BOOST_CHECK(compare("1.1.3-prerel.123", "1.1.3-prerel.120") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_prerel_multiple_num_lt) {
|
||||
BOOST_CHECK(compare("1.1.3-prerel.123", "1.1.3-prerel.125") == -1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_prerel_single_alpha_gt) {
|
||||
BOOST_CHECK(compare("1.1.3-alpha", "1.1.3-beta") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_prerel_single_alpha_lt) {
|
||||
BOOST_CHECK(compare("1.1.3-beta", "1.1.3-gamma") == -1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_prerel_single_alpha_gt_2) {
|
||||
BOOST_CHECK(compare("1.1.3-alpha5", "1.1.3-alpha4") == 1);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(compare_prerel_single_alpha_lt_2) {
|
||||
BOOST_CHECK(compare("1.1.3-beta3", "1.1.3-beta5") == -1);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,257 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Marko Zivanovic
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE semver200_parser_tests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "version.h"
|
||||
|
||||
using namespace version;
|
||||
|
||||
Version_data parse(const std::string& s) {
|
||||
Semver200_parser p;
|
||||
return p.parse(s);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal) {
|
||||
auto r = parse("1.0.0");
|
||||
BOOST_CHECK_EQUAL(r.major, 1);
|
||||
BOOST_CHECK_EQUAL(r.minor, 0);
|
||||
BOOST_CHECK_EQUAL(r.patch, 0);
|
||||
BOOST_CHECK_EQUAL(r.release, "");
|
||||
BOOST_CHECK_EQUAL(r.build, "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_bad_format_1) {
|
||||
BOOST_CHECK_THROW(parse("bad.version"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_bad_format_2) {
|
||||
BOOST_CHECK_THROW(parse("1.2.3.4"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_single) {
|
||||
auto r = parse("1.0.0-prerelease");
|
||||
BOOST_CHECK_EQUAL(r.major, 1);
|
||||
BOOST_CHECK_EQUAL(r.minor, 0);
|
||||
BOOST_CHECK_EQUAL(r.patch, 0);
|
||||
BOOST_CHECK_EQUAL(r.release, "prerelease");
|
||||
BOOST_CHECK_EQUAL(r.build, "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_ok_multiple_1) {
|
||||
auto r = parse("1.0.0-prerelease.rel-1");
|
||||
BOOST_CHECK_EQUAL(r.major, 1);
|
||||
BOOST_CHECK_EQUAL(r.minor, 0);
|
||||
BOOST_CHECK_EQUAL(r.patch, 0);
|
||||
BOOST_CHECK_EQUAL(r.release, "prerelease.rel-1");
|
||||
BOOST_CHECK_EQUAL(r.build, "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_ok_multiple_2) {
|
||||
auto r = parse("1.0.0-prerelease.rel-1.b.c.f");
|
||||
BOOST_CHECK_EQUAL(r.major, 1);
|
||||
BOOST_CHECK_EQUAL(r.minor, 0);
|
||||
BOOST_CHECK_EQUAL(r.patch, 0);
|
||||
BOOST_CHECK_EQUAL(r.release, "prerelease.rel-1.b.c.f");
|
||||
BOOST_CHECK_EQUAL(r.build, "");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_build_single) {
|
||||
auto r = parse("1.0.0+test");
|
||||
BOOST_CHECK_EQUAL(r.major, 1);
|
||||
BOOST_CHECK_EQUAL(r.minor, 0);
|
||||
BOOST_CHECK_EQUAL(r.patch, 0);
|
||||
BOOST_CHECK_EQUAL(r.release, "");
|
||||
BOOST_CHECK_EQUAL(r.build, "test");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_build_multiple) {
|
||||
auto r = parse("1.0.0+test.123.4.5");
|
||||
BOOST_CHECK_EQUAL(r.major, 1);
|
||||
BOOST_CHECK_EQUAL(r.minor, 0);
|
||||
BOOST_CHECK_EQUAL(r.patch, 0);
|
||||
BOOST_CHECK_EQUAL(r.release, "");
|
||||
BOOST_CHECK_EQUAL(r.build, "test.123.4.5");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_prerel_single_build_single) {
|
||||
auto r = parse("1.0.0-prerel+test");
|
||||
BOOST_CHECK_EQUAL(r.major, 1);
|
||||
BOOST_CHECK_EQUAL(r.minor, 0);
|
||||
BOOST_CHECK_EQUAL(r.patch, 0);
|
||||
BOOST_CHECK_EQUAL(r.release, "prerel");
|
||||
BOOST_CHECK_EQUAL(r.build, "test");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_prerel_single_build_multiple) {
|
||||
auto r = parse("1.0.0-prerel+test.1.2.3");
|
||||
BOOST_CHECK_EQUAL(r.major, 1);
|
||||
BOOST_CHECK_EQUAL(r.minor, 0);
|
||||
BOOST_CHECK_EQUAL(r.patch, 0);
|
||||
BOOST_CHECK_EQUAL(r.release, "prerel");
|
||||
BOOST_CHECK_EQUAL(r.build, "test.1.2.3");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_prerel_multiple_build_single) {
|
||||
auto r = parse("1.0.0-prerel.1.2.3+test");
|
||||
BOOST_CHECK_EQUAL(r.major, 1);
|
||||
BOOST_CHECK_EQUAL(r.minor, 0);
|
||||
BOOST_CHECK_EQUAL(r.patch, 0);
|
||||
BOOST_CHECK_EQUAL(r.release, "prerel.1.2.3");
|
||||
BOOST_CHECK_EQUAL(r.build, "test");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_prerel_multiple_build_multiple) {
|
||||
auto r = parse("1.0.0-prerel.1.2.3+test.1.2.3");
|
||||
BOOST_CHECK_EQUAL(r.major, 1);
|
||||
BOOST_CHECK_EQUAL(r.minor, 0);
|
||||
BOOST_CHECK_EQUAL(r.patch, 0);
|
||||
BOOST_CHECK_EQUAL(r.release, "prerel.1.2.3");
|
||||
BOOST_CHECK_EQUAL(r.build, "test.1.2.3");
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_all_empty) {
|
||||
BOOST_CHECK_THROW(parse(".."), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_major_empty) {
|
||||
BOOST_CHECK_THROW(parse(".0.0"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_minor_empty) {
|
||||
BOOST_CHECK_THROW(parse("1..0"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_patch_empty) {
|
||||
BOOST_CHECK_THROW(parse("1.1."), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_major_with_letters) {
|
||||
BOOST_CHECK_THROW(parse("1a.0.0"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_minor_with_letters) {
|
||||
BOOST_CHECK_THROW(parse("1.0a.0"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_patch_with_letters) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0a"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_major_leading_0) {
|
||||
BOOST_CHECK_THROW(parse("01.0.0"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_minor_leading_0) {
|
||||
BOOST_CHECK_THROW(parse("1.00.0"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_patch_leading_0) {
|
||||
BOOST_CHECK_THROW(parse("1.0.00"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_major_negative) {
|
||||
BOOST_CHECK_THROW(parse("-1.0.0"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_minor_negative) {
|
||||
BOOST_CHECK_THROW(parse("1.-1.0"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_normal_patch_negative) {
|
||||
BOOST_CHECK_THROW(parse("1.0.-1"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_multiple) {
|
||||
BOOST_CHECK_NO_THROW(parse("1.0.0-pre-rel.123.test.deadbeef.31415"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_invalid_chars) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0-prerelease#1"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_empty_id) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0-prerel..test"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_num_with_leading_0) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0-prerel.01"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_build_single_id) {
|
||||
BOOST_CHECK_NO_THROW(parse("1.0.0+build"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_build_multiple_id) {
|
||||
BOOST_CHECK_NO_THROW(parse("1.0.0+build.123.test.deadbeef.31415"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_build_invalid_chars) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0+build#1"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_build_empty_id) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0+build..test"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_single_build_single) {
|
||||
BOOST_CHECK_NO_THROW(parse("1.0.0-prerelease+build"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_multiple_build_single) {
|
||||
BOOST_CHECK_NO_THROW(parse("1.0.0-pre-rel.123.test.deadbeef.31415+build"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_invalid_chars_build_single) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0-prerelease#1+build"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_empty_id_build_single) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0-prerel..test+build"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_num_with_leading_0_build_single) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0-prerel.01+build"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_single_build_multiple) {
|
||||
BOOST_CHECK_NO_THROW(parse("1.0.0-prerelease+build.1.2.3"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_multiple_build_multiple) {
|
||||
BOOST_CHECK_NO_THROW(parse("1.0.0-pre-rel.123.test.deadbeef.31415+build.1.2.3"));
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_invalid_chars_build_multiple) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0-prerelease#1+build.1.2.3"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_empty_id_build_multiple) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0-prerel..test+build.1.2.3"), Parse_error);
|
||||
}
|
||||
|
||||
BOOST_AUTO_TEST_CASE(parse_prerel_num_with_leading_0_build_multiple) {
|
||||
BOOST_CHECK_THROW(parse("1.0.0-prerel.01+build.1.2.3"), Parse_error);
|
||||
}
|
||||
@@ -0,0 +1,31 @@
|
||||
/*
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2015 Marko Zivanovic
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
in the Software without restriction, including without limitation the rights
|
||||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||
copies of the Software, and to permit persons to whom the Software is
|
||||
furnished to do so, subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||
SOFTWARE.
|
||||
*/
|
||||
|
||||
#define BOOST_TEST_MODULE semver200_validator_tests
|
||||
|
||||
#include <boost/test/unit_test.hpp>
|
||||
#include "version.h"
|
||||
|
||||
using namespace version;
|
||||
|
||||
Reference in New Issue
Block a user