Skip to content

Commit

Permalink
fixed limit
Browse files Browse the repository at this point in the history
reverted the fix for this comment musescore#25782 (review)
  • Loading branch information
Eism committed Dec 11, 2024
1 parent 2c7851c commit 634587d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
15 changes: 8 additions & 7 deletions src/framework/uicomponents/tests/doubleinputvalidator_tests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,6 @@ class DoubleInputValidatorTests : public ::testing::Test, public QObject
void SetUp() override
{
m_validator = new DoubleInputValidator(nullptr);
m_validator->setTop(100.0);
m_validator->setBottom(-100.0);
m_validator->setDecimal(2);
}

void TearDown() override
Expand All @@ -55,7 +52,11 @@ TEST_F(DoubleInputValidatorTests, Validate) {
QString fixedStr;
};

std::vector<Input> validInputs = {
m_validator->setTop(100.0);
m_validator->setBottom(-100.0);
m_validator->setDecimal(2);

std::vector<Input> inputs = {
{ "-0.1", QValidator::Acceptable },
{ "0", QValidator::Acceptable },
{ "1.23", QValidator::Acceptable },
Expand All @@ -68,12 +69,12 @@ TEST_F(DoubleInputValidatorTests, Validate) {
{ "2.", QValidator::Intermediate, "2" },
{ "-100.1", QValidator::Intermediate, "-100" },
{ "100.1", QValidator::Intermediate, "100" },
{ "1.123", QValidator::Intermediate, "1.12" },
{ "abc", QValidator::Invalid, "" }
{ "1.123", QValidator::Invalid }, // more than 2 decimal
{ "abc", QValidator::Invalid }
};

int pos = 0;
for (Input& input : validInputs) {
for (Input& input : inputs) {
EXPECT_EQ(m_validator->validate(input.str, pos), input.expectedState);

if (QValidator::Invalid == input.expectedState) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ QValidator::State DoubleInputValidator::validate(QString& inputStr, int& cursorP
state = Acceptable;
}
} else if (inputStr.contains(QRegularExpression("^\\-?\\d{0,3}\\.?$"))
|| inputStr.contains(QRegularExpression(QString("^\\-?\\d{0,3}\\.\\d{%1,}$").arg(m_decimal)))) {
|| inputStr.contains(QRegularExpression(QString("^\\-?\\d{0,3}\\.\\d{0,%1}$").arg(m_decimal)))) {
state = Intermediate;
} else {
cursorPos = 0;
Expand Down

0 comments on commit 634587d

Please sign in to comment.