added tests, fixed issues with overriding/format
In the documentation it states that child values can override the parent values. Originally this code did not support that but now it does. Also added in testing inspired by the previous tests. Signed-off-by: cullvox <cullvox@outlook.com>
This commit is contained in:
@ -56,3 +56,6 @@ ecm_add_test(Index_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}:
|
||||
|
||||
ecm_add_test(Version_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||
TEST_NAME Version)
|
||||
|
||||
ecm_add_test(MetaComponentParse_test.cpp LINK_LIBRARIES Launcher_logic Qt${QT_VERSION_MAJOR}::Test
|
||||
TEST_NAME MetaComponentParse)
|
108
tests/MetaComponentParse_test.cpp
Normal file
108
tests/MetaComponentParse_test.cpp
Normal file
@ -0,0 +1,108 @@
|
||||
// SPDX-License-Identifier: GPL-3.0-only
|
||||
/*
|
||||
* Prism Launcher - Minecraft Launcher
|
||||
* Copyright (C) 2022 Sefa Eyeoglu <contact@scrumplex.net>
|
||||
*
|
||||
* 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, version 3.
|
||||
*
|
||||
* 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/>.
|
||||
*
|
||||
* This file incorporates work covered by the following copyright and
|
||||
* permission notice:
|
||||
*
|
||||
* Copyright 2013-2021 MultiMC 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.
|
||||
*/
|
||||
|
||||
#include <QTest>
|
||||
#include <QTimer>
|
||||
#include <QJsonDocument>
|
||||
#include <QJsonObject>
|
||||
#include <QJsonValue>
|
||||
|
||||
#include <FileSystem.h>
|
||||
|
||||
#include <minecraft/mod/tasks/LocalResourcePackParseTask.h>
|
||||
|
||||
class MetaComponentParseTest : public QObject {
|
||||
Q_OBJECT
|
||||
|
||||
void doTest(QString name)
|
||||
{
|
||||
QString source = QFINDTESTDATA("testdata/MetaComponentParse");
|
||||
|
||||
QString comp_rp = FS::PathCombine(source, name);
|
||||
|
||||
QFile file;
|
||||
file.setFileName(comp_rp);
|
||||
QVERIFY(file.open(QIODevice::ReadOnly | QIODevice::Text));
|
||||
QString data = file.readAll();
|
||||
file.close();
|
||||
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data.toUtf8());
|
||||
QJsonObject obj = doc.object();
|
||||
|
||||
QJsonValue description_json = obj.value("description");
|
||||
QJsonValue expected_json = obj.value("expected_output");
|
||||
|
||||
QVERIFY(description_json.isUndefined() == false);
|
||||
QVERIFY(expected_json.isString() == true);
|
||||
|
||||
QString expected = expected_json.toString();
|
||||
|
||||
QString processed;
|
||||
bool valid = ResourcePackUtils::processComponent(description_json, processed);
|
||||
|
||||
QVERIFY(processed == expected);
|
||||
QVERIFY(valid == true);
|
||||
}
|
||||
|
||||
private slots:
|
||||
void test_parseComponentBasic()
|
||||
{
|
||||
doTest("component_basic.json");
|
||||
}
|
||||
|
||||
void test_parseComponentWithFormat()
|
||||
{
|
||||
doTest("component_with_format.json");
|
||||
}
|
||||
|
||||
void test_parseComponentWithExtra()
|
||||
{
|
||||
doTest("component_with_extra.json");
|
||||
}
|
||||
|
||||
void test_parseComponentWithLink()
|
||||
{
|
||||
doTest("component_with_link.json");
|
||||
}
|
||||
|
||||
void test_parseComponentWithMixed()
|
||||
{
|
||||
doTest("component_with_mixed.json");
|
||||
}
|
||||
};
|
||||
|
||||
QTEST_GUILESS_MAIN(MetaComponentParseTest)
|
||||
|
||||
#include "MetaComponentParse_test.moc"
|
4
tests/testdata/MetaComponentParse/component_basic.json
vendored
Normal file
4
tests/testdata/MetaComponentParse/component_basic.json
vendored
Normal file
@ -0,0 +1,4 @@
|
||||
{
|
||||
"description": [{"text": "Hello, Component!"}],
|
||||
"expected_output": "Hello, Component!"
|
||||
}
|
18
tests/testdata/MetaComponentParse/component_with_extra.json
vendored
Normal file
18
tests/testdata/MetaComponentParse/component_with_extra.json
vendored
Normal file
@ -0,0 +1,18 @@
|
||||
{
|
||||
"description": [
|
||||
{
|
||||
"text": "Hello, ",
|
||||
"color": "red",
|
||||
"bold": true,
|
||||
"italic": true,
|
||||
"extra": [
|
||||
{
|
||||
"extra": "Component!",
|
||||
"bold": false,
|
||||
"italic": false
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"expected_output": "<font color=\"red\"><b><i>Hello, </i></b></font><font color=\"red\">Component!</font>"
|
||||
}
|
13
tests/testdata/MetaComponentParse/component_with_format.json
vendored
Normal file
13
tests/testdata/MetaComponentParse/component_with_format.json
vendored
Normal file
@ -0,0 +1,13 @@
|
||||
{
|
||||
"description": [
|
||||
{
|
||||
"text": "Hello, Component!",
|
||||
"color": "blue",
|
||||
"bold": true,
|
||||
"italic": true,
|
||||
"underlined": true,
|
||||
"strikethrough": true
|
||||
}
|
||||
],
|
||||
"expected_output": "<font color=\"blue\"><b><i><u><s>Hello, Component!</s></u></i></b></font>"
|
||||
}
|
12
tests/testdata/MetaComponentParse/component_with_link.json
vendored
Normal file
12
tests/testdata/MetaComponentParse/component_with_link.json
vendored
Normal file
@ -0,0 +1,12 @@
|
||||
{
|
||||
"description": [
|
||||
{
|
||||
"text": "Hello, Component!",
|
||||
"clickEvent": {
|
||||
"open_url": true,
|
||||
"value": "https://google.com"
|
||||
}
|
||||
}
|
||||
],
|
||||
"expected_output": "<a href=\"https://google.com\">Hello, Component!</a>"
|
||||
}
|
40
tests/testdata/MetaComponentParse/component_with_mixed.json
vendored
Normal file
40
tests/testdata/MetaComponentParse/component_with_mixed.json
vendored
Normal file
@ -0,0 +1,40 @@
|
||||
{
|
||||
"description": [
|
||||
{
|
||||
"text": "The quick ",
|
||||
"color": "blue",
|
||||
"italic": true
|
||||
},
|
||||
{
|
||||
"text": "brown fox ",
|
||||
"color": "#873600",
|
||||
"bold": true,
|
||||
"underlined": true,
|
||||
"extra": {
|
||||
"text": "jumped over ",
|
||||
"color": "blue",
|
||||
"bold": false,
|
||||
"underlined": false,
|
||||
"italic": true,
|
||||
"strikethrough": true
|
||||
}
|
||||
},
|
||||
{
|
||||
"text": "the lazy dog's back. ",
|
||||
"color": "green",
|
||||
"bold": true,
|
||||
"italic": true,
|
||||
"underlined": true,
|
||||
"strikethrough": true,
|
||||
"extra": [
|
||||
{
|
||||
"text": "1234567890 ",
|
||||
"color": "black",
|
||||
"strikethrough": false,
|
||||
"extra": "How vexingly quick daft zebras jump!"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"expected_output": "<font color=\"blue\"><i>The quick </i></font><font color=\"#873600\"><b><u>brown fox </u></b></font><font color=\"blue\"><i><s>jumped over </s></i></font><font color=\"green\"><b><i><u><s>the lazy dog's back. </s></u></i></b></font><font color=\"black\"><b><i><u>1234567890 </u></i></b></font><font color=\"black\"><b><i><u>How vexingly quick daft zebras jump!</u></i></b></font>"
|
||||
}
|
Reference in New Issue
Block a user