cmdr
Artifact Content
Not logged in

Artifact d85b09dfd9801a27aeabc7c8a92ba47a14f83b71:


# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
# # ## ### ##### ######## ############# #####################
## Testing the cmdr::validate package (ISO year number).

kt check Tcl     8.5
kt check tcltest 2

kt require support debug
kt require support debug::caller

kt local   support cmdr::validate::common
kt local   testing cmdr::validate::year

# # ## ### ##### ######## ############# #####################
## Basic API.

set vtype cmdr::validate::year
set vtdef [clock format [clock seconds] -format %Y] ;# current year. [**]
kt source vtype.tcl

# (Ad **): Race condition possible in the tests, here. If the tests
# are run across a tear border (Dec 31 into Jan 1 Midnight) bogus
# failure will appear in the standard API tests.

# # ## ### ##### ######## ############# #####################
## Specific behaviour - validation

## Print table of short years, to determine where the border
## current/previous lies.
# for {set i 0} {$i <99} {incr i} { puts  "SHORT $i == [$vtype validate P $i]" }
# Border 37/38

test vt-${vtype}-validate-2.0 "$vtype validate, fail" -body {
    $vtype validate P bogus
} -returnCodes error -result {Expected a year for T "P", got "bogus"}

test vt-${vtype}-validate-2.1 "$vtype validate, fail, strict" -body {
    $vtype validate P {}
} -returnCodes error -result {Expected a year for T "P", got ""}

test vt-${vtype}-validate-2.2 "$vtype validate, fail, octal" -body {
    $vtype validate P 010
} -returnCodes error -result {Expected a year for T "P", got "010"}

test vt-${vtype}-validate-2.3 "$vtype validate, fail, hex" -body {
    $vtype validate P 0xff
} -returnCodes error -result {Expected a year for T "P", got "0xff"}

test vt-${vtype}-validate-2.4 "$vtype validate, fail, negative" -body {
    $vtype validate P -2
} -returnCodes error -result {Expected a year for T "P", got "-2"}

test vt-${vtype}-validate-2.5 "$vtype validate, fail, negative" -body {
    $vtype validate P -1
} -returnCodes error -result {Expected a year for T "P", got "-1"}

test vt-${vtype}-validate-2.6 "$vtype validate, fail, neither short nor long year" -body {
    $vtype validate P 333
} -returnCodes error -result {Expected a year for T "P", got "333"}

test vt-${vtype}-validate-2.7 "$vtype validate, fail, neither short nor long year" -body {
    $vtype validate P 33333
} -returnCodes error -result {Expected a year for T "P", got "33333"}

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

test vt-${vtype}-validate-2.8 "$vtype validate, ok, zero, short year, current century" -body {
    $vtype validate P 0
} -result 2000

test vt-${vtype}-validate-2.9 "$vtype validate, ok, positive, short year, current century" -body {
    $vtype validate P 1
} -result 2001

test vt-${vtype}-validate-2.10 "$vtype validate, ok, positive, short year, current century" -body {
    $vtype validate P 33
} -result 2033

test vt-${vtype}-validate-2.11 "$vtype validate, ok, positive, short year, previous century" -body {
    $vtype validate P 37
} -result 2037

test vt-${vtype}-validate-2.12 "$vtype validate, ok, positive, short year, previous century" -body {
    $vtype validate P 38
} -result 1938

test vt-${vtype}-validate-2.13 "$vtype validate, ok, positive, short year, previous century" -body {
    $vtype validate P 99
} -result 1999

test vt-${vtype}-validate-2.14 "$vtype validate, ok, positive, long year" -body {
    $vtype validate P 1923
} -result 1923

# # ## ### ##### ######## ############# #####################
cleanupTests
return