cmdr
Artifact Content
Not logged in

Artifact 4b247c04a10e757aaef76b382b4d2ffd796a1115:


# -*- 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::amex

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

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

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



test vt-${vtype}-validate-2.0 {creditcard amex validation failure, bad char} -body {
    $vtype validate P 34A345627491046
} -returnCodes error \
    -result {Not a CREDITCARD AMEX number, expected only digits}

foreach {n in} {
    1  03064061545
    2  97803064
} {
    test vt-${vtype}-validate-2.1.$n {creditcard amex validation failure, bad length} -body {
    $vtype validate P $in
    } -returnCodes error \
        -result {Not a CREDITCARD AMEX number, incorrect length, expected 15 characters}
}

foreach {n in} {
    1  340123456789012
    2  344321098765432
    3  379927398717559
    4  371234567812345
} {
    test vt-${vtype}-validate-2.2.$n {creditcard amex validation failure, bad check} -body {
	$vtype validate P $in
    } -returnCodes error \
	-result {Not a CREDITCARD AMEX number, the check digit is incorrect}
}

foreach {n in} {
    1  977289045892557
    2  828529847584756
} {
    test vt-${vtype}-validate-2.3.$n {creditcard amex validation failure, bad prefix} -body {
	$vtype validate P $in
    } -returnCodes error \
	-result {Not a CREDITCARD AMEX number, incorrect prefix, expected one of 34, or 37}
}


test vt-${vtype}-validate-3.0 {creditcard amex checkdigit wrong\#args} -body {
    valtype::creditcard::amex checkdigit
} -returnCodes error \
    -result {wrong # args: should be "valtype::creditcard::amex checkdigit value"}

test vt-${vtype}-validate-3.1 {creditcard amex checkdigit wrong\#args} -body {
    valtype::creditcard::amex checkdigit A B
} -returnCodes error \
    -result {wrong # args: should be "valtype::creditcard::amex checkdigit value"}

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

test vt-${vtype}-validate-5.0 {creditcard amex checkdigit calculation failure, bad char} -body {
    valtype::creditcard::amex checkdigit 34A01234567894
} -returnCodes error \
    -result {Not a CREDITCARD AMEX number, expected only digits}

test valtype-creditcad-amex-5.1 {creditcard amex checkdigit calculation failure, bad length} -body {
    valtype::creditcard::amex checkdigit 401234
} -returnCodes error \
    -result {Not a CREDITCARD AMEX number without checkdigit, incorrect length, expected 14 characters}

test valtype-creditcad-amex-5.2 {creditcard amex checkdigit calculation failure, bad length} -body {
    valtype::creditcard::amex checkdigit 01234567890124
} -returnCodes error \
    -result {Not a CREDITCARD AMEX number without checkdigit, incorrect prefix, expected one of 34, or 37}

foreach {n in check} {
    1  34012345678901 4
    2  34109876543210 1
    3  37992739871753 5
    4  37123456781234 8
} {
    test vt-${vtype}-validate-4.$n {creditcard amex validation} -body {
	$vtype validate P $in$check
    } -result $in$check

    # TODO: Expose checkdigit through validation type, later
    if {0} {test vt-${vtype}-validate-6.$n {creditcard amex checkdigit} -body {
	valtype::creditcard::amex checkdigit $in
    } -result $check}
}


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