|
OpenTTD Source 20260110-master-g14e0917ae4
|
Tests for the Squirrel -> JSON conversion in ScriptAdmin. More...
#include "../stdafx.h"#include "../3rdparty/catch2/catch.hpp"#include "../game/game_instance.hpp"#include "../script/api/script_admin.hpp"#include "../script/api/script_event_types.hpp"#include "../script/script_instance.hpp"#include "../script/squirrel.hpp"#include "../3rdparty/fmt/format.h"#include "../3rdparty/nlohmann/json.hpp"#include <squirrel.h>#include "../safeguards.h"Go to the source code of this file.
Data Structures | |
| class | TestScriptController |
| A controller to start enough so we can use Squirrel for testing. More... | |
Functions | |
| bool | ScriptAdminMakeJSON (nlohmann::json &json, HSQUIRRELVM vm, SQInteger index, int depth=0) |
| static std::optional< std::string > | TestScriptAdminMakeJSON (std::string_view squirrel) |
| Small wrapper around ScriptAdmin's MakeJSON that prepares the Squirrel engine if it was called from actual scripting. | |
| static std::optional< std::string > | TestScriptEventAdminPort (const std::string &json) |
| Validate ScriptEventAdminPort can convert JSON to Squirrel. | |
| TEST_CASE ("Squirrel -> JSON conversion") | |
| TEST_CASE ("JSON -> Squirrel conversion") | |
Tests for the Squirrel -> JSON conversion in ScriptAdmin.
Definition in file test_script_admin.cpp.
| TEST_CASE | ( | "JSON -> Squirrel conversion" | ) |
Definition at line 144 of file test_script_admin.cpp.
| TEST_CASE | ( | "Squirrel -> JSON conversion" | ) |
Definition at line 121 of file test_script_admin.cpp.
|
static |
Small wrapper around ScriptAdmin's MakeJSON that prepares the Squirrel engine if it was called from actual scripting.
Definition at line 52 of file test_script_admin.cpp.
|
static |
Validate ScriptEventAdminPort can convert JSON to Squirrel.
This function is not actually part of ScriptAdmin, but we will use MakeJSON, and as such need to be inside this class.
The easiest way to do validate, is to first use ScriptEventAdminPort (the function we are testing) to convert the JSON to a Squirrel table. Then to use MakeJSON to convert it back to JSON.
Sadly, Squirrel has no way to easily compare if two tables are identical, so we use the JSON -> Squirrel -> JSON method to validate the conversion. But mind you, a failure in the final JSON might also mean a bug in MakeJSON.
| json | The JSON-string to convert to Squirrel |
Definition at line 102 of file test_script_admin.cpp.