cmdr
Artifact Content
Not logged in
Bounty program for improvements to Tcl and certain Tcl packages.
Tcl 2019 Conference, Houston/TX, US, Nov 4-8
Send your abstracts to [email protected]
or submit via the online form by Sep 9.

Artifact 399fb9c45dfb6cb4fd9c002ec20b97993a373b73:


# -*- tcl -*- Include file for cmdr.test.
# # ## ### ##### ######## ############# #####################

test cmdr-private-1.0 {private basics, parameter default settings, fragment use} -body {
    cmdr create x foo {
	common def {
	    input  INPUT  INPUT-DESC
	    option OPTION OPTION-DESC
	    state  STATE  STATE-DESC
	}
	private bar {
	    description TEST
	    use def
	} ::snafu
    }
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: 'TEST'
        store (def): '
	    input  INPUT  INPUT-DESC
	    option OPTION OPTION-DESC
	    state  STATE  STATE-DESC
	'
        argument (INPUT)
        option (--help) = help
        option (--no-OPTION) = OPTION
        option (--OPTION) = OPTION
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-OPTION)
        map --no --> (--no-OPTION)
        map --no- --> (--no-OPTION)
        map --no-O --> (--no-OPTION)
        map --no-OP --> (--no-OPTION)
        map --no-OPT --> (--no-OPTION)
        map --no-OPTI --> (--no-OPTION)
        map --no-OPTIO --> (--no-OPTION)
        map --no-OPTION --> (--no-OPTION)
        map --O --> (--OPTION)
        map --OP --> (--OPTION)
        map --OPT --> (--OPTION)
        map --OPTI --> (--OPTION)
        map --OPTIO --> (--OPTION)
        map --OPTION --> (--OPTION)
        map -? --> (-?)
        map -h --> (-h)
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (INPUT) {
            description: 'INPUT-DESC'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (OPTION) {
            description: 'OPTION-DESC'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-OPTION --OPTION]
                --no-OPTION = inverted
                --OPTION = primary
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (STATE) {
            description: 'STATE-DESC'
            unordered, hidden, single, required, silent, defered
            default: ''
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
    }
}

test cmdr-private-1.1 {private basics, optional arguments, thresholding} -body {
    cmdr create x foo {
	private bar {
	    description 6.1
	    input A - {}
	    input B - { optional }
	    input C - {}
	    input D - { optional }
	    input E - {}
	} ::snafu
    }
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: '6.1'
        argument (A)
        argument (B)
        argument (C)
        argument (D)
        argument (E)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (B) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: ''
            mode=threshold 2
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (C) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (D) {
            description: '-'
            ordered, cmdline, single, optional, silent, immediate
            default: ''
            mode=threshold 1
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (E) {
            description: '-'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################
## Parameter declaration commands: input, splat, option, state

test cmdr-private-2.0 {private, input, wrong num args, not enough} -setup {
    cmdr create x foo { private bar { input } ::snafu }
} -body {
    [x lookup bar] keys
} -cleanup {
    x destroy
} -returnCodes error -result "wrong # args: should be \"input name desc ?spec?\""

test cmdr-private-2.1 {private, input, wrong num args, not enough} -setup {
    cmdr create x foo { private bar { input A } ::snafu }
} -body {
    [x lookup bar] keys
} -cleanup {
    x destroy
} -returnCodes error -result "wrong # args: should be \"input name desc ?spec?\""

test cmdr-private-2.2 {private, input, wrong num args, too many} -setup {
    cmdr create x foo { private bar { input A D V X } ::snafu }
} -body {
    [x lookup bar] keys
} -cleanup {
    x destroy
} -returnCodes error -result "wrong # args: should be \"input name desc ?spec?\""

test cmdr-private-2.3 {private, input, defaults} -setup {
    cmdr create x foo { private bar { input A D } ::snafu }
} -body {
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: ''
        argument (A)
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: 'D'
            ordered, cmdline, single, required, silent, immediate
            no default
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################

test cmdr-private-3.0 {private, option, wrong num args, not enough} -setup {
    cmdr create x foo { private bar { option } ::snafu }
} -body {
    [x lookup bar] keys
} -cleanup {
    x destroy
} -returnCodes error -result "wrong # args: should be \"option name desc ?spec?\""

test cmdr-private-3.1 {private, option, wrong num args, not enough} -setup {
    cmdr create x foo { private bar { option A } ::snafu }
} -body {
    [x lookup bar] keys
} -cleanup {
    x destroy
} -returnCodes error -result "wrong # args: should be \"option name desc ?spec?\""

test cmdr-private-3.2 {private, option, wrong num args, too many} -setup {
    cmdr create x foo { private bar { option A D V X } ::snafu }
} -body {
    [x lookup bar] keys
} -cleanup {
    x destroy
} -returnCodes error -result "wrong # args: should be \"option name desc ?spec?\""

test cmdr-private-3.3 {private, option, defaults} -setup {
    cmdr create x foo { private bar { option A D } ::snafu }
} -body {
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (--no-A) = A
        option (-?) = help
        option (-A) = A
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map --n --> (--no-A)
        map --no --> (--no-A)
        map --no- --> (--no-A)
        map --no-A --> (--no-A)
        map -? --> (-?)
        map -A --> (-A)
        map -h --> (-h)
        para (A) {
            description: 'D'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--no-A -A]
                --no-A = inverted
                -A = primary
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################

test cmdr-private-4.0 {private, state, wrong num args, not enough} -setup {
    cmdr create x foo { private bar { state } ::snafu }
} -body {
    [x lookup bar] keys
} -cleanup {
    x destroy
} -returnCodes error -result "wrong # args: should be \"state name desc ?spec?\""

test cmdr-private-4.1 {private, state, wrong num args, not enough} -setup {
    cmdr create x foo { private bar { state A } ::snafu }
} -body {
    [x lookup bar] keys
} -cleanup {
    x destroy
} -returnCodes error -result "wrong # args: should be \"state name desc ?spec?\""

test cmdr-private-4.2 {private, state, wrong num args, too many} -setup {
    cmdr create x foo { private bar { state A D V X } ::snafu }
} -body {
    [x lookup bar] keys
} -cleanup {
    x destroy
} -returnCodes error -result "wrong # args: should be \"state name desc ?spec?\""

test cmdr-private-4.3 {private, state, defaults} -setup {
    cmdr create x foo { private bar { state A D } ::snafu }
} -body {
    ShowPrivate [x lookup bar]
} -cleanup {
    x destroy
} -result {
    foo bar = {
        description: ''
        option (--help) = help
        option (-?) = help
        option (-h) = help
        map --h --> (--help)
        map --he --> (--help)
        map --hel --> (--help)
        map --help --> (--help)
        map -? --> (-?)
        map -h --> (-h)
        para (A) {
            description: 'D'
            unordered, hidden, single, required, silent, defered
            default: ''
            flags []
            ge ()
            va (::cmdr::validate::identity)
            wd ()
        }
        para (help) {
            description: '
	    Show the help of the application or of the current
	    command, and stop.
	'
            unordered, cmdline, single, optional, silent, immediate
            default: 'no'
            flags [--help -? -h]
                --help = primary
                -? = alias
                -h = alias
            ge ()
            va (::cmdr::validate::boolean)
            wd ()
        }
    }
}

# # ## ### ##### ######## ############# #####################
return