File: isbn.test

package info (click to toggle)
tcllib 2.0%2Bdfsg-5
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 83,560 kB
  • sloc: tcl: 306,798; ansic: 14,272; sh: 3,035; xml: 1,766; yacc: 1,157; pascal: 881; makefile: 124; perl: 84; f90: 84; python: 33; ruby: 13; php: 11
file content (127 lines) | stat: -rw-r--r-- 3,966 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
# -------------------------------------------------------------------------
# isbn.test -*- tcl -*-
# (C) 2011 Andreas Kupries. BSD licensed.
# -------------------------------------------------------------------------

source [file join \
	[file dirname [file dirname [file join [pwd] [info script]]]] \
	devtools testutilities.tcl]

testsNeedTcl     8.5
testsNeedTcltest 2.0

support {
    use      snit/snit2.tcl snit            ;# snit v2 fixed, due Tcl 8.5
    useLocal valtype.tcl    valtype::common
}
testing {
    useLocal isbn.tcl valtype::isbn
}

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

test valtype-isbn-1.0 {isbn validation wrong\#args} -body {
    valtype::isbn validate
} -returnCodes error \
    -result {wrong # args: should be "valtype::isbn validate value"}

test valtype-isbn-1.1 {isbn validation wrong\#args} -body {
    valtype::isbn validate A B
} -returnCodes error \
    -result {wrong # args: should be "valtype::isbn validate value"}

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

test valtype-isbn-2.0 {isbn validation failure, bad char} -body {
    valtype::isbn validate A
} -returnCodes error \
    -result {Not an ISBN number, expected only digits, and possibly 'X' or 'x' as checkdigit}

foreach {n in} {
    1  030640615
    2  978030640615
} {
    test valtype-isbn-2.1.$n {isbn validation failure, bad length} -body {
    valtype::isbn validate $in
    } -returnCodes error \
        -result {Not an ISBN number, incorrect length, expected one of 10, or 13 characters}
}

foreach {n in} {
    1  0306406150
    2  978030640615x
} {
    test valtype-isbn-2.2.$n {isbn validation failure, bad check} -body {
	valtype::isbn validate $in
    } -returnCodes error \
	-result {Not an ISBN number, the check digit is incorrect}
}

foreach {n in} {
    1  9774444444444
} {
    test valtype-isbn-2.3.$n {isbn validation failure, bad prefix} -body {
	valtype::isbn validate $in
    } -returnCodes error \
	-result {Not an ISBN number, incorrect prefix, expected one of 978, or 979}
}

test valtype-isbn-3.0 {isbn checkdigit wrong\#args} -body {
    valtype::isbn checkdigit
} -returnCodes error \
    -result {wrong # args: should be "valtype::isbn checkdigit value"}

test valtype-isbn-3.1 {isbn checkdigit wrong\#args} -body {
    valtype::isbn checkdigit A B
} -returnCodes error \
    -result {wrong # args: should be "valtype::isbn checkdigit value"}

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

test valtype-isbn-5.0 {isbn checkdigit calculation failure, bad char} -body {
    valtype::isbn checkdigit A
} -returnCodes error \
    -result {Not an ISBN number (without checkdigit), expected only digits}

test valtype-isbn-5.1 {isbn checkdigit calculation failure, bad length} -body {
    valtype::isbn checkdigit 01234
} -returnCodes error \
    -result {Not an ISBN number (without checkdigit), incorrect length, expected one of 9, or 12 characters}


test valtype-isbn-5.2 {isbn checkdigit calculation failure, bad char} -body {
    valtype::isbn checkdigit 977444444444
} -returnCodes error \
    -result {Not an ISBN number (without checkdigit), incorrect prefix, expected one of 978, or 979}

foreach {n in check out} {
    1  030640615    2 9780306406157
    2  978030640615 7 9780306406157
} {
    test valtype-isbn-4.$n {isbn validation} -body {
	valtype::isbn validate $in$check
    } -result $out

    test valtype-isbn-6.$n {isbn checkdigit} -body {
	valtype::isbn checkdigit $in
    } -result $check
}

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

foreach {n in out} {
    1  0306406152 9780306406157
} {
    test valtype-isbn-7.$n {isbn transformation isbn10 to isbn13} -body {
	valtype::isbn 13of $in
    } -result $out
}

# -------------------------------------------------------------------------
testsuiteCleanup
return

# Local Variables:
#  mode: tcl
#  indent-tabs-mode: nil
# End: