Hold Parser test (and related renames)

This commit is contained in:
Takeshi Yokemura 2021-08-15 15:58:46 +09:00
parent 252a84d618
commit 60068f313a
5 changed files with 35 additions and 15 deletions

View File

@ -121,6 +121,7 @@ public:
beginTest ("Down slope");
String input14 = "3to0in4";
std::vector<int> result14 = parser.parseSlope(input14, 0, 15, &error);
expect(result14.size() == 4);
expect(result14[0] == 3);
expect(result14[1] == 2);
expect(result14[2] == 1);
@ -129,6 +130,7 @@ public:
beginTest ("Slow decrement");
String input15 = "2to0in8";
std::vector<int> result15 = parser.parseSlope(input15, 0, 15, &error);
expect(result15.size() == 8);
expect(result15[0] == 2);
expect(result15[1] == 2);
expect(result15[2] == 1);
@ -141,6 +143,7 @@ public:
beginTest ("Fast decrement");
String input16 = "15to0in5";
std::vector<int> result16 = parser.parseSlope(input16, 0, 15, &error);
expect(result16.size() == 5);
expect(result16[0] == 15);
expect(result16[1] == 11);
expect(result16[2] == 8);
@ -150,6 +153,7 @@ public:
beginTest ("Up slope");
String input17 = "0to3in4";
std::vector<int> result17 = parser.parseSlope(input17, 0, 15, &error);
expect(result17.size() == 4);
expect(result17[0] == 0);
expect(result17[1] == 1);
expect(result17[2] == 2);
@ -175,12 +179,28 @@ public:
std::vector<int> result21 = parser.parseSlope(input21, 0, 15, &error);
expect(error == kParseErrorMissingSlopeFrameCount);
//-------------------------------------------------------
//
// Hold
//
//-------------------------------------------------------
beginTest ("Hold");
String input22 = "15x3";
std::vector<int> result22 = parser.parseHold(input22, 0, 15, &error);
expect(result22.size() == 3);
expect(result22[0] == 15);
expect(result22[1] == 15);
expect(result22[2] == 15);
//-------------------------------------------------------
//
// Repeat
//
//-------------------------------------------------------
beginTest ("[Error] Missing value");
String input23 = "x3";
std::vector<int> result23 = parser.parseHold(input23, 0, 15, &error);
expect(error == kParseErrorMissingHoldValue);
beginTest ("[Error] Missing value");
String input24 = "3x";
std::vector<int> result24 = parser.parseHold(input24, 0, 15, &error);
expect(error == kParseErrorMissingHoldFrameCount);
//-------------------------------------------------------
//

View File

@ -70,11 +70,11 @@ String getParseErrorString (ParseError err, int minValue, int maxValue)
return TRANS ("Frame count should be more than 2");
break;
case kParseErrorMissingValueForRepeatDelimiter:
case kParseErrorMissingHoldValue:
return TRANS ("Operator x should be followed by a number.");
break;
case kParseErrorMissingFrameCountForRepeatDelimiter:
case kParseErrorMissingHoldFrameCount:
return TRANS ("A number should be specified after operator x.");
break;

View File

@ -31,8 +31,8 @@ enum ParseError
kParseErrorNotANumber,
kParseErrorValueOutOfRange,
kParseErrorFrameLengthTooShort,
kParseErrorMissingValueForRepeatDelimiter,
kParseErrorMissingFrameCountForRepeatDelimiter,
kParseErrorMissingHoldValue,
kParseErrorMissingHoldFrameCount,
};
String getParseErrorString (ParseError err, int minValue = 0, int maxValue = 0);

View File

@ -116,7 +116,7 @@ std::vector<int> FrameSequenceParser::parseSlope (const String& input,
return retval;
}
std::vector<int> FrameSequenceParser::parseRepeat (const String& input,
std::vector<int> FrameSequenceParser::parseHold (const String& input,
int minValue,
int maxValue,
ParseError* error)
@ -127,13 +127,13 @@ std::vector<int> FrameSequenceParser::parseRepeat (const String& input,
if (xIndex < 1)
{
*error = kParseErrorMissingValueForRepeatDelimiter;
*error = kParseErrorMissingHoldValue;
return retval;
}
if (xIndex > input.length() - 1)
if (xIndex >= input.length() - 1)
{
*error = kParseErrorMissingFrameCountForRepeatDelimiter;
*error = kParseErrorMissingHoldFrameCount;
return retval;
}
@ -195,7 +195,7 @@ std::vector<int> FrameSequenceParser::parseSegment (const String& input,
else if (aToken.contains ("x"))
{
// parse as repeat-fixed-value
parsed = parseRepeat (aToken, minValue, maxValue, error);
parsed = parseHold (aToken, minValue, maxValue, error);
}
else
{

View File

@ -36,7 +36,7 @@ struct FrameSequenceParser
int minValue,
int maxValue,
ParseError* error);
std::vector<int> parseRepeat (const String& input,
std::vector<int> parseHold (const String& input,
int minValue,
int maxValue,
ParseError* error);