mirror of
https://github.com/yokemura/Magical8bitPlug2.git
synced 2025-05-24 23:00:21 -04:00
Hold Parser test (and related renames)
This commit is contained in:
parent
252a84d618
commit
60068f313a
@ -121,6 +121,7 @@ public:
|
|||||||
beginTest ("Down slope");
|
beginTest ("Down slope");
|
||||||
String input14 = "3to0in4";
|
String input14 = "3to0in4";
|
||||||
std::vector<int> result14 = parser.parseSlope(input14, 0, 15, &error);
|
std::vector<int> result14 = parser.parseSlope(input14, 0, 15, &error);
|
||||||
|
expect(result14.size() == 4);
|
||||||
expect(result14[0] == 3);
|
expect(result14[0] == 3);
|
||||||
expect(result14[1] == 2);
|
expect(result14[1] == 2);
|
||||||
expect(result14[2] == 1);
|
expect(result14[2] == 1);
|
||||||
@ -129,6 +130,7 @@ public:
|
|||||||
beginTest ("Slow decrement");
|
beginTest ("Slow decrement");
|
||||||
String input15 = "2to0in8";
|
String input15 = "2to0in8";
|
||||||
std::vector<int> result15 = parser.parseSlope(input15, 0, 15, &error);
|
std::vector<int> result15 = parser.parseSlope(input15, 0, 15, &error);
|
||||||
|
expect(result15.size() == 8);
|
||||||
expect(result15[0] == 2);
|
expect(result15[0] == 2);
|
||||||
expect(result15[1] == 2);
|
expect(result15[1] == 2);
|
||||||
expect(result15[2] == 1);
|
expect(result15[2] == 1);
|
||||||
@ -141,6 +143,7 @@ public:
|
|||||||
beginTest ("Fast decrement");
|
beginTest ("Fast decrement");
|
||||||
String input16 = "15to0in5";
|
String input16 = "15to0in5";
|
||||||
std::vector<int> result16 = parser.parseSlope(input16, 0, 15, &error);
|
std::vector<int> result16 = parser.parseSlope(input16, 0, 15, &error);
|
||||||
|
expect(result16.size() == 5);
|
||||||
expect(result16[0] == 15);
|
expect(result16[0] == 15);
|
||||||
expect(result16[1] == 11);
|
expect(result16[1] == 11);
|
||||||
expect(result16[2] == 8);
|
expect(result16[2] == 8);
|
||||||
@ -150,6 +153,7 @@ public:
|
|||||||
beginTest ("Up slope");
|
beginTest ("Up slope");
|
||||||
String input17 = "0to3in4";
|
String input17 = "0to3in4";
|
||||||
std::vector<int> result17 = parser.parseSlope(input17, 0, 15, &error);
|
std::vector<int> result17 = parser.parseSlope(input17, 0, 15, &error);
|
||||||
|
expect(result17.size() == 4);
|
||||||
expect(result17[0] == 0);
|
expect(result17[0] == 0);
|
||||||
expect(result17[1] == 1);
|
expect(result17[1] == 1);
|
||||||
expect(result17[2] == 2);
|
expect(result17[2] == 2);
|
||||||
@ -175,12 +179,28 @@ public:
|
|||||||
std::vector<int> result21 = parser.parseSlope(input21, 0, 15, &error);
|
std::vector<int> result21 = parser.parseSlope(input21, 0, 15, &error);
|
||||||
expect(error == kParseErrorMissingSlopeFrameCount);
|
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);
|
||||||
|
|
||||||
//-------------------------------------------------------
|
beginTest ("[Error] Missing value");
|
||||||
//
|
String input23 = "x3";
|
||||||
// Repeat
|
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);
|
||||||
|
|
||||||
//-------------------------------------------------------
|
//-------------------------------------------------------
|
||||||
//
|
//
|
||||||
|
@ -70,11 +70,11 @@ String getParseErrorString (ParseError err, int minValue, int maxValue)
|
|||||||
return TRANS ("Frame count should be more than 2");
|
return TRANS ("Frame count should be more than 2");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kParseErrorMissingValueForRepeatDelimiter:
|
case kParseErrorMissingHoldValue:
|
||||||
return TRANS ("Operator x should be followed by a number.");
|
return TRANS ("Operator x should be followed by a number.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case kParseErrorMissingFrameCountForRepeatDelimiter:
|
case kParseErrorMissingHoldFrameCount:
|
||||||
return TRANS ("A number should be specified after operator x.");
|
return TRANS ("A number should be specified after operator x.");
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
@ -31,8 +31,8 @@ enum ParseError
|
|||||||
kParseErrorNotANumber,
|
kParseErrorNotANumber,
|
||||||
kParseErrorValueOutOfRange,
|
kParseErrorValueOutOfRange,
|
||||||
kParseErrorFrameLengthTooShort,
|
kParseErrorFrameLengthTooShort,
|
||||||
kParseErrorMissingValueForRepeatDelimiter,
|
kParseErrorMissingHoldValue,
|
||||||
kParseErrorMissingFrameCountForRepeatDelimiter,
|
kParseErrorMissingHoldFrameCount,
|
||||||
};
|
};
|
||||||
|
|
||||||
String getParseErrorString (ParseError err, int minValue = 0, int maxValue = 0);
|
String getParseErrorString (ParseError err, int minValue = 0, int maxValue = 0);
|
||||||
|
@ -116,7 +116,7 @@ std::vector<int> FrameSequenceParser::parseSlope (const String& input,
|
|||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<int> FrameSequenceParser::parseRepeat (const String& input,
|
std::vector<int> FrameSequenceParser::parseHold (const String& input,
|
||||||
int minValue,
|
int minValue,
|
||||||
int maxValue,
|
int maxValue,
|
||||||
ParseError* error)
|
ParseError* error)
|
||||||
@ -127,13 +127,13 @@ std::vector<int> FrameSequenceParser::parseRepeat (const String& input,
|
|||||||
|
|
||||||
if (xIndex < 1)
|
if (xIndex < 1)
|
||||||
{
|
{
|
||||||
*error = kParseErrorMissingValueForRepeatDelimiter;
|
*error = kParseErrorMissingHoldValue;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (xIndex > input.length() - 1)
|
if (xIndex >= input.length() - 1)
|
||||||
{
|
{
|
||||||
*error = kParseErrorMissingFrameCountForRepeatDelimiter;
|
*error = kParseErrorMissingHoldFrameCount;
|
||||||
return retval;
|
return retval;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -195,7 +195,7 @@ std::vector<int> FrameSequenceParser::parseSegment (const String& input,
|
|||||||
else if (aToken.contains ("x"))
|
else if (aToken.contains ("x"))
|
||||||
{
|
{
|
||||||
// parse as repeat-fixed-value
|
// parse as repeat-fixed-value
|
||||||
parsed = parseRepeat (aToken, minValue, maxValue, error);
|
parsed = parseHold (aToken, minValue, maxValue, error);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -36,7 +36,7 @@ struct FrameSequenceParser
|
|||||||
int minValue,
|
int minValue,
|
||||||
int maxValue,
|
int maxValue,
|
||||||
ParseError* error);
|
ParseError* error);
|
||||||
std::vector<int> parseRepeat (const String& input,
|
std::vector<int> parseHold (const String& input,
|
||||||
int minValue,
|
int minValue,
|
||||||
int maxValue,
|
int maxValue,
|
||||||
ParseError* error);
|
ParseError* error);
|
||||||
|
Loading…
Reference in New Issue
Block a user