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

Commit

Permalink
Merge pull request #398 from goganchic/master
Browse files Browse the repository at this point in the history
Add typed attribute
  • Loading branch information
pksunkara authored Aug 4, 2016
2 parents d3701c5 + 4734229 commit f41c5b1
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/MSON.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,12 +130,13 @@ namespace mson {

/** Attribute of a type */
enum TypeAttribute {
RequiredTypeAttribute = (1 << 0), // The type is required
OptionalTypeAttribute = (1 << 1), // The type is optional
FixedTypeAttribute = (1 << 2), // The type is fixed
SampleTypeAttribute = (1 << 3), // The type is a sample
DefaultTypeAttribute = (1 << 4), // The type is default
NullableTypeAttribute = (1 << 5) // The type is nullable
RequiredTypeAttribute = (1 << 0), // The type is required
OptionalTypeAttribute = (1 << 1), // The type is optional
FixedTypeAttribute = (1 << 2), // The type is fixed
SampleTypeAttribute = (1 << 3), // The type is a sample
DefaultTypeAttribute = (1 << 4), // The type is default
NullableTypeAttribute = (1 << 5), // The type is nullable
FixedTypeTypeAttribute = (1 << 6) // This type works like fixed, but it is unheritable
};

/** List of type attributes */
Expand Down
3 changes: 3 additions & 0 deletions src/MSONUtility.h
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,9 @@ namespace mson {
else if (attribute == "nullable") {
typeAttributes |= NullableTypeAttribute;
}
else if (attribute == "fixed-type") {
typeAttributes |= FixedTypeTypeAttribute;
}
else {
isAttribute = false;
}
Expand Down
25 changes: 25 additions & 0 deletions test/test-MSONUtility.cc
Original file line number Diff line number Diff line change
Expand Up @@ -188,6 +188,7 @@ TEST_CASE("Parse required type attribute", "[mson][utility]")
REQUIRE((typeAttributes & SampleTypeAttribute) == 0);
REQUIRE((typeAttributes & DefaultTypeAttribute) == 0);
REQUIRE((typeAttributes & NullableTypeAttribute) == 0);
REQUIRE((typeAttributes & FixedTypeTypeAttribute) == 0);
REQUIRE(isAttributeParsed);
}

Expand All @@ -205,6 +206,7 @@ TEST_CASE("Parse optional type attribute", "[mson][utility]")
REQUIRE((typeAttributes & SampleTypeAttribute) == 0);
REQUIRE((typeAttributes & DefaultTypeAttribute) == 0);
REQUIRE((typeAttributes & NullableTypeAttribute) == 0);
REQUIRE((typeAttributes & FixedTypeTypeAttribute) == 0);
REQUIRE(isAttributeParsed);
}

Expand All @@ -222,6 +224,7 @@ TEST_CASE("Parse fixed type attribute", "[mson][utility]")
REQUIRE((typeAttributes & SampleTypeAttribute) == 0);
REQUIRE((typeAttributes & DefaultTypeAttribute) == 0);
REQUIRE((typeAttributes & NullableTypeAttribute) == 0);
REQUIRE((typeAttributes & FixedTypeTypeAttribute) == 0);
REQUIRE(isAttributeParsed);
}

Expand All @@ -239,6 +242,7 @@ TEST_CASE("Parse sample type attribute", "[mson][utility]")
REQUIRE((typeAttributes & SampleTypeAttribute) == SampleTypeAttribute);
REQUIRE((typeAttributes & DefaultTypeAttribute) == 0);
REQUIRE((typeAttributes & NullableTypeAttribute) == 0);
REQUIRE((typeAttributes & FixedTypeTypeAttribute) == 0);
REQUIRE(isAttributeParsed);
}

Expand All @@ -256,6 +260,7 @@ TEST_CASE("Parse default type attribute", "[mson][utility]")
REQUIRE((typeAttributes & SampleTypeAttribute) == 0);
REQUIRE((typeAttributes & DefaultTypeAttribute) == DefaultTypeAttribute);
REQUIRE((typeAttributes & NullableTypeAttribute) == 0);
REQUIRE((typeAttributes & FixedTypeTypeAttribute) == 0);
REQUIRE(isAttributeParsed);
}

Expand All @@ -273,6 +278,25 @@ TEST_CASE("Parse nullable type attribute", "[mson][utility]")
REQUIRE((typeAttributes & SampleTypeAttribute) == 0);
REQUIRE((typeAttributes & DefaultTypeAttribute) == 0);
REQUIRE((typeAttributes & NullableTypeAttribute) == NullableTypeAttribute);
REQUIRE((typeAttributes & FixedTypeTypeAttribute) == 0);
REQUIRE(isAttributeParsed);
}

TEST_CASE("Parse typed type attribute", "[mson][utility]")
{
std::string source = "fixed-type";
TypeAttributes typeAttributes = 0;

bool isAttributeParsed;
isAttributeParsed = parseTypeAttribute(source, typeAttributes);

REQUIRE((typeAttributes & RequiredTypeAttribute) == 0);
REQUIRE((typeAttributes & OptionalTypeAttribute) == 0);
REQUIRE((typeAttributes & FixedTypeAttribute) == 0);
REQUIRE((typeAttributes & SampleTypeAttribute) == 0);
REQUIRE((typeAttributes & DefaultTypeAttribute) == 0);
REQUIRE((typeAttributes & NullableTypeAttribute) == 0);
REQUIRE((typeAttributes & FixedTypeTypeAttribute) == FixedTypeTypeAttribute);
REQUIRE(isAttributeParsed);
}

Expand All @@ -290,6 +314,7 @@ TEST_CASE("Parse required type attribute enclosed in backticks", "[mson][utility
REQUIRE((typeAttributes & SampleTypeAttribute) == 0);
REQUIRE((typeAttributes & DefaultTypeAttribute) == 0);
REQUIRE((typeAttributes & NullableTypeAttribute) == 0);
REQUIRE((typeAttributes & FixedTypeTypeAttribute) == 0);
REQUIRE(isAttributeParsed == false);
}

Expand Down

0 comments on commit f41c5b1

Please sign in to comment.