#! /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 ToIntTest

public class ToIntTest inherits QUnit::Test {
    constructor() : Test("FloorTest", "1.1") {
        addTestCase("Test <string>::toInt()", \testToInt(), NOTHING);
        addTestCase("Test Qore::int()", \testInt(), NOTHING);

        set_return_value(main());
    }

    testToInt() {
        assertEq(254, "fe".toInt(16));
        assertEq(-19, "-34".toInt(5));
        assertEq(2, "2p".toInt(25));
        assertEq(77, "2p".toInt(26));
        assertEq(-107, "-2z".toInt(36));
        assertEq(21, "21".toInt());
        assertEq(21, "21".toInt(0));
        assertEq(-17, "-021".toInt(0));
        assertEq(33, "0x21".toInt(0));
    }

    testInt() {
        assertEq(-254, int("-fe", 16));
        assertEq(19, int("34", 5));
        assertEq(2, int("2p", 25));
        assertEq(77, int("2p", 26));
        assertEq(107, int("2z", 36));
        assertEq(21, int("21"));
        assertEq(21, int("21", 0));
        assertEq(17, int("021", 0));
        assertEq(-33, int("-0x21", 0));
    }
}
