Skip to content

Commit 14bf652

Browse files
committed
fix up new tests (mostly)
1 parent 28c50a4 commit 14bf652

File tree

6 files changed

+142
-68
lines changed

6 files changed

+142
-68
lines changed

src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp

Lines changed: 120 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,6 @@ namespace SettingsModelLocalTests
6161

6262
void SerializationTests::GlobalSettings()
6363
{
64-
DebugBreak();
6564
// This needs to be in alphabetical order.
6665
const std::string globalsString{
6766
"{"
@@ -70,7 +69,6 @@ namespace SettingsModelLocalTests
7069
"\"confirmCloseAllTabs\": true,"
7170
"\"copyFormatting\": \"all\","
7271
"\"copyOnSelect\": false,"
73-
"\"debugFeatures\": true,"
7472
"\"defaultProfile\": \"{61c54bbd-c2c6-5271-96e7-009a87ff44bf}\","
7573
"\"experimental.input.forceVT\": false,"
7674
"\"experimental.rendering.forceFullRepaint\": false,"
@@ -113,42 +111,41 @@ namespace SettingsModelLocalTests
113111

114112
void SerializationTests::Profile()
115113
{
116-
DebugBreak();
114+
// This needs to be in alphabetical order.
117115
const std::string profileString{
118116
"{"
119-
"\"name\": \"Windows PowerShell\","
120-
"\"guid\": \"{61c54bbd-c2c6-5271-96e7-009a87ff44bf}\","
121-
"\"hidden\": false,"
122-
"\"foreground\": \"#AABBCC\","
117+
"\"altGrAliasing\": true,"
118+
"\"antialiasingMode\": \"grayscale\","
123119
"\"background\": \"#BBCCAA\","
124-
"\"selectionBackground\": \"#CCAABB\","
125-
"\"cursorColor\": \"#CCBBAA\","
120+
"\"backgroundImage\": \"made_you_look.jpeg\","
121+
"\"backgroundImageAlignment\": \"center\","
122+
"\"backgroundImageOpacity\": 1.0,"
123+
"\"backgroundImageStretchMode\": \"uniformToFill\","
124+
"\"closeOnExit\": \"graceful\","
126125
"\"colorScheme\": \"Campbell\","
127-
"\"historySize\": 9001,"
128-
"\"snapOnInput\": true,"
129-
"\"altGrAliasing\": true,"
130-
"\"cursorHeight\": null,"
126+
"\"commandline\": \"%SystemRoot%\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe\","
127+
"\"cursorColor\": \"#CCBBAA\","
128+
"\"cursorHeight\": 10,"
131129
"\"cursorShape\": \"bar\","
132-
"\"tabTitle\": null,"
133-
"\"fontWeight\": \"normal\","
134-
//"\"connectionType\": null,"
135-
"\"commandline\": \"%SystemRoot%\\System32\\WindowsPowerShell\\v1.0\\powershell.exe\","
130+
"\"experimental.retroTerminalEffect\": false,"
136131
"\"fontFace\": \"Cascadia Mono\","
137132
"\"fontSize\": 12,"
138-
"\"useAcrylic\": false,"
139-
"\"suppressApplicationTitle\": false,"
140-
"\"closeOnExit\": \"graceful\","
133+
"\"fontWeight\": \"normal\","
134+
"\"foreground\": \"#AABBCC\","
135+
"\"guid\": \"{61c54bbd-c2c6-5271-96e7-009a87ff44bf}\","
136+
"\"hidden\": false,"
137+
"\"historySize\": 9001,"
138+
"\"icon\": \"ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png\","
139+
"\"name\": \"Windows PowerShell\","
141140
"\"padding\": \"8, 8, 8, 8\","
142141
"\"scrollbarState\": \"visible\","
142+
"\"selectionBackground\": \"#CCAABB\","
143+
"\"snapOnInput\": true,"
143144
"\"startingDirectory\": \"%USERPROFILE%\","
144-
"\"icon\": \"ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png\","
145-
"\"backgroundImage\": null,"
146-
"\"backgroundImageOpacity\": 1.0,"
147-
"\"backgroundImageStretchMode\": \"uniformToFill\","
148-
"\"backgroundImageAlignment\": \"center\","
149-
"\"experimental.retroTerminalEffect\": false,"
150-
"\"antialiasingMode\": \"grayscale\""
145+
"\"suppressApplicationTitle\": false,"
151146
"\"tabColor\": \"#0C0C0C\","
147+
"\"tabTitle\": \"Cool Tab\","
148+
"\"useAcrylic\": false"
152149
"}"
153150
};
154151

@@ -160,9 +157,9 @@ namespace SettingsModelLocalTests
160157

161158
auto roundtripTest = [this](auto jsonString) {
162159
const auto json{ VerifyParseSucceeded(jsonString) };
163-
const auto globals{ implementation::Profile::FromJson(json) };
160+
const auto profile{ implementation::Profile::FromJson(json) };
164161

165-
const auto result{ globals->ToJson() };
162+
const auto result{ profile->ToJson() };
166163

167164
VERIFY_ARE_EQUAL(jsonString, toString(result));
168165
};
@@ -173,47 +170,112 @@ namespace SettingsModelLocalTests
173170

174171
void SerializationTests::ColorScheme()
175172
{
176-
DebugBreak();
173+
// This needs to be in alphabetical order.
177174
const std::string schemeString{ "{"
178-
"\"name\" : \"Campbell\","
179-
"\"foreground\" : \"#F2F2F2\","
180-
"\"background\" : \"#0C0C0C\","
181-
"\"selectionBackground\" : \"#131313\","
182-
"\"cursorColor\" : \"#FFFFFF\","
183-
"\"black\" : \"#0C0C0C\","
184-
"\"red\" : \"#C50F1F\","
185-
"\"green\" : \"#13A10E\","
186-
"\"yellow\" : \"#C19C00\""
187-
"\"blue\" : \"#0037DA\","
188-
"\"purple\" : \"#881798\","
189-
"\"cyan\" : \"#3A96DD\","
190-
"\"white\" : \"#CCCCCC\","
191-
"\"brightBlack\" : \"#767676\","
192-
"\"brightRed\" : \"#E74856\","
193-
"\"brightGreen\" : \"#16C60C\","
194-
"\"brightYellow\" : \"#F9F1A5\","
195-
"\"brightBlue\" : \"#3B78FF\","
196-
"\"brightPurple\" : \"#B4009E\","
197-
"\"brightCyan\" : \"#61D6D6\","
198-
"\"brightWhite\" : \"#F2F2F2\""
175+
"\"background\": \"#0C0C0C\","
176+
"\"black\": \"#0C0C0C\","
177+
"\"blue\": \"#0037DA\","
178+
"\"brightBlack\": \"#767676\","
179+
"\"brightBlue\": \"#3B78FF\","
180+
"\"brightCyan\": \"#61D6D6\","
181+
"\"brightGreen\": \"#16C60C\","
182+
"\"brightPurple\": \"#B4009E\","
183+
"\"brightRed\": \"#E74856\","
184+
"\"brightWhite\": \"#F2F2F2\","
185+
"\"brightYellow\": \"#F9F1A5\","
186+
"\"cursorColor\": \"#FFFFFF\","
187+
"\"cyan\": \"#3A96DD\","
188+
"\"foreground\": \"#F2F2F2\","
189+
"\"green\": \"#13A10E\","
190+
"\"name\": \"Campbell\","
191+
"\"purple\": \"#881798\","
192+
"\"red\": \"#C50F1F\","
193+
"\"selectionBackground\": \"#131313\","
194+
"\"white\": \"#CCCCCC\","
195+
"\"yellow\": \"#C19C00\""
199196
"}" };
200197

201198
const auto json{ VerifyParseSucceeded(schemeString) };
202-
const auto profile{ implementation::ColorScheme::FromJson(json) };
199+
const auto scheme{ implementation::ColorScheme::FromJson(json) };
203200

204-
const auto result{ profile->ToJson() };
205-
VERIFY_ARE_EQUAL(json, result);
201+
const auto result{ scheme->ToJson() };
202+
VERIFY_ARE_EQUAL(schemeString, toString(result));
206203
}
207204

208205
void SerializationTests::CascadiaSettings()
209206
{
210207
DebugBreak();
211-
const std::string settingsString{ "" };
208+
// clang-format off
209+
// This needs to be in alphabetical order.
210+
const std::string settingsString{ "{"
211+
"\"$schema\": \"https://aka.ms/terminal-profiles-schema\","
212+
"\"actions\": ["
213+
"{\"command\": {\"action\": \"renameTab\",\"input\": \"Liang Tab\"},\"keys\": \"ctrl+t\"}"
214+
"],"
215+
"\"defaultProfile\": \"{61c54bbd-1111-5271-96e7-009a87ff44bf}\","
216+
"\"keybindings\": ["
217+
"{\"command\": {\"action\": \"sendInput\",\"input\": \"VT Griese Mode\"},\"keys\": \"ctrl+k\"}"
218+
"],"
219+
"\"profiles\": {"
220+
"\"defaults\": {"
221+
"\"fontFace\": \"Zamora Code\""
222+
"},"
223+
"\"list\": ["
224+
"{"
225+
"\"fontFace\": \"Cascadia Code\","
226+
"\"guid\": \"{61c54bbd-1111-5271-96e7-009a87ff44bf}\","
227+
"\"name\": \"HowettShell\""
228+
"},"
229+
"{"
230+
"\"antialiasingMode\": \"aliased\","
231+
"\"name\": \"NiksaShell\""
232+
"},"
233+
"{"
234+
"\"name\": \"BhojwaniShell\","
235+
"\"source\": \"local\""
236+
"}"
237+
"]"
238+
"},"
239+
"\"schemes\": ["
240+
"{"
241+
"\"background\": \"#3C0315\","
242+
"\"black\": \"#282A2E\","
243+
"\"blue\": \"#0170C5\","
244+
"\"brightBlack\": \"#676E7A\","
245+
"\"brightBlue\": \"#5C98C5\","
246+
"\"brightCyan\": \"#8ABEB7\","
247+
"\"brightGreen\": \"#B5D680\","
248+
"\"brightPurple\": \"#AC79BB\","
249+
"\"brightRed\": \"#BD6D85\","
250+
"\"brightWhite\": \"#FFFFFD\","
251+
"\"brightYellow\": \"#FFFD76\","
252+
"\"cursorColor\": \"#FFFFFD\","
253+
"\"cyan\": \"#3F8D83\","
254+
"\"foreground\": \"#FFFFFD\","
255+
"\"green\": \"#76AB23\","
256+
"\"name\": \"Cinnamon Roll\","
257+
"\"purple\": \"#7D498F\","
258+
"\"red\": \"#BD0940\","
259+
"\"selectionBackground\": \"#FFFFFF\","
260+
"\"white\": \"#FFFFFD\","
261+
"\"yellow\": \"#E0DE48\""
262+
"}"
263+
"]"
264+
"}" };
265+
// clang-format on
212266

213-
const auto json{ VerifyParseSucceeded(settingsString) };
214-
const auto settings{ implementation::CascadiaSettings::FromJson(json) };
267+
auto settings{ winrt::make_self<implementation::CascadiaSettings>(false) };
268+
settings->_ParseJsonString(settingsString, false);
269+
settings->_ApplyDefaultsFromUserSettings();
270+
settings->LayerJson(settings->_userSettings);
271+
settings->_ValidateSettings();
215272

273+
// TODO CARLOS:
274+
// - temp/DebugBreak is only for testing. Remove after we're done here.
275+
// - NiksaShell prints out a guid, when it shouldn't be
276+
// - BhojwaniShell is missing entirely
216277
const auto result{ settings->ToJson() };
217-
VERIFY_ARE_EQUAL(json, result);
278+
const auto temp{ toString(result) };
279+
VERIFY_ARE_EQUAL(settingsString, toString(result));
218280
}
219281
}

src/cascadia/TerminalSettingsModel/CascadiaSettings.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -488,7 +488,8 @@ void CascadiaSettings::_ValidateAllSchemesExist()
488488
const auto schemeName = profile.ColorSchemeName();
489489
if (!_globals->ColorSchemes().HasKey(schemeName))
490490
{
491-
profile.ColorSchemeName({ L"Campbell" });
491+
// Clear the user set color scheme. We'll just fallback instead.
492+
profile.ClearColorSchemeName();
492493
foundInvalidScheme = true;
493494
}
494495
}

src/cascadia/TerminalSettingsModel/CascadiaSettings.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ Author(s):
2929
// fwdecl unittest classes
3030
namespace SettingsModelLocalTests
3131
{
32+
class SerializationTests;
3233
class DeserializationTests;
3334
class ProfileTests;
3435
class ColorSchemeTests;
@@ -142,6 +143,7 @@ namespace winrt::Microsoft::Terminal::Settings::Model::implementation
142143
void _ValidateKeybindings();
143144
void _ValidateNoGlobalsKey();
144145

146+
friend class SettingsModelLocalTests::SerializationTests;
145147
friend class SettingsModelLocalTests::DeserializationTests;
146148
friend class SettingsModelLocalTests::ProfileTests;
147149
friend class SettingsModelLocalTests::ColorSchemeTests;

src/cascadia/TerminalSettingsModel/CascadiaSettingsSerialization.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1049,20 +1049,21 @@ Json::Value CascadiaSettings::ToJson() const
10491049
// "profiles" will always be serialized as an object
10501050
Json::Value profiles{ Json::ValueType::objectValue };
10511051
profiles[JsonKey(DefaultSettingsKey)] = _userDefaultProfileSettings->ToJson();
1052-
profiles[JsonKey(ProfilesListKey)] = { Json::ValueType::arrayValue };
1052+
Json::Value profilesList{ Json::ValueType::arrayValue };
10531053
for (const auto& entry : _profiles)
10541054
{
10551055
const auto prof{ winrt::get_self<implementation::Profile>(entry) };
1056-
json[JsonKey(ProfilesKey)].append(prof->ToJson());
1056+
profilesList.append(prof->ToJson());
10571057
}
1058+
profiles[JsonKey(ProfilesListKey)] = profilesList;
10581059
json[JsonKey(ProfilesKey)] = profiles;
10591060

10601061
// "schemes" will be an accumulation of _all_ the color schemes
10611062
Json::Value schemes{ Json::ValueType::arrayValue };
10621063
for (const auto& entry : _globals->ColorSchemes())
10631064
{
10641065
const auto scheme{ winrt::get_self<implementation::ColorScheme>(entry.Value()) };
1065-
json[JsonKey(SchemesKey)].append(scheme->ToJson());
1066+
schemes.append(scheme->ToJson());
10661067
}
10671068
json[JsonKey(SchemesKey)] = schemes;
10681069

src/cascadia/TerminalSettingsModel/GlobalAppSettings.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -352,6 +352,7 @@ Json::Value GlobalAppSettings::ToJson() const
352352
{
353353
Json::Value json{ Json::ValueType::objectValue };
354354

355+
// Exclude DebugFeatures from the list below
355356
// clang-format off
356357
JsonUtils::SetValueForKey(json, DefaultProfileKey, _UnparsedDefaultProfile);
357358
JsonUtils::SetValueForKey(json, AlwaysShowTabsKey, _AlwaysShowTabs);
@@ -370,7 +371,6 @@ Json::Value GlobalAppSettings::ToJson() const
370371
JsonUtils::SetValueForKey(json, ThemeKey, _Theme);
371372
JsonUtils::SetValueForKey(json, TabWidthModeKey, _TabWidthMode);
372373
JsonUtils::SetValueForKey(json, SnapToGridOnResizeKey, _SnapToGridOnResize);
373-
JsonUtils::SetValueForKey(json, DebugFeaturesKey, _DebugFeaturesEnabled);
374374
JsonUtils::SetValueForKey(json, ForceFullRepaintRenderingKey, _ForceFullRepaintRendering);
375375
JsonUtils::SetValueForKey(json, SoftwareRenderingKey, _SoftwareRendering);
376376
JsonUtils::SetValueForKey(json, ForceVTInputKey, _ForceVTInput);

src/cascadia/TerminalSettingsModel/JsonUtils.h

Lines changed: 13 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -707,8 +707,7 @@ namespace Microsoft::Terminal::Settings::Model::JsonUtils
707707
template<typename T, typename Converter>
708708
void SetValueForKey(Json::Value& json, std::string_view key, const T& target, Converter&& conv)
709709
{
710-
// demand guarantees that it will return a value or throw an exception
711-
auto out{ json.demand(&*key.cbegin(), (&*key.cbegin()) + key.size()) };
710+
std::optional<Json::Value> out;
712711
if constexpr (Detail::DeduceOptional<T>::IsOptional)
713712
{
714713
// FOR OPTION TYPES
@@ -720,19 +719,28 @@ namespace Microsoft::Terminal::Settings::Model::JsonUtils
720719
// We consider them optional so that they can be zero-constructed
721720
// and we store it as an empty string
722721
// However, we need to differentiate between hstring and optional<hstring>
723-
*out = conv.ToJson(target);
722+
out = conv.ToJson(target);
724723
}
725724
else
726725
{
727726
if (target)
728727
{
729-
*out = conv.ToJson(*target);
728+
out = conv.ToJson(*target);
730729
}
731730
}
732731
}
733732
else
734733
{
735-
*out = conv.ToJson(target);
734+
out = conv.ToJson(target);
735+
}
736+
737+
if (out)
738+
{
739+
// demand guarantees that it will return a value or throw an exception
740+
// _Only_ call it if we are writing a value. Otherwise, we'll write the key
741+
// in the json, and initialize it's value to "null". Instead, we use "out"
742+
// to completely omit writing this setting if we don't have a value.
743+
*json.demand(&*key.cbegin(), (&*key.cbegin()) + key.size()) = *out;
736744
}
737745
}
738746

0 commit comments

Comments
 (0)