Files
reasampler/tests/test_resample_name.cpp
T

46 lines
2.0 KiB
C++

// Standalone tests for reasampler::model::resample_name — no REAPER, no framework.
//
// Covers: the first iteration, the chain incrementing rather than stacking, the empty
// name, and the tails that are NOT one of ours and must be left alone.
#include "../src/core/model/resample_name.h"
#include <cstdio>
using reasampler::model::nextIterationName;
static int g_fail = 0;
#define CHECK(cond) do { if(!(cond)) { \
std::printf("FAIL line %d: %s\n", __LINE__, #cond); ++g_fail; } } while(0)
int main() {
CHECK(nextIterationName("Kick") == "Kick r2");
CHECK(nextIterationName("Kick r2") == "Kick r3");
CHECK(nextIterationName("Kick r9") == "Kick r10");
CHECK(nextIterationName("Kick r10") == "Kick r11");
// The chain composes: three bakes read as r2, r3, r4 — not "Kick r2 r2 r2".
CHECK(nextIterationName(nextIterationName(nextIterationName("Kick"))) == "Kick r4");
CHECK(nextIterationName("") == "resample r2");
CHECK(nextIterationName(" ") == " r2"); // a name of spaces is still a name
// Tails that are not ours: appended to, never rewritten.
CHECK(nextIterationName("Kick r") == "Kick r r2");
CHECK(nextIterationName("Kick r0") == "Kick r0 r2");
CHECK(nextIterationName("Kick rx") == "Kick rx r2");
CHECK(nextIterationName("Kickr2") == "Kickr2 r2"); // no space before the r
CHECK(nextIterationName("Kick R2") == "Kick R2 r2"); // capital R is not the marker
CHECK(nextIterationName("r2") == "r2 r2"); // no stem to attach the tail to
CHECK(nextIterationName("2") == "2 r2");
CHECK(nextIterationName("Take 3") == "Take 3 r2"); // digits without the " r"
// A digit run past the counting bound is left alone rather than wrapping into a low
// number that would collide with an existing entry's name.
CHECK(nextIterationName("Kick r99999999999999999999") ==
"Kick r99999999999999999999 r2");
if (g_fail == 0) std::printf("resample_name: all tests passed\n");
return g_fail ? 1 : 0;
}