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

class ValueCoalescingTest inherits QUnit::Test {
    constructor() : QUnit::Test("Value coalescing test", "1.0") {
        addTestCase("Test", \testCoalescing());
        set_return_value(main());
    }

    testCoalescing() {
        code code_example = any sub() {return;};
        File file_example = new File();

        assertEq(2, 2 ?* 3, "int ?* int");
        assertEq(3, 0 ?* 3, "zero ?* int");
        assertEq(3, NOTHING ?* 3, "NOTHING ?* int");
        assertEq("a", "a" ?* 3, "str ?* int");
        assertEq(3, "" ?* 3, "empty_str ?* int");
        assertEq("", "" ?* "", "empty_str ?* empty_str");
        assertEq(0, "" ?* 0, "empty_str ?* zero");
        assertEq(code_example, code_example ?* 3, "code ?* int");
        assertEq('a', NOTHING ?* 'a', "NOTHING ?* str");
        assertEq(NOTHING, NOTHING ?* NOTHING, "NOTHING ?* NOTHING");
        assertEq(True, False ?* True, "False ?* True");
        assertEq(4, NOTHING ?* NOTHING ?* 4 ?* NOTHING, "NOTHING ?* NOTHING ?* int ?* NOTHING");
        assertEq('a', True ?* False ? 'a' : 'b', "?: has lower prio");
        assertEq(file_example, file_example ?* 3, "object ?* int");
    }
}

