Commit is being made to allow additions of GPL3+ code previously un-addable. With these changes, contributions back to cuberite are possible with the backporting exemtion, as well as adding stuff in minetest with minetest code properly being read through and implimented to upgrade it to GPL3 from GPL2. project still has Apache2.0 license and credits to all its contributers, but now has the freedom of GPL3+ and all the code that can be implimented and shared with it.
151 lines
3.9 KiB
C++
151 lines
3.9 KiB
C++
|
|
/*
|
|
* Copyright 2011-2022 Cuberite Contributors
|
|
*
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
* you may not use this file except in compliance with the License.
|
|
* You may obtain a copy of the License at
|
|
*
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
*
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
* See the License for the specific language governing permissions and
|
|
* limitations under the License.
|
|
*/
|
|
|
|
// CompositeChatTest.cpp
|
|
|
|
// Implements the main app entrypoint for the cCompositeChat class test
|
|
|
|
#include "Globals.h"
|
|
#include "../TestHelpers.h"
|
|
#include "CompositeChat.h"
|
|
|
|
|
|
|
|
|
|
|
|
static void TestParser1(void)
|
|
{
|
|
cCompositeChat Msg;
|
|
Msg.ParseText("Testing &2color codes and http://links parser");
|
|
const auto & Parts = Msg.GetParts();
|
|
TEST_EQUAL(Parts.size(), 4);
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
|
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "");
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[1]));
|
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[1]).Style, "2");
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[2]));
|
|
TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[2]).Style, "2");
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[3]));
|
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[3]).Style, "2");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void TestParser2(void)
|
|
{
|
|
cCompositeChat Msg;
|
|
Msg.ParseText("&3Advanced stuff: &5overriding color codes and http://links.with/&4color-in-them handling");
|
|
const auto & Parts = Msg.GetParts();
|
|
TEST_EQUAL(Parts.size(), 4);
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
|
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "3");
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[1]));
|
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[1]).Style, "35");
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[2]));
|
|
TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[2]).Style, "35");
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[3]));
|
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[3]).Style, "35");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void TestParser3(void)
|
|
{
|
|
cCompositeChat Msg;
|
|
Msg.ParseText("http://links.starting the text");
|
|
const auto & Parts = Msg.GetParts();
|
|
TEST_EQUAL(Parts.size(), 2);
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[0]));
|
|
TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[0]).Style, "");
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[1]));
|
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[1]).Style, "");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void TestParser4(void)
|
|
{
|
|
cCompositeChat Msg;
|
|
Msg.ParseText("links finishing the text: http://some.server");
|
|
const auto & Parts = Msg.GetParts();
|
|
TEST_EQUAL(Parts.size(), 2);
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
|
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "");
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[1]));
|
|
TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[1]).Style, "");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
static void TestParser5(void)
|
|
{
|
|
cCompositeChat Msg;
|
|
Msg.ParseText("http://only.links");
|
|
const auto & Parts = Msg.GetParts();
|
|
TEST_EQUAL(Parts.size(), 1);
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::UrlPart>(Parts[0]));
|
|
TEST_EQUAL(std::get<cCompositeChat::UrlPart>(Parts[0]).Style, "");
|
|
}
|
|
|
|
|
|
|
|
|
|
static void TestParser6(void)
|
|
{
|
|
cCompositeChat Msg;
|
|
Msg.ParseText("Hello World");
|
|
const auto & Parts = Msg.GetParts();
|
|
TEST_EQUAL(Parts.size(), 1);
|
|
|
|
TEST_TRUE(std::holds_alternative<cCompositeChat::TextPart>(Parts[0]));
|
|
TEST_EQUAL(std::get<cCompositeChat::TextPart>(Parts[0]).Style, "");
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
IMPLEMENT_TEST_MAIN("CompositeChat",
|
|
TestParser1();
|
|
TestParser2();
|
|
TestParser3();
|
|
TestParser4();
|
|
TestParser5();
|
|
TestParser6();
|
|
)
|