Skip to content

Commit

Permalink
added test for simple template arguments in type signature
Browse files Browse the repository at this point in the history
  • Loading branch information
vt4a2h committed Aug 1, 2015
1 parent 28384d5 commit ba7e5a0
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 14 deletions.
41 changes: 27 additions & 14 deletions gui/componentsmaker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@ namespace gui {
{
{models::DisplayPart::Fields, {{FieldGroupNames::Namespaces, reservedKeywords|types},
{FieldGroupNames::Typename, reservedKeywords},
{FieldGroupNames::Name, types}}},
{FieldGroupNames::Name, types},
{FieldGroupNames::TemplateArgs, reservedKeywords}}},
};

using MakerFunction = std::function<MessageEntity()>;
Expand All @@ -101,12 +102,12 @@ namespace gui {
const QVector<CapIndexKeywords> &rules = componentIndexesMap[display];
for (int groupIndex = 1; groupIndex < groupsCount; ++groupIndex)
{
const QString &cap = match.captured(groupIndex).trimmed();
QString cap = match.captured(groupIndex).trimmed();
captured[groupIndex] = cap;

auto it = utility::find_if(rules, [&](const CapIndexKeywords &c){ return int(c.first) == groupIndex; });
if (it != cend(rules)) {
const QStringList &tmpList = cap.split("::", QString::SkipEmptyParts);
const QStringList &tmpList = cap.remove(QChar::Space).split(QRegExp("::|,"), QString::SkipEmptyParts);
if (!(tmpList.toSet() & it->second).isEmpty()) {
captured.clear();
return false;
Expand Down Expand Up @@ -317,19 +318,31 @@ namespace gui {
}
}

if (extendedType->isConst() || !extendedType->pl().isEmpty()) {
QStringList namespaces = m_LastCaptured[int(FieldGroupNames::Namespaces)]
if (!m_LastCaptured[int(FieldGroupNames::TemplateArgs)].isEmpty()) {
QStringList arguments = m_LastCaptured[int(FieldGroupNames::TemplateArgs)]
.remove(QChar::Space)
.split("::", QString::SkipEmptyParts);
if (!namespaces.isEmpty()) {
} else {
const entity::TypesList &types = m_Scope->types();
auto it = utility::find_if(types, [=](const entity::SharedType &type) {
return extendedType->isEqual(*type, false);
});
if (it == cend(types))
m_Scope->addExistsType(extendedType);
.split(",", QString::SkipEmptyParts);
entity::ScopesList scopes = m_Model->currentProject()->database()->scopes();
scopes.append(m_Model->globalDatabase()->scopes());

// TODO: add namespaces, * and const
for (auto &&name : arguments) {
entity::SharedType t;
utility::find_if(scopes, [&](auto &&sc){ t = sc->typeByName(name); return !!t; });
if (t)
extendedType->addTemplateParameter(t->id());
else
return {tr("Template parameter \"%1\" not found.").arg(name), nullptr};
}
}

if (extendedType->isConst() || !extendedType->templateParameters().isEmpty() || !extendedType->pl().isEmpty()) {
const entity::TypesList &types = m_Scope->types();
auto it = utility::find_if(types, [=](const entity::SharedType &type) {
return extendedType->isEqual(*type, false);
});
if (it == cend(types))
m_Scope->addExistsType(extendedType);

newField->setTypeId(extendedType->id());
} else {
Expand Down
8 changes: 8 additions & 0 deletions tests/test/cases/componentsmakercases.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ namespace {
{"std::vector<int><int> vec", false},
{"std::vector< vec", false},
{"std::vector> vec", false},
{"std::vector<class, const> vec", false},
};

auto to_f(const entity::BasicEntity *e){ return static_cast<const entity::Field*>(e); }
Expand Down Expand Up @@ -113,4 +114,11 @@ TEST_F(ComponentsMaker, MakingField)
ASSERT_TRUE(!!scopeStd) << "Scope std should be found.";
t = m_GlobalDatabase->depthTypeSearch(field->typeId());
ASSERT_TRUE(!!t) << "std::unordered_set should be placed in global database.";

// with templates parameters
result = m_Maker->makeComponent("std::vector<int> v", models::DisplayPart::Fields);
ASSERT_TRUE(result.first.isEmpty()) << "There are some message: " << result.first.toStdString().c_str();
field = to_f(result.second.get());
auto vecOfInt = m_Project->database()->depthTypeSearch(field->typeId());
ASSERT_TRUE(!!vecOfInt) << "Vector of int must be created in project database.";
}

0 comments on commit ba7e5a0

Please sign in to comment.