|
5 | 5 |
|
6 | 6 | #include <inflection/dialog/InflectableStringConcept.hpp> |
7 | 7 | #include <inflection/dialog/SemanticFeatureModel.hpp> |
| 8 | +#include <inflection/dialog/SemanticFeature.hpp> |
8 | 9 | #include <inflection/dialog/SpeakableString.hpp> |
9 | 10 | #include <inflection/dialog/LocalizedCommonConceptFactoryProvider.hpp> |
10 | 11 | #include <inflection/exception/XMLParseException.hpp> |
@@ -35,9 +36,26 @@ static std::string getInfoStringForTestInput(const ::inflection::dialog::Semanti |
35 | 36 | return "locale=" + model.getLocale().getName() + (source.isEmpty() ? "" : std::string(" source=") + inflection::util::StringUtils::to_string(source.toString())) + " {" + constraintsStr + "}"; |
36 | 37 | } |
37 | 38 |
|
38 | | -static void compareInflection(const ::inflection::dialog::SemanticFeatureModel& model, const ::inflection::dialog::SpeakableString& expected, const ::inflection::dialog::SpeakableString& source, const std::map<std::u16string, std::u16string>& constraints, const std::map<std::u16string, std::u16string>& resultAttributes) |
| 39 | +static void compareInflection(const ::inflection::dialog::SemanticFeatureModel& model, |
| 40 | + const ::inflection::dialog::SpeakableString& expected, |
| 41 | + const ::inflection::dialog::SpeakableString& source, |
| 42 | + const std::map<std::u16string, std::u16string>& constraints, |
| 43 | + const std::map<std::u16string, std::u16string>& resultAttributes, |
| 44 | + const std::map<std::u16string, std::u16string>& initialAttributes) |
39 | 45 | { |
40 | | - inflection::dialog::InflectableStringConcept inflectableConcept(&model, source); |
| 46 | + std::map<inflection::dialog::SemanticFeature, ::std::u16string> intitialConstraints; |
| 47 | + for(const auto& [attrKey, attrVal] : initialAttributes) { |
| 48 | + auto featureName = model.getFeature(attrKey); |
| 49 | + if (featureName == nullptr) { |
| 50 | + FAIL_CHECK(model.getLocale().getName() + std::string(": feature name is not recognized: ") + inflection::util::StringUtils::to_string(attrKey)); |
| 51 | + } |
| 52 | + const auto& boundedValues(npc(featureName)->getBoundedValues()); |
| 53 | + if (!boundedValues.empty() && boundedValues.find(attrVal) == boundedValues.end()) { |
| 54 | + FAIL_CHECK(model.getLocale().getName() + std::string(": feature value \"") + inflection::util::StringUtils::to_string(attrVal) + "\" is not valid for feature \"" + inflection::util::StringUtils::to_string(attrKey) + "\""); |
| 55 | + } |
| 56 | + intitialConstraints[*featureName] = attrVal; |
| 57 | + } |
| 58 | + inflection::dialog::InflectableStringConcept inflectableConcept(&model, source, intitialConstraints); |
41 | 59 | for (const auto& constraint : constraints) { |
42 | 60 | auto featureName = model.getFeature(constraint.first); |
43 | 61 | if (featureName == nullptr) { |
@@ -171,16 +189,26 @@ TEST_CASE("InflectionTest#testInflections") |
171 | 189 | if (xmlStrEqual(sourceNode->name, (const xmlChar *) "source") == 0) { |
172 | 190 | throw ::inflection::exception::XMLParseException(u"Expecting element <source>, got <" + ::inflection::util::StringUtils::to_u16string(std::string(reinterpret_cast<const char*>(sourceNode->name))) + u">"); |
173 | 191 | } |
174 | | - xmlNodePtr resultNode = xmlNextElementSibling(sourceNode); |
175 | | - if (xmlStrEqual(resultNode->name, (const xmlChar *) "result") == 0) { |
176 | | - throw ::inflection::exception::XMLParseException(u"Expecting element <result>, got <" + ::inflection::util::StringUtils::to_u16string(std::string(reinterpret_cast<const char*>(resultNode->name))) + u">"); |
| 192 | + |
| 193 | + // optional initial child tag |
| 194 | + curTestChild = xmlNextElementSibling(sourceNode); |
| 195 | + xmlNodePtr initialNode = nullptr; |
| 196 | + if(xmlStrEqual(curTestChild->name, (const xmlChar*) "initial") != 0) { |
| 197 | + initialNode = curTestChild; |
| 198 | + curTestChild = xmlNextElementSibling(curTestChild); |
| 199 | + } |
| 200 | + |
| 201 | + if (xmlStrEqual(curTestChild->name, (const xmlChar *) "result") == 0) { |
| 202 | + throw ::inflection::exception::XMLParseException(u"Expecting element <result>, got <" + ::inflection::util::StringUtils::to_u16string(std::string(reinterpret_cast<const char*>(curTestChild->name))) + u">"); |
177 | 203 | } |
| 204 | + xmlNodePtr resultNode = curTestChild; |
178 | 205 | auto sourceConstraints(XMLUtils::getAttributes(sourceNode)); |
179 | 206 | auto resultAttributes(XMLUtils::getAttributes(resultNode)); |
| 207 | + auto initialAttributes(XMLUtils::getAttributes(initialNode)); |
180 | 208 | auto sourceString(getSpeakableString(sourceNode)); |
181 | 209 | auto resultString(getSpeakableString(resultNode)); |
182 | 210 |
|
183 | | - compareInflection(*npc(model), resultString, sourceString, sourceConstraints, resultAttributes); |
| 211 | + compareInflection(*npc(model), resultString, sourceString, sourceConstraints, resultAttributes, initialAttributes); |
184 | 212 | numTests++; |
185 | 213 | } |
186 | 214 | xmlFreeDoc(xmlDoc); |
|
0 commit comments