#!/usr/bin/env qore
# -*- mode: qore; indent-tabs-mode: nil -*-

%new-style
%enable-all-warnings
%require-types
%strict-args

%requires ../../../../qlib/QUnit.qm

%exec-class StrmulTest

public class StrmulTest inherits QUnit::Test {
    constructor() : Test("StrmulTest", "1.0") {
        addTestCase("Exercise strmul()", \strmulTestMethod(), NOTHING);

        # Return for compatibility with test harness that checks return value.
        set_return_value(main());
    }

    strmulTestMethod() {
        testAssertion("truncate", \strmul(), ("%s,", 3, 1), new TestResultValue("%s,%s,%s"));
        testAssertion("no truncate", \strmul(), ("%s,", 3, 0), new TestResultValue("%s,%s,%s,"));
        testAssertion("repeat 1 time", \strmul(), ("xxx", 1), new TestResultValue("xxx"));
        testAssertion("remove all chars", \strmul(), ("xxx", 1, 3), new TestResultValue(""));

        testAssertion("remove more chars than exists", \strmul(), ("xxx", 1, 4), new TestResultExceptionDetail("STRMUL-ERROR", "Offset (4) is greater than string length (3)"));
        testAssertion("repeat 0 times", \strmul(), ("xxx", 0), new TestResultValue(""));
    }
}
