Skip to content
This repository has been archived by the owner on Oct 1, 2018. It is now read-only.

Commit

Permalink
Added tests for #138 and #362
Browse files Browse the repository at this point in the history
  • Loading branch information
pksunkara committed Apr 5, 2016
1 parent 5063816 commit 23e2221
Showing 1 changed file with 67 additions and 25 deletions.
92 changes: 67 additions & 25 deletions test/test-BlueprintParser.cc
Original file line number Diff line number Diff line change
Expand Up @@ -413,7 +413,7 @@ TEST_CASE("Parsing unexpected blocks", "[blueprint]")
"# GET /\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
REQUIRE(blueprint.report.warnings.size() == 1); // no response
Expand Down Expand Up @@ -607,7 +607,7 @@ TEST_CASE("Parser blueprint correctly when having a big chain of inheritance in
"Clone\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
REQUIRE(blueprint.report.warnings.empty());
Expand Down Expand Up @@ -644,7 +644,7 @@ TEST_CASE("Report error when coming across a super type reference to non existen
"+ id: 25OFF (string)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 62, 27);
Expand All @@ -659,7 +659,7 @@ TEST_CASE("Report error when a Data Structure inherits from itself", "[blueprint
"+ id (string)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 19, 9);
Expand All @@ -674,7 +674,7 @@ TEST_CASE("Report error when named type inherits a sub type in array", "[bluepri
"## B (A)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 35, 9);
Expand All @@ -690,7 +690,7 @@ TEST_CASE("Report error when data Structure inheritance graph contains a cycle",
"## C (A)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 19, 9);
Expand All @@ -708,7 +708,7 @@ TEST_CASE("Report error when data Structure inheritance graph with only a few of
"## E (C)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 37, 9);
Expand All @@ -724,7 +724,7 @@ TEST_CASE("Do not report error when named sub type is referenced in nested membe
"+ person (A)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
REQUIRE(blueprint.report.warnings.empty());
Expand Down Expand Up @@ -767,7 +767,7 @@ TEST_CASE("Do not report error when there are circular references in nested memb
"+ id (B)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
REQUIRE(blueprint.report.warnings.empty());
Expand Down Expand Up @@ -823,7 +823,7 @@ TEST_CASE("Do not report error when named sub type is referenced in nested membe
"## A (B)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
REQUIRE(blueprint.report.warnings.empty());
Expand Down Expand Up @@ -867,7 +867,7 @@ TEST_CASE("Do not report error when a resource attributes type is circularly ref
"+ posts (Post)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
REQUIRE(blueprint.report.warnings.empty());
Expand Down Expand Up @@ -918,7 +918,7 @@ TEST_CASE("Report error when named sub type is referenced as mixin", "[blueprint
"+ Include A\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 35, 10);
Expand All @@ -935,7 +935,7 @@ TEST_CASE("Report error when named sub type is referenced as mixin when referenc
"## A (B)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 26, 10);
Expand All @@ -953,7 +953,7 @@ TEST_CASE("Report error when circular reference in mixins", "[blueprint]")
"+ Include A\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 45, 10);
Expand All @@ -969,7 +969,7 @@ TEST_CASE("Do not report error when named type references itself in array", "[bl
"+ children (array[Comment])\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
REQUIRE(blueprint.report.warnings.empty());
Expand Down Expand Up @@ -1009,7 +1009,7 @@ TEST_CASE("Report error when a named type is defined twice with inheritance", "[
"## C (object)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 19, 9);
Expand All @@ -1024,7 +1024,7 @@ TEST_CASE("Report error when a named type is defined twice with base type", "[bl
"## A (object)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 33, 14);
Expand All @@ -1040,7 +1040,7 @@ TEST_CASE("Report error when a named type is defined twice, once with base type
"## B (object)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
SourceMapHelper::check(blueprint.report.error.location, 28, 14);
Expand All @@ -1053,7 +1053,7 @@ TEST_CASE("Parse mson signature attributes with mismatched square brackets", "[b
"+ Attributes (array[Note)";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
}
Expand All @@ -1065,7 +1065,7 @@ TEST_CASE("Parse named type mson signature attributes with no closing bracket",
"## B (A(";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
REQUIRE(blueprint.report.error.message == "base type 'A(' is not defined in the document");
Expand All @@ -1084,7 +1084,7 @@ TEST_CASE("Parse correctly when a resource named type is non-circularly referenc
" + bla (Question)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
}
Expand All @@ -1097,7 +1097,7 @@ TEST_CASE("Report error when not finding a super type of the nested member", "[b
"+ choice (B)\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
REQUIRE(blueprint.report.error.message == "base type 'B' is not defined in the document");
Expand All @@ -1111,7 +1111,7 @@ TEST_CASE("Report error when not finding a nested super type of the nested membe
"+ choice (array[B])\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
REQUIRE(blueprint.report.error.message == "base type 'B' is not defined in the document");
Expand All @@ -1125,7 +1125,7 @@ TEST_CASE("Report error when not finding a mixin type", "[blueprint]")
"+ Include B\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == MSONError);
REQUIRE(blueprint.report.error.message == "base type 'B' is not defined in the document");
Expand Down Expand Up @@ -1241,7 +1241,7 @@ TEST_CASE("Any named type data structure should be able to be overridden when re
" + relation: family\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption, Models(), &blueprint);
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
REQUIRE(blueprint.report.warnings.empty());
Expand Down Expand Up @@ -1301,3 +1301,45 @@ TEST_CASE("Any named type data structure should be able to be overridden when re
REQUIRE(property3.valueDefinition.values[0].literal == "family");
REQUIRE(property3.valueDefinition.typeDefinition.empty());
}

TEST_CASE("Parse attributes with mixin and no base type mentioned for attributes", "[blueprint][#362]")
{
mdp::ByteBuffer source = \
"# GET /\n"\
"+ Response 200\n"\
" + Attributes\n"\
" + Include A\n"\
"\n"\
"# Data Structures\n"\
"\n"\
"## A (object)\n"\
"+ a: a\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
REQUIRE(blueprint.report.warnings.empty());
REQUIRE(blueprint.node.content.elements().size() == 2);
}

TEST_CASE("Parse attributes with mixin and no base type mentioned for mixin", "[blueprint][#138]")
{
mdp::ByteBuffer source = \
"# GET /\n"\
"+ Response 200\n"\
" + Attributes (object)\n"\
" + Include A\n"\
"\n"\
"# Data Structures\n"\
"\n"\
"## A\n"\
"+ a: a\n";

ParseResult<Blueprint> blueprint;
SectionParserHelper<Blueprint, BlueprintParser>::parse(source, BlueprintSectionType, blueprint, ExportSourcemapOption);

REQUIRE(blueprint.report.error.code == Error::OK);
REQUIRE(blueprint.report.warnings.empty());
REQUIRE(blueprint.node.content.elements().size() == 2);
}

0 comments on commit 23e2221

Please sign in to comment.