From 60068f313a6b0a21c8bd7ba110d6c44d3e41d485 Mon Sep 17 00:00:00 2001 From: Takeshi Yokemura Date: Sun, 15 Aug 2021 15:58:46 +0900 Subject: [PATCH] Hold Parser test (and related renames) --- Source/EnvelopeParserTest.h | 30 ++++++++++++++++++++++++----- Source/FrameSequenceParseErrors.cpp | 4 ++-- Source/FrameSequenceParseErrors.h | 4 ++-- Source/FrameSequenceParser.cpp | 10 +++++----- Source/FrameSequenceParser.h | 2 +- 5 files changed, 35 insertions(+), 15 deletions(-) diff --git a/Source/EnvelopeParserTest.h b/Source/EnvelopeParserTest.h index d9f8043..b860700 100644 --- a/Source/EnvelopeParserTest.h +++ b/Source/EnvelopeParserTest.h @@ -121,6 +121,7 @@ public: beginTest ("Down slope"); String input14 = "3to0in4"; std::vector 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 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 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 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 result21 = parser.parseSlope(input21, 0, 15, &error); expect(error == kParseErrorMissingSlopeFrameCount); + //------------------------------------------------------- + // + // Hold + // + //------------------------------------------------------- + beginTest ("Hold"); + String input22 = "15x3"; + std::vector 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 result23 = parser.parseHold(input23, 0, 15, &error); + expect(error == kParseErrorMissingHoldValue); + + beginTest ("[Error] Missing value"); + String input24 = "3x"; + std::vector result24 = parser.parseHold(input24, 0, 15, &error); + expect(error == kParseErrorMissingHoldFrameCount); //------------------------------------------------------- // diff --git a/Source/FrameSequenceParseErrors.cpp b/Source/FrameSequenceParseErrors.cpp index 49e4553..84cbc03 100644 --- a/Source/FrameSequenceParseErrors.cpp +++ b/Source/FrameSequenceParseErrors.cpp @@ -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; diff --git a/Source/FrameSequenceParseErrors.h b/Source/FrameSequenceParseErrors.h index a65a076..3afa5fe 100644 --- a/Source/FrameSequenceParseErrors.h +++ b/Source/FrameSequenceParseErrors.h @@ -31,8 +31,8 @@ enum ParseError kParseErrorNotANumber, kParseErrorValueOutOfRange, kParseErrorFrameLengthTooShort, - kParseErrorMissingValueForRepeatDelimiter, - kParseErrorMissingFrameCountForRepeatDelimiter, + kParseErrorMissingHoldValue, + kParseErrorMissingHoldFrameCount, }; String getParseErrorString (ParseError err, int minValue = 0, int maxValue = 0); diff --git a/Source/FrameSequenceParser.cpp b/Source/FrameSequenceParser.cpp index c3807a5..00ae721 100644 --- a/Source/FrameSequenceParser.cpp +++ b/Source/FrameSequenceParser.cpp @@ -116,7 +116,7 @@ std::vector FrameSequenceParser::parseSlope (const String& input, return retval; } -std::vector FrameSequenceParser::parseRepeat (const String& input, +std::vector FrameSequenceParser::parseHold (const String& input, int minValue, int maxValue, ParseError* error) @@ -127,13 +127,13 @@ std::vector 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 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 { diff --git a/Source/FrameSequenceParser.h b/Source/FrameSequenceParser.h index dccc77a..60cd77d 100644 --- a/Source/FrameSequenceParser.h +++ b/Source/FrameSequenceParser.h @@ -36,7 +36,7 @@ struct FrameSequenceParser int minValue, int maxValue, ParseError* error); - std::vector parseRepeat (const String& input, + std::vector parseHold (const String& input, int minValue, int maxValue, ParseError* error);