-
Notifications
You must be signed in to change notification settings - Fork 243
Expand file tree
/
Copy pathPathname_test.rb
More file actions
851 lines (721 loc) · 26.2 KB
/
Pathname_test.rb
File metadata and controls
851 lines (721 loc) · 26.2 KB
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
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
require_relative "test_helper"
require 'pathname'
class PathnameSingletonTest < Test::Unit::TestCase
include TestHelper
library 'pathname'
testing 'singleton(::Pathname)'
def test_getwd
assert_send_type '() -> Pathname',
Pathname, :getwd
end
def test_glob
assert_send_type '(String) -> Array[Pathname]',
Pathname, :glob, '*'
assert_send_type '(Array[String]) -> Array[Pathname]',
Pathname, :glob, ['*', 'lib/*']
assert_send_type '(String, ?Integer) -> Array[Pathname]',
Pathname, :glob, '*', File::FNM_NOESCAPE
assert_send_type '(String) { (Pathname) -> untyped } -> nil',
Pathname, :glob, '*' do true end
end
def test_pwd
assert_send_type '() -> Pathname',
Pathname, :pwd
end
def test_initialize
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'
assert_send_type '(String) -> Pathname',
Pathname, :new, 'foo'
assert_send_type '(ToStr) -> Pathname',
Pathname, :new, ToStr.new('foo')
assert_send_type '(Pathname) -> Pathname',
Pathname, :new, Pathname('foo')
end
end
class PathnameInstanceTest < Test::Unit::TestCase
include TestHelper
library 'pathname'
testing '::Pathname'
def test_plus
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'
assert_send_type '(Pathname) -> Pathname',
Pathname('foo'), :+, Pathname('bar')
assert_send_type '(String) -> Pathname',
Pathname('foo'), :+, 'bar'
assert_send_type '(ToStr) -> Pathname',
Pathname('foo'), :+, ToStr.new('bar')
end
def test_slash
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'
assert_send_type '(Pathname) -> Pathname',
Pathname('foo'), :/, Pathname('bar')
assert_send_type '(String) -> Pathname',
Pathname('foo'), :/, 'bar'
assert_send_type '(ToStr) -> Pathname',
Pathname('foo'), :/, ToStr.new('bar')
end
def test_spaceship
assert_send_type '(Pathname) -> Integer',
Pathname('foo'), :<=>, Pathname('bar')
assert_send_type '(untyped) -> nil',
Pathname('foo'), :<=>, 'foo'
end
def test_eqeq
assert_send_type '(Pathname) -> bool',
Pathname('foo'), :==, Pathname('bar')
assert_send_type '(Pathname) -> bool',
Pathname('foo'), :==, Pathname('foo')
end
def test_eqeqeq
assert_send_type '(Pathname) -> bool',
Pathname('foo'), :===, Pathname('bar')
assert_send_type '(Pathname) -> bool',
Pathname('foo'), :===, Pathname('foo')
end
def test_absolute?
assert_send_type '() -> bool',
Pathname('foo'), :absolute?
assert_send_type '() -> bool',
Pathname('/foo'), :absolute?
end
def test_ascend
assert_send_type '() { (Pathname) -> untyped } -> nil',
Pathname('foo'), :ascend do end
assert_send_type '() -> Enumerator[Pathname, nil]',
Pathname('foo'), :ascend
end
def test_atime
assert_send_type '() -> Time',
Pathname('/'), :atime
end
def test_basename
assert_send_type '() -> Pathname',
Pathname('foo/bar.rb'), :basename
assert_send_type '(String) -> Pathname',
Pathname('foo/bar.rb'), :basename, '.rb'
assert_send_type '(ToStr) -> Pathname',
Pathname('foo/bar.rb'), :basename, ToStr.new('.rb')
end
def test_binread
assert_send_type '() -> String',
Pathname(File.expand_path(__FILE__)), :binread
assert_send_type '(Integer) -> String',
Pathname(File.expand_path(__FILE__)), :binread, 42
assert_send_type '(Integer, Integer) -> String',
Pathname(File.expand_path(__FILE__)), :binread, 42, 43
end
def test_binwrite
Tempfile.create('rbs-pathname-binwrite-test') do |f|
f.close
path = Pathname(f.path)
assert_send_type '(String) -> Integer',
path, :binwrite, 'foo'
assert_send_type '(String, Integer) -> Integer',
path, :binwrite, 'foo', 42
assert_send_type '(String, Integer, textmode: String) -> Integer',
path, :binwrite, 'foo', 42, textmode: "true"
end
end
def test_birthtime
assert_send_type '() -> Time',
Pathname('/'), :birthtime
rescue NotImplementedError
end
def test_blockdev?
assert_send_type '() -> bool',
Pathname('/'), :blockdev?
assert_send_type '() -> bool',
Pathname('/unknown'), :blockdev?
assert_send_type '() -> bool',
Pathname('/dev/sda1'), :blockdev?
end
def test_chardev?
assert_send_type '() -> bool',
Pathname('/'), :chardev?
assert_send_type '() -> bool',
Pathname('/unknown'), :chardev?
assert_send_type '() -> bool',
Pathname('/dev/sda1'), :chardev?
end
def test_children
assert_send_type '() -> Array[Pathname]',
Pathname('.'), :children
assert_send_type '(bool) -> Array[Pathname]',
Pathname('.'), :children, false
end
def test_chmod
Tempfile.create('rbs-pathname-chmod-test') do |f|
path = Pathname(f.path)
assert_send_type '(Integer) -> Integer',
path, :chmod, 0644
end
end
def test_chown
Tempfile.create('rbs-pathname-chown-test') do |f|
path = Pathname(f.path)
assert_send_type '(Integer, Integer) -> Integer',
path, :chown, path.stat.uid, path.stat.gid
end
end
def test_cleanpath
assert_send_type '() -> Pathname',
Pathname('foo/../bar'), :cleanpath
assert_send_type '(bool) -> Pathname',
Pathname('foo/../bar'), :cleanpath, true
end
def test_ctime
assert_send_type '() -> Time',
Pathname('/'), :ctime
end
def test_delete
Tempfile.create('rbs-pathname-delete-test') do |f|
path = Pathname(f.path)
assert_send_type '() -> Integer',
path, :delete
end
end
def test_descend
assert_send_type '() { (Pathname) -> untyped } -> nil',
Pathname('foo'), :descend do end
assert_send_type '() -> Enumerator[Pathname, nil]',
Pathname('foo'), :descend
end
def test_directory?
assert_send_type '() -> bool',
Pathname('foo'), :directory?
assert_send_type '() -> bool',
Pathname('.'), :directory?
end
def test_dirname
assert_send_type '() -> Pathname',
Pathname('foo'), :dirname
end
def test_each_child
assert_send_type '() { (Pathname) -> untyped } -> Array[Pathname]',
Pathname('.'), :each_child do end
assert_send_type '() -> Enumerator[Pathname, Array[Pathname]]',
Pathname('.'), :each_child
end
def test_each_entry
assert_send_type '() { (Pathname) -> untyped } -> nil',
Pathname('.'), :each_entry do end
end
def test_each_filename
assert_send_type '() { (String) -> untyped } -> nil',
Pathname('/usr/bin/ruby'), :each_filename do end
assert_send_type '() -> Enumerator[String, nil]',
Pathname('/usr/bin/ruby'), :each_filename
end
def test_each_line
path = Pathname(File.expand_path(__FILE__))
assert_send_type '() { (String) -> untyped } -> nil',
path, :each_line do end
assert_send_type '(String) { (String) -> untyped } -> nil',
path, :each_line, 'def' do end
assert_send_type '(String, Integer) { (String) -> untyped } -> nil',
path, :each_line, 'def', 42 do end
assert_send_type '(Integer) { (String) -> untyped } -> nil',
path, :each_line, 42 do end
assert_send_type '() -> Enumerator[String, nil]',
path, :each_line
end
def test_empty?
assert_send_type '() -> bool',
Pathname('.'), :empty?
end
def test_entries
assert_send_type '() -> Array[Pathname]',
Pathname(__dir__), :entries
end
def test_eql?
path = Pathname('.')
assert_send_type '(untyped) -> bool',
path, :eql?, path
assert_send_type '(untyped) -> bool',
path, :eql?, 'foobar'
end
def test_executable?
assert_send_type '() -> bool',
Pathname('/usr/bin/env'), :executable?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :executable?
end
def test_executable_real?
assert_send_type '() -> bool',
Pathname('/usr/bin/env'), :executable_real?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :executable_real?
end
def test_exist?
assert_send_type '() -> bool',
Pathname('/'), :exist?
assert_send_type '() -> bool',
Pathname('/unknown'), :exist?
end
def test_expand_path
assert_send_type '() -> Pathname',
Pathname('~/'), :expand_path
assert_send_type '(String) -> Pathname',
Pathname('./foo'), :expand_path, __dir__
end
def test_extname
assert_send_type '() -> String',
Pathname('test.rb'), :extname
end
def test_file?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :file?
assert_send_type '() -> bool',
Pathname('/unknown'), :file?
end
def test_find
assert_send_type '() { (Pathname) -> untyped } -> nil',
Pathname(__dir__), :find do end
assert_send_type '(ignore_error: bool) -> Enumerator[Pathname, nil]',
Pathname(__dir__), :find, ignore_error: true
assert_send_type '(ignore_error: Symbol) -> Enumerator[Pathname, nil]',
Pathname(__dir__), :find, ignore_error: :true
assert_send_type '() -> Enumerator[Pathname, nil]',
Pathname(__dir__), :find
end
def test_fnmatch
assert_send_type '(String) -> bool',
Pathname('foo'), :fnmatch, 'fo*'
assert_send_type '(String) -> bool',
Pathname('foo'), :fnmatch, 'ba*'
end
def test_fnmatch?
assert_send_type '(String) -> bool',
Pathname('foo'), :fnmatch?, 'fo*'
assert_send_type '(String) -> bool',
Pathname('foo'), :fnmatch?, 'ba*'
end
def test_freeze
assert_send_type '() -> Pathname',
Pathname('foo'), :freeze
end
def test_ftype
assert_send_type '() -> String',
Pathname(File.expand_path(__FILE__)), :ftype
assert_send_type '() -> String',
Pathname(__dir__), :ftype
end
def test_glob
assert_send_type '(String) -> Array[Pathname]',
Pathname('.'), :glob, '*'
assert_send_type '(Array[String]) -> Array[Pathname]',
Pathname('.'), :glob, ['*', 'lib/*']
assert_send_type '(String, ?Integer) -> Array[Pathname]',
Pathname('.'), :glob, '*', File::FNM_NOESCAPE
assert_send_type '(String) { (Pathname) -> untyped } -> nil',
Pathname('.'), :glob, '*' do end
end
def test_grpowned?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :grpowned?
assert_send_type '() -> bool',
Pathname('/'), :grpowned?
end
def test_hash
assert_send_type '() -> Integer',
Pathname('.'), :hash
end
def test_inspect
assert_send_type '() -> String',
Pathname('.'), :inspect
end
def test_join
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'
assert_send_type '() -> Pathname',
Pathname('.'), :join
assert_send_type '(String) -> Pathname',
Pathname('.'), :join, 'foo'
assert_send_type '(String, String) -> Pathname',
Pathname('.'), :join, 'foo', 'bar'
assert_send_type '(ToStr) -> Pathname',
Pathname('.'), :join, ToStr.new('foo')
assert_send_type '(Pathname) -> Pathname',
Pathname('.'), :join, Pathname('foo')
end
def test_lchmod
Tempfile.create('rbs-pathname-lchmod-test') do |f|
path = Pathname(f.path)
assert_send_type '(Integer) -> Integer',
path, :lchmod, 0644
rescue NotImplementedError
end
end
def test_lchown
Tempfile.create('rbs-pathname-lchown-test') do |f|
path = Pathname(f.path)
assert_send_type '(Integer, Integer) -> Integer',
path, :lchown, path.stat.uid, path.stat.gid
end
end
def test_lstat
assert_send_type '() -> ::File::Stat',
Pathname(File.expand_path(__FILE__)), :lstat
end
def test_make_link
Dir.mktmpdir do |dir|
dir = Pathname(dir)
src = dir + 'src'
FileUtils.touch src
assert_send_type '(String) -> Integer',
dir + 'dst1', :make_link, src.to_s
assert_send_type '(Pathname) -> Integer',
dir + 'dst2', :make_link, src
assert_send_type '(ToStr) -> Integer',
dir + 'dst3', :make_link, ToStr.new(src.to_s)
end
end
def test_make_symlink
Dir.mktmpdir do |dir|
dir = Pathname(dir)
src = dir + 'src'
FileUtils.touch src
assert_send_type '(String) -> Integer',
dir + 'dst1', :make_symlink, src.to_s
assert_send_type '(Pathname) -> Integer',
dir + 'dst2', :make_symlink, src
assert_send_type '(ToStr) -> Integer',
dir + 'dst3', :make_symlink, ToStr.new(src.to_s)
end
end
def test_mkdir
Dir.mktmpdir do |dir|
dir = Pathname(dir)
assert_send_type '() -> Integer',
dir + 'a', :mkdir
assert_send_type '(Integer) -> Integer',
dir + 'b', :mkdir, 0700
end
end
def test_mkpath
Dir.mktmpdir do |dir|
dir = Pathname(dir)
assert_send_type '() -> Pathname',
dir + 'a/b/c', :mkpath
end
end
def test_mountpoint?
assert_send_type '() -> bool',
Pathname('/'), :mountpoint?
assert_send_type '() -> bool',
Pathname('/etc'), :mountpoint?
end
def test_mtime
assert_send_type '() -> Time',
Pathname('/'), :mtime
end
def test_open
Tempfile.create('rbs-pathname-binwrite-test') do |f|
path = Pathname(f.path)
assert_send_type '() -> File',
path, :open
assert_send_type '(String) -> File',
path, :open, 'r'
assert_send_type '(String, Integer) -> File',
path, :open, 'r', 0644
assert_send_type '() { (File) -> true} -> true',
path, :open do true end
end
end
def test_opendir
assert_send_type '() -> Dir',
Pathname(__dir__), :opendir
assert_send_type '() { (Dir) -> true } -> true',
Pathname(__dir__), :opendir do true end
refute_send_type '(encoding: Encoding) -> Dir',
Pathname(__dir__), :opendir, encoding: Encoding::UTF_8
end
def test_owened?
assert_send_type '() -> bool',
Pathname('/'), :owned?
end
def test_parent
assert_send_type '() -> Pathname',
Pathname('/foo/bar'), :parent
assert_send_type '() -> Pathname',
Pathname('/'), :parent
end
def test_pipe?
assert_send_type '() -> bool',
Pathname('/'), :pipe?
end
def test_read
assert_send_type '() -> String',
Pathname(File.expand_path(__FILE__)), :read
assert_send_type '(Integer) -> String',
Pathname(File.expand_path(__FILE__)), :read, 42
assert_send_type '(Integer, Integer) -> String',
Pathname(File.expand_path(__FILE__)), :read, 42, 43
assert_send_type '(encoding: String) -> String',
Pathname(File.expand_path(__FILE__)), :read, encoding: 'UTF-8'
assert_send_type '(encoding: ToStr) -> String',
Pathname(File.expand_path(__FILE__)), :read, encoding: ToStr.new('UTF-8')
assert_send_type '(encoding: Encoding) -> String',
Pathname(File.expand_path(__FILE__)), :read, encoding: Encoding::UTF_8
end
def test_readable?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :readable?
end
def test_readable_real?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :readable_real?
end
def test_readlines
assert_send_type '() -> Array[String]',
Pathname(File.expand_path(__FILE__)), :readlines
assert_send_type '(String) -> Array[String]',
Pathname(File.expand_path(__FILE__)), :readlines, 'a'
assert_send_type '(Integer) -> Array[String]',
Pathname(File.expand_path(__FILE__)), :readlines, 42
assert_send_type '(String, Integer) -> Array[String]',
Pathname(File.expand_path(__FILE__)), :readlines, 'a', 42
assert_send_type '(String, Integer, chomp: true) -> Array[String]',
Pathname(File.expand_path(__FILE__)), :readlines, 'a', 42, chomp: true
assert_send_type '(String, Integer, binmode: true) -> Array[String]',
Pathname(File.expand_path(__FILE__)), :readlines, 'a', 42, binmode: true
end
def test_readlink
Dir.mktmpdir do |dir|
dir = Pathname(dir)
src = dir.join('src')
dst = dir.join('dst')
FileUtils.touch src
dst.make_symlink(src)
assert_send_type '() -> Pathname',
dst, :readlink
end
end
def test_realdirpath
assert_send_type '() -> Pathname',
Pathname(File.expand_path(__FILE__)), :realdirpath
assert_send_type '(String) -> Pathname',
Pathname(File.expand_path(__FILE__)), :realdirpath, '.'
assert_send_type '(ToStr) -> Pathname',
Pathname(File.expand_path(__FILE__)), :realdirpath, ToStr.new('.')
assert_send_type '(Pathname) -> Pathname',
Pathname(File.expand_path(__FILE__)), :realdirpath, Pathname.new('.')
end
def test_realpath
assert_send_type '() -> Pathname',
Pathname(File.expand_path(__FILE__)), :realpath
assert_send_type '(String) -> Pathname',
Pathname(File.expand_path(__FILE__)), :realpath, '.'
assert_send_type '(ToStr) -> Pathname',
Pathname(File.expand_path(__FILE__)), :realpath, ToStr.new('.')
assert_send_type '(Pathname) -> Pathname',
Pathname(File.expand_path(__FILE__)), :realpath, Pathname.new('.')
end
def test_relative?
assert_send_type '() -> bool',
Pathname('.'), :relative?
assert_send_type '() -> bool',
Pathname('/'), :relative?
end
def test_relative_path_from
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'
assert_send_type '(Pathname) -> Pathname',
Pathname('.'), :relative_path_from, Pathname('.')
assert_send_type '(String) -> Pathname',
Pathname('.'), :relative_path_from, '.'
assert_send_type '(_ToStr) -> Pathname',
Pathname('.'), :relative_path_from, ToStr.new('.').__with_object_methods(:is_a?)
end
def test_rename
Dir.mktmpdir do |dir|
dir = Pathname(dir)
src = dir.join('src')
dst1 = dir.join('dst1')
dst2 = dir.join('dst2')
dst3 = dir.join('dst3')
FileUtils.touch src
assert_send_type '(Pathname) -> 0',
src, :rename, dst1
assert_send_type '(String) -> 0',
dst1, :rename, dst2.to_s
assert_send_type '(ToStr) -> 0',
dst2, :rename, ToStr.new(dst3.to_s)
end
end
def test_rmdir
Dir.mktmpdir do |dir|
target = Pathname(dir).join('target')
target.mkdir
assert_send_type '() -> 0',
target, :rmdir
end
end
def test_rmtree
Dir.mktmpdir do |dir|
target = Pathname(dir).join('target')
target.mkdir
assert_send_type '() -> Pathname',
target, :rmtree
end
end
def test_root?
assert_send_type '() -> bool',
Pathname('.'), :root?
assert_send_type '() -> bool',
Pathname('/'), :root?
end
def test_setgid?
assert_send_type '() -> bool',
Pathname('.'), :setgid?
end
def test_setuid?
assert_send_type '() -> bool',
Pathname('.'), :setuid?
end
def test_size
assert_send_type '() -> Integer',
Pathname(File.expand_path(__FILE__)), :size
end
def test_size?
assert_send_type '() -> Integer',
Pathname(File.expand_path(__FILE__)), :size?
assert_send_type '() -> nil',
Pathname('/does/not/exist'), :size?
end
def test_socket?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :socket?
end
def test_split
assert_send_type '() -> [Pathname, Pathname]',
Pathname(File.expand_path(__FILE__)), :split
assert_send_type '() -> [Pathname, Pathname]',
Pathname('/'), :split
end
def test_stat
assert_send_type '() -> File::Stat',
Pathname(File.expand_path(__FILE__)), :stat
end
def test_sticky?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :sticky?
end
def test_sub
assert_send_type '(String, String) -> Pathname',
Pathname("/usr/bin/perl"), :sub, "perl", 'ruby'
assert_send_type '(ToStr, ToStr) -> Pathname',
Pathname("/usr/bin/perl"), :sub, ToStr.new("perl"), ToStr.new('ruby')
assert_send_type '(Regexp, Hash[String, String]) -> Pathname',
Pathname("/usr/bin/perl"), :sub, /perl/, { 'perl' => 'ruby' }
assert_send_type '(String) { (String) -> String } -> Pathname',
Pathname("/usr/bin/perl"), :sub, 'perl' do 'ruby' end
end
def test_sub_ext
assert_send_type '(String) -> Pathname',
Pathname("foo.rb"), :sub_ext, '.rbs'
assert_send_type '(ToStr) -> Pathname',
Pathname("foo.rb"), :sub_ext, ToStr.new('.rbs')
end
def test_symlink?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :symlink?
end
def test_sysopen
assert_send_type '() -> Integer',
Pathname(File.expand_path(__FILE__)), :sysopen
assert_send_type '(String) -> Integer',
Pathname(File.expand_path(__FILE__)), :sysopen, 'r'
assert_send_type '(String, Integer) -> Integer',
Pathname(File.expand_path(__FILE__)), :sysopen, 'r', 0644
end
def test_taint
if Pathname.method_defined?(:taint)
assert_send_type '() -> Pathname',
Pathname(File.expand_path(__FILE__)), :taint
end
end
def test_to_path
assert_send_type '() -> String',
Pathname(File.expand_path(__FILE__)), :to_path
end
def test_truncate
Tempfile.create('rbs-pathname-truncate-test') do |f|
path = Pathname(f.path)
assert_send_type '(Integer) -> 0',
path, :truncate, 42
end
end
def test_unlink
Tempfile.create('rbs-pathname-unlink-test') do |f|
path = Pathname(f.path)
assert_send_type '() -> Integer',
path, :unlink
end
end
def test_untaint
if Pathname.method_defined?(:untaint)
assert_send_type '() -> Pathname',
Pathname(File.expand_path(__FILE__)), :untaint
end
end
def test_utime
Tempfile.create('rbs-pathname-unlink-test') do |f|
path = Pathname(f.path)
now = Time.now
assert_send_type '(Time, Time) -> Integer',
path, :utime, now, now
assert_send_type '(Integer, Integer) -> Integer',
path, :utime, now.to_i, now.to_i
end
end
def test_world_readable?
assert_send_type '() -> (Integer | nil)',
Pathname(File.expand_path(__FILE__)), :world_readable?
assert_send_type '() -> (Integer | nil)',
Pathname('/'), :world_readable?
end
def test_world_writable?
assert_send_type '() -> (Integer | nil)',
Pathname(File.expand_path(__FILE__)), :world_writable?
assert_send_type '() -> (Integer | nil)',
Pathname('/'), :world_writable?
end
def test_writable?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :writable?
assert_send_type '() -> bool',
Pathname('/'), :writable?
end
def test_write
Tempfile.create('rbs-pathname-write-test') do |f|
path = Pathname(f.path)
assert_send_type '(String) -> Integer',
path, :write, 'foo'
assert_send_type '(String, Integer) -> Integer',
path, :write, 'foo', 42
assert_send_type '(String, Integer, encoding: Encoding) -> Integer',
path, :write, 'foo', 42, encoding: Encoding::UTF_8
end
end
def test_zero?
assert_send_type '() -> bool',
Pathname(File.expand_path(__FILE__)), :zero?
end
end
class PathnameKernelTest < Test::Unit::TestCase
include TestHelper
library 'pathname'
testing '::Kernel'
def test_Pathname
omit "Pathname is developing in head" if RUBY_VERSION >= '3.5'
with_string("Gemfile") do
assert_send_type(
"(::string) -> ::Pathname",
self, :Pathname, _1
)
end
assert_send_type(
"(::Pathname) -> ::Pathname",
self, :Pathname, Pathname.pwd
)
end
end