Skip to content

Commit a80316d

Browse files
1 more test
1 parent 9703815 commit a80316d

File tree

1 file changed

+58
-0
lines changed

1 file changed

+58
-0
lines changed

src/cascadia/UnitTests_SettingsModel/SerializationTests.cpp

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,12 @@ using namespace winrt::Microsoft::Terminal::Control;
2424
#define SEND_INPUT_ARCH_SPECIFIC_ACTION_HASH "A020D2"
2525
#endif
2626

27+
#if defined(_M_IX86)
28+
#define SEND_INPUT2_ARCH_SPECIFIC_ACTION_HASH "56911147"
29+
#else
30+
#define SEND_INPUT2_ARCH_SPECIFIC_ACTION_HASH "58D1971"
31+
#endif
32+
2733
namespace SettingsModelUnitTests
2834
{
2935
class SerializationTests : public JsonTestClass
@@ -49,6 +55,7 @@ namespace SettingsModelUnitTests
4955
TEST_METHOD(GeneratedActionIDsEqualForIdenticalCommands);
5056
TEST_METHOD(RoundtripLegacyToModernActions);
5157
TEST_METHOD(RoundtripUserActionsSameAsInBoxAreRemoved);
58+
TEST_METHOD(RoundtripActionsSameNameDifferentCommandsAreRetained);
5259
TEST_METHOD(MultipleActionsAreCollapsed);
5360

5461
private:
@@ -1180,6 +1187,57 @@ namespace SettingsModelUnitTests
11801187
VERIFY_ARE_EQUAL(toString(newResult), toString(oldResult));
11811188
}
11821189

1190+
void SerializationTests::RoundtripActionsSameNameDifferentCommandsAreRetained()
1191+
{
1192+
static constexpr std::string_view oldSettingsJson{ R"(
1193+
{
1194+
"actions": [
1195+
{
1196+
"command": { "action": "sendInput", "input": "just some input" },
1197+
"name": "mySendInput"
1198+
},
1199+
{
1200+
"command": { "action": "sendInput", "input": "just some input 2" },
1201+
"name": "mySendInput"
1202+
}
1203+
]
1204+
})" };
1205+
1206+
// There are two different actions with the same name,
1207+
// ensure that both are kept but have different IDs generated for them
1208+
static constexpr std::string_view newSettingsJson{ R"(
1209+
{
1210+
"actions": [
1211+
{
1212+
"name": "mySendInput",
1213+
"command": { "action": "sendInput", "input": "just some input" },
1214+
"id": "User.sendInput.)" SEND_INPUT_ARCH_SPECIFIC_ACTION_HASH R"("
1215+
},
1216+
{
1217+
"name": "mySendInput",
1218+
"command": { "action": "sendInput", "input": "just some input 2" },
1219+
"id": "User.sendInput.)" SEND_INPUT2_ARCH_SPECIFIC_ACTION_HASH R"("
1220+
}
1221+
]
1222+
})" };
1223+
1224+
implementation::SettingsLoader loader{ oldSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
1225+
loader.MergeInboxIntoUserSettings();
1226+
loader.FinalizeLayering();
1227+
VERIFY_IS_TRUE(loader.FixupUserSettings(), L"Validate that this will indicate we need to write them back to disk");
1228+
const auto settings = winrt::make_self<implementation::CascadiaSettings>(std::move(loader));
1229+
const auto oldResult{ settings->ToJson() };
1230+
1231+
implementation::SettingsLoader newLoader{ newSettingsJson, implementation::LoadStringResource(IDR_DEFAULTS) };
1232+
newLoader.MergeInboxIntoUserSettings();
1233+
newLoader.FinalizeLayering();
1234+
VERIFY_IS_FALSE(newLoader.FixupUserSettings(), L"Validate that there is no need to write back to disk");
1235+
const auto newSettings = winrt::make_self<implementation::CascadiaSettings>(std::move(newLoader));
1236+
const auto newResult{ newSettings->ToJson() };
1237+
1238+
VERIFY_ARE_EQUAL(toString(newResult), toString(oldResult));
1239+
}
1240+
11831241
void SerializationTests::MultipleActionsAreCollapsed()
11841242
{
11851243
static constexpr std::string_view oldSettingsJson{ R"(

0 commit comments

Comments
 (0)