mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-11-05 17:43:23 -08:00
[Fonts] Retire max font size setting into theme CardText min/max range
This commit is contained in:
parent
90665e6e8b
commit
748f9fb40d
19 changed files with 486 additions and 53 deletions
|
|
@ -10,6 +10,7 @@
|
|||
#include <QTemporaryDir>
|
||||
#include <QTextStream>
|
||||
#include <gtest/gtest.h>
|
||||
#include <string>
|
||||
|
||||
namespace
|
||||
{
|
||||
|
|
@ -186,6 +187,76 @@ TEST(FontConfigTest, InequalityComparesRoles)
|
|||
EXPECT_NE(left, right);
|
||||
}
|
||||
|
||||
TEST(FontConfigTest, CardTextMinRoundTrip)
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
ASSERT_TRUE(tmp.isValid());
|
||||
|
||||
FontConfig cfg;
|
||||
cfg.fonts[AppFont::CardText] = makeFont("Noto Serif", 14);
|
||||
cfg.cardTextMinSize = 3;
|
||||
ASSERT_TRUE(cfg.hasFonts());
|
||||
|
||||
const QString filePath = writeTempFile(tmp, "fonts.toml", cfg.toToml());
|
||||
const FontConfig loaded = FontConfig::fromFile(filePath);
|
||||
|
||||
EXPECT_EQ(loaded, cfg);
|
||||
EXPECT_EQ(loaded.fonts[AppFont::CardText].pointSize(), 14);
|
||||
EXPECT_EQ(loaded.cardTextMinSize, 3);
|
||||
}
|
||||
|
||||
TEST(FontConfigTest, CardTextMinDefaultIsOmitted)
|
||||
{
|
||||
FontConfig cfg;
|
||||
cfg.fonts[AppFont::CardText] = makeFont("Noto Serif", 12);
|
||||
EXPECT_EQ(cfg.cardTextMinSize, 1);
|
||||
|
||||
const QString toml = cfg.toToml();
|
||||
EXPECT_TRUE(toml.contains(QStringLiteral("CardText")));
|
||||
EXPECT_FALSE(toml.contains(QStringLiteral("CardTextMinSize")));
|
||||
|
||||
QTemporaryDir tmp;
|
||||
ASSERT_TRUE(tmp.isValid());
|
||||
const QString filePath = writeTempFile(tmp, "fonts.toml", toml);
|
||||
EXPECT_EQ(FontConfig::fromFile(filePath).cardTextMinSize, 1);
|
||||
}
|
||||
|
||||
TEST(FontConfigTest, MalformedMinIsSkipped)
|
||||
{
|
||||
QTemporaryDir tmp;
|
||||
ASSERT_TRUE(tmp.isValid());
|
||||
|
||||
const QString filePath = writeTempFile(tmp, "fonts.toml",
|
||||
"[Fonts]\n"
|
||||
"CardText = \"Noto Serif, 14\"\n"
|
||||
"CardTextMinSize = big\n");
|
||||
|
||||
// Each malformed value parses independently, so rewrite the file per case.
|
||||
const QStringList badValues = {"big", "0", "-3", "", "Inter, 10"};
|
||||
for (const QString &bad : badValues) {
|
||||
const QString badPath = writeTempFile(
|
||||
tmp, "bad.toml", QString("[Fonts]\nCardText = \"Noto Serif, 14\"\nCardTextMinSize = %1\n").arg(bad));
|
||||
const FontConfig loaded = FontConfig::fromFile(badPath);
|
||||
EXPECT_EQ(loaded.cardTextMinSize, 1) << "bad value: " << bad.toStdString();
|
||||
ASSERT_TRUE(loaded.fonts.contains(AppFont::CardText));
|
||||
EXPECT_EQ(loaded.fonts[AppFont::CardText].pointSize(), 14);
|
||||
}
|
||||
|
||||
// The valid file still loads.
|
||||
EXPECT_EQ(FontConfig::fromFile(filePath).cardTextMinSize, 1);
|
||||
}
|
||||
|
||||
TEST(FontConfigTest, InequalityComparesMinSize)
|
||||
{
|
||||
FontConfig left;
|
||||
left.fonts[AppFont::CardText] = makeFont("Noto Serif", 12);
|
||||
left.cardTextMinSize = 1;
|
||||
|
||||
FontConfig right = left;
|
||||
right.cardTextMinSize = 2;
|
||||
EXPECT_NE(left, right);
|
||||
}
|
||||
|
||||
// Every test brings its own main(): GTest is not guaranteed to be found on the build machines, and
|
||||
// the fallback then links the bare gtest library without gtest_main.
|
||||
int main(int argc, char **argv)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue