Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ Two new properties should be added in the json settings file:

2. Both X value and Y values are optional. If any one of them is missing, or the value is invalid, system default value will be used. Examples:

"1000" equals (1000, 1000)
", 1000" equals (default, 1000)
"1000, " equals (1000, default)
"," equals (default, default)
Expand Down
2 changes: 1 addition & 1 deletion src/cascadia/LocalTests_TerminalApp/SettingsTests.cpp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: undo changes to this file

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I edited the file in GitHub’s web editor — it showed no difference at the time, but now the diff shows up anyways😅

Original file line number Diff line number Diff line change
Expand Up @@ -1619,4 +1619,4 @@ namespace TerminalAppLocalTests
}
}

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,10 @@ Module Name:
// - Helper for converting a pair of comma separated, potentially absent integer values
// into the corresponding left and right values. The leftValue and rightValue functions
// will be called back with the associated parsed integer value, assuming it's present.
// (100, 100): leftValue and rightValue functions both called back with 100.
// (100, 100), (100): leftValue and rightValue functions both called back with 100.
// (100, ), (100, abc): leftValue function called back with 100
// (, 100), (abc, 100): rightValue function called back with 100
// (,): no function called back
// (,), (abc): no function called back
// (100, 100, 100): we only read the first two values, this is equivalent to (100, 100)
// Arguments:
// - string: The string to parse
Expand All @@ -45,6 +45,7 @@ _TIL_INLINEPREFIX void ParseCommaSeparatedPair(const std::string& string,
if (index == 0)
{
leftValue(value);
if (string.find(',') == std::string::npos) {rightValue(value);}
}

if (index == 1)
Expand Down
47 changes: 47 additions & 0 deletions src/cascadia/UnitTests_SettingsModel/TerminalSettingsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
#include <pcg_random.hpp>

#include "../TerminalSettingsModel/CascadiaSettings.h"
#include "../TerminalSettingsModel/ModelSerializationHelpers.h"
#include "TestUtils.h"

using namespace Microsoft::Console;
Expand Down Expand Up @@ -52,6 +53,7 @@ namespace SettingsModelUnitTests
TEST_METHOD(MakeSettingsForDefaultProfileThatDoesntExist);
TEST_METHOD(TestLayerProfileOnColorScheme);
TEST_METHOD(TestCommandlineToTitlePromotion);
TEST_METHOD(TestInitialPositionParsing);
};

// CascadiaSettings::_normalizeCommandLine abuses some aspects from CommandLineToArgvW
Expand Down Expand Up @@ -891,4 +893,49 @@ namespace SettingsModelUnitTests
VERIFY_ARE_EQUAL(L"", settingsStruct.DefaultSettings()->StartingTitle());
}
}
void TerminalSettingsTests::TestInitialPositionParsing()
{
{
const auto pos = LaunchPositionFromString("50");
VERIFY_IS_TRUE(pos.X.Value());
VERIFY_IS_TRUE(pos.Y.Value());
VERIFY_ARE_EQUAL(50, static_cast<int32_t>(pos.X.Value()));
VERIFY_ARE_EQUAL(50, static_cast<int32_t>(pos.Y.Value()));
}

{
const auto pos = LaunchPositionFromString("100,");
VERIFY_IS_TRUE(pos.X.Value());
VERIFY_ARE_EQUAL(100, static_cast<int32_t>(pos.X.Value()));
VERIFY_IS_TRUE(pos.Y == nullptr);
}

{
const auto pos = LaunchPositionFromString(",100");
VERIFY_IS_TRUE(pos.X == nullptr);
VERIFY_IS_TRUE(pos.Y.Value());
VERIFY_ARE_EQUAL(100, static_cast<int32_t>(pos.Y.Value()));
}

{
const auto pos = LaunchPositionFromString("50,50");
VERIFY_IS_TRUE(pos.X.Value());
VERIFY_ARE_EQUAL(50, static_cast<int32_t>(pos.X.Value()));
VERIFY_IS_TRUE(pos.Y.Value());
VERIFY_ARE_EQUAL(50, static_cast<int32_t>(pos.Y.Value()));
}

{
const auto pos = LaunchPositionFromString("abc,100");
VERIFY_IS_TRUE(pos.X == nullptr);
VERIFY_IS_TRUE(pos.Y.Value());
VERIFY_ARE_EQUAL(100, static_cast<int32_t>(pos.Y.Value()));
}

{
const auto pos = LaunchPositionFromString("abc");
VERIFY_IS_TRUE(pos.X == nullptr);
VERIFY_IS_TRUE(pos.Y == nullptr);
}
}
}