• R/O
  • SSH

kink: Commit

Kink runtime


Commit MetaInfo

Revision31b890c52cd60af7dd0fb77e7aa9618e5b45c601 (tree)
Time2019-11-28 22:21:53
Authormiyakawataku
Commitermiyakawataku

Log Message

add param checking to TIME.new

Change Summary

Incremental Difference

diff -r c7ff0eeee6b9 -r 31b890c52cd6 src/main/resources/kink-mods/kink/datetime/TIME.kn
--- a/src/main/resources/kink-mods/kink/datetime/TIME.kn Mon Nov 25 22:15:58 2019 +0900
+++ b/src/main/resources/kink-mods/kink/datetime/TIME.kn Thu Nov 28 22:21:53 2019 +0900
@@ -7,6 +7,13 @@
77 :Object_class <- JAVA.class('java.lang.Object')
88
99 :new <- {(:Hour :Minute :Second)
10+ :Desc = 'TIME.new(Hour Minute Second)'
11+ NUM.num?(Hour) && Hour.int? && 0 <= Hour && Hour <= 23 || raise(
12+ '{}: required int num in [0, 23] for Hour, but got {}'.format(Desc Hour.repr))
13+ NUM.num?(Minute) && Minute.int? && 0 <= Minute && Minute <= 59 || raise(
14+ '{}: required int num in [0, 59] for Minute, but got {}'.format(Desc Minute.repr))
15+ NUM.num?(Second) && Second.scale <= 9 && 0 <= Second && Second < 60 || raise(
16+ '{}: required num in [0.000000000 59.999999999] for Second, but got {}'.format(Desc Second.repr))
1017 :Sec_int = Second // 1
1118 :Sec_nano = Second % 1 * Nano_to_sec
1219 :Java_lt = LocalTime_class.call_static('of' [
diff -r c7ff0eeee6b9 -r 31b890c52cd6 src/test/kink/datetime/TIME_test.kn
--- a/src/test/kink/datetime/TIME_test.kn Mon Nov 25 22:15:58 2019 +0900
+++ b/src/test/kink/datetime/TIME_test.kn Thu Nov 28 22:21:53 2019 +0900
@@ -1,7 +1,159 @@
11 :TIME.require_from('kink/datetime/')
22 :TEST.require_from('kink/test/')
3+:CONTROL.require_from('kink/')
34
4-TEST.group('time'){
5+TEST.group('TIME.new'){ # {{{1
6+ TEST.test('minimum time'){
7+ :Time = TIME.new(0 0 0.000000000)
8+ :Trio = [Time.hour Time.minute Time.second]
9+ Trio == [0 0 0.000000000] || raise('got {}'.format(Trio.repr))
10+ }
11+
12+ TEST.test('maximum time'){
13+ :Time = TIME.new(23 59 59.999999999)
14+ :Trio = [Time.hour Time.minute Time.second]
15+ Trio == [23 59 59.999999999] || raise('got {}'.format(Trio.repr))
16+ }
17+
18+ TEST.group('require hour'){
19+ TEST.test('is a num'){
20+ CONTROL.try(
21+ { TIME.new(nada 50 56) }
22+ {(:R) raise('got {}'.format(R.repr)) }
23+ {(:Msg :Traces)
24+ Msg.have_slice?('nada') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
25+ }
26+ )
27+ }
28+
29+ TEST.test('is an int'){
30+ CONTROL.try(
31+ { TIME.new(1.5 50 56) }
32+ {(:R) raise('got {}'.format(R.repr)) }
33+ {(:Msg :Traces)
34+ Msg.have_slice?('1.5') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
35+ }
36+ )
37+ }
38+
39+ TEST.test('must be >= 0'){
40+ CONTROL.try(
41+ { TIME.new(-1 0 0.000000000) }
42+ {(:R) raise('got {}'.format(R.repr)) }
43+ {(:Msg :Traces)
44+ Msg.have_slice?('-1') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
45+ }
46+ )
47+ }
48+
49+ TEST.test('must be <= 23'){
50+ CONTROL.try(
51+ { TIME.new(24 0 0.000000000) }
52+ {(:R) raise('got {}'.format(R.repr)) }
53+ {(:Msg :Traces)
54+ Msg.have_slice?('24') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
55+ }
56+ )
57+ }
58+ }
59+
60+ TEST.group('require minute'){
61+ TEST.test('is a num'){
62+ CONTROL.try(
63+ { TIME.new(0 nada 0.000000000) }
64+ {(:R) raise('got {}'.format(R.repr)) }
65+ {(:Msg :Traces)
66+ Msg.have_slice?('nada') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
67+ }
68+ )
69+ }
70+
71+ TEST.test('is an int'){
72+ CONTROL.try(
73+ { TIME.new(0 1.5 0.000000000) }
74+ {(:R) raise('got {}'.format(R.repr)) }
75+ {(:Msg :Traces)
76+ Msg.have_slice?('1.5') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
77+ }
78+ )
79+ }
80+
81+ TEST.test('must be >= 0'){
82+ CONTROL.try(
83+ { TIME.new(0 (-1) 0.000000000) }
84+ {(:R) raise('got {}'.format(R.repr)) }
85+ {(:Msg :Traces)
86+ Msg.have_slice?('-1') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
87+ }
88+ )
89+ }
90+
91+ TEST.test('must be <= 59'){
92+ CONTROL.try(
93+ { TIME.new(0 60 0.000000000) }
94+ {(:R) raise('got {}'.format(R.repr)) }
95+ {(:Msg :Traces)
96+ Msg.have_slice?('60') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
97+ }
98+ )
99+ }
100+ }
101+
102+ TEST.group('require second'){
103+ TEST.test('is a num'){
104+ CONTROL.try(
105+ { TIME.new(0 0 nada) }
106+ {(:R) raise('got {}'.format(R.repr)) }
107+ {(:Msg :Traces)
108+ Msg.have_slice?('nada') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
109+ }
110+ )
111+ }
112+
113+ TEST.test('is a num'){
114+ CONTROL.try(
115+ { TIME.new(0 0 nada) }
116+ {(:R) raise('got {}'.format(R.repr)) }
117+ {(:Msg :Traces)
118+ Msg.have_slice?('nada') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
119+ }
120+ )
121+ }
122+
123+ TEST.test('scale must be <= 9'){
124+ CONTROL.try(
125+ { TIME.new(0 0 0.000_000_000_0) }
126+ {(:R) raise('got {}'.format(R.repr)) }
127+ {(:Msg :Traces)
128+ Msg.have_slice?('0.0000000000') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
129+ }
130+ )
131+ }
132+
133+ TEST.test('must be >= 0'){
134+ CONTROL.try(
135+ { TIME.new(0 0 (-0.000_000_001)) }
136+ {(:R) raise('got {}'.format(R.repr)) }
137+ {(:Msg :Traces)
138+ Msg.have_slice?('-0.000000001') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
139+ }
140+ )
141+ }
142+
143+ TEST.test('must be < 60'){
144+ CONTROL.try(
145+ { TIME.new(0 0 60.000000000) }
146+ {(:R) raise('got {}'.format(R.repr)) }
147+ {(:Msg :Traces)
148+ Msg.have_slice?('60.000000000') && Msg.have_slice?('TIME.new') || reraise(Msg Traces)
149+ }
150+ )
151+ }
152+ }
153+}
154+
155+# }}}1
156+TEST.group('time'){ # {{{1
5157 TEST.test('.hour'){
6158 :Time = TIME.new(14 22 11.123456789)
7159 :Result = Time.hour
@@ -72,4 +224,6 @@
72224 }
73225 }
74226
75-# vim: et sw=2 sts=2
227+# }}}1
228+
229+# vim: et sw=2 sts=2 fdm=marker
Show on old repository browser