-
Notifications
You must be signed in to change notification settings - Fork 8.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add Serializer to CascadiaSettings #8018
Merged
Merged
Changes from 9 commits
Commits
Show all changes
25 commits
Select commit
Hold shift + click to select a range
48d8d06
Add Serializer to CascadiaSettings
carlos-zamora a3695fa
fix up new tests (mostly)
carlos-zamora 5db3d03
only perform guid generation in getter
carlos-zamora 8ba6394
serialize hidden shells
carlos-zamora e6b1bef
Revert "serialize hidden shells"
carlos-zamora fda5ddd
fix tests
carlos-zamora 5833bb9
polish
carlos-zamora df10fc4
fix unit test
carlos-zamora 6bb948f
add Export()
carlos-zamora 4377296
address Mike's PR comments
carlos-zamora 917679b
address Niksa + Griese PR comments
carlos-zamora f6ad218
only write backup if none exists
carlos-zamora 31dd278
use CREATE_NEW to make this more right
carlos-zamora 396c1a1
work with miniksa to make this look right
carlos-zamora c4f2733
timestamp the backup file
carlos-zamora dd04469
remove a semicolon
carlos-zamora c51f9b4
make timestamp look right
carlos-zamora 92dc467
Merge branch 'dev/cazamor/tsm/serialization' of https://github.com/mi…
carlos-zamora 29f7769
spellcheck
carlos-zamora 8db53af
Merge branch 'main' into dev/cazamor/tsm/serialization
carlos-zamora 125860e
propagate 'useTabSwitcher'-->'tabSwitcherMode' change
carlos-zamora ecf88ae
Merge remote-tracking branch 'origin/main' into dev/cazamor/tsm/seria…
DHowett 4c058e2
remove unnecessary comment
carlos-zamora 0c5aedb
polish writing settings to disk (verified)
carlos-zamora 5d7fc4a
deserialize source
carlos-zamora File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
279 changes: 279 additions & 0 deletions
279
src/cascadia/LocalTests_SettingsModel/SerializationTests.cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,279 @@ | ||
// Copyright (c) Microsoft Corporation. | ||
// Licensed under the MIT license. | ||
|
||
#include "pch.h" | ||
|
||
#include "../TerminalSettingsModel/ColorScheme.h" | ||
#include "../TerminalSettingsModel/CascadiaSettings.h" | ||
#include "JsonTestClass.h" | ||
#include "TestUtils.h" | ||
#include <defaults.h> | ||
#include "../ut_app/TestDynamicProfileGenerator.h" | ||
|
||
using namespace Microsoft::Console; | ||
using namespace WEX::Logging; | ||
using namespace WEX::TestExecution; | ||
using namespace WEX::Common; | ||
using namespace winrt::Microsoft::Terminal::Settings::Model; | ||
using namespace winrt::Microsoft::Terminal::TerminalControl; | ||
|
||
namespace SettingsModelLocalTests | ||
{ | ||
// TODO:microsoft/terminal#3838: | ||
// Unfortunately, these tests _WILL NOT_ work in our CI. We're waiting for | ||
// an updated TAEF that will let us install framework packages when the test | ||
// package is deployed. Until then, these tests won't deploy in CI. | ||
|
||
class SerializationTests : public JsonTestClass | ||
{ | ||
// Use a custom AppxManifest to ensure that we can activate winrt types | ||
// from our test. This property will tell taef to manually use this as | ||
// the AppxManifest for this test class. | ||
// This does not yet work for anything XAML-y. See TabTests.cpp for more | ||
// details on that. | ||
BEGIN_TEST_CLASS(SerializationTests) | ||
TEST_CLASS_PROPERTY(L"RunAs", L"UAP") | ||
TEST_CLASS_PROPERTY(L"UAP:AppXManifest", L"TestHostAppXManifest.xml") | ||
END_TEST_CLASS() | ||
|
||
TEST_METHOD(GlobalSettings); | ||
TEST_METHOD(Profile); | ||
TEST_METHOD(ColorScheme); | ||
TEST_METHOD(CascadiaSettings); | ||
|
||
TEST_CLASS_SETUP(ClassSetup) | ||
{ | ||
InitializeJsonReader(); | ||
return true; | ||
} | ||
|
||
private: | ||
std::string toString(const Json::Value& json) | ||
{ | ||
// set indentation to empty string to remove newlines | ||
// enableYAMLCompatibility adds a space after ':' | ||
Json::StreamWriterBuilder builder; | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
builder["indentation"] = ""; | ||
builder["enableYAMLCompatibility"] = true; | ||
return Json::writeString(builder, json); | ||
} | ||
}; | ||
|
||
void SerializationTests::GlobalSettings() | ||
{ | ||
// This needs to be in alphabetical order. | ||
const std::string globalsString{ | ||
"{" | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"\"alwaysOnTop\": false," | ||
"\"alwaysShowTabs\": true," | ||
"\"confirmCloseAllTabs\": true," | ||
"\"copyFormatting\": \"all\"," | ||
"\"copyOnSelect\": false," | ||
"\"defaultProfile\": \"{61c54bbd-c2c6-5271-96e7-009a87ff44bf}\"," | ||
"\"experimental.input.forceVT\": false," | ||
"\"experimental.rendering.forceFullRepaint\": false," | ||
"\"experimental.rendering.software\": false," | ||
"\"initialCols\": 120," | ||
"\"initialPosition\": \",\"," | ||
"\"initialRows\": 30," | ||
"\"largePasteWarning\": true," | ||
"\"launchMode\": \"default\"," | ||
"\"multiLinePasteWarning\": true," | ||
"\"showTabsInTitlebar\": true," | ||
"\"showTerminalTitleInTitlebar\": true," | ||
"\"snapToGridOnResize\": true," | ||
"\"startOnUserLogin\": false," | ||
"\"tabWidthMode\": \"equal\"," | ||
"\"theme\": \"system\"," | ||
"\"useTabSwitcher\": true," | ||
"\"wordDelimiters\": \" /\\\\()\\\"'-.,:;<>~!@#$%^&*|+=[]{}~?\\u2502\"" | ||
"}" | ||
}; | ||
|
||
const std::string smallGlobalsString{ | ||
"{" | ||
"\"defaultProfile\": \"{61c54bbd-c2c6-5271-96e7-009a87ff44bf}\"" | ||
"}" | ||
}; | ||
|
||
auto roundtripTest = [this](auto jsonString) { | ||
const auto json{ VerifyParseSucceeded(jsonString) }; | ||
const auto globals{ implementation::GlobalAppSettings::FromJson(json) }; | ||
|
||
const auto result{ globals->ToJson() }; | ||
|
||
VERIFY_ARE_EQUAL(jsonString, toString(result)); | ||
}; | ||
|
||
roundtripTest(globalsString); | ||
roundtripTest(smallGlobalsString); | ||
} | ||
|
||
void SerializationTests::Profile() | ||
{ | ||
// This needs to be in alphabetical order. | ||
const std::string profileString{ | ||
"{" | ||
"\"altGrAliasing\": true," | ||
"\"antialiasingMode\": \"grayscale\"," | ||
"\"background\": \"#BBCCAA\"," | ||
"\"backgroundImage\": \"made_you_look.jpeg\"," | ||
"\"backgroundImageAlignment\": \"center\"," | ||
"\"backgroundImageOpacity\": 1.0," | ||
"\"backgroundImageStretchMode\": \"uniformToFill\"," | ||
"\"closeOnExit\": \"graceful\"," | ||
"\"colorScheme\": \"Campbell\"," | ||
"\"commandline\": \"%SystemRoot%\\\\System32\\\\WindowsPowerShell\\\\v1.0\\\\powershell.exe\"," | ||
"\"cursorColor\": \"#CCBBAA\"," | ||
"\"cursorHeight\": 10," | ||
"\"cursorShape\": \"bar\"," | ||
"\"experimental.retroTerminalEffect\": false," | ||
"\"fontFace\": \"Cascadia Mono\"," | ||
"\"fontSize\": 12," | ||
"\"fontWeight\": \"normal\"," | ||
"\"foreground\": \"#AABBCC\"," | ||
"\"guid\": \"{61c54bbd-c2c6-5271-96e7-009a87ff44bf}\"," | ||
"\"hidden\": false," | ||
"\"historySize\": 9001," | ||
"\"icon\": \"ms-appx:///ProfileIcons/{61c54bbd-c2c6-5271-96e7-009a87ff44bf}.png\"," | ||
"\"name\": \"Windows PowerShell\"," | ||
"\"padding\": \"8, 8, 8, 8\"," | ||
"\"scrollbarState\": \"visible\"," | ||
"\"selectionBackground\": \"#CCAABB\"," | ||
"\"snapOnInput\": true," | ||
"\"startingDirectory\": \"%USERPROFILE%\"," | ||
"\"suppressApplicationTitle\": false," | ||
"\"tabColor\": \"#0C0C0C\"," | ||
"\"tabTitle\": \"Cool Tab\"," | ||
"\"useAcrylic\": false" | ||
"}" | ||
}; | ||
|
||
const std::string smallProfileString{ | ||
"{" | ||
"\"name\": \"Custom Profile\"" | ||
"}" | ||
}; | ||
|
||
auto roundtripTest = [this](auto jsonString) { | ||
const auto json{ VerifyParseSucceeded(jsonString) }; | ||
const auto profile{ implementation::Profile::FromJson(json) }; | ||
|
||
const auto result{ profile->ToJson() }; | ||
|
||
VERIFY_ARE_EQUAL(jsonString, toString(result)); | ||
}; | ||
|
||
roundtripTest(profileString); | ||
roundtripTest(smallProfileString); | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
|
||
void SerializationTests::ColorScheme() | ||
{ | ||
// This needs to be in alphabetical order. | ||
const std::string schemeString{ "{" | ||
"\"background\": \"#0C0C0C\"," | ||
"\"black\": \"#0C0C0C\"," | ||
"\"blue\": \"#0037DA\"," | ||
"\"brightBlack\": \"#767676\"," | ||
"\"brightBlue\": \"#3B78FF\"," | ||
"\"brightCyan\": \"#61D6D6\"," | ||
"\"brightGreen\": \"#16C60C\"," | ||
"\"brightPurple\": \"#B4009E\"," | ||
"\"brightRed\": \"#E74856\"," | ||
"\"brightWhite\": \"#F2F2F2\"," | ||
"\"brightYellow\": \"#F9F1A5\"," | ||
"\"cursorColor\": \"#FFFFFF\"," | ||
"\"cyan\": \"#3A96DD\"," | ||
"\"foreground\": \"#F2F2F2\"," | ||
"\"green\": \"#13A10E\"," | ||
"\"name\": \"Campbell\"," | ||
"\"purple\": \"#881798\"," | ||
"\"red\": \"#C50F1F\"," | ||
"\"selectionBackground\": \"#131313\"," | ||
"\"white\": \"#CCCCCC\"," | ||
"\"yellow\": \"#C19C00\"" | ||
"}" }; | ||
|
||
const auto json{ VerifyParseSucceeded(schemeString) }; | ||
const auto scheme{ implementation::ColorScheme::FromJson(json) }; | ||
|
||
const auto result{ scheme->ToJson() }; | ||
VERIFY_ARE_EQUAL(schemeString, toString(result)); | ||
} | ||
|
||
void SerializationTests::CascadiaSettings() | ||
{ | ||
// clang-format off | ||
// This needs to be in alphabetical order. | ||
const std::string settingsString{ "{" | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"\"$schema\": \"https://aka.ms/terminal-profiles-schema\"," | ||
"\"actions\": [" | ||
"{\"command\": {\"action\": \"renameTab\",\"input\": \"Liang Tab\"},\"keys\": \"ctrl+t\"}" | ||
"]," | ||
"\"defaultProfile\": \"{61c54bbd-1111-5271-96e7-009a87ff44bf}\"," | ||
"\"keybindings\": [" | ||
"{\"command\": {\"action\": \"sendInput\",\"input\": \"VT Griese Mode\"},\"keys\": \"ctrl+k\"}" | ||
"]," | ||
"\"profiles\": {" | ||
"\"defaults\": {" | ||
"\"fontFace\": \"Zamora Code\"" | ||
"}," | ||
"\"list\": [" | ||
"{" | ||
"\"fontFace\": \"Cascadia Code\"," | ||
"\"guid\": \"{61c54bbd-1111-5271-96e7-009a87ff44bf}\"," | ||
"\"name\": \"HowettShell\"" | ||
"}," | ||
"{" | ||
"\"hidden\": true," | ||
"\"name\": \"BhojwaniShell\"" | ||
"}," | ||
"{" | ||
"\"antialiasingMode\": \"aliased\"," | ||
"\"name\": \"NiksaShell\"" | ||
"}" | ||
"]" | ||
"}," | ||
"\"schemes\": [" | ||
"{" | ||
"\"background\": \"#3C0315\"," | ||
"\"black\": \"#282A2E\"," | ||
"\"blue\": \"#0170C5\"," | ||
"\"brightBlack\": \"#676E7A\"," | ||
"\"brightBlue\": \"#5C98C5\"," | ||
"\"brightCyan\": \"#8ABEB7\"," | ||
"\"brightGreen\": \"#B5D680\"," | ||
"\"brightPurple\": \"#AC79BB\"," | ||
"\"brightRed\": \"#BD6D85\"," | ||
"\"brightWhite\": \"#FFFFFD\"," | ||
"\"brightYellow\": \"#FFFD76\"," | ||
"\"cursorColor\": \"#FFFFFD\"," | ||
"\"cyan\": \"#3F8D83\"," | ||
"\"foreground\": \"#FFFFFD\"," | ||
"\"green\": \"#76AB23\"," | ||
"\"name\": \"Cinnamon Roll\"," | ||
"\"purple\": \"#7D498F\"," | ||
"\"red\": \"#BD0940\"," | ||
"\"selectionBackground\": \"#FFFFFF\"," | ||
"\"white\": \"#FFFFFD\"," | ||
"\"yellow\": \"#E0DE48\"" | ||
"}" | ||
"]" | ||
"}" }; | ||
// clang-format on | ||
|
||
auto settings{ winrt::make_self<implementation::CascadiaSettings>(false) }; | ||
settings->_ParseJsonString(settingsString, false); | ||
settings->_ApplyDefaultsFromUserSettings(); | ||
settings->LayerJson(settings->_userSettings); | ||
settings->_ValidateSettings(); | ||
|
||
// TODO CARLOS: | ||
carlos-zamora marked this conversation as resolved.
Show resolved
Hide resolved
|
||
// - temp/DebugBreak is only for testing. Remove after we're done here. | ||
// - BhojwaniShell is missing entirely | ||
const auto result{ settings->ToJson() }; | ||
const auto temp{ toString(result) }; | ||
VERIFY_ARE_EQUAL(settingsString, toString(result)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FYI, we can do this now. Did you check whether these tests work in our CI or not? I swear I put this module on in CI.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It looks like none of the helix tests are running.