icu_tournament 1.9.3 → 1.10.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.rdoc +5 -1
- data/lib/icu_tournament/player.rb +1 -2
- data/lib/icu_tournament/result.rb +2 -2
- data/lib/icu_tournament/tournament.rb +38 -0
- data/lib/icu_tournament/tournament_fcsv.rb +1 -1
- data/lib/icu_tournament/tournament_krause.rb +19 -8
- data/lib/icu_tournament/util.rb +4 -4
- data/lib/icu_tournament/version.rb +1 -1
- data/spec/player_spec.rb +118 -120
- data/spec/result_spec.rb +66 -66
- data/spec/team_spec.rb +16 -16
- data/spec/tie_break_spec.rb +51 -51
- data/spec/tournament_fcsv_spec.rb +94 -94
- data/spec/tournament_krause_spec.rb +170 -151
- data/spec/tournament_sp_spec.rb +89 -89
- data/spec/tournament_spec.rb +323 -276
- data/spec/tournament_spx_spec.rb +95 -95
- data/spec/util_spec.rb +127 -127
- metadata +59 -77
data/spec/tournament_spx_spec.rb
CHANGED
@@ -49,72 +49,72 @@ EXPORT
|
|
49
49
|
end
|
50
50
|
|
51
51
|
it "should parse without exception" do
|
52
|
-
|
52
|
+
expect { @p.parse!(@x, @opt) }.not_to raise_error
|
53
53
|
end
|
54
54
|
|
55
55
|
it "should parse without error" do
|
56
56
|
@p.parse(@x, @opt)
|
57
|
-
@p.error.
|
57
|
+
expect(@p.error).to be_nil
|
58
58
|
end
|
59
59
|
|
60
60
|
it "players should have all the right names and numbers" do
|
61
|
-
@t.player(1).name.
|
62
|
-
@t.player(2).name.
|
63
|
-
@t.player(3).name.
|
61
|
+
expect(@t.player(1).name).to eq("Duck, Daffy")
|
62
|
+
expect(@t.player(2).name).to eq("Mouse, Minerva")
|
63
|
+
expect(@t.player(3).name).to eq("Mouse, Mickey")
|
64
64
|
end
|
65
65
|
|
66
66
|
it "players should have correct ICU IDs" do
|
67
|
-
@t.player(1).id.
|
68
|
-
@t.player(2).id.
|
69
|
-
@t.player(3).id.
|
67
|
+
expect(@t.player(1).id).to eq(12345)
|
68
|
+
expect(@t.player(2).id).to be_nil
|
69
|
+
expect(@t.player(3).id).to be_nil
|
70
70
|
end
|
71
71
|
|
72
72
|
it "players should have correct FIDE IDs" do
|
73
|
-
@t.player(1).fide_id.
|
74
|
-
@t.player(2).fide_id.
|
75
|
-
@t.player(3).fide_id.
|
73
|
+
expect(@t.player(1).fide_id).to be_nil
|
74
|
+
expect(@t.player(2).fide_id).to eq(1234568)
|
75
|
+
expect(@t.player(3).fide_id).to eq(1234567)
|
76
76
|
end
|
77
77
|
|
78
78
|
it "players should have correct ICU ratings" do
|
79
|
-
@t.player(1).rating.
|
80
|
-
@t.player(2).rating.
|
81
|
-
@t.player(3).rating.
|
79
|
+
expect(@t.player(1).rating).to eq(2200)
|
80
|
+
expect(@t.player(2).rating).to be_nil
|
81
|
+
expect(@t.player(3).rating).to be_nil
|
82
82
|
end
|
83
83
|
|
84
84
|
it "players should have correct FIDE ratings" do
|
85
|
-
@t.player(1).fide_rating.
|
86
|
-
@t.player(2).fide_rating.
|
87
|
-
@t.player(3).fide_rating.
|
85
|
+
expect(@t.player(1).fide_rating).to be_nil
|
86
|
+
expect(@t.player(2).fide_rating).to eq(1900)
|
87
|
+
expect(@t.player(3).fide_rating).to be_nil
|
88
88
|
end
|
89
89
|
|
90
90
|
it "players should have correct titles" do
|
91
|
-
@t.player(1).title.
|
92
|
-
@t.player(2).title.
|
93
|
-
@t.player(3).title.
|
91
|
+
expect(@t.player(1).title).to eq("IM")
|
92
|
+
expect(@t.player(2).title).to be_nil
|
93
|
+
expect(@t.player(3).title).to eq("GM")
|
94
94
|
end
|
95
95
|
|
96
96
|
it "players should have correct federations" do
|
97
|
-
@t.player(1).fed.
|
98
|
-
@t.player(2).fed.
|
99
|
-
@t.player(3).fed.
|
97
|
+
expect(@t.player(1).fed).to eq("IRL")
|
98
|
+
expect(@t.player(2).fed).to be_nil
|
99
|
+
expect(@t.player(3).fed).to eq("USA")
|
100
100
|
end
|
101
101
|
|
102
102
|
it "players should have correct scores" do
|
103
|
-
@t.player(1).points.
|
104
|
-
@t.player(2).points.
|
105
|
-
@t.player(3).points.
|
103
|
+
expect(@t.player(1).points).to eq(2.0)
|
104
|
+
expect(@t.player(2).points).to eq(1.5)
|
105
|
+
expect(@t.player(3).points).to eq(1.0)
|
106
106
|
end
|
107
107
|
|
108
108
|
it "players should have correct ranks" do
|
109
|
-
@t.player(1).rank.
|
110
|
-
@t.player(2).rank.
|
111
|
-
@t.player(3).rank.
|
109
|
+
expect(@t.player(1).rank).to eq(1)
|
110
|
+
expect(@t.player(2).rank).to eq(2)
|
111
|
+
expect(@t.player(3).rank).to eq(3)
|
112
112
|
end
|
113
113
|
|
114
114
|
it "players should have correct results" do
|
115
|
-
@t.player(1).spx_signature2.
|
116
|
-
@t.player(2).spx_signature2.
|
117
|
-
@t.player(3).spx_signature2.
|
115
|
+
expect(@t.player(1).spx_signature2).to eq('123|DWD|FTT')
|
116
|
+
expect(@t.player(2).spx_signature2).to eq('123|DDD|TFT')
|
117
|
+
expect(@t.player(3).spx_signature2).to eq('123|DLD|TTF')
|
118
118
|
end
|
119
119
|
end
|
120
120
|
|
@@ -135,43 +135,43 @@ EXPORT
|
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should round trip" do
|
138
|
-
@p.error.
|
139
|
-
@r.spx_signature.
|
140
|
-
@r.player(1).spx_signature.
|
141
|
-
@r.player(2).spx_signature.
|
142
|
-
@r.player(3).spx_signature.
|
138
|
+
expect(@p.error).to be_nil
|
139
|
+
expect(@r.spx_signature).to eq("Bangor Masters|3|2009-11-09|3")
|
140
|
+
expect(@r.player(1).spx_signature).to eq("Fischer, Bobby||1.5|123|DLW|---|TFT")
|
141
|
+
expect(@r.player(2).spx_signature).to eq("Kasparov, Garry||1.0|123|LWL|---|FTT")
|
142
|
+
expect(@r.player(3).spx_signature).to eq("Orr, Mark|1350|0.5|123|DLL|---|TTF")
|
143
143
|
end
|
144
144
|
|
145
145
|
it "should show all columns by default" do
|
146
|
-
@x.
|
147
|
-
@x.
|
146
|
+
expect(@x).to match(/^No\s*Name\s*Feder\s*Intl Id\s*Loc Id\s*Rtg\s*Loc\s*Title\s*Total\s*1\s*2\s*3\s*/)
|
147
|
+
expect(@x).to match(/1\s*Fischer,\s*Bobby\s*1\.5\s*3:D\s*0?:L?\s*2:W\s*/)
|
148
148
|
end
|
149
149
|
|
150
150
|
it "can have custom columns" do
|
151
151
|
@x = @t.serialize('SPExport', :only => [])
|
152
|
-
@x.
|
152
|
+
expect(@x).to match(/^No\s*Name\s*1\s*2\s*3\s*/)
|
153
153
|
@x = @t.serialize('SPExport', :only => [:points])
|
154
|
-
@x.
|
154
|
+
expect(@x).to match(/^No\s*Name\s*Total\s*1\s*2\s*3\s*/)
|
155
155
|
@x = @t.serialize('SPExport', :only => [:points, :id])
|
156
|
-
@x.
|
156
|
+
expect(@x).to match(/^No\s*Name\s*Loc Id\s*Total\s*1\s*2\s*3\s*/)
|
157
157
|
@x = @t.serialize('SPExport', :only => [:points, :id, :fed])
|
158
|
-
@x.
|
158
|
+
expect(@x).to match(/^No\s*Name\s*Feder\s*Loc Id\s*Total\s*1\s*2\s*3\s*/)
|
159
159
|
@x = @t.serialize('SPExport', :only => [:points, :id, :fed, "fed", :rubbish, "fide_id"])
|
160
|
-
@x.
|
160
|
+
expect(@x).to match(/^No\s*Name\s*Feder\s*Intl Id\s*Loc Id\s*Total\s*1\s*2\s*3\s*/)
|
161
161
|
@x = @t.serialize('SPExport', :only => [:fed, "fide_id", :points, :id, :rating])
|
162
|
-
@x.
|
162
|
+
expect(@x).to match(/^No\s*Name\s*Feder\s*Intl Id\s*Loc Id\s*Loc\s*Total\s*1\s*2\s*3\s*/)
|
163
163
|
@x = @t.serialize('SPExport', :only => [:fed, :fide_id, "fide_rating", :points, :id, :rating])
|
164
|
-
@x.
|
165
|
-
@x.
|
164
|
+
expect(@x).to match(/^No\s*Name\s*Feder\s*Intl Id\s*Loc Id\s*Rtg\s*Loc\s*Total\s*1\s*2\s*3\s*/)
|
165
|
+
expect(@x).to match(/3\s*Orr,\s*Mark\s*IRL\s*2500035\s*1350\s*2250\s*2200\s*0.5\s*1:D\s*2:L\s*:\s*/)
|
166
166
|
end
|
167
167
|
|
168
168
|
it "the :only and :except options are logical opposites" do
|
169
|
-
@t.serialize('SPExport', :only => [:points, :id, "fed"]).
|
170
|
-
@t.serialize('SPExport', :only => ["points"]).
|
171
|
-
@t.serialize('SPExport', :only => [:rating, :fide_rating, :title, :id, :fed, :points]).
|
172
|
-
@t.serialize('SPExport', :only => %w{rating fide_rating fide_id title id fed points}).
|
173
|
-
@t.serialize('SPExport', :only => []).
|
174
|
-
@t.serialize('SPExport', :except => []).
|
169
|
+
expect(@t.serialize('SPExport', :only => [:points, :id, "fed"])).to eq(@t.serialize('SPExport', :except => [:fide_id, :rating, "fide_rating", :title]))
|
170
|
+
expect(@t.serialize('SPExport', :only => ["points"])).to eq(@t.serialize('SPExport', :except => ["fide_id", :rating, :fide_rating, :title, :id, :fed]))
|
171
|
+
expect(@t.serialize('SPExport', :only => [:rating, :fide_rating, :title, :id, :fed, :points])).to eq(@t.serialize('SPExport', :except => [:fide_id]))
|
172
|
+
expect(@t.serialize('SPExport', :only => %w{rating fide_rating fide_id title id fed points})).to eq(@t.serialize('SPExport', :except => []))
|
173
|
+
expect(@t.serialize('SPExport', :only => [])).to eq(@t.serialize('SPExport', :except => [:rating, :fide_rating, :fide_id, :title, :id, :fed, :points]))
|
174
|
+
expect(@t.serialize('SPExport', :except => [])).to eq(@t.serialize('SPExport'))
|
175
175
|
end
|
176
176
|
end
|
177
177
|
|
@@ -189,9 +189,9 @@ EXPORT
|
|
189
189
|
end
|
190
190
|
|
191
191
|
it "players should have correct results" do
|
192
|
-
@t.player(1).spx_signature2.
|
193
|
-
@t.player(2).spx_signature2.
|
194
|
-
@t.player(3).spx_signature2.
|
192
|
+
expect(@t.player(1).spx_signature2).to eq('123|DWD|FTT')
|
193
|
+
expect(@t.player(2).spx_signature2).to eq('123|DDD|TFT')
|
194
|
+
expect(@t.player(3).spx_signature2).to eq('123|DLD|TTF')
|
195
195
|
end
|
196
196
|
end
|
197
197
|
|
@@ -209,9 +209,9 @@ EXPORT
|
|
209
209
|
end
|
210
210
|
|
211
211
|
it "players should have correct results" do
|
212
|
-
@t.player(1).spx_signature2.
|
213
|
-
@t.player(2).spx_signature2.
|
214
|
-
@t.player(3).spx_signature2.
|
212
|
+
expect(@t.player(1).spx_signature2).to eq('123|WWD|FFF')
|
213
|
+
expect(@t.player(2).spx_signature2).to eq('123|WDD|FFF')
|
214
|
+
expect(@t.player(3).spx_signature2).to eq('123|DDL|FFF')
|
215
215
|
end
|
216
216
|
end
|
217
217
|
|
@@ -229,15 +229,15 @@ EXPORT
|
|
229
229
|
end
|
230
230
|
|
231
231
|
it "players should have canonicalised names" do
|
232
|
-
@t.player(1).name.
|
233
|
-
@t.player(2).name.
|
234
|
-
@t.player(3).name.
|
232
|
+
expect(@t.player(1).name).to eq('Duck, Daffy')
|
233
|
+
expect(@t.player(2).name).to eq('Mouse, Minerva')
|
234
|
+
expect(@t.player(3).name).to eq('Mouse, Mickey')
|
235
235
|
end
|
236
236
|
|
237
237
|
it "players should have original names" do
|
238
|
-
@t.player(1).original_name.
|
239
|
-
@t.player(2).original_name.
|
240
|
-
@t.player(3).original_name.
|
238
|
+
expect(@t.player(1).original_name).to eq('daffy duck')
|
239
|
+
expect(@t.player(2).original_name).to eq('MOUSE, minerva')
|
240
|
+
expect(@t.player(3).original_name).to eq('mouse, MICKEY')
|
241
241
|
end
|
242
242
|
end
|
243
243
|
|
@@ -255,21 +255,21 @@ EXPORT
|
|
255
255
|
end
|
256
256
|
|
257
257
|
it "players should have all the right names and numbers" do
|
258
|
-
@t.player(1).name.
|
259
|
-
@t.player(2).name.
|
260
|
-
@t.player(3).name.
|
258
|
+
expect(@t.player(1).name).to eq("Duck, Daffy")
|
259
|
+
expect(@t.player(2).name).to eq("Mouse, Minerva")
|
260
|
+
expect(@t.player(3).name).to eq("Mouse, Mickey")
|
261
261
|
end
|
262
262
|
|
263
263
|
it "players should have correct results" do
|
264
|
-
@t.player(1).spx_signature2.
|
265
|
-
@t.player(2).spx_signature2.
|
266
|
-
@t.player(3).spx_signature2.
|
264
|
+
expect(@t.player(1).spx_signature2).to eq('123|DWD|FFT')
|
265
|
+
expect(@t.player(2).spx_signature2).to eq('123|DLD|FFT')
|
266
|
+
expect(@t.player(3).spx_signature2).to eq('123|DLD|FFF')
|
267
267
|
end
|
268
268
|
|
269
269
|
it "players should have correct ranks given default name tie-break" do
|
270
|
-
@t.player(1).rank.
|
271
|
-
@t.player(2).rank.
|
272
|
-
@t.player(3).rank.
|
270
|
+
expect(@t.player(1).rank).to eq(1)
|
271
|
+
expect(@t.player(2).rank).to eq(3)
|
272
|
+
expect(@t.player(3).rank).to eq(2)
|
273
273
|
end
|
274
274
|
end
|
275
275
|
|
@@ -287,16 +287,16 @@ EXPORT
|
|
287
287
|
|
288
288
|
it "UTF-8" do
|
289
289
|
t = @p.parse(@x, @opt)
|
290
|
-
@p.error.
|
291
|
-
t.player(1).name.
|
292
|
-
t.player(2).name.
|
290
|
+
expect(@p.error).to be_nil
|
291
|
+
expect(t.player(1).name).to eq("Dück, Dâffy")
|
292
|
+
expect(t.player(2).name).to eq("Möuse, Mickéy")
|
293
293
|
end
|
294
294
|
|
295
295
|
it "Latin-1" do
|
296
296
|
t = @p.parse(@x.encode("ISO-8859-1"), @opt)
|
297
|
-
@p.error.
|
298
|
-
t.player(1).name.
|
299
|
-
t.player(2).name.
|
297
|
+
expect(@p.error).to be_nil
|
298
|
+
expect(t.player(1).name).to eq("Dück, Dâffy")
|
299
|
+
expect(t.player(2).name).to eq("Möuse, Mickéy")
|
300
300
|
end
|
301
301
|
end
|
302
302
|
|
@@ -313,7 +313,7 @@ No Name Total 1 2
|
|
313
313
|
1 Duck, Daffy 1.5 2:W 2:D
|
314
314
|
2 Mouse, Mickey 0.5 1:L 1:D
|
315
315
|
EXPORT
|
316
|
-
|
316
|
+
expect { @p.parse!(data, @opt) }.not_to raise_error
|
317
317
|
end
|
318
318
|
|
319
319
|
it "no header" do
|
@@ -321,7 +321,7 @@ EXPORT
|
|
321
321
|
1 Duck, Daffy 1.5 2:W 2:D
|
322
322
|
2 Mouse, Mickey 0.5 1:L 1:L
|
323
323
|
EXPORT
|
324
|
-
|
324
|
+
expect { @p.parse!(data, @opt) }.to raise_error(/header/)
|
325
325
|
end
|
326
326
|
|
327
327
|
it "invalid header" do
|
@@ -331,7 +331,7 @@ Xx Name Total 1 2
|
|
331
331
|
1 Duck, Daffy 1.5 2:W 2:D
|
332
332
|
2 Mouse, Mickey 0.5 1:L 1:D
|
333
333
|
EXPORT
|
334
|
-
|
334
|
+
expect { @p.parse!(data, @opt) }.to raise_error(/header/)
|
335
335
|
end
|
336
336
|
|
337
337
|
it "missing round 1" do
|
@@ -341,7 +341,7 @@ No Name Total 2 3
|
|
341
341
|
1 Duck, Daffy 1.5 2:W 2:D
|
342
342
|
2 Mouse, Mickey 0.0 1:L 1:L
|
343
343
|
EXPORT
|
344
|
-
|
344
|
+
expect { @p.parse!(data, @opt) }.to raise_error(/round 1/)
|
345
345
|
end
|
346
346
|
|
347
347
|
it "missing round 2" do
|
@@ -351,7 +351,7 @@ No Name Total 1 3
|
|
351
351
|
1 Duck, Daffy 1.5 2:W 2:D
|
352
352
|
2 Mouse, Mickey 0.0 1:L 1:L
|
353
353
|
EXPORT
|
354
|
-
|
354
|
+
expect { @p.parse!(data, @opt) }.to raise_error(/round 2/)
|
355
355
|
end
|
356
356
|
|
357
357
|
it "incorrect total" do
|
@@ -361,7 +361,7 @@ No Name Total 1 2
|
|
361
361
|
1 Duck, Daffy 1.5 2:W 2:D
|
362
362
|
2 Mouse, Mickey 1.0 1:L 1:D
|
363
363
|
EXPORT
|
364
|
-
|
364
|
+
expect { @p.parse!(data, @opt) }.to raise_error(/total/)
|
365
365
|
end
|
366
366
|
|
367
367
|
|
@@ -372,7 +372,7 @@ No Name Total 1 2
|
|
372
372
|
1 Duck, Daffy 1.5 2:W 2:D
|
373
373
|
2 Mouse, Mickey 0.0 1:L 1:L
|
374
374
|
EXPORT
|
375
|
-
|
375
|
+
expect { @p.parse!(data, @opt) }.to raise_error(/result/)
|
376
376
|
end
|
377
377
|
|
378
378
|
it "invalid attribute, title for example)" do
|
@@ -382,7 +382,7 @@ No Name Title Total 1 2
|
|
382
382
|
1 Duck, Daffy mg 1.5 2:W 2:D
|
383
383
|
2 Mouse, Mickey 0.5 1:L 1:D
|
384
384
|
EXPORT
|
385
|
-
|
385
|
+
expect { @p.parse!(data, @opt) }.to raise_error(/title/)
|
386
386
|
end
|
387
387
|
end
|
388
388
|
|
@@ -394,19 +394,19 @@ EXPORT
|
|
394
394
|
end
|
395
395
|
|
396
396
|
it "should parse and have the right basic details" do
|
397
|
-
@p.error.
|
398
|
-
@t.spx_signature.
|
397
|
+
expect(@p.error).to be_nil
|
398
|
+
expect(@t.spx_signature).to eq("Gonzaga Chess Classic 2010 Challengers Section|6|2010-01-29|56")
|
399
399
|
end
|
400
400
|
|
401
401
|
it "should have correct details for selected players" do
|
402
|
-
@t.player(2).spx_signature.
|
403
|
-
@t.player(4).spx_signature.
|
404
|
-
@t.player(45).spx_signature.
|
405
|
-
@t.player(56).spx_signature.
|
402
|
+
expect(@t.player(2).spx_signature).to eq("Mullooly, Neil M.|6438|6.0|123456|WWWWWW|------|TTTTTT") # winner
|
403
|
+
expect(@t.player(4).spx_signature).to eq("Gallagher, Mark|12138|4.0|123456|WLWWWL|------|FTTTTT") # had one bye
|
404
|
+
expect(@t.player(45).spx_signature).to eq("Catre, Loredan||3.5|123456|WDLWLW|------|FTTTFT") # had two byes
|
405
|
+
expect(@t.player(56).spx_signature).to eq("McDonnell, Cathal||0.0|123456|LLLLLL|------|FFFFFF") # last, all defaults
|
406
406
|
end
|
407
407
|
|
408
408
|
it "should have consistent ranks" do
|
409
|
-
@t.players.map{ |p| p.rank }.sort.join('').
|
409
|
+
expect(@t.players.map{ |p| p.rank }.sort.join('')).to eq((1..@t.players.size).to_a.join(''))
|
410
410
|
end
|
411
411
|
end
|
412
412
|
end
|
data/spec/util_spec.rb
CHANGED
@@ -6,33 +6,33 @@ module ICU
|
|
6
6
|
describe Date do
|
7
7
|
context "#parse" do
|
8
8
|
it "should parse standard dates" do
|
9
|
-
Date.parse('2001-01-01').
|
10
|
-
Date.parse('1955-11-09').
|
9
|
+
expect(Date.parse('2001-01-01')).to eq('2001-01-01')
|
10
|
+
expect(Date.parse('1955-11-09')).to eq('1955-11-09')
|
11
11
|
end
|
12
12
|
|
13
13
|
it "should handle US format" do
|
14
|
-
Date.parse('03/30/2009').
|
14
|
+
expect(Date.parse('03/30/2009')).to eq('2009-03-30')
|
15
15
|
end
|
16
16
|
|
17
17
|
it "should handle European format" do
|
18
|
-
Date.parse('30/03/2009').
|
18
|
+
expect(Date.parse('30/03/2009')).to eq('2009-03-30')
|
19
19
|
end
|
20
20
|
|
21
21
|
it "should prefer European format" do
|
22
|
-
Date.parse('02/03/2009').
|
22
|
+
expect(Date.parse('02/03/2009')).to eq('2009-03-02')
|
23
23
|
end
|
24
24
|
|
25
25
|
it "should handle US style when there's no alternative" do
|
26
|
-
Date.parse('02/23/2009').
|
26
|
+
expect(Date.parse('02/23/2009')).to eq('2009-02-23')
|
27
27
|
end
|
28
28
|
|
29
29
|
it "should handle single digits" do
|
30
|
-
Date.parse('9/8/2006').
|
30
|
+
expect(Date.parse('9/8/2006')).to eq('2006-08-09')
|
31
31
|
end
|
32
32
|
|
33
33
|
it "should handle names of monthsx" do
|
34
|
-
Date.parse('9th Nov 1955').
|
35
|
-
Date.parse('16th June 1986').
|
34
|
+
expect(Date.parse('9th Nov 1955')).to eq('1955-11-09')
|
35
|
+
expect(Date.parse('16th June 1986')).to eq('1986-06-16')
|
36
36
|
end
|
37
37
|
end
|
38
38
|
end
|
@@ -44,23 +44,23 @@ module ICU
|
|
44
44
|
end
|
45
45
|
|
46
46
|
it "should read ASCII" do
|
47
|
-
File.read_utf8("#{@s}/ascii.txt").
|
47
|
+
expect(File.read_utf8("#{@s}/ascii.txt")).to eq("Resume\nResume\n")
|
48
48
|
end
|
49
49
|
|
50
50
|
it "should read Latin-1" do
|
51
|
-
File.read_utf8("#{@s}/latin1.txt").
|
51
|
+
expect(File.read_utf8("#{@s}/latin1.txt")).to eq("Résumé\nRésumé\n")
|
52
52
|
end
|
53
53
|
|
54
54
|
it "should read Windows CP1252" do
|
55
|
-
File.read_utf8("#{@s}/cp1252.txt").
|
55
|
+
expect(File.read_utf8("#{@s}/cp1252.txt")).to eq("€3\n£7\n¥1\n")
|
56
56
|
end
|
57
57
|
|
58
58
|
it "should read UTF-8" do
|
59
|
-
File.read_utf8("#{@s}/utf8.txt").
|
59
|
+
expect(File.read_utf8("#{@s}/utf8.txt")).to eq("ヒラガナ\nヒラガナ\n")
|
60
60
|
end
|
61
61
|
|
62
62
|
it "should thow an exception for a non-existant file" do
|
63
|
-
|
63
|
+
expect { File.read_utf8("#{@s}/no_such_file.txt") }.to raise_error
|
64
64
|
end
|
65
65
|
end
|
66
66
|
|
@@ -71,44 +71,44 @@ module ICU
|
|
71
71
|
|
72
72
|
it "should read ASCII" do
|
73
73
|
data = File.load_ini("#{@s}/ascii.ini")
|
74
|
-
data.
|
75
|
-
data["Pairing"]["UseRating"].
|
74
|
+
expect(data).to be_an_instance_of(Hash)
|
75
|
+
expect(data["Pairing"]["UseRating"]).to eq("0")
|
76
76
|
data["NoKeys"] == nil
|
77
|
-
data["Tournament Info"]["Arbiter"].
|
78
|
-
data["Tournament Info"]["DrawSymbol"].
|
77
|
+
expect(data["Tournament Info"]["Arbiter"]).to eq("Herbert Scarry")
|
78
|
+
expect(data["Tournament Info"]["DrawSymbol"]).to eq("D")
|
79
79
|
end
|
80
80
|
|
81
81
|
it "should read Latin1" do
|
82
82
|
data = File.load_ini("#{@s}/latin1.ini")
|
83
|
-
data.
|
84
|
-
data["Tournament Info"]["Arbiter"].
|
85
|
-
data["Tournament Info"]["DrawSymbol"].
|
83
|
+
expect(data).to be_an_instance_of(Hash)
|
84
|
+
expect(data["Tournament Info"]["Arbiter"]).to eq("Gearóidín")
|
85
|
+
expect(data["Tournament Info"]["DrawSymbol"]).to eq("½")
|
86
86
|
end
|
87
87
|
|
88
88
|
it "should read Windows-1252" do
|
89
89
|
data = File.load_ini("#{@s}/cp1252.ini")
|
90
|
-
data.
|
91
|
-
data["Tournament Info"]["Entry Fee"].
|
90
|
+
expect(data).to be_an_instance_of(Hash)
|
91
|
+
expect(data["Tournament Info"]["Entry Fee"]).to eq("€50")
|
92
92
|
end
|
93
93
|
|
94
94
|
it "should read UTF8" do
|
95
95
|
data = File.load_ini("#{@s}/utf8.ini")
|
96
|
-
data.
|
97
|
-
data["Tournament Info"]["Entry Fee"].
|
98
|
-
data["Tournament Info"]["Arbiter"].
|
99
|
-
data["Tournament Info"]["DrawSymbol"].
|
96
|
+
expect(data).to be_an_instance_of(Hash)
|
97
|
+
expect(data["Tournament Info"]["Entry Fee"]).to eq("€50")
|
98
|
+
expect(data["Tournament Info"]["Arbiter"]).to eq("ヒラガナ")
|
99
|
+
expect(data["Tournament Info"]["DrawSymbol"]).to eq("½")
|
100
100
|
end
|
101
101
|
|
102
102
|
it "should handle untidily formatted files" do
|
103
103
|
data = File.load_ini("#{@s}/untidy.ini")
|
104
|
-
data.
|
105
|
-
data["Tournament Info"]["Entry Fee"].
|
106
|
-
data["Tournament Info"]["DrawSymbol"].
|
107
|
-
data["Pairing"]["Use Rating"].
|
104
|
+
expect(data).to be_an_instance_of(Hash)
|
105
|
+
expect(data["Tournament Info"]["Entry Fee"]).to eq("€50")
|
106
|
+
expect(data["Tournament Info"]["DrawSymbol"]).to eq("½")
|
107
|
+
expect(data["Pairing"]["Use Rating"]).to eq("0")
|
108
108
|
end
|
109
109
|
|
110
110
|
it "should thow an exception for a non-existant file" do
|
111
|
-
|
111
|
+
expect { File.read_utf8("#{@s}/no_such_file.ini") }.to raise_error
|
112
112
|
end
|
113
113
|
end
|
114
114
|
end
|
@@ -122,16 +122,16 @@ module ICU
|
|
122
122
|
end
|
123
123
|
|
124
124
|
it "should not have an accessor unless declared" do
|
125
|
-
@obj.respond_to?(:myatr).
|
126
|
-
@obj.respond_to?(:myatr=).
|
125
|
+
expect(@obj.respond_to?(:myatr)).to be_falsey
|
126
|
+
expect(@obj.respond_to?(:myatr=)).to be_falsey
|
127
127
|
end
|
128
128
|
|
129
129
|
it "should have a getter but no setter with the default declaration" do
|
130
130
|
@class.attr_accessor('myatr')
|
131
|
-
@obj.respond_to?(:myatr).
|
132
|
-
@obj.respond_to?(:myatr=).
|
131
|
+
expect(@obj.respond_to?(:myatr)).to be_truthy
|
132
|
+
expect(@obj.respond_to?(:myatr=)).to be_falsey
|
133
133
|
@obj.instance_eval { @myatr = 42 }
|
134
|
-
@obj.myatr.
|
134
|
+
expect(@obj.myatr).to eq(42)
|
135
135
|
end
|
136
136
|
|
137
137
|
it "should be able to create do-it-yourself setters such as for a positive integer" do
|
@@ -140,17 +140,17 @@ module ICU
|
|
140
140
|
raise "invalid positive integer (#{val})" unless tmp > 0
|
141
141
|
tmp
|
142
142
|
end
|
143
|
-
@obj.respond_to?(:myatr).
|
144
|
-
@obj.respond_to?(:myatr=).
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
@obj.myatr.
|
150
|
-
|
151
|
-
@obj.myatr.
|
152
|
-
|
153
|
-
@obj.myatr.
|
143
|
+
expect(@obj.respond_to?(:myatr)).to be_truthy
|
144
|
+
expect(@obj.respond_to?(:myatr=)).to be_truthy
|
145
|
+
expect { @obj.myatr = "no number here" }.to raise_error(/invalid positive integer \(no number here\)/)
|
146
|
+
expect { @obj.myatr = -1 }.to raise_error
|
147
|
+
expect { @obj.myatr = 0 }.to raise_error
|
148
|
+
expect { @obj.myatr = 1 }.not_to raise_error
|
149
|
+
expect(@obj.myatr).to eq(1)
|
150
|
+
expect { @obj.myatr = '42' }.not_to raise_error
|
151
|
+
expect(@obj.myatr).to eq(42)
|
152
|
+
expect { @obj.myatr = ' 0371 ' }.not_to raise_error
|
153
|
+
expect(@obj.myatr).to eq(371)
|
154
154
|
end
|
155
155
|
end
|
156
156
|
|
@@ -163,36 +163,36 @@ module ICU
|
|
163
163
|
end
|
164
164
|
|
165
165
|
it "should have a getter and setter" do
|
166
|
-
@obj.respond_to?(:myint).
|
167
|
-
@obj.respond_to?(:myint=).
|
166
|
+
expect(@obj.respond_to?(:myint)).to be_truthy
|
167
|
+
expect(@obj.respond_to?(:myint=)).to be_truthy
|
168
168
|
end
|
169
169
|
|
170
170
|
it "should work with ints" do
|
171
171
|
@obj.myint = -43
|
172
|
-
@obj.myint.
|
172
|
+
expect(@obj.myint).to eq(-43)
|
173
173
|
end
|
174
174
|
|
175
175
|
it "should work with strings" do
|
176
176
|
@obj.myint = " -99 "
|
177
|
-
@obj.myint.
|
177
|
+
expect(@obj.myint).to eq(-99)
|
178
178
|
end
|
179
179
|
|
180
180
|
it "should handle zero" do
|
181
|
-
|
182
|
-
|
181
|
+
expect { @obj.myint = 0 }.not_to raise_error
|
182
|
+
expect { @obj.myint = '0' }.not_to raise_error
|
183
183
|
end
|
184
184
|
|
185
185
|
it "should reject nil and other non-numbers" do
|
186
|
-
|
187
|
-
|
188
|
-
|
189
|
-
|
186
|
+
expect { @obj.myint = nil }.to raise_error(/invalid/)
|
187
|
+
expect { @obj.myint = "N" }.to raise_error(/invalid/)
|
188
|
+
expect { @obj.myint = " " }.to raise_error(/invalid/)
|
189
|
+
expect { @obj.myint = '' }.to raise_error(/invalid/)
|
190
190
|
end
|
191
191
|
|
192
192
|
it "should handle multiple names" do
|
193
193
|
@class.attr_integer :yourint, :hisint
|
194
|
-
@obj.respond_to?(:yourint).
|
195
|
-
@obj.respond_to?(:hisint=).
|
194
|
+
expect(@obj.respond_to?(:yourint)).to be_truthy
|
195
|
+
expect(@obj.respond_to?(:hisint=)).to be_truthy
|
196
196
|
end
|
197
197
|
end
|
198
198
|
|
@@ -205,27 +205,27 @@ module ICU
|
|
205
205
|
end
|
206
206
|
|
207
207
|
it "should have a getter and setter" do
|
208
|
-
@obj.respond_to?(:myint).
|
209
|
-
@obj.respond_to?(:myint=).
|
208
|
+
expect(@obj.respond_to?(:myint)).to be_truthy
|
209
|
+
expect(@obj.respond_to?(:myint=)).to be_truthy
|
210
210
|
end
|
211
211
|
|
212
212
|
it "should work with ints and nil and spaces" do
|
213
213
|
@obj.myint = 43
|
214
|
-
@obj.myint.
|
214
|
+
expect(@obj.myint).to eq(43)
|
215
215
|
@obj.myint = nil
|
216
|
-
@obj.myint.
|
216
|
+
expect(@obj.myint).to eq(nil)
|
217
217
|
@obj.myint = ' '
|
218
|
-
@obj.myint.
|
218
|
+
expect(@obj.myint).to eq(nil)
|
219
219
|
end
|
220
220
|
|
221
221
|
it "should reject non-numbers" do
|
222
|
-
|
222
|
+
expect { @obj.myint = "N" }.to raise_error(/invalid/)
|
223
223
|
end
|
224
224
|
|
225
225
|
it "should handle multiple names" do
|
226
226
|
@class.attr_integer :yourint, :hisint
|
227
|
-
@obj.respond_to?(:yourint).
|
228
|
-
@obj.respond_to?(:hisint=).
|
227
|
+
expect(@obj.respond_to?(:yourint)).to be_truthy
|
228
|
+
expect(@obj.respond_to?(:hisint=)).to be_truthy
|
229
229
|
end
|
230
230
|
end
|
231
231
|
|
@@ -238,26 +238,26 @@ module ICU
|
|
238
238
|
end
|
239
239
|
|
240
240
|
it "should have a getter and setter" do
|
241
|
-
@obj.respond_to?(:mypos).
|
242
|
-
@obj.respond_to?(:mypos=).
|
241
|
+
expect(@obj.respond_to?(:mypos)).to be_truthy
|
242
|
+
expect(@obj.respond_to?(:mypos=)).to be_truthy
|
243
243
|
end
|
244
244
|
|
245
245
|
it "should work as expected" do
|
246
246
|
@obj.mypos = "34"
|
247
|
-
@obj.mypos.
|
247
|
+
expect(@obj.mypos).to eq(34)
|
248
248
|
end
|
249
249
|
|
250
250
|
it "should reject nil and other non-positive integers" do
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
251
|
+
expect { @obj.mypos = nil }.to raise_error(/invalid/)
|
252
|
+
expect { @obj.mypos = 'X' }.to raise_error(/invalid/)
|
253
|
+
expect { @obj.mypos = '0' }.to raise_error(/invalid/)
|
254
|
+
expect { @obj.mypos = -13 }.to raise_error(/invalid/)
|
255
255
|
end
|
256
256
|
|
257
257
|
it "should handle multiple names" do
|
258
258
|
@class.attr_integer :ourpos, :theirpos
|
259
|
-
@obj.respond_to?(:ourpos).
|
260
|
-
@obj.respond_to?(:theirpos=).
|
259
|
+
expect(@obj.respond_to?(:ourpos)).to be_truthy
|
260
|
+
expect(@obj.respond_to?(:theirpos=)).to be_truthy
|
261
261
|
end
|
262
262
|
end
|
263
263
|
|
@@ -270,31 +270,31 @@ module ICU
|
|
270
270
|
end
|
271
271
|
|
272
272
|
it "should have a getter and setter" do
|
273
|
-
@obj.respond_to?(:mypon).
|
274
|
-
@obj.respond_to?(:mypon=).
|
273
|
+
expect(@obj.respond_to?(:mypon)).to be_truthy
|
274
|
+
expect(@obj.respond_to?(:mypon=)).to be_truthy
|
275
275
|
end
|
276
276
|
|
277
277
|
it "should work with numbers, nil, empty strings and spaces" do
|
278
278
|
@obj.mypon = " 54 "
|
279
|
-
@obj.mypon.
|
279
|
+
expect(@obj.mypon).to eq(54)
|
280
280
|
@obj.mypon = nil
|
281
|
-
@obj.mypon.
|
281
|
+
expect(@obj.mypon).to be_nil
|
282
282
|
@obj.mypon = ''
|
283
|
-
@obj.mypon.
|
283
|
+
expect(@obj.mypon).to be_nil
|
284
284
|
@obj.mypon = ' '
|
285
|
-
@obj.mypon.
|
285
|
+
expect(@obj.mypon).to be_nil
|
286
286
|
end
|
287
287
|
|
288
288
|
it "should reject non-integers and non-positive integers" do
|
289
|
-
|
290
|
-
|
291
|
-
|
289
|
+
expect { @obj.mypon = 'X' }.to raise_error(/invalid/)
|
290
|
+
expect { @obj.mypon = '0' }.to raise_error(/invalid/)
|
291
|
+
expect { @obj.mypon = -13 }.to raise_error(/invalid/)
|
292
292
|
end
|
293
293
|
|
294
294
|
it "should handle multiple names" do
|
295
295
|
@class.attr_integer :ourpon, :theirpon
|
296
|
-
@obj.respond_to?(:ourpon).
|
297
|
-
@obj.respond_to?(:theirpon=).
|
296
|
+
expect(@obj.respond_to?(:ourpon)).to be_truthy
|
297
|
+
expect(@obj.respond_to?(:theirpon=)).to be_truthy
|
298
298
|
end
|
299
299
|
end
|
300
300
|
|
@@ -307,26 +307,26 @@ module ICU
|
|
307
307
|
end
|
308
308
|
|
309
309
|
it "should have a getter and setter" do
|
310
|
-
@obj.respond_to?(:mydate).
|
311
|
-
@obj.respond_to?(:mydate=).
|
310
|
+
expect(@obj.respond_to?(:mydate)).to be_truthy
|
311
|
+
expect(@obj.respond_to?(:mydate=)).to be_truthy
|
312
312
|
end
|
313
313
|
|
314
314
|
it "should work as expected" do
|
315
315
|
@obj.mydate = "2009/11/09"
|
316
|
-
@obj.mydate.
|
316
|
+
expect(@obj.mydate).to eq('2009-11-09')
|
317
317
|
end
|
318
318
|
|
319
319
|
it "should reject nil and other non-dates" do
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
320
|
+
expect { @obj.mydate = nil }.to raise_error(/invalid/)
|
321
|
+
expect { @obj.mydate = 'blah de blah' }.to raise_error(/invalid/)
|
322
|
+
expect { @obj.mydate = ' ' }.to raise_error(/invalid/)
|
323
|
+
expect { @obj.mydate = 0 }.to raise_error(/invalid/)
|
324
324
|
end
|
325
325
|
|
326
326
|
it "should handle multiple names" do
|
327
327
|
@class.attr_date :ourdate, :theirdate
|
328
|
-
@obj.respond_to?(:ourdate).
|
329
|
-
@obj.respond_to?(:theirdate=).
|
328
|
+
expect(@obj.respond_to?(:ourdate)).to be_truthy
|
329
|
+
expect(@obj.respond_to?(:theirdate=)).to be_truthy
|
330
330
|
end
|
331
331
|
end
|
332
332
|
|
@@ -339,26 +339,26 @@ module ICU
|
|
339
339
|
end
|
340
340
|
|
341
341
|
it "should have a getter and setter" do
|
342
|
-
@obj.respond_to?(:mydate).
|
343
|
-
@obj.respond_to?(:mydate=).
|
342
|
+
expect(@obj.respond_to?(:mydate)).to be_truthy
|
343
|
+
expect(@obj.respond_to?(:mydate=)).to be_truthy
|
344
344
|
end
|
345
345
|
|
346
346
|
it "should work as expected, including with nil" do
|
347
347
|
@obj.mydate = "2009/11/09"
|
348
|
-
@obj.mydate.
|
348
|
+
expect(@obj.mydate).to eq('2009-11-09')
|
349
349
|
@obj.mydate = nil
|
350
|
-
@obj.mydate.
|
350
|
+
expect(@obj.mydate).to be_nil
|
351
351
|
end
|
352
352
|
|
353
353
|
it "should reject non-dates" do
|
354
|
-
|
355
|
-
|
354
|
+
expect { @obj.mydate = 'blah de blah' }.to raise_error(/invalid/)
|
355
|
+
expect { @obj.mydate = 0 }.to raise_error(/invalid/)
|
356
356
|
end
|
357
357
|
|
358
358
|
it "should handle multiple names" do
|
359
359
|
@class.attr_date :ourdate, :theirdate
|
360
|
-
@obj.respond_to?(:ourdate).
|
361
|
-
@obj.respond_to?(:theirdate=).
|
360
|
+
expect(@obj.respond_to?(:ourdate)).to be_truthy
|
361
|
+
expect(@obj.respond_to?(:theirdate=)).to be_truthy
|
362
362
|
end
|
363
363
|
end
|
364
364
|
|
@@ -371,28 +371,28 @@ module ICU
|
|
371
371
|
end
|
372
372
|
|
373
373
|
it "should have a getter and setter" do
|
374
|
-
@obj.respond_to?(:mystring).
|
375
|
-
@obj.respond_to?(:mystring=).
|
374
|
+
expect(@obj.respond_to?(:mystring)).to be_truthy
|
375
|
+
expect(@obj.respond_to?(:mystring=)).to be_truthy
|
376
376
|
end
|
377
377
|
|
378
378
|
it "should work as expected" do
|
379
379
|
@obj.mystring = " mark "
|
380
|
-
@obj.mystring.
|
380
|
+
expect(@obj.mystring).to eq('mark')
|
381
381
|
end
|
382
382
|
|
383
383
|
it "should reject values that don't match" do
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
388
|
-
|
389
|
-
|
384
|
+
expect { @obj.mystring = nil }.to raise_error(/invalid/)
|
385
|
+
expect { @obj.mystring = ' 123 ' }.to raise_error(/invalid/)
|
386
|
+
expect { @obj.mystring = ' ' }.to raise_error(/invalid/)
|
387
|
+
expect { @obj.mystring = 0 }.to raise_error(/invalid/)
|
388
|
+
expect { @obj.mystring = ' a ' }.not_to raise_error
|
389
|
+
expect { @obj.mystring = 'ZYX' }.not_to raise_error
|
390
390
|
end
|
391
391
|
|
392
392
|
it "should handle multiple names" do
|
393
393
|
@class.attr_string %r%^[A-Z]{3}$%, :ourstring, :theirstring
|
394
|
-
@obj.respond_to?(:ourstring=).
|
395
|
-
@obj.respond_to?(:theirstring).
|
394
|
+
expect(@obj.respond_to?(:ourstring=)).to be_truthy
|
395
|
+
expect(@obj.respond_to?(:theirstring)).to be_truthy
|
396
396
|
end
|
397
397
|
end
|
398
398
|
|
@@ -405,30 +405,30 @@ module ICU
|
|
405
405
|
end
|
406
406
|
|
407
407
|
it "should have a getter and setter" do
|
408
|
-
@obj.respond_to?(:mystring).
|
409
|
-
@obj.respond_to?(:mystring=).
|
408
|
+
expect(@obj.respond_to?(:mystring)).to be_truthy
|
409
|
+
expect(@obj.respond_to?(:mystring=)).to be_truthy
|
410
410
|
end
|
411
411
|
|
412
412
|
it "should work as expected" do
|
413
413
|
@obj.mystring = " 12345 "
|
414
|
-
@obj.mystring.
|
414
|
+
expect(@obj.mystring).to eq('12345')
|
415
415
|
@obj.mystring = nil
|
416
|
-
@obj.mystring.
|
416
|
+
expect(@obj.mystring).to be_nil
|
417
417
|
@obj.mystring = ' '
|
418
|
-
@obj.mystring.
|
418
|
+
expect(@obj.mystring).to be_nil
|
419
419
|
end
|
420
420
|
|
421
421
|
it "should reject values that don't match" do
|
422
|
-
|
423
|
-
|
424
|
-
|
425
|
-
|
422
|
+
expect { @obj.mystring = ' 0 ' }.to raise_error(/invalid/)
|
423
|
+
expect { @obj.mystring = 0 }.to raise_error(/invalid/)
|
424
|
+
expect { @obj.mystring = -1 }.to raise_error(/invalid/)
|
425
|
+
expect { @obj.mystring = 98 }.not_to raise_error
|
426
426
|
end
|
427
427
|
|
428
428
|
it "should handle multiple names" do
|
429
429
|
@class.attr_string %r%^[A-Z][a-z]+%, :ourstring, :theirstring
|
430
|
-
@obj.respond_to?(:ourstring=).
|
431
|
-
@obj.respond_to?(:theirstring).
|
430
|
+
expect(@obj.respond_to?(:ourstring=)).to be_truthy
|
431
|
+
expect(@obj.respond_to?(:theirstring)).to be_truthy
|
432
432
|
end
|
433
433
|
end
|
434
434
|
end
|