Skip to content

Commit

Permalink
fix remaining tests
Browse files Browse the repository at this point in the history
  • Loading branch information
PankajBhojwani committed May 2, 2024
1 parent 2b16acd commit 193e573
Show file tree
Hide file tree
Showing 2 changed files with 71 additions and 62 deletions.
64 changes: 32 additions & 32 deletions src/cascadia/UnitTests_SettingsModel/KeyBindingsTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -271,32 +271,32 @@ namespace SettingsModelUnitTests
auto actionMap = winrt::make_self<implementation::ActionMap>();
VERIFY_IS_FALSE(actionMap->IsKeyChordExplicitlyUnbound(keyChord));

actionMap->LayerJson(bindings0Json, OriginTag::None);
actionMap->LayerJson(bindings0Json, OriginTag::User);
VERIFY_IS_FALSE(actionMap->IsKeyChordExplicitlyUnbound(keyChord));

actionMap->LayerJson(bindings1Json, OriginTag::None);
actionMap->LayerJson(bindings1Json, OriginTag::User);
VERIFY_IS_TRUE(actionMap->IsKeyChordExplicitlyUnbound(keyChord));

actionMap->LayerJson(bindings2Json, OriginTag::None);
actionMap->LayerJson(bindings2Json, OriginTag::User);
VERIFY_IS_FALSE(actionMap->IsKeyChordExplicitlyUnbound(keyChord));
}

void KeyBindingsTests::TestArbitraryArgs()
{
const std::string bindings0String{ R"([
{ "command": "copy", "keys": ["ctrl+c"] },
{ "command": { "action": "copy", "singleLine": false }, "keys": ["ctrl+shift+c"] },
{ "command": { "action": "copy", "singleLine": true }, "keys": ["alt+shift+c"] },
{ "command": "copy", "id": "Test.CopyNoArgs", "keys": ["ctrl+c"] },
{ "command": { "action": "copy", "singleLine": false }, "id": "Test.CopyMultiline", "keys": ["ctrl+shift+c"] },
{ "command": { "action": "copy", "singleLine": true }, "id": "Test.CopySingleline", "keys": ["alt+shift+c"] },
{ "command": "newTab", "keys": ["ctrl+t"] },
{ "command": { "action": "newTab", "index": 0 }, "keys": ["ctrl+shift+t"] },
{ "command": { "action": "newTab", "index": 11 }, "keys": ["ctrl+shift+y"] },
{ "command": "newTab", "id": "Test.NewTabNoArgs", "keys": ["ctrl+t"] },
{ "command": { "action": "newTab", "index": 0 }, "id": "Test.NewTab0", "keys": ["ctrl+shift+t"] },
{ "command": { "action": "newTab", "index": 11 }, "id": "Test.NewTab11", "keys": ["ctrl+shift+y"] },
{ "command": { "action": "copy", "madeUpBool": true }, "keys": ["ctrl+b"] },
{ "command": { "action": "copy" }, "keys": ["ctrl+shift+b"] },
{ "command": { "action": "copy", "madeUpBool": true }, "id": "Test.CopyFakeArgs", "keys": ["ctrl+b"] },
{ "command": { "action": "copy" }, "id": "Test.CopyNullArgs", "keys": ["ctrl+shift+b"] },
{ "command": { "action": "adjustFontSize", "delta": 1 }, "keys": ["ctrl+f"] },
{ "command": { "action": "adjustFontSize", "delta": -1 }, "keys": ["ctrl+g"] }
{ "command": { "action": "adjustFontSize", "delta": 1 }, "id": "Test.EnlargeFont", "keys": ["ctrl+f"] },
{ "command": { "action": "adjustFontSize", "delta": -1 }, "id": "Test.ReduceFont", "keys": ["ctrl+g"] }
])" };

Expand Down Expand Up @@ -428,10 +428,10 @@ namespace SettingsModelUnitTests
void KeyBindingsTests::TestSplitPaneArgs()
{
const std::string bindings0String{ R"([
{ "keys": ["ctrl+d"], "command": { "action": "splitPane", "split": "vertical" } },
{ "keys": ["ctrl+e"], "command": { "action": "splitPane", "split": "horizontal" } },
{ "keys": ["ctrl+g"], "command": { "action": "splitPane" } },
{ "keys": ["ctrl+h"], "command": { "action": "splitPane", "split": "auto" } }
{ "keys": ["ctrl+d"], "id": "Test.SplitPaneVertical", "command": { "action": "splitPane", "split": "vertical" } },
{ "keys": ["ctrl+e"], "id": "Test.SplitPaneHorizontal", "command": { "action": "splitPane", "split": "horizontal" } },
{ "keys": ["ctrl+g"], "id": "Test.SplitPane", "command": { "action": "splitPane" } },
{ "keys": ["ctrl+h"], "id": "Test.SplitPaneAuto", "command": { "action": "splitPane", "split": "auto" } }
])" };

const auto bindings0Json = VerifyParseSucceeded(bindings0String);
Expand Down Expand Up @@ -478,9 +478,9 @@ namespace SettingsModelUnitTests
void KeyBindingsTests::TestSetTabColorArgs()
{
const std::string bindings0String{ R"([
{ "keys": ["ctrl+c"], "command": { "action": "setTabColor", "color": null } },
{ "keys": ["ctrl+d"], "command": { "action": "setTabColor", "color": "#123456" } },
{ "keys": ["ctrl+f"], "command": "setTabColor" },
{ "keys": ["ctrl+c"], "id": "Test.SetTabColorNull", "command": { "action": "setTabColor", "color": null } },
{ "keys": ["ctrl+d"], "id": "Test.SetTabColor", "command": { "action": "setTabColor", "color": "#123456" } },
{ "keys": ["ctrl+f"], "id": "Test.SetTabColorNoArgs", "command": "setTabColor" },
])" };

const auto bindings0Json = VerifyParseSucceeded(bindings0String);
Expand Down Expand Up @@ -521,7 +521,7 @@ namespace SettingsModelUnitTests
void KeyBindingsTests::TestStringOverload()
{
const std::string bindings0String{ R"([
{ "command": "copy", "keys": "ctrl+c" }
{ "command": "copy", "id": "Test.Copy", "keys": "ctrl+c" }
])" };

const auto bindings0Json = VerifyParseSucceeded(bindings0String);
Expand All @@ -543,12 +543,12 @@ namespace SettingsModelUnitTests
void KeyBindingsTests::TestScrollArgs()
{
const std::string bindings0String{ R"([
{ "keys": ["up"], "command": "scrollUp" },
{ "keys": ["down"], "command": "scrollDown" },
{ "keys": ["ctrl+up"], "command": { "action": "scrollUp" } },
{ "keys": ["ctrl+down"], "command": { "action": "scrollDown" } },
{ "keys": ["ctrl+shift+up"], "command": { "action": "scrollUp", "rowsToScroll": 10 } },
{ "keys": ["ctrl+shift+down"], "command": { "action": "scrollDown", "rowsToScroll": 10 } }
{ "keys": ["up"], "id": "Test.ScrollUp0", "command": "scrollUp" },
{ "keys": ["down"], "id": "Test.ScrollDown0", "command": "scrollDown" },
{ "keys": ["ctrl+up"], "id": "Test.ScrollUp1", "command": { "action": "scrollUp" } },
{ "keys": ["ctrl+down"], "id": "Test.ScrollDown1", "command": { "action": "scrollDown" } },
{ "keys": ["ctrl+shift+up"], "id": "Test.ScrollUp2", "command": { "action": "scrollUp", "rowsToScroll": 10 } },
{ "keys": ["ctrl+shift+down"], "id": "Test.ScrollDown2", "command": { "action": "scrollDown", "rowsToScroll": 10 } }
])" };

const auto bindings0Json = VerifyParseSucceeded(bindings0String);
Expand Down Expand Up @@ -620,8 +620,8 @@ namespace SettingsModelUnitTests
void KeyBindingsTests::TestMoveTabArgs()
{
const std::string bindings0String{ R"([
{ "keys": ["up"], "command": { "action": "moveTab", "direction": "forward" } },
{ "keys": ["down"], "command": { "action": "moveTab", "direction": "backward" } }
{ "keys": ["up"], "id": "Test.MoveTabUp", "command": { "action": "moveTab", "direction": "forward" } },
{ "keys": ["down"], "id": "Test.MoveTabDown", "command": { "action": "moveTab", "direction": "backward" } }
])" };

const auto bindings0Json = VerifyParseSucceeded(bindings0String);
Expand Down Expand Up @@ -665,9 +665,9 @@ namespace SettingsModelUnitTests
void KeyBindingsTests::TestToggleCommandPaletteArgs()
{
const std::string bindings0String{ R"([
{ "keys": ["up"], "command": "commandPalette" },
{ "keys": ["ctrl+up"], "command": { "action": "commandPalette", "launchMode" : "action" } },
{ "keys": ["ctrl+shift+up"], "command": { "action": "commandPalette", "launchMode" : "commandLine" } }
{ "keys": ["up"], "id": "Test.CmdPal", "command": "commandPalette" },
{ "keys": ["ctrl+up"], "id": "Test.CmdPalActionMode", "command": { "action": "commandPalette", "launchMode" : "action" } },
{ "keys": ["ctrl+shift+up"], "id": "Test.CmdPalLineMode", "command": { "action": "commandPalette", "launchMode" : "commandLine" } }
])" };

const auto bindings0Json = VerifyParseSucceeded(bindings0String);
Expand Down
69 changes: 39 additions & 30 deletions src/cascadia/UnitTests_SettingsModel/SerializationTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,15 @@ namespace SettingsModelUnitTests
"experimental.input.forceVT": false,
"actions": []
"actions": [],
"keybindings": []
})" };

static constexpr std::string_view smallGlobalsString{ R"(
{
"defaultProfile": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}",
"actions": []
"actions": [],
"keybindings": []
})" };

RoundtripTest<implementation::GlobalAppSettings>(globalsString);
Expand Down Expand Up @@ -275,47 +277,50 @@ namespace SettingsModelUnitTests
{
// simple command
static constexpr std::string_view actionsString1{ R"([
{ "command": "paste" }
{ "command": "paste", "id": "Test.Paste" }
])" };

// complex command
static constexpr std::string_view actionsString2A{ R"([
{ "command": { "action": "setTabColor" } }
{ "command": { "action": "setTabColor" }, "id": "Test.SetTabColor" }
])" };
static constexpr std::string_view actionsString2B{ R"([
{ "command": { "action": "setTabColor", "color": "#112233" } }
{ "command": { "action": "setTabColor", "color": "#112233" }, "id": "Test.SetTabColor112233" }
])" };
static constexpr std::string_view actionsString2C{ R"([
{ "command": { "action": "copy" } },
{ "command": { "action": "copy", "singleLine": true, "copyFormatting": "html" } }
{ "command": { "action": "copy" }, "id": "Test.Copy" },
{ "command": { "action": "copy", "singleLine": true, "copyFormatting": "html" }, "id": "Test.CopyWithArgs" }
])" };

// simple command with key chords
static constexpr std::string_view actionsString3{ R"([
{ "command": "toggleAlwaysOnTop", "keys": "ctrl+a" },
{ "command": "toggleAlwaysOnTop", "keys": "ctrl+b" }
])" };
static constexpr std::string_view actionsString3{ R"({ "actions": [
{ "command": "toggleAlwaysOnTop", "id": "Test.ToggleAlwaysOnTop" } ],
"keybindings": [
{ "keys": "ctrl+a", "id": "Test.ToggleAlwaysOnTop" },
{ "keys": "ctrl+b", "id": "Test.ToggleAlwaysOnTop" } ]})" };

// complex command with key chords
static constexpr std::string_view actionsString4A{ R"([
{ "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+c" },
{ "command": { "action": "adjustFontSize", "delta": 1 }, "keys": "ctrl+d" }
])" };
static constexpr std::string_view actionsString4A{ R"({ "actions":[
{ "command": { "action": "adjustFontSize", "delta": 1 }, "id": "Test.EnlargeFont" } ],
"keybindings": [
{ "keys": "ctrl+c", "id": "Test.EnlargeFont" },
{ "keys": "ctrl+d", "id": "Test.EnlargeFont" } ]})" };

// command with name and icon and multiple key chords
static constexpr std::string_view actionsString5{ R"([
{ "icon": "image.png", "name": "Scroll To Top Name", "command": "scrollToTop", "keys": "ctrl+e" },
{ "command": "scrollToTop", "keys": "ctrl+f" }
])" };
static constexpr std::string_view actionsString5{ R"({ "actions":[
{ "icon": "image.png", "name": "Scroll To Top Name", "command": "scrollToTop", "id": "Test.ScrollToTop" } ],
"keybindings": [
{ "id": "Test.ScrollToTop", "keys": "ctrl+f" },
{ "id": "Test.ScrollToTop", "keys": "ctrl+e" } ]})" };

// complex command with new terminal args
static constexpr std::string_view actionsString6{ R"([
{ "command": { "action": "newTab", "index": 0 }, "keys": "ctrl+g" },
{ "command": { "action": "newTab", "index": 0 }, "id": "Test.NewTerminal" },
])" };

// complex command with meaningful null arg
static constexpr std::string_view actionsString7{ R"([
{ "command": { "action": "renameWindow", "name": null }, "keys": "ctrl+h" }
{ "command": { "action": "renameWindow", "name": null }, "id": "Test.MeaningfulNull" }
])" };

// nested command
Expand Down Expand Up @@ -397,9 +402,9 @@ namespace SettingsModelUnitTests
])"" };

// unbound command
static constexpr std::string_view actionsString10{ R"([
{ "command": "unbound", "keys": "ctrl+c" }
])" };
static constexpr std::string_view actionsString10{ R"({ "actions": [],
"keybindings": [
{ "id": null, "keys": "ctrl+c" } ]})" };

Log::Comment(L"simple command");
RoundtripTest<implementation::ActionMap>(actionsString1);
Expand All @@ -409,14 +414,16 @@ namespace SettingsModelUnitTests
RoundtripTest<implementation::ActionMap>(actionsString2B);
RoundtripTest<implementation::ActionMap>(actionsString2C);

// ActionMap has effectively 2 "to json" calls we need to make, one for the actions and one for the keybindings
// So we cannot use RoundtripTest<ActionMap> for actions + keychords, just use RoundTripTest<GlobalAppSettings>
Log::Comment(L"simple command with key chords");
RoundtripTest<implementation::ActionMap>(actionsString3);
RoundtripTest<implementation::GlobalAppSettings>(actionsString3);

Log::Comment(L"complex commands with key chords");
RoundtripTest<implementation::ActionMap>(actionsString4A);
RoundtripTest<implementation::GlobalAppSettings>(actionsString4A);

Log::Comment(L"command with name and icon and multiple key chords");
RoundtripTest<implementation::ActionMap>(actionsString5);
RoundtripTest<implementation::GlobalAppSettings>(actionsString5);

Log::Comment(L"complex command with new terminal args");
RoundtripTest<implementation::ActionMap>(actionsString6);
Expand All @@ -434,7 +441,7 @@ namespace SettingsModelUnitTests
RoundtripTest<implementation::ActionMap>(actionsString9D);

Log::Comment(L"unbound command");
RoundtripTest<implementation::ActionMap>(actionsString10);
RoundtripTest<implementation::GlobalAppSettings>(actionsString10);
}

void SerializationTests::CascadiaSettings()
Expand Down Expand Up @@ -503,7 +510,10 @@ namespace SettingsModelUnitTests
}
],
"actions": [
{ "command": { "action": "sendInput", "input": "VT Griese Mode" }, "id": "User.sendInput.E02B3DF9", "keys": "ctrl+k" }
{ "command": { "action": "sendInput", "input": "VT Griese Mode" }, "id": "Test.SendInput" }
],
"keybindings": [
{ "id": "Test.SendInput", "keys": "ctrl+k" }
],
"theme": "system",
"themes": []
Expand Down Expand Up @@ -995,7 +1005,6 @@ namespace SettingsModelUnitTests
{
"name": "foo",
"command": "closePane",
"keys": "ctrl+shift+w",
"id": "thisIsMyClosePane"
},
{
Expand Down

0 comments on commit 193e573

Please sign in to comment.