Repository: microsoft/terminal
File: src/cascadia/UnitTests_SettingsModel/ProfileTests.cpp (C++)

Code before:
        const std::string profileWithRawGuid{ R"({
                                              "name" : "profile4",
                                              "guid" : "6239a42c-1de4-49a3-80bd-e8fdd045185c"
                                              })" };
        const std::string profileWithGuidFormatP{ R"({
                                              "name" : "profile4",
                                              "guid" : "(6239a42c-1de4-49a3-80bd-e8fdd045185c)\\"
                                              })" };
        // Valid GUIDs
        const std::string profileWithNullGuid{ R"({
                                              "name" : "profile3",
                                              "guid" : "{00000000-0000-0000-0000-000000000000}"
                                              })" };
        const std::string profileWithGuidFormatB{ R"({
                                              "name" : "profile4",
                                              "guid" : "{6239a42c-1de4-49a3-80bd-e8fdd045185c}"
                                              })" };
        const std::string profileWithGuidUpperCaseFormatB{ R"({
                                              "name" : "profile4",
                                              "guid" : "{6239A42C-1DE4-49A3-80BD-E8FDD045185C}"
                                              })" };

        parseAndVerifyProfile(profileWithoutGuid, false);
        parseAndVerifyProfile(secondProfileWithoutGuid, false);

        // The following crash JSON parsing
        //parseAndVerifyProfile(profileWithRawGuid, false);
        //parseAndVerifyProfile(profileWithHyphenlessGuid, false);
        //parseAndVerifyProfile(profileWithGuidFormatP, false);

        const auto parsedNullGuidProfile = parseAndVerifyProfile(profileWithNullGuid, true);
        const auto parsedGuidProfileFormatB = parseAndVerifyProfile(profileWithGuidFormatB, true);
        const auto parsedGuidProfileUpperCaseFormatB = parseAndVerifyProfile(profileWithGuidUpperCaseFormatB, true);

        const winrt::guid nullGuid{};
        const winrt::guid cmdGuid = Utils::GuidFromString(L"{6239a42c-1de4-49a3-80bd-e8fdd045185c}");

        VERIFY_ARE_EQUAL(parsedNullGuidProfile->Guid(), nullGuid);
        VERIFY_ARE_EQUAL(parsedGuidProfileFormatB->Guid(), cmdGuid);
        VERIFY_ARE_EQUAL(parsedGuidProfileUpperCaseFormatB->Guid(), cmdGuid);
    }

    void ProfileTests::LayerProfileProperties()
    {
        static constexpr std::string_view profile0String{ R"({
            "name": "profile0",
            "guid": "{6239a42c-1111-49a3-80bd-e8fdd045185c}",
            "foreground": "#000000",
            "background": "#010101",
            "selectionBackground": "#010101"
        })" };

Review comment (suggestion):
FWIW, this should throw an exception which you can verify you caught with `VERIFY_THROWS`!

Code after:
        const std::string profileWithRawGuid{ R"({
                                              "name" : "profile4",
                                              "guid" : "6239a42c-1de4-49a3-80bd-e8fdd045185c"
                                              })" };
        const std::string profileWithGuidFormatP{ R"({
                                              "name" : "profile4",
                                              "guid" : "(6239a42c-1de4-49a3-80bd-e8fdd045185c)\\"
                                              })" };
        // Valid GUIDs
        const std::string profileWithNullGuid{ R"({
                                              "name" : "profile3",
                                              "guid" : "{00000000-0000-0000-0000-000000000000}"
                                              })" };
        const std::string profileWithGuidFormatB{ R"({
                                              "name" : "profile4",
                                              "guid" : "{6239a42c-1de4-49a3-80bd-e8fdd045185c}"
                                              })" };
        const std::string profileWithGuidUpperCaseFormatB{ R"({
                                              "name" : "profile4",
                                              "guid" : "{6239A42C-1DE4-49A3-80BD-E8FDD045185C}"
                                              })" };

        parseAndVerifyProfile(profileWithoutGuid, false);
        parseAndVerifyProfile(secondProfileWithoutGuid, false);

        // The following crash JSON parsing
        VERIFY_THROWS(parseAndVerifyProfile(profileWithHyphenlessGuid, false), std::exception);
        VERIFY_THROWS(parseAndVerifyProfile(profileWithRawGuid, false), std::exception);
        VERIFY_THROWS(parseAndVerifyProfile(profileWithGuidFormatP, false), std::exception);

        const auto parsedNullGuidProfile = parseAndVerifyProfile(profileWithNullGuid, true);
        const auto parsedGuidProfileFormatB = parseAndVerifyProfile(profileWithGuidFormatB, true);
        const auto parsedGuidProfileUpperCaseFormatB = parseAndVerifyProfile(profileWithGuidUpperCaseFormatB, true);

        const winrt::guid nullGuid{};
        const winrt::guid cmdGuid = Utils::GuidFromString(L"{6239a42c-1de4-49a3-80bd-e8fdd045185c}");

        VERIFY_ARE_EQUAL(parsedNullGuidProfile->Guid(), nullGuid);
        VERIFY_ARE_EQUAL(parsedGuidProfileFormatB->Guid(), cmdGuid);
        VERIFY_ARE_EQUAL(parsedGuidProfileUpperCaseFormatB->Guid(), cmdGuid);
    }

    void ProfileTests::LayerProfileProperties()
    {
        static constexpr std::string_view profile0String{ R"({
            "name": "profile0",
            "guid": "{6239a42c-1111-49a3-80bd-e8fdd045185c}",
            "foreground": "#000000",
            "background": "#010101",
            "selectionBackground": "#010101"
        })" };