# -*- tcl -*- Include file for cmdr.test.
# # ## ### ##### ######## ############# #####################
## Hierarchy of actions, aliases, defaults.

test cmdr-officer-1.0 {hierarchy: defaults, aliases, descriptions, commons} -body {
    cmdr create x foo {
	common K D
	description TEST
	officer bar {}
	default
	alias snafu
	officer tool {
	    common U V
	    officer pliers {}
	    officer hammer {}
	    default pliers
	}
	alias pliers = tool pliers
    }
    ShowOfficer x
} -cleanup {
    x destroy
} -result {
    foo = {
        description: 'TEST'
        default: bar
        store (K): 'D'
        bar --> bar
        help --> help
        pliers --> pliers
        snafu --> bar
        tool --> tool
    }
    foo bar = {
        description: ''
        no default
        store (K): 'D'
        help --> help
    }
    foo tool = {
        description: ''
        default: pliers
        store (K): 'D'
        store (U): 'V'
        hammer --> hammer
        help --> help
        pliers --> pliers
    }
    foo tool hammer = {
        description: ''
        no default
        store (K): 'D'
        store (U): 'V'
        help --> help
    }
    foo tool pliers = {
        description: ''
        no default
        store (K): 'D'
        store (U): 'V'
        help --> help
    }
}

# # ## ### ##### ######## ############# #####################
## Error cases of the action DSL.

test cmdr-officer-2.0 {officer/action DSL, officer, wrong\#args} -setup {
    cmdr create x foo {
	officer
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result "wrong # args: should be \"officer name ...\""

test cmdr-officer-2.1 {officer/action DSL, officer, wrong\#args} -setup {
    cmdr create x foo {
	officer foo
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error -match glob \
    -result "wrong # args: should be \"cmdr::officer create ::oo::*::officer_foo super name actions\""

test cmdr-officer-2.2 {officer/action DSL, officer, wrong\#args} -setup {
    cmdr create x foo {
	officer foo {} x
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error -match glob \
    -result "wrong # args: should be \"cmdr::officer create ::oo::*::officer_foo super name actions\""

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

test cmdr-officer-3.0 {officer/action DSL, default, missing previous definition} -setup {
    cmdr create x foo {
	default
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result {Cannot be used as first command}

test cmdr-officer-3.1 {officer/action DSL, default, wrong\#args} -setup {
    cmdr create x foo {
	default x y
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result {wrong # args: should be "default ?name?"}

test cmdr-officer-3.2 {officer/action DSL, default, unknown action} -setup {
    cmdr create x foo {
	default x
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result {Unable to set default, expected action, got "x"}

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

test cmdr-officer-4.0 {officer/action DSL, alias, wrong\#args} -setup {
    cmdr create x foo {
	alias
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result "wrong # args: should be \"alias name ...\""

test cmdr-officer-4.1 {officer/action DSL, alias, wrong\#args} -setup {
    cmdr create x foo {
	alias x =
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result "wrong#args: should be \"name ?= cmd ?word...??\""

test cmdr-officer-4.2 {officer/action DSL, alias, wrong\#args} -setup {
    cmdr create x foo {
	alias x + a
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result "wrong#args: should be \"name ?= cmd ?word...??\""

test cmdr-officer-4.3 {officer/action DSL, alias, missing previous definition} -setup {
    cmdr create x foo {
	alias x
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result {Cannot be used as first command}

test cmdr-officer-4.4 {officer/action DSL, alias, missing definition} -setup {
    cmdr create x foo {
	alias x = y
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result {Expected action name, got "y"}

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

test cmdr-officer-5.1 {officer/action DSL, description, wrong\#args} -setup {
    cmdr create x foo {
	description
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result "wrong # args: should be \"description text\""

test cmdr-officer-5.2 {officer/action DSL, description, wrong\#args} -setup {
    cmdr create x foo {
	description a b
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result "wrong # args: should be \"description text\""

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

test cmdr-officer-6.1 {officer/action DSL, common, wrong\#args} -setup {
    cmdr create x foo {
	common
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result "wrong # args: should be \"common key data\""

test cmdr-officer-6.2 {officer/action DSL, common, wrong\#args} -setup {
    cmdr create x foo {
	common KEY
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result "wrong # args: should be \"common key data\""

test cmdr-officer-6.3 {officer/action DSL, common, wrong\#args} -setup {
    cmdr create x foo {
	common KEY DATA X
    }
} -body {
    x known
} -cleanup {
    x destroy
} -returnCodes error \
    -result "wrong # args: should be \"common key data\""

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