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 ba8cf74492e1ea12a0095fe9268a8b1c6672d07b:


# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
# # ## ### ##### ######## ############# #####################
## Testing the cmdr::validate package (sub: valtype::ean13).

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::valtype::creditcard::visa

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

set vtype cmdr::validate::valtype::creditcard::visa
set vtdef {}
kt source vtype.tcl

# # ## ### ##### ######## ############# #####################
## Specific behaviour

test vt-${vtype}-validate-2.0 {creditcard visa validation failure, bad char} -body {
    $vtype validate P 4A34562749104
} -returnCodes error \
    -result {Not a CREDITCARD VISA number, expected only digits}

foreach {n in} {
    1  030640615
    2  978030640615
} {
    test vt-${vtype}-validate-2.1.$n {creditcard visa validation failure, bad length} -body {
    $vtype validate P $in
    } -returnCodes error \
        -result {Not a CREDITCARD VISA number, incorrect length, expected one of 13, or 16 characters}
}

foreach {n in} {
    1  4012345678901
    2  4109876543210
    3  4992739871755
    4  4123456781234
    5  4012345678901234
    6  4432109876543210
    7  4992739871755987
    8  4123456781234567
} {
    test vt-${vtype}-validate-2.2.$n {creditcard visa validation failure, bad check} -body {
	$vtype validate P $in
    } -returnCodes error \
	-result {Not a CREDITCARD VISA number, the check digit is incorrect}
}

foreach {n in} {
    1  9772890458925
    2  8285298475847568
} {
    test vt-${vtype}-validate-2.3.$n {creditcard visa validation failure, bad prefix} -body {
	$vtype validate P $in
    } -returnCodes error \
	-result {Not a CREDITCARD VISA number, incorrect prefix, expected 4}
}

# -------------------------------------------------------------------------

foreach {n in check} {
    1  401234567890 9
    2  410987654321 1
    3  499273987175 8
    4  412345678123 2
} {
    test vt-${vtype}-validate-4.$n {creditcard visa validation} -body {
	$vtype validate P $in$check
    } -result $in$check
}

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