Add support for TEST_RANGE with exclusive end

If the range is <start, end, step> instead of [start, end, step], the
end value will not be included in the range.

This can be useful if you have a define that defines e.g. the size of
something and you want to use this define as the end value. As the
pre-processor doesn't evalutate expressions (unless you do some macro
magic) you can't specify the range as [0, MY_SIZE - 1, 1]. With this
change you can then instead give the range <0, MY_SIZE, 1>.
This commit is contained in:
Erik Flodin
2021-04-16 12:02:15 +02:00
committed by Erik Flodin
parent 22777c4810
commit 563786f97c
3 changed files with 32 additions and 5 deletions

View File

@ -173,6 +173,32 @@ void test_CharsArePreserved(unsigned index, char c)
NextExpectedCharIndex++;
}
TEST_RANGE([0, 10, 2])
void test_SingleRange(unsigned value)
{
TEST_ASSERT_EQUAL(0, value % 2);
TEST_ASSERT_LESS_OR_EQUAL(10, value);
}
TEST_RANGE([1, 2, 1], [2, 1, -1])
void test_TwoRanges(unsigned first, unsigned second)
{
TEST_ASSERT_LESS_OR_EQUAL(4, first * second);
}
TEST_RANGE(<0, 10, 2>)
void test_SingleExclusiveRange(unsigned value)
{
TEST_ASSERT_EQUAL(0, value % 2);
TEST_ASSERT_LESS_THAN(10, value);
}
TEST_RANGE([2, 4, 1], <1, 2, 1>)
void test_BothInclusiveAndExclusiveRange(unsigned first, unsigned second)
{
TEST_ASSERT_LESS_THAN(first, second);
}
TEST_CASE(0,
1)