Repository navigation
checkEqual compares only real strings by their characters [#739] - #744
Open
ambroise-leclerc wants to merge 1 commit into
Open
ambroise-leclerc wants to merge 1 commit into
ambroise-leclerc wants to merge 1 commit into
Conversation
A type that merely converts to std::string_view, such as nlohmann::json with MSVC, took the string path of impl::equal and impl::append: checkEqual(json, "text") converted the JSON value and threw instead of comparing with ==. The string path is now taken for C strings, character arrays, std::string, std::string_view and the classes derived from them, or a type that opts in with webfront::bdd::isString. Other types are compared with == and written by their Printer.
This branch has not been deployed
This file contains hidden or 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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #739.
Problem
impl::equalandimpl::append(bdd/Core.hpp) took the string path for any type withstd::is_convertible_v<const T&, std::string_view>. With MSVC,nlohmann::jsonhas an implicit, templated conversion tostd::string_view, socheckEqual(json, "text"),checkEqual(json, json)andcheckEqual(json, std::string)converted the JSON value and threwtype_error.302instead of comparing with==.Changes
char*,const char*, a character array), astd::stringor astd::string_view, or a class derived from them (impl::String). A type that merely converts tostd::string_viewis compared with==and written by itsPrinter(or{?}in the operands of a failure).template <> inline constexpr bool webfront::bdd::isString<Name> = true;.docs/BDD.mddocuments the rule and the opt-in; changelog: aBreakingentry (such a type is no longer written as text byinfo(),fail()andcheckEqualunless it opts in or has aPrinter) and aFixedentry.Tests
BddSelfTestgains aJsontype that mimicsnlohmann::jsonwith MSVC (a templated implicit conversion tostd::string_viewthat throws unless it holds a string):checkEqual(object, object),checkEqual(object, "text"),checkEqual(object, std::string)compare with==; a failedcheckEqual(Json{...}, "text")is written by itsPrinter; a type opting in withisStringis compared by its characters; static checks ofimpl::String.