@@ -97,6 +97,8 @@ namespace TerminalAppLocalTests
9797 TEST_METHOD (TestUnbindNestedCommand);
9898 TEST_METHOD (TestRebindNestedCommand);
9999
100+ TEST_METHOD (TestIterableColorSchemeCommands);
101+
100102 TEST_CLASS_SETUP (ClassSetup)
101103 {
102104 InitializeJsonReader ();
@@ -3946,4 +3948,141 @@ namespace TerminalAppLocalTests
39463948 }
39473949 }
39483950
3951+ void SettingsTests::TestIterableColorSchemeCommands ()
3952+ {
3953+ // For this test, put an iterable command with a given `name`,
3954+ // containing a ${profile.name} to replace. When we expand it, it should
3955+ // have created one command for each profile.
3956+
3957+ const std::string settingsJson{ R"(
3958+ {
3959+ "defaultProfile": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
3960+ "profiles": [
3961+ {
3962+ "name": "profile0",
3963+ "guid": "{6239a42c-0000-49a3-80bd-e8fdd045185c}",
3964+ "historySize": 1,
3965+ "commandline": "cmd.exe"
3966+ },
3967+ {
3968+ "name": "profile1",
3969+ "guid": "{6239a42c-1111-49a3-80bd-e8fdd045185c}",
3970+ "historySize": 2,
3971+ "commandline": "pwsh.exe"
3972+ },
3973+ {
3974+ "name": "profile2",
3975+ "historySize": 3,
3976+ "commandline": "wsl.exe"
3977+ }
3978+ ],
3979+ "schemes": [
3980+ { "name": "scheme_0" },
3981+ { "name": "scheme_1" },
3982+ { "name": "scheme_2" },
3983+ ],
3984+ "bindings": [
3985+ {
3986+ "name": "iterable command ${scheme.name}",
3987+ "iterateOn": "schemes",
3988+ "command": { "action": "splitPane", "profile": "${scheme.name}" }
3989+ },
3990+ ]
3991+ })" };
3992+
3993+ VerifyParseSucceeded (settingsJson);
3994+ CascadiaSettings settings{};
3995+ settings._ParseJsonString (settingsJson, false );
3996+ settings.LayerJson (settings._userSettings );
3997+
3998+ VERIFY_ARE_EQUAL (0u , settings._warnings .size ());
3999+
4000+ VERIFY_ARE_EQUAL (3u , settings.GetProfiles ().size ());
4001+
4002+ auto & commands = settings._globals .GetCommands ();
4003+ VERIFY_ARE_EQUAL (1u , commands.Size ());
4004+
4005+ {
4006+ auto command = commands.Lookup (L" iterable command ${scheme.name}" );
4007+ VERIFY_IS_NOT_NULL (command);
4008+ auto actionAndArgs = command.Action ();
4009+ VERIFY_IS_NOT_NULL (actionAndArgs);
4010+ VERIFY_ARE_EQUAL (ShortcutAction::SplitPane, actionAndArgs.Action ());
4011+ const auto & realArgs = actionAndArgs.Args ().try_as <SplitPaneArgs>();
4012+ VERIFY_IS_NOT_NULL (realArgs);
4013+ // Verify the args have the expected value
4014+ VERIFY_ARE_EQUAL (winrt::TerminalApp::SplitState::Automatic, realArgs.SplitStyle ());
4015+ VERIFY_IS_NOT_NULL (realArgs.TerminalArgs ());
4016+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().Commandline ().empty ());
4017+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().StartingDirectory ().empty ());
4018+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().TabTitle ().empty ());
4019+ VERIFY_IS_FALSE (realArgs.TerminalArgs ().Profile ().empty ());
4020+ VERIFY_ARE_EQUAL (L" ${scheme.name}" , realArgs.TerminalArgs ().Profile ());
4021+ }
4022+
4023+ auto expandedCommands = implementation::TerminalPage::_ExpandCommands (commands.GetView (), settings.GetProfiles (), settings._globals .GetColorSchemes ());
4024+ _logCommandNames (expandedCommands);
4025+
4026+ VERIFY_ARE_EQUAL (0u , settings._warnings .size ());
4027+ VERIFY_ARE_EQUAL (3u , expandedCommands.Size ());
4028+
4029+ // Yes, this test is testing splitPane with profiles named after each
4030+ // color scheme. These would obviously not work in real life, they're
4031+ // just easy tests to write.
4032+
4033+ {
4034+ auto command = expandedCommands.Lookup (L" iterable command scheme_0" );
4035+ VERIFY_IS_NOT_NULL (command);
4036+ auto actionAndArgs = command.Action ();
4037+ VERIFY_IS_NOT_NULL (actionAndArgs);
4038+ VERIFY_ARE_EQUAL (ShortcutAction::SplitPane, actionAndArgs.Action ());
4039+ const auto & realArgs = actionAndArgs.Args ().try_as <SplitPaneArgs>();
4040+ VERIFY_IS_NOT_NULL (realArgs);
4041+ // Verify the args have the expected value
4042+ VERIFY_ARE_EQUAL (winrt::TerminalApp::SplitState::Automatic, realArgs.SplitStyle ());
4043+ VERIFY_IS_NOT_NULL (realArgs.TerminalArgs ());
4044+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().Commandline ().empty ());
4045+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().StartingDirectory ().empty ());
4046+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().TabTitle ().empty ());
4047+ VERIFY_IS_FALSE (realArgs.TerminalArgs ().Profile ().empty ());
4048+ VERIFY_ARE_EQUAL (L" scheme_0" , realArgs.TerminalArgs ().Profile ());
4049+ }
4050+
4051+ {
4052+ auto command = expandedCommands.Lookup (L" iterable command scheme_1" );
4053+ VERIFY_IS_NOT_NULL (command);
4054+ auto actionAndArgs = command.Action ();
4055+ VERIFY_IS_NOT_NULL (actionAndArgs);
4056+ VERIFY_ARE_EQUAL (ShortcutAction::SplitPane, actionAndArgs.Action ());
4057+ const auto & realArgs = actionAndArgs.Args ().try_as <SplitPaneArgs>();
4058+ VERIFY_IS_NOT_NULL (realArgs);
4059+ // Verify the args have the expected value
4060+ VERIFY_ARE_EQUAL (winrt::TerminalApp::SplitState::Automatic, realArgs.SplitStyle ());
4061+ VERIFY_IS_NOT_NULL (realArgs.TerminalArgs ());
4062+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().Commandline ().empty ());
4063+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().StartingDirectory ().empty ());
4064+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().TabTitle ().empty ());
4065+ VERIFY_IS_FALSE (realArgs.TerminalArgs ().Profile ().empty ());
4066+ VERIFY_ARE_EQUAL (L" scheme_1" , realArgs.TerminalArgs ().Profile ());
4067+ }
4068+
4069+ {
4070+ auto command = expandedCommands.Lookup (L" iterable command scheme_2" );
4071+ VERIFY_IS_NOT_NULL (command);
4072+ auto actionAndArgs = command.Action ();
4073+ VERIFY_IS_NOT_NULL (actionAndArgs);
4074+ VERIFY_ARE_EQUAL (ShortcutAction::SplitPane, actionAndArgs.Action ());
4075+ const auto & realArgs = actionAndArgs.Args ().try_as <SplitPaneArgs>();
4076+ VERIFY_IS_NOT_NULL (realArgs);
4077+ // Verify the args have the expected value
4078+ VERIFY_ARE_EQUAL (winrt::TerminalApp::SplitState::Automatic, realArgs.SplitStyle ());
4079+ VERIFY_IS_NOT_NULL (realArgs.TerminalArgs ());
4080+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().Commandline ().empty ());
4081+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().StartingDirectory ().empty ());
4082+ VERIFY_IS_TRUE (realArgs.TerminalArgs ().TabTitle ().empty ());
4083+ VERIFY_IS_FALSE (realArgs.TerminalArgs ().Profile ().empty ());
4084+ VERIFY_ARE_EQUAL (L" scheme_2" , realArgs.TerminalArgs ().Profile ());
4085+ }
4086+ }
4087+
39494088}
0 commit comments