when_exe 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,224 @@
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2015 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ module MiniTest::LinkedData
10
+
11
+ class Resouece < MiniTest::TestCase
12
+
13
+ Dates = {
14
+ 'HinduLuniSolar?note=HinduNoteDetailed&location=(_co:Indian::Ujjain)&start_month=5&type=SBSA(1936-10%3C10-)' => {"@context"=>
15
+ {"xsd"=>"http://www.w3.org/2001/XMLSchema",
16
+ "rdf"=>"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
17
+ "rdfs"=>"http://www.w3.org/2000/01/rdf-schema#",
18
+ "owl"=>"http://www.w3.org/2002/07/owl#",
19
+ "dc"=>"http://purl.org/dc/elements/1.1/",
20
+ "dcq"=>"http://purl.org/dc/terms/",
21
+ "dct"=>"http://purl.org/dc/dcmitype/",
22
+ "ts"=>"http://hosi.org/ts#",
23
+ "day"=>"http://hosi.org/When/CalendarNote/HinduNoteDetailed/Notes::day::"},
24
+ "@graph"=>
25
+ [{"rdf:type"=>{"@id"=>"http://hosi.org/ts/When/TM/CalDate"},
26
+ "@id"=>
27
+ "http://hosi.org/tp/1936-10%3C10-%5E%5EHinduLuniSolar?note=HinduNoteDetailed&location=(_co:Indian::Ujjain)&start_month=5&type=SBSA",
28
+ "ts:sdn"=>2457038,
29
+ "ts:frame"=>
30
+ {"@id"=>
31
+ "http://hosi.org/When/CalendarTypes/HinduLuniSolar?note=HinduNoteDetailed&location=(_co:Indian::Ujjain)&start_month=5&type=SBSA"},
32
+ "ts:coordinate"=>"10",
33
+ "@reverse"=>
34
+ {"rdfs:member"=>
35
+ {"@id"=>
36
+ "http://hosi.org/tp/1936-10%3C%5E%5EHinduLuniSolar?note=HinduNoteDetailed&location=(_co:Indian::Ujjain)&start_month=5&type=SBSA"}},
37
+ "day:tithi"=>"Dashami(00:42)",
38
+ "day:vara"=>"Guru(07:07)",
39
+ "day:naksatra"=>"Anurādhā(04:59)",
40
+ "day:yoga"=>"Gaṇḍa(21:11)",
41
+ "day:karana"=>["Viṣṭi(12:34)", "Bava(00:42)"]}]},
42
+ 'Civil?note=Ephemeris(2015-01-15)' => {"@context"=>
43
+ {"xsd"=>"http://www.w3.org/2001/XMLSchema",
44
+ "rdf"=>"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
45
+ "rdfs"=>"http://www.w3.org/2000/01/rdf-schema#",
46
+ "owl"=>"http://www.w3.org/2002/07/owl#",
47
+ "dc"=>"http://purl.org/dc/elements/1.1/",
48
+ "dcq"=>"http://purl.org/dc/terms/",
49
+ "dct"=>"http://purl.org/dc/dcmitype/",
50
+ "ts"=>"http://hosi.org/ts#",
51
+ "day"=>"http://hosi.org/When/CalendarNote/Ephemeris/Notes::day::"},
52
+ "@graph"=>
53
+ [{"rdf:type"=>{"@id"=>"http://hosi.org/ts/When/TM/CalDate"},
54
+ "@id"=>"http://hosi.org/tp/2015-01-15%5E%5ECivil?note=Ephemeris",
55
+ "ts:sdn"=>2457038,
56
+ "ts:frame"=>
57
+ {"@id"=>"http://hosi.org/When/CalendarTypes/Civil?note=Ephemeris"},
58
+ "ts:coordinate"=>"15",
59
+ "@reverse"=>
60
+ {"rdfs:member"=>
61
+ {"@id"=>"http://hosi.org/tp/2015-01%5E%5ECivil?note=Ephemeris"}},
62
+ "day:Moon_Age"=>"Moon_Age(25.4)"}]},
63
+ '明治5-12-' => {"@context"=>
64
+ {"xsd"=>"http://www.w3.org/2001/XMLSchema",
65
+ "rdf"=>"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
66
+ "rdfs"=>"http://www.w3.org/2000/01/rdf-schema#",
67
+ "owl"=>"http://www.w3.org/2002/07/owl#",
68
+ "dc"=>"http://purl.org/dc/elements/1.1/",
69
+ "dcq"=>"http://purl.org/dc/terms/",
70
+ "dct"=>"http://purl.org/dc/dcmitype/",
71
+ "ts"=>"http://hosi.org/ts#",
72
+ "MonthNote"=>"http://hosi.org/When/CalendarNote/Japanese/Notes::月::",
73
+ "LunarMansion"=>"http://hosi.org/When/Coordinates/Common::宿::",
74
+ "Stem-Branch"=>"http://hosi.org/When/Coordinates/Common::干支::",
75
+ "DayNote"=>"http://hosi.org/When/CalendarNote/Japanese/Notes::日::",
76
+ "Week"=>"http://hosi.org/When/Coordinates/Common::Week::"},
77
+ "@graph"=>
78
+ [{"rdf:type"=>{"@id"=>"http://hosi.org/ts/When/TM/CalDate"},
79
+ "@id"=>"http://hosi.org/tp/明治05(1872)-12-",
80
+ "ts:sdn"=>2405158,
81
+ "ts:frame"=>{"@id"=>"http://hosi.org/When/CalendarTypes/Japanese"},
82
+ "ts:calendarEra"=>
83
+ {"@id"=>"http://hosi.org/When/TM/CalendarEra/Japanese::明治"},
84
+ "ts:coordinate"=>"12",
85
+ "ts:ruler"=>
86
+ {"@id"=>"http://hosi.org/When/TM/CalendarEra/Japanese::明治::明治天皇"},
87
+ "@reverse"=>{"rdfs:member"=>{"@id"=>"http://hosi.org/tp/明治05(1872)"}},
88
+ "MonthNote:月名"=>"十二月",
89
+ "MonthNote:廿八宿"=>{"@id"=>"LunarMansion:危宿"},
90
+ "MonthNote:月建"=>{"@id"=>"Stem-Branch:癸丑"},
91
+ "MonthNote:天道"=>"西行",
92
+ "MonthNote:天徳"=>"庚",
93
+ "MonthNote:月煞"=>"辰",
94
+ "MonthNote:用時"=>"乙丁辛亥",
95
+ "MonthNote:月徳"=>"庚",
96
+ "MonthNote:月徳合"=>"乙",
97
+ "MonthNote:月空"=>"甲",
98
+ "MonthNote:三鏡"=>"甲乙丁庚辛癸",
99
+ "MonthNote:土府"=>"子",
100
+ "MonthNote:土公"=>"庭",
101
+ "MonthNote:大小"=>"改(2)"},
102
+ {"rdf:type"=>{"@id"=>"http://hosi.org/ts/When/TM/CalDate"},
103
+ "@id"=>"http://hosi.org/tp/明治05(1872)-12-01",
104
+ "ts:sdn"=>2405158,
105
+ "ts:frame"=>{"@id"=>"http://hosi.org/When/CalendarTypes/Japanese"},
106
+ "ts:calendarEra"=>
107
+ {"@id"=>"http://hosi.org/When/TM/CalendarEra/Japanese::明治"},
108
+ "ts:coordinate"=>"1",
109
+ "ts:ruler"=>
110
+ {"@id"=>"http://hosi.org/When/TM/CalendarEra/Japanese::明治::明治天皇"},
111
+ "@reverse"=>{"rdfs:member"=>{"@id"=>"http://hosi.org/tp/明治05(1872)-12-"}},
112
+ "DayNote:干支"=>{"@id"=>"Stem-Branch:辛亥"},
113
+ "DayNote:納音"=>"金",
114
+ "DayNote:十二直"=>"閉",
115
+ "DayNote:七曜"=>{"@id"=>"Week:Monday"},
116
+ "DayNote:廿八宿"=>{"@id"=>"LunarMansion:張宿"},
117
+ "DayNote:天一"=>"丑寅",
118
+ "DayNote:沐浴"=>"沐浴",
119
+ "DayNote:大小歳"=>"大歳位",
120
+ "DayNote:天恩"=>"天恩",
121
+ "DayNote:重"=>"重",
122
+ "DayNote:大明"=>"大明",
123
+ "DayNote:一粒万倍"=>"一粒万倍",
124
+ "DayNote:三寶吉"=>"三吉",
125
+ "DayNote:神吉"=>"神吉",
126
+ "DayNote:小字注"=>"裁衣市買納財塞穴吉"},
127
+ {"rdf:type"=>{"@id"=>"http://hosi.org/ts/When/TM/CalDate"},
128
+ "@id"=>"http://hosi.org/tp/明治05(1872)-12-02",
129
+ "ts:sdn"=>2405159,
130
+ "ts:frame"=>{"@id"=>"http://hosi.org/When/CalendarTypes/Japanese"},
131
+ "ts:calendarEra"=>
132
+ {"@id"=>"http://hosi.org/When/TM/CalendarEra/Japanese::明治"},
133
+ "ts:coordinate"=>"2",
134
+ "ts:ruler"=>
135
+ {"@id"=>"http://hosi.org/When/TM/CalendarEra/Japanese::明治::明治天皇"},
136
+ "@reverse"=>{"rdfs:member"=>{"@id"=>"http://hosi.org/tp/明治05(1872)-12-"}},
137
+ "DayNote:干支"=>{"@id"=>"Stem-Branch:壬子"},
138
+ "DayNote:納音"=>"木",
139
+ "DayNote:十二直"=>"建",
140
+ "DayNote:七曜"=>{"@id"=>"Week:Tuesday"},
141
+ "DayNote:廿八宿"=>{"@id"=>"LunarMansion:翼宿"},
142
+ "DayNote:七十二候"=>"雪下出麦",
143
+ "DayNote:大將軍"=>"遊北",
144
+ "DayNote:天一"=>"丑寅",
145
+ "DayNote:六蛇"=>"六蛇",
146
+ "DayNote:凶会"=>"陰陽倶錯",
147
+ "DayNote:厭"=>"厭",
148
+ "DayNote:八專"=>"八專始",
149
+ "DayNote:一粒万倍"=>"一粒万倍",
150
+ "DayNote:小字注"=>"不為誓願不動財"}]},
151
+ 'SE1936-07%3C10-' => {"@context"=>
152
+ {"xsd"=>"http://www.w3.org/2001/XMLSchema",
153
+ "rdf"=>"http://www.w3.org/1999/02/22-rdf-syntax-ns#",
154
+ "rdfs"=>"http://www.w3.org/2000/01/rdf-schema#",
155
+ "owl"=>"http://www.w3.org/2002/07/owl#",
156
+ "dc"=>"http://purl.org/dc/elements/1.1/",
157
+ "dcq"=>"http://purl.org/dc/terms/",
158
+ "dct"=>"http://purl.org/dc/dcmitype/",
159
+ "ts"=>"http://hosi.org/ts#",
160
+ "day"=>"http://hosi.org/When/CalendarNote/Balinese/Notes::day::",
161
+ "Dwiwara"=>
162
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Dwiwara::",
163
+ "Triwara"=>
164
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Triwara::",
165
+ "Tjaturwara"=>
166
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Tjaturwara::",
167
+ "Pantjawara"=>
168
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Pantjawara::",
169
+ "Perinkelan"=>
170
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Perinkelan::",
171
+ "Sadwara"=>
172
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Sadwara::",
173
+ "Septawara"=>
174
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Septawara::",
175
+ "Astawara"=>
176
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Astawara::",
177
+ "Sangawara"=>
178
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Sangawara::",
179
+ "Dasawara"=>
180
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Dasawara::",
181
+ "Ingkel"=>"http://hosi.org/When/CalendarNote/Balinese/Notes::day::Ingkel::",
182
+ "Watek"=>"http://hosi.org/When/CalendarNote/Balinese/Notes::day::Watek::",
183
+ "Lintang"=>
184
+ "http://hosi.org/When/CalendarNote/Balinese/Notes::day::Lintang::",
185
+ "Wuku"=>"http://hosi.org/When/CalendarNote/Balinese/Notes::day::Wuku::"},
186
+ "@graph"=>
187
+ [{"rdf:type"=>{"@id"=>"http://hosi.org/ts/When/TM/CalDate"},
188
+ "@id"=>"http://hosi.org/tp/SE1936(2014)-07%3C10-",
189
+ "ts:sdn"=>2457038,
190
+ "ts:frame"=>
191
+ {"@id"=>"http://hosi.org/When/CalendarTypes/BalineseLuniSolar2003"},
192
+ "ts:calendarEra"=>
193
+ {"@id"=>"http://hosi.org/When/TM/CalendarEra/BalineseLuniSolar::SE"},
194
+ "ts:coordinate"=>"10",
195
+ "@reverse"=>
196
+ {"rdfs:member"=>{"@id"=>"http://hosi.org/tp/SE1936(2014)-07%3C"}},
197
+ "day:Hari"=>"Pare",
198
+ "day:Dwiwara"=>{"@id"=>"Dwiwara:Menga"},
199
+ "day:Triwara"=>{"@id"=>"Triwara:Pasah"},
200
+ "day:Tjaturwara"=>{"@id"=>"Tjaturwara:Sri"},
201
+ "day:Pantjawara"=>{"@id"=>"Pantjawara:Wage"},
202
+ "day:Perinkelan"=>{"@id"=>"Perinkelan:Tungleh"},
203
+ "day:Sadwara"=>{"@id"=>"Sadwara:Mina"},
204
+ "day:Septawara"=>{"@id"=>"Septawara:Wraspati"},
205
+ "day:Astawara"=>{"@id"=>"Astawara:Ludra"},
206
+ "day:Sangawara"=>{"@id"=>"Sangawara:Dangu"},
207
+ "day:Dasawara"=>{"@id"=>"Dasawara:Suka"},
208
+ "day:Ingkel"=>{"@id"=>"Ingkel:Mina"},
209
+ "day:Watek"=>{"@id"=>"Watek:Watu-Lintah"},
210
+ "day:Lintang"=>{"@id"=>"Lintang:Kumba"},
211
+ "day:Wuku"=>{"@id"=>"Wuku:Pujut"}}]}
212
+ }
213
+
214
+ def test__rdf_graph
215
+ Dates.each_pair do |key, value|
216
+ date = When.when?(key)
217
+ hash = date.rdf_graph({'@context'=>{}, :context=>true,
218
+ :include=>true, :included=>true,
219
+ :note=>{:precision=>When::MINUTE}})
220
+ assert_equal(value, hash)
221
+ end
222
+ end
223
+ end
224
+ end
@@ -1,193 +1,193 @@
1
- # -*- coding: utf-8 -*-
2
- =begin
3
- Copyright (C) 2011-2014 Takashi SUGA
4
-
5
- You may use and/or modify this file according to the license
6
- described in the LICENSE.txt file included in this archive.
7
- =end
8
-
9
- module MiniTest
10
-
11
- class M17n < MiniTest::TestCase
12
-
13
- First = [
14
- ["Calendar", "Calendar", nil],
15
- ["Month", "月", "http://ja.wikipedia.org/wiki/%E6%9C%88_(%E6%9A%A6)"],
16
- ["Month", "月", "http://ja.wikipedia.org/wiki/%E6%9C%88_(%E6%9A%A6)"],
17
- ["January", "1月", "http://ja.wikipedia.org/wiki/1%E6%9C%88"]
18
- ]
19
-
20
- Second = [
21
- ["January", "1月", "http://ja.wikipedia.org/wiki/1%E6%9C%88" ],
22
- ["February", "2月", "http://ja.wikipedia.org/wiki/2%E6%9C%88" ],
23
- ["March", "3月", "http://ja.wikipedia.org/wiki/3%E6%9C%88" ],
24
- ["April", "4月", "http://ja.wikipedia.org/wiki/4%E6%9C%88" ],
25
- ["May", "5月", "http://ja.wikipedia.org/wiki/5%E6%9C%88" ],
26
- ["June", "6月", "http://ja.wikipedia.org/wiki/6%E6%9C%88" ],
27
- ["July", "7月", "http://ja.wikipedia.org/wiki/7%E6%9C%88" ],
28
- ["August", "8月", "http://ja.wikipedia.org/wiki/8%E6%9C%88" ],
29
- ["September", "9月", "http://ja.wikipedia.org/wiki/9%E6%9C%88" ],
30
- ["October", "10月", "http://ja.wikipedia.org/wiki/10%E6%9C%88"],
31
- ["November", "11月", "http://ja.wikipedia.org/wiki/11%E6%9C%88"],
32
- ["December", "12月", "http://ja.wikipedia.org/wiki/12%E6%9C%88"]
33
- ]
34
-
35
- def test__m17n_1
36
- ['examples/Terms.m17n', '_m:Calendar'].each do |head|
37
- When.Resource(head)
38
-
39
- # pp When::Parts::Resource[head].child.map {|v| v.label}
40
- assert_equal('Month', When::Parts::Resource[head].child[1].label.to_s)
41
-
42
- assert_equal(First,
43
- [head,
44
- head + '::Month',
45
- head + '::Month::Month',
46
- head + '::Month::January'].inject([]) { |first, iri|
47
- obj = When::Parts::Resource[iri]
48
- first << [obj.label, obj.translate('ja'), obj.reference('ja')]
49
- }
50
- )
51
-
52
- assert_equal(Second,
53
- When::Parts::Resource[head + '::Month'].child.inject([]) { |second, obj|
54
- second << [obj.label, obj.translate('ja'), obj.reference('ja')]
55
- }
56
- )
57
- end
58
- end
59
-
60
- def test__m17n_2
61
- march = When.m17n(['en:March=en_ns:', 'ja:3月=ja_ns:'],
62
- {'en_ns'=>'http://en.wikipedia.org/wiki/',
63
- 'ja_ns'=>'http://ja.wikipedia.org/wiki/'})
64
-
65
- [
66
- ['ja', ["3月", "3月", "http://ja.wikipedia.org/wiki/3%E6%9C%88"]],
67
- ['en', ["March", "March", "http://en.wikipedia.org/wiki/March" ]]
68
- ].each do |sample|
69
- assert_equal(sample[1], [march.translate(sample[0]), march.translate(sample[0]), march.reference(sample[0])])
70
- end
71
-
72
- date = When.when?('CE2010.4.12')
73
- era = When.era('CE')[0]
74
- assert_raises(NoMethodError) {When.m17n('[::_m:Calendar::Month::*]').map {|v| v.to_s}}
75
- When.Resource('_m:Calendar::Month::*')
76
- assert_equal(Second.map {|v| v[0]}, When.m17n('[::_m:Calendar::Month::*]').map {|v| v.to_s})
77
- assert_equal(["Accession", true, "http://hosi.org/When/BasicTypes/M17n/EpochEvents::Accession"],
78
- [era['::_m:EpochEvents::Accession'].to_s,
79
- era['::_m:EpochEvents::Accession'].registered?,
80
- era['::_m:EpochEvents::Accession'].iri])
81
-
82
- assert_equal(era['::_m:EpochEvents::*'].map {|v| v.to_s},
83
- ["Accession", "FelicitousEvent", "NaturalDisaster", "InauspiciousYear", "Foundation", "CalendarReform", "CalendarEpoch"])
84
-
85
- term = []
86
- term << When.m17n('[日本語, English]', nil, ', en').translate('ja')
87
- term << When.m17n('[日本語, English]', nil, ['ja', 'en']).translate('ja')
88
- term << When.m17n('[ja:日本語, en:English]').translate('ja')
89
- term << When.m17n(['ja:日本語', 'en:English']).translate('ja')
90
- term.each do |result|
91
- assert_equal("日本語", result)
92
- end
93
-
94
- date = When.when?('明治6.10.1')
95
- era = When.era('明治')[0]
96
- event = era.reference_event
97
- assert_equal("代始", event.translate('ja'))
98
- assert_equal(["Accession", true, "http://hosi.org/When/BasicTypes/M17n/EpochEvents::Accession"],
99
- [era['::_m:EpochEvents::Accession'].to_s,
100
- era['::_m:EpochEvents::Accession'].registered?,
101
- era['::_m:EpochEvents::Accession'].iri])
102
- end
103
-
104
- def test__m17n_3
105
- january = When.Resource('_m:Calendar::Month::January')
106
- [['en', 'January'], ['ja', '1月'], ['fr', 'janvier']].each do |sample|
107
- assert_equal(sample[1], january.translate(sample[0]))
108
- end
109
- end
110
-
111
- def test__m17n_4
112
- january = When.Resource('_m:Calendar::Month::January')
113
- [['en', 'January'], ['ja', '1月'], ['fr', 'janvier']].each do |sample|
114
- assert_equal(sample[1], january.translate(sample[0]))
115
- end
116
- end
117
-
118
- def test__m17n_5
119
- month = When.Resource('_m:Calendar::Month')
120
- [['en', 'Month'], ['ja', '月'], ['fr', 'Mois']].each do |sample|
121
- assert_equal(sample[1], month.translate(sample[0]))
122
- end
123
- end
124
-
125
- def test__to_h
126
- [
127
- ['HLC0.0.0.0.0',
128
- {:calendar=>["_e:LongCount::PHLC",-13], :sdn=>584283, :cal_date=>[13, 0, 0, 0, 0],
129
- :notes=>[[{:note=>"Trecena", :value=>"Trecena(4/13)"},
130
- {:note=>"Tzolk'in", :value=>"Ajaw(19/20)"},
131
- {:note=>"Lords_of_the_Night", :value=>"G9(0/9)"},
132
- {:note=>"Haab'", :value=>"8Kumk'u/365"}]]}],
133
-
134
- ['1985-1-1',
135
- {:calendar=>["_c:Gregorian"], :sdn=>2446067, :cal_date=>[1985, 1, 1],
136
- :notes=>[[{:note=>"Month", :value=>"January"}],[{:note=>"Week", :value=>"Tuesday(1)"}]]}],
137
-
138
- ['明治7.5.7',
139
- {:calendar=>["_e:Japanese::明治",1867], :sdn=>2405651, :cal_date=>[7, 5, 7],
140
- :notes=>[[{:note=>"干支", :value=>"甲戌(10)", :position=>"共通"}],
141
- [{:note=>"月名", :value=>"May", :position=>"月建"}],
142
- [{:note=>"七曜", :value=>"Thursday(3)", :position=>"共通"},
143
- {:note=>"干支", :value=>"甲子(00)", :position=>"共通"},
144
- {:note=>"六曜", :value=>"赤口", :position=>"民間"}]]}],
145
-
146
- ['明治17.5.7',
147
- {:calendar=>["_e:Japanese::明治",1867], :sdn=>2409304, :cal_date=>[17, 5, 7],
148
- :notes=>[[{:note=>"干支", :value=>"甲申(20)", :position=>"共通"}],
149
- [{:note=>"月名", :value=>"May", :position=>"月建"}],
150
- [{:note=>"七曜", :value=>"Wednesday(2)", :position=>"共通"},
151
- {:note=>"干支", :value=>"丁巳(53)", :position=>"共通"},
152
- {:note=>"六曜", :value=>"先負", :position=>"民間"}]]}],
153
-
154
- ['CE-2010.06.08T12:00:00+09:00',
155
- {:calendar=>["_e:Common::BCE", 1, true], :sdn=>987064, :cal_date=>[-2011, 6, 8],
156
- :notes=>[[{:note=>"Month", :value=>"June"}],[]],
157
- :clk_time=>[987064, 12, 0, 0]}],
158
-
159
- [11,
160
- {:calendar=>["_tm:JulianDate"], :sdn=>11,
161
- :notes=>[[{:note=>"Week", :value=>"Friday(4)"},
162
- {:note=>"干支", :value=>"甲子(00)"}]]}],
163
-
164
- [11.0,
165
- {:calendar=>["_tm:JulianDate"], :sdn=>11,
166
- :notes=>[[{:note=>"Week", :value=>"Friday(4)"},
167
- {:note=>"干支", :value=>"甲子(00)"}]],
168
- :clk_time=>[11, 12, 0, 0]}]
169
-
170
- ].each do |sample|
171
- date, verify = sample
172
- list = When.when?(date).to_h({:method=>:to_m17n, :prefix=>true})
173
- [:calendar, :cal_date, :sdn, :clk_time].each do |key|
174
- assert_equal(verify[key], list[key])
175
- end
176
- verify[:notes].each_index do |i|
177
- verify[:notes][i].each_index do |k|
178
- assert_equal(verify[:notes][i][k], list[:notes][i][k])
179
- end
180
- end
181
- end
182
-
183
- assert_equal({:Frame=>"http://hosi.org/When/CalendarTypes/Gregorian",
184
- :Precision=>0,
185
- :Sdn=>2456388,
186
- :Calendar=>["http://hosi.org/When/CalendarTypes/Gregorian"],
187
- :Notes=>[[{:Note=>"Month", :Value=>"April"}],
188
- [{:Note=>"Week", :Value=>"Friday(4)"}]],
189
- :CalDate=>[2013, 4, 5]},
190
- When.when?('2013-4-5').to_h(:method=>:to_m17n, :locale=>'en', :camel=>true))
191
- end
192
- end
193
- end
1
+ # -*- coding: utf-8 -*-
2
+ =begin
3
+ Copyright (C) 2011-2015 Takashi SUGA
4
+
5
+ You may use and/or modify this file according to the license
6
+ described in the LICENSE.txt file included in this archive.
7
+ =end
8
+
9
+ module MiniTest
10
+
11
+ class M17n < MiniTest::TestCase
12
+
13
+ First = [
14
+ ["Calendar", "Calendar", nil],
15
+ ["Month", "月", "http://ja.wikipedia.org/wiki/%E6%9C%88_(%E6%9A%A6)"],
16
+ ["Month", "月", "http://ja.wikipedia.org/wiki/%E6%9C%88_(%E6%9A%A6)"],
17
+ ["January", "1月", "http://ja.wikipedia.org/wiki/1%E6%9C%88"]
18
+ ]
19
+
20
+ Second = [
21
+ ["January", "1月", "http://ja.wikipedia.org/wiki/1%E6%9C%88" ],
22
+ ["February", "2月", "http://ja.wikipedia.org/wiki/2%E6%9C%88" ],
23
+ ["March", "3月", "http://ja.wikipedia.org/wiki/3%E6%9C%88" ],
24
+ ["April", "4月", "http://ja.wikipedia.org/wiki/4%E6%9C%88" ],
25
+ ["May", "5月", "http://ja.wikipedia.org/wiki/5%E6%9C%88" ],
26
+ ["June", "6月", "http://ja.wikipedia.org/wiki/6%E6%9C%88" ],
27
+ ["July", "7月", "http://ja.wikipedia.org/wiki/7%E6%9C%88" ],
28
+ ["August", "8月", "http://ja.wikipedia.org/wiki/8%E6%9C%88" ],
29
+ ["September", "9月", "http://ja.wikipedia.org/wiki/9%E6%9C%88" ],
30
+ ["October", "10月", "http://ja.wikipedia.org/wiki/10%E6%9C%88"],
31
+ ["November", "11月", "http://ja.wikipedia.org/wiki/11%E6%9C%88"],
32
+ ["December", "12月", "http://ja.wikipedia.org/wiki/12%E6%9C%88"]
33
+ ]
34
+
35
+ def test__m17n_1
36
+ ['examples/Terms.m17n', '_m:Calendar'].each do |head|
37
+ When.Resource(head)
38
+
39
+ # pp When::Parts::Resource[head].child.map {|v| v.label}
40
+ assert_equal('Month', When::Parts::Resource[head].child[1].label.to_s)
41
+
42
+ assert_equal(First,
43
+ [head,
44
+ head + '::Month',
45
+ head + '::Month::Month',
46
+ head + '::Month::January'].inject([]) { |first, iri|
47
+ obj = When::Parts::Resource[iri]
48
+ first << [obj.label, obj.translate('ja'), obj.reference('ja')]
49
+ }
50
+ )
51
+
52
+ assert_equal(Second,
53
+ When::Parts::Resource[head + '::Month'].child.inject([]) { |second, obj|
54
+ second << [obj.label, obj.translate('ja'), obj.reference('ja')]
55
+ }
56
+ )
57
+ end
58
+ end
59
+
60
+ def test__m17n_2
61
+ march = When.m17n(['en:March=en_ns:', 'ja:3月=ja_ns:'],
62
+ {'en_ns'=>'http://en.wikipedia.org/wiki/',
63
+ 'ja_ns'=>'http://ja.wikipedia.org/wiki/'})
64
+
65
+ [
66
+ ['ja', ["3月", "3月", "http://ja.wikipedia.org/wiki/3%E6%9C%88"]],
67
+ ['en', ["March", "March", "http://en.wikipedia.org/wiki/March" ]]
68
+ ].each do |sample|
69
+ assert_equal(sample[1], [march.translate(sample[0]), march.translate(sample[0]), march.reference(sample[0])])
70
+ end
71
+
72
+ date = When.when?('CE2010.4.12')
73
+ era = When.era('CE')[0]
74
+ assert_raises(NoMethodError) {When.m17n('[::_m:Calendar::Month::*]').map {|v| v.to_s}}
75
+ When.Resource('_m:Calendar::Month::*')
76
+ assert_equal(Second.map {|v| v[0]}, When.m17n('[::_m:Calendar::Month::*]').map {|v| v.to_s})
77
+ assert_equal(["Accession", true, "http://hosi.org/When/BasicTypes/M17n/EpochEvents::Accession"],
78
+ [era['::_m:EpochEvents::Accession'].to_s,
79
+ era['::_m:EpochEvents::Accession'].registered?,
80
+ era['::_m:EpochEvents::Accession'].iri])
81
+
82
+ assert_equal(era['::_m:EpochEvents::*'].map {|v| v.to_s},
83
+ ["Accession", "FelicitousEvent", "NaturalDisaster", "InauspiciousYear", "Foundation", "CalendarReform", "CalendarEpoch"])
84
+
85
+ term = []
86
+ term << When.m17n('[日本語, English]', nil, ', en').translate('ja')
87
+ term << When.m17n('[日本語, English]', nil, ['ja', 'en']).translate('ja')
88
+ term << When.m17n('[ja:日本語, en:English]').translate('ja')
89
+ term << When.m17n(['ja:日本語', 'en:English']).translate('ja')
90
+ term.each do |result|
91
+ assert_equal("日本語", result)
92
+ end
93
+
94
+ date = When.when?('明治6.10.1')
95
+ era = When.era('明治')[0]
96
+ event = era.reference_event
97
+ assert_equal("代始", event.translate('ja'))
98
+ assert_equal(["Accession", true, "http://hosi.org/When/BasicTypes/M17n/EpochEvents::Accession"],
99
+ [era['::_m:EpochEvents::Accession'].to_s,
100
+ era['::_m:EpochEvents::Accession'].registered?,
101
+ era['::_m:EpochEvents::Accession'].iri])
102
+ end
103
+
104
+ def test__m17n_3
105
+ january = When.Resource('_m:Calendar::Month::January')
106
+ [['en', 'January'], ['ja', '1月'], ['fr', 'janvier']].each do |sample|
107
+ assert_equal(sample[1], january.translate(sample[0]))
108
+ end
109
+ end
110
+
111
+ def test__m17n_4
112
+ january = When.Resource('_m:Calendar::Month::January')
113
+ [['en', 'January'], ['ja', '1月'], ['fr', 'janvier']].each do |sample|
114
+ assert_equal(sample[1], january.translate(sample[0]))
115
+ end
116
+ end
117
+
118
+ def test__m17n_5
119
+ month = When.Resource('_m:Calendar::Month')
120
+ [['en', 'Month'], ['ja', '月'], ['fr', 'Mois']].each do |sample|
121
+ assert_equal(sample[1], month.translate(sample[0]))
122
+ end
123
+ end
124
+
125
+ def test__to_h
126
+ [
127
+ ['HLC0.0.0.0.0',
128
+ {:calendar=>["PHLC",-13], :sdn=>584283, :cal_date=>[13, 0, 0, 0, 0],
129
+ :notes=>[[{:note=>"Trecena", :value=>"Trecena(4/13)"},
130
+ {:note=>"Tzolk'in", :value=>"Ajaw(19/20)"},
131
+ {:note=>"Lords_of_the_Night", :value=>"G9(0/9)"},
132
+ {:note=>"Haab'", :value=>"8Kumk'u/365"}]], :locale=>'en'}],
133
+
134
+ ['1985-1-1',
135
+ {:calendar=>["Gregorian"], :sdn=>2446067, :cal_date=>[1985, 1, 1],
136
+ :notes=>[[{:note=>"Month", :value=>"January"}],[{:note=>"Week", :value=>"Tuesday(1)"}]], :locale=>'en'}],
137
+
138
+ ['明治7.5.7',
139
+ {:calendar=>["明治",1867], :sdn=>2405651, :cal_date=>[7, 5, 7],
140
+ :notes=>[[{:note=>"干支", :value=>"甲戌(10)", :position=>"共通"}],
141
+ [{:note=>"月名", :value=>"5月", :position=>"月建"}],
142
+ [{:note=>"七曜", :value=>"木曜日(3)", :position=>"共通"},
143
+ {:note=>"干支", :value=>"甲子(00)", :position=>"共通"},
144
+ {:note=>"六曜", :value=>"赤口", :position=>"民間"}]], :locale=>'ja'}],
145
+
146
+ ['明治17.5.7',
147
+ {:calendar=>["明治",1867], :sdn=>2409304, :cal_date=>[17, 5, 7],
148
+ :notes=>[[{:note=>"干支", :value=>"甲申(20)", :position=>"共通"}],
149
+ [{:note=>"月名", :value=>"5月", :position=>"月建"}],
150
+ [{:note=>"七曜", :value=>"水曜日(2)", :position=>"共通"},
151
+ {:note=>"干支", :value=>"丁巳(53)", :position=>"共通"},
152
+ {:note=>"六曜", :value=>"先負", :position=>"民間"}]], :locale=>'ja'}],
153
+
154
+ ['CE-2010.06.08T12:00:00+09:00',
155
+ {:calendar=>["BeforeCommonEra", 1, true], :sdn=>987064, :cal_date=>[-2011, 6, 8],
156
+ :notes=>[[{:note=>"Month", :value=>"June"}],[]], :locale=>'en',
157
+ :clk_time=>[987064, 12, 0, 0]}],
158
+
159
+ [11,
160
+ {:calendar=>["_tm:JulianDate"], :sdn=>11,
161
+ :notes=>[[{:note=>"", :value=>"金曜日(4)"},
162
+ {:note=>"干支", :value=>"甲子(00)"}]], :locale=>'ja'}],
163
+
164
+ [11.0,
165
+ {:calendar=>["_tm:JulianDate"], :sdn=>11,
166
+ :notes=>[[{:note=>"", :value=>"金曜日(4)"},
167
+ {:note=>"干支", :value=>"甲子(00)"}]], :locale=>'ja',
168
+ :clk_time=>[11, 12, 0, 0]}]
169
+
170
+ ].each do |sample|
171
+ date, verify = sample
172
+ list = When.when?(date).to_h({:method=>:to_m17n, :locale=>verify[:locale], :prefix=>true})
173
+ [:calendar, :cal_date, :sdn, :clk_time].each do |key|
174
+ assert_equal(verify[key], list[key])
175
+ end
176
+ verify[:notes].each_index do |i|
177
+ verify[:notes][i].each_index do |k|
178
+ assert_equal(verify[:notes][i][k], list[:notes][i][k])
179
+ end
180
+ end
181
+ end
182
+
183
+ assert_equal({:Frame=>"Gregorian",
184
+ :Precision=>0,
185
+ :Sdn=>2456388,
186
+ :Calendar=>["Gregorian"],
187
+ :Notes=>[[{:Note=>"Month", :Value=>"April"}],
188
+ [{:Note=>"Week", :Value=>"Friday(4)"}]],
189
+ :CalDate=>[2013, 4, 5]},
190
+ When.when?('2013-4-5').to_h(:method=>:to_m17n, :locale=>'en', :camel=>true))
191
+ end
192
+ end
193
+ end