<commit_before>//
// Aspia Project
// Copyright (C) 2019 <NAME> <<EMAIL>>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#include "base/version.h"

#include <gtest/gtest.h>

#include <cstddef>
#include <cstdint>
#include <utility>

namespace {

TEST(VersionTest, DefaultConstructor)
{
    base::Version v;
    EXPECT_FALSE(v.isValid());
}

TEST(VersionTest, ValueSemantics)
{
    base::Version v1("1.2.3.4");
    EXPECT_TRUE(v1.isValid());
    base::Version v3;
    EXPECT_FALSE(v3.isValid());
    {
        base::Version v2(v1);
        v3 = v2;
        EXPECT_TRUE(v2.isValid());
        EXPECT_EQ(v1, v2);
    }
    EXPECT_EQ(v3, v1);
}

TEST(VersionTest, MoveSemantics)
{
    const std::vector<uint32_t> components = { 1, 2, 3, 4 };
    base::Version v1(std::move(components));
    EXPECT_TRUE(v1.isValid());
    base::Version v2("1.2.3.4");
    EXPECT_EQ(v1, v2);
}

TEST(VersionTest, GetVersionFromString)
{
    static const struct version_string
    {
        const char* input;
        size_t parts;
        uint32_t firstpart;
        bool success;
    } cases[] =
    {
        { "", 0, 0, false },
        { " ", 0, 0, false },
        { "\t", 0, 0, false },
        { "\n", 0, 0, false },
        { "  ", 0, 0, false },
        { ".", 0, 0, false },
        { " . ", 0, 0, false },
        { "0", 1, 0, true },
        { "0.", 0, 0, false },
        { "0.0", 2, 0, true },
        { "4294967295.0", 2, 4294967295, true },
        { "4294967296.0", 0, 0, false },
        { "-1.0", 0, 0, false },
        { "1.-1.0", 0, 0, false },
        { "1,--1.0", 0, 0, false },
        { "+1.0", 0, 0, false },
        { "1.+1.0", 0, 0, false },
        { "1+1.0", 0, 0, false },
        { "++1.0", 0, 0, false },
        { "1.0a", 0, 0, false },
        { "1.2.3.4.5.6.7.8.9.0", 10, 1, true },
        { "02.1", 0, 0, false },
        { "0.01", 2, 0, true },
        { "f.1", 0, 0, false },
        { "15.007.20011", 3, 15, true },
        { "15.5.28.130162", 4, 15, true },
    };

    int index = 0;

    for (const auto& i : cases)
    {
        printf("case %d\n", index);
        base::Version version(i.input);
        EXPECT_EQ(i.success, version.isValid());
        if (i.success)
        {
            EXPECT_EQ(i.parts, version.components().size());<commit_msg>- Remove unneeded printf.<commit_after>//
// Aspia Project
// Copyright (C) 2019 <NAME> <<EMAIL>>
//
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with this program. If not, see <https://www.gnu.org/licenses/>.
//

#include "base/version.h"

#include <gtest/gtest.h>

#include <cstddef>
#include <cstdint>
#include <utility>

namespace {

TEST(VersionTest, DefaultConstructor)
{
    base::Version v;
    EXPECT_FALSE(v.isValid());
}

TEST(VersionTest, ValueSemantics)
{
    base::Version v1("1.2.3.4");
    EXPECT_TRUE(v1.isValid());
    base::Version v3;
    EXPECT_FALSE(v3.isValid());
    {
        base::Version v2(v1);
        v3 = v2;
        EXPECT_TRUE(v2.isValid());
        EXPECT_EQ(v1, v2);
    }
    EXPECT_EQ(v3, v1);
}

TEST(VersionTest, MoveSemantics)
{
    const std::vector<uint32_t> components = { 1, 2, 3, 4 };
    base::Version v1(std::move(components));
    EXPECT_TRUE(v1.isValid());
    base::Version v2("1.2.3.4");
    EXPECT_EQ(v1, v2);
}

TEST(VersionTest, GetVersionFromString)
{
    static const struct version_string
    {
        const char* input;
        size_t parts;
        uint32_t firstpart;
        bool success;
    } cases[] =
    {
        { "", 0, 0, false },
        { " ", 0, 0, false },
        { "\t", 0, 0, false },
        { "\n", 0, 0, false },
        { "  ", 0, 0, false },
        { ".", 0, 0, false },
        { " . ", 0, 0, false },
        { "0", 1, 0, true },
        { "0.", 0, 0, false },
        { "0.0", 2, 0, true },
        { "4294967295.0", 2, 4294967295, true },
        { "4294967296.0", 0, 0, false },
        { "-1.0", 0, 0, false },
        { "1.-1.0", 0, 0, false },
        { "1,--1.0", 0, 0, false },
        { "+1.0", 0, 0, false },
        { "1.+1.0", 0, 0, false },
        { "1+1.0", 0, 0, false },
        { "++1.0", 0, 0, false },
        { "1.0a", 0, 0, false },
        { "1.2.3.4.5.6.7.8.9.0", 10, 1, true },
        { "02.1", 0, 0, false },
        { "0.01", 2, 0, true },
        { "f.1", 0, 0, false },
        { "15.007.20011", 3, 15, true },
        { "15.5.28.130162", 4, 15, true },
    };

    int index = 0;

    for (const auto& i : cases)
    {
        base::Version version(i.input);
        EXPECT_EQ(i.success, version.isValid());
        if (i.success)
        {
            EXPECT_EQ(i.parts, version.components().size());
{'fraction_non_alphanumeric': 0.17829727843684579, 'fraction_numerical': 0.06559665038381018, 'mean_word_length': 2.1259541984732824, 'pattern_counts': {'":': 0, '<': 21, '<?xml version=': 0, '>': 21, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 10, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5372764', 'n_tokens_mistral': 2226, 'n_tokens_neox': 2039, 'n_words': 579}