cmdr
Check-in [1e68d757fb]
Not logged in

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Fix issues with time::minute validation. Added testsuite.
Timelines: family | ancestors | descendants | both | vtype-testing
Files: files | file ages | folders
SHA1:1e68d757fbc50d9c2090330cded5b58f63b1f3b7
User & Date: aku 2015-07-03 05:01:10
Context
2015-07-03
05:01
Merge VT test work back to main line. check-in: dd4c6bd2ac user: aku tags: trunk
05:01
Fix issues with time::minute validation. Added testsuite. Closed-Leaf check-in: 1e68d757fb user: aku tags: vtype-testing
04:37
Flipped tests for weekday and year, were swapped. check-in: 0afbe6cc28 user: aku tags: vtype-testing
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Added tests/v_time_minute.test.



















































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
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
# -*- tcl -*- tcl.tk//DSL tcltest//EN//2.0
# # ## ### ##### ######## ############# #####################
## Testing the cmdr::validate package (sub: posint (integer > 0)).

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::time::minute

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

set vtype cmdr::validate::time::minute
set vtdef [expr {([clock seconds] / 60) % 1440}] ;# (**)
kt source vtype.tcl

# (Ad **) Possible race condition here if the tests cross a minute
# boundary (59 -> 00). Then a bogus failure may appear in the standard
# API tests.

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

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

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

test vt-${vtype}-validate-2.2 "$vtype validate, fail, negative" -body {
    $vtype validate P -2
} -returnCodes error -result {Expected a time to the minute for T "P", got "-2"}

test vt-${vtype}-validate-2.3 "$vtype validate, fail, negative" -body {
    $vtype validate P -1
} -returnCodes error -result {Expected a time to the minute for T "P", got "-1"}

test vt-${vtype}-validate-2.4 "$vtype validate, fail, " -body {
    $vtype validate P -1:-3
} -returnCodes error -result {Expected a time to the minute for T "P", got "-1:-3"}

test vt-${vtype}-validate-2.5 "$vtype validate, fail, " -body {
    $vtype validate P -1:23
} -returnCodes error -result {Expected a time to the minute for T "P", got "-1:23"}

# # ## ### ##### ######## ############# #####################
## Valid inputs, minute offset and hour:minute data

foreach {n expected input external} {
     0    0     0 00:00
     1    0 00:00 00:00
     2  180   180 03:00
     3  180 03:00 03:00
     4  251   251 04:11
     5  251 04:11 04:11
     6    0  1440 00:00
     7    1  1441 00:01
     8 1234  1234 20:34
     9 1234 20:34 20:34
    10  564 33:24 09:24
} {
    test vt-${vtype}-validate-3.$n "$vtype validate, ok $input" -body {
	$vtype validate P $input
    } -result $expected

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

    test vt-${vtype}-2external-4.$n "$vtype 2external $expected" -body {
	$vtype 2external $expected
    } -result $external
}

test vt-${vtype}-validate-5.0 "$vtype validate, ok, octal" -body {
    $vtype validate P 010
} -result 8

test vt-${vtype}-validate-5.1 "$vtype validate, ok, hex" -body {
    $vtype validate P 0xff
} -result 255

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

Changes to vt_time_minute.tcl.

58
59
60
61
62
63
64

65
66
67
68
69
70
71
72
..
80
81
82
83
84
85
86
87
88
89
90
91
92
93




94
95
96
97
98
debug prefix cmdr/validate/time/minute {[debug caller] | }

# # ## ### ##### ######## ############# #####################
## Times as parsed by clock::iso86

proc ::cmdr::validate::time::minute::2external {x}  {
    debug.cmdr/validate/time/minute {}

    return [clock format $x -format {%H:%M}]
}

proc ::cmdr::validate::time::minute::release  {p x} { return }
proc ::cmdr::validate::time::minute::default  {p}  {
    debug.cmdr/validate/time/minute {}
    # Today, limited to the minute from midnight
    return [expr {([clock seconds] / 60) % 1440}]
................................................................................
    debug.cmdr/validate/time/minute {}
    try {
	if {[string is integer -strict $x] && ($x >= 0)} {
	    # Integer, direct offset from midnight, force range.
	    set minoffset [expr {$x % 1440}]
	} else {
	    # TODO: error code in clock::iso8601.
	    set minoffset [expr {([clock::iso8601 parse_time ${x}:00] / 60) % 1440}]
	}
    } on error {e o} {
	fail $p TIME "a time to the minute" $x
    } 
    return $minoffset
}





# # ## ### ##### ######## ############# #####################
## Ready
package provide cmdr::validate::time::minute 1
return







>
|







 







|



|


>
>
>
>





58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
..
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
debug prefix cmdr/validate/time/minute {[debug caller] | }

# # ## ### ##### ######## ############# #####################
## Times as parsed by clock::iso86

proc ::cmdr::validate::time::minute::2external {x}  {
    debug.cmdr/validate/time/minute {}
    # x in [0..1440) => [0..86400) seconds.
    return [clock format [expr {$x * 60 + [DayBase]}] -format {%H:%M}]
}

proc ::cmdr::validate::time::minute::release  {p x} { return }
proc ::cmdr::validate::time::minute::default  {p}  {
    debug.cmdr/validate/time/minute {}
    # Today, limited to the minute from midnight
    return [expr {([clock seconds] / 60) % 1440}]
................................................................................
    debug.cmdr/validate/time/minute {}
    try {
	if {[string is integer -strict $x] && ($x >= 0)} {
	    # Integer, direct offset from midnight, force range.
	    set minoffset [expr {$x % 1440}]
	} else {
	    # TODO: error code in clock::iso8601.
	    set minoffset [expr {(([clock::iso8601 parse_time ${x}:00] - [DayBase]) / 60) % 1440}]
	}
    } on error {e o} {
	fail $p TIME "a time to the minute" $x
    }
    return $minoffset
}

proc ::cmdr::validate::time::minute::DayBase {}  {
    clock::iso8601 parse_time 00:00:00
}

# # ## ### ##### ######## ############# #####################
## Ready
package provide cmdr::validate::time::minute 1
return