mirror of
https://github.com/yokemura/Magical8bitPlug2.git
synced 2025-06-03 00:58:05 -04:00
Test split string
This commit is contained in:
parent
60068f313a
commit
b1928a6929
@ -28,12 +28,21 @@ public:
|
||||
// Section index
|
||||
//
|
||||
//-------------------------------------------------------
|
||||
String str_beforeRepeat;
|
||||
String str_insideRepeat;
|
||||
String str_release;
|
||||
|
||||
beginTest ("No repeat");
|
||||
String input1 = "aaa"; // At this phase it doesn't matter if it contains numbers or not
|
||||
auto result1 = parser.findSegment(input1);
|
||||
expect(result1.repeatStartIndex == SegmentIndexes::NONE);
|
||||
expect(result1.repeatEndIndex == SegmentIndexes::NONE);
|
||||
expect(result1.releaseBlockIndex == SegmentIndexes::NONE);
|
||||
|
||||
parser.splitSegment(input1, result1, str_beforeRepeat, str_insideRepeat, str_release);
|
||||
expect(str_beforeRepeat == "aaa");
|
||||
expect(str_insideRepeat == "");
|
||||
expect(str_release == "");
|
||||
|
||||
beginTest ("With repeat, no release");
|
||||
String input2 = "aa[bbb]";
|
||||
@ -42,6 +51,14 @@ public:
|
||||
expect(result2.repeatEndIndex == 6);
|
||||
expect(result2.releaseBlockIndex == SegmentIndexes::NONE);
|
||||
|
||||
str_beforeRepeat = "";
|
||||
str_insideRepeat = "";
|
||||
str_release = "";
|
||||
parser.splitSegment(input2, result2, str_beforeRepeat, str_insideRepeat, str_release);
|
||||
expect(str_beforeRepeat == "aa");
|
||||
expect(str_insideRepeat == "bbb");
|
||||
expect(str_release == "");
|
||||
|
||||
beginTest ("Repeat segment starts from the top");
|
||||
String input3 = "[aaa]";
|
||||
auto result3 = parser.findSegment(input3);
|
||||
@ -49,6 +66,14 @@ public:
|
||||
expect(result3.repeatEndIndex == 4);
|
||||
expect(result3.releaseBlockIndex == SegmentIndexes::NONE);
|
||||
|
||||
str_beforeRepeat = "";
|
||||
str_insideRepeat = "";
|
||||
str_release = "";
|
||||
parser.splitSegment(input3, result3, str_beforeRepeat, str_insideRepeat, str_release);
|
||||
expect(str_beforeRepeat == "");
|
||||
expect(str_insideRepeat == "aaa");
|
||||
expect(str_release == "");
|
||||
|
||||
beginTest ("No repeat, with release");
|
||||
String input4 = "aaa|bbbb";
|
||||
auto result4 = parser.findSegment(input4);
|
||||
@ -56,6 +81,14 @@ public:
|
||||
expect(result4.repeatEndIndex == 3); // It doesn't repeat, but it has to keep the last index of pre-release segment
|
||||
expect(result4.releaseBlockIndex == 4);
|
||||
|
||||
str_beforeRepeat = "";
|
||||
str_insideRepeat = "";
|
||||
str_release = "";
|
||||
parser.splitSegment(input4, result4, str_beforeRepeat, str_insideRepeat, str_release);
|
||||
expect(str_beforeRepeat == "aaa");
|
||||
expect(str_insideRepeat == "");
|
||||
expect(str_release == "bbbb");
|
||||
|
||||
beginTest ("Release segment without pre-release segment");
|
||||
String input5 = "|bbbb";
|
||||
auto result5 = parser.findSegment(input5);
|
||||
@ -63,6 +96,14 @@ public:
|
||||
expect(result5.repeatEndIndex == 0); // This results in an immediate transition to Release Phase
|
||||
expect(result5.releaseBlockIndex == 1);
|
||||
|
||||
str_beforeRepeat = "";
|
||||
str_insideRepeat = "";
|
||||
str_release = "";
|
||||
parser.splitSegment(input5, result5, str_beforeRepeat, str_insideRepeat, str_release);
|
||||
expect(str_beforeRepeat == "");
|
||||
expect(str_insideRepeat == "");
|
||||
expect(str_release == "bbbb");
|
||||
|
||||
beginTest ("Repeat and release (no pre-repeat)");
|
||||
String input6 = "[aaa]|bbbb";
|
||||
auto result6 = parser.findSegment(input6);
|
||||
@ -70,6 +111,14 @@ public:
|
||||
expect(result6.repeatEndIndex == 4);
|
||||
expect(result6.releaseBlockIndex == 6);
|
||||
|
||||
str_beforeRepeat = "";
|
||||
str_insideRepeat = "";
|
||||
str_release = "";
|
||||
parser.splitSegment(input6, result6, str_beforeRepeat, str_insideRepeat, str_release);
|
||||
expect(str_beforeRepeat == "");
|
||||
expect(str_insideRepeat == "aaa");
|
||||
expect(str_release == "bbbb");
|
||||
|
||||
beginTest ("Repeat and release (with pre-repeat)");
|
||||
String input7 = "aaa[bbb]|cccc";
|
||||
auto result7 = parser.findSegment(input7);
|
||||
@ -77,6 +126,14 @@ public:
|
||||
expect(result7.repeatEndIndex == 7);
|
||||
expect(result7.releaseBlockIndex == 9);
|
||||
|
||||
str_beforeRepeat = "";
|
||||
str_insideRepeat = "";
|
||||
str_release = "";
|
||||
parser.splitSegment(input7, result7, str_beforeRepeat, str_insideRepeat, str_release);
|
||||
expect(str_beforeRepeat == "aaa");
|
||||
expect(str_insideRepeat == "bbb");
|
||||
expect(str_release == "cccc");
|
||||
|
||||
beginTest ("Empty repeat section");
|
||||
String input8 = "aaa[]|cccc";
|
||||
auto result8 = parser.findSegment(input8);
|
||||
@ -84,6 +141,14 @@ public:
|
||||
expect(result8.repeatEndIndex == 4);
|
||||
expect(result8.releaseBlockIndex == 6);
|
||||
|
||||
str_beforeRepeat = "";
|
||||
str_insideRepeat = "";
|
||||
str_release = "";
|
||||
parser.splitSegment(input8, result8, str_beforeRepeat, str_insideRepeat, str_release);
|
||||
expect(str_beforeRepeat == "aaa");
|
||||
expect(str_insideRepeat == "");
|
||||
expect(str_release == "cccc");
|
||||
|
||||
beginTest ("Empty release section");
|
||||
String input9 = "aaa[bbb]|";
|
||||
auto result9 = parser.findSegment(input9);
|
||||
@ -91,6 +156,14 @@ public:
|
||||
expect(result9.repeatEndIndex == 7);
|
||||
expect(result9.releaseBlockIndex == 9);
|
||||
|
||||
str_beforeRepeat = "";
|
||||
str_insideRepeat = "";
|
||||
str_release = "";
|
||||
parser.splitSegment(input9, result9, str_beforeRepeat, str_insideRepeat, str_release);
|
||||
expect(str_beforeRepeat == "aaa");
|
||||
expect(str_insideRepeat == "bbb");
|
||||
expect(str_release == "");
|
||||
|
||||
beginTest ("[Error] Multiple open bracket");
|
||||
String input10 = "aaa[[bbb]";
|
||||
auto result10 = parser.findSegment(input10);
|
||||
@ -110,7 +183,7 @@ public:
|
||||
String input13 = "aaa|[bbb]";
|
||||
auto result13 = parser.findSegment(input13);
|
||||
expect(result13.error = kParseErrorRepeatingInReleaseBlock);
|
||||
|
||||
|
||||
//-------------------------------------------------------
|
||||
//
|
||||
// Slope
|
||||
|
@ -58,6 +58,10 @@ String getParseErrorString (ParseError err, int minValue, int maxValue)
|
||||
return TRANS ("Missing destination value before \"in\"");
|
||||
break;
|
||||
|
||||
case kParseErrorMissingSlopeFrameCount:
|
||||
return TRANS ("Frame count should be specified after \"in\"");
|
||||
break;
|
||||
|
||||
case kParseErrorNotANumber:
|
||||
return TRANS ("Number parse failed.");
|
||||
break;
|
||||
|
@ -344,6 +344,46 @@ SegmentIndexes FrameSequenceParser::findSegment(const String& input) {
|
||||
return retval;
|
||||
}
|
||||
|
||||
void FrameSequenceParser::splitSegment (const String& input,
|
||||
SegmentIndexes indexes,
|
||||
String& beforeRepeat,
|
||||
String& insideRepeat,
|
||||
String& afterRelease) {
|
||||
int releaseBlockIndex = indexes.releaseBlockIndex;
|
||||
int repeatStartIndex = indexes.repeatStartIndex;
|
||||
int repeatEndIndex = indexes.repeatEndIndex;
|
||||
|
||||
// Just for convenience
|
||||
bool hasRelease = (releaseBlockIndex >= 0);
|
||||
bool shouldRepeat = (repeatStartIndex >= 0);
|
||||
|
||||
if (shouldRepeat)
|
||||
{
|
||||
if (hasRelease)
|
||||
{
|
||||
beforeRepeat = input.substring(0, repeatStartIndex - 1);
|
||||
insideRepeat = input.substring (repeatStartIndex, repeatEndIndex);
|
||||
afterRelease = input.substring(releaseBlockIndex, input.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
beforeRepeat = input.substring(0, repeatStartIndex - 1);
|
||||
insideRepeat = input.substring (repeatStartIndex, repeatEndIndex);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if (hasRelease) {
|
||||
beforeRepeat = input.substring (0, releaseBlockIndex - 1);
|
||||
afterRelease = input.substring (releaseBlockIndex, input.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
beforeRepeat = input.substring (0, input.length());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
FrameSequence FrameSequenceParser::parse (const String& input,
|
||||
int minValue,
|
||||
int maxValue,
|
||||
@ -366,13 +406,9 @@ FrameSequence FrameSequenceParser::parse (const String& input,
|
||||
//
|
||||
SegmentIndexes si = findSegment(trimmed);
|
||||
|
||||
int releaseBlockIndex = si.releaseBlockIndex;
|
||||
int repeatStartIndex = si.repeatStartIndex;
|
||||
int repeatEndIndex = si.repeatEndIndex;
|
||||
|
||||
// Just for convenience
|
||||
bool hasRelease = (releaseBlockIndex >= 0);
|
||||
bool shouldRepeat = (repeatStartIndex >= 0);
|
||||
bool hasRelease = (si.releaseBlockIndex >= 0);
|
||||
bool shouldRepeat = (si.repeatStartIndex >= 0);
|
||||
|
||||
//-----------------------------------
|
||||
//
|
||||
@ -384,31 +420,7 @@ FrameSequence FrameSequenceParser::parse (const String& input,
|
||||
String str_insideRepeat;
|
||||
String str_release;
|
||||
|
||||
if (shouldRepeat)
|
||||
{
|
||||
if (hasRelease)
|
||||
{
|
||||
str_release = trimmed.substring(releaseBlockIndex, trimmed.length());
|
||||
}
|
||||
str_beforeRepeat = trimmed.substring(0, repeatStartIndex - 1);
|
||||
str_insideRepeat = trimmed.substring (repeatStartIndex, repeatEndIndex); }
|
||||
else
|
||||
{
|
||||
if (hasRelease)
|
||||
{
|
||||
str_beforeRepeat = trimmed.substring (0, releaseBlockIndex - 1);
|
||||
str_release = trimmed.substring (releaseBlockIndex, trimmed.length());
|
||||
}
|
||||
else
|
||||
{
|
||||
str_beforeRepeat = trimmed.substring (0, trimmed.length());
|
||||
}
|
||||
}
|
||||
|
||||
std::cout << "before repeat : " + str_beforeRepeat + "\n";
|
||||
std::cout << "inside repeat : " + str_insideRepeat + "\n";
|
||||
std::cout << "after release : " + str_release + "\n";
|
||||
|
||||
splitSegment(trimmed, si, str_beforeRepeat, str_insideRepeat, str_release);
|
||||
|
||||
//-----------------------------------
|
||||
//
|
||||
|
@ -44,5 +44,10 @@ struct FrameSequenceParser
|
||||
int minValue,
|
||||
int maxValue,
|
||||
ParseError* error);
|
||||
void splitSegment (const String& input,
|
||||
SegmentIndexes indexes,
|
||||
String& beforeRepeat,
|
||||
String& insideRepeat,
|
||||
String& afterRelease);
|
||||
SegmentIndexes findSegment(const String& input);
|
||||
};
|
||||
|
Loading…
x
Reference in New Issue
Block a user