tagen 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/.gitignore +2 -0
- data/.yardopts +5 -0
- data/Gemfile +7 -0
- data/Gemfile.lock +24 -0
- data/README.md +60 -0
- data/Rakefile +9 -0
- data/docs/Architecture.md +17 -0
- data/docs/CoreExtensions.md +56 -0
- data/docs/ExtraExtensions.md +20 -0
- data/lib/tagen/audioinfo.rb +21 -0
- data/lib/tagen/cairo.rb +809 -0
- data/lib/tagen/core.rb +34 -0
- data/lib/tagen/core/array.rb +41 -0
- data/lib/tagen/core/array/extract_options.rb +40 -0
- data/lib/tagen/core/hash.rb +17 -0
- data/lib/tagen/core/io.rb +29 -0
- data/lib/tagen/core/kernel.rb +73 -0
- data/lib/tagen/core/marshal.rb +34 -0
- data/lib/tagen/core/module.rb +25 -0
- data/lib/tagen/core/numeric.rb +10 -0
- data/lib/tagen/core/object.rb +21 -0
- data/lib/tagen/core/pa.rb +187 -0
- data/lib/tagen/core/pa/cmd.rb +374 -0
- data/lib/tagen/core/pa/dir.rb +144 -0
- data/lib/tagen/core/pa/path.rb +190 -0
- data/lib/tagen/core/pa/state.rb +56 -0
- data/lib/tagen/core/process.rb +11 -0
- data/lib/tagen/core/re.rb +8 -0
- data/lib/tagen/core/string.rb +43 -0
- data/lib/tagen/core/string/pyformat.rb +322 -0
- data/lib/tagen/core/time.rb +8 -0
- data/lib/tagen/gdk_pixbuf2.rb +26 -0
- data/lib/tagen/gtk2.rb +122 -0
- data/lib/tagen/magick.rb +23 -0
- data/lib/tagen/ncurses.rb +245 -0
- data/lib/tagen/net/http.rb +34 -0
- data/lib/tagen/pathname.rb +8 -0
- data/lib/tagen/poppler.rb +47 -0
- data/lib/tagen/socket.rb +20 -0
- data/lib/tagen/tree.rb +75 -0
- data/lib/tagen/vim.rb +19 -0
- data/lib/tagen/xmpp4r.rb +1 -0
- data/lib/tagen/xmpp4r/roster.rb +20 -0
- data/spec/cairo_spec.rb +137 -0
- data/spec/core/pa/cmd_spec.rb +251 -0
- data/spec/core/pa/dir_spec.rb +59 -0
- data/spec/core/string/pyformat_spec.rb +86 -0
- data/spec/spec_helper.rb +0 -0
- data/tagen.gemspec +20 -0
- data/version.rb +7 -0
- metadata +117 -0
@@ -0,0 +1,47 @@
|
|
1
|
+
=begin
|
2
|
+
* **Install**: Ruby-Gnome
|
3
|
+
=end
|
4
|
+
module Poppler
|
5
|
+
|
6
|
+
=begin
|
7
|
+
Additional Method List
|
8
|
+
---------------------
|
9
|
+
* \#npages: _alias from size_
|
10
|
+
=end
|
11
|
+
class Document
|
12
|
+
alias npages size
|
13
|
+
# get width height
|
14
|
+
def wh; self[0].size end
|
15
|
+
# get width
|
16
|
+
def w; wh[0] end
|
17
|
+
# get height
|
18
|
+
def h; wh[1] end
|
19
|
+
end # class Document
|
20
|
+
|
21
|
+
=begin
|
22
|
+
Additional Method List
|
23
|
+
----------------------
|
24
|
+
* \#wh: _alias from size_
|
25
|
+
=end
|
26
|
+
class Page
|
27
|
+
alias wh size
|
28
|
+
# get width
|
29
|
+
def w; size[0] end
|
30
|
+
# get height
|
31
|
+
def h; size[1] end
|
32
|
+
|
33
|
+
# used when 'cairo' is installed
|
34
|
+
#
|
35
|
+
# @return [Cairo::Context]
|
36
|
+
def cairo_context
|
37
|
+
require "cairo"
|
38
|
+
require_relative "cairo"
|
39
|
+
surface = Cairo::ImageSurface.new(*self.wh)
|
40
|
+
ctx = Cairo::Context.new(surface)
|
41
|
+
render(ctx)
|
42
|
+
ctx
|
43
|
+
end # def cairo_context
|
44
|
+
|
45
|
+
end # class Page
|
46
|
+
|
47
|
+
end # module Poppler
|
data/lib/tagen/socket.rb
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
class Socket
|
2
|
+
class <<self
|
3
|
+
# pack human-readable address to Socket address
|
4
|
+
#
|
5
|
+
# @example
|
6
|
+
# addr("192.168.1.1") #=> "\xC0\xA8\x01\x01"
|
7
|
+
#
|
8
|
+
# @return [String] address used by Socket
|
9
|
+
# @see unaddr
|
10
|
+
def addr(str) str.split(".").map{|v|v.to_i}.pack("CCCC") end
|
11
|
+
|
12
|
+
# unpack to humna-readable address from Socket address
|
13
|
+
#
|
14
|
+
# @example
|
15
|
+
# unaddr("\xC0\xA8\x01\x01") #=> "192.168.1.1"
|
16
|
+
#
|
17
|
+
# @return [String] human readable address
|
18
|
+
def unaddr(str) str.unpack("CCCC").join(".") end
|
19
|
+
end
|
20
|
+
end
|
data/lib/tagen/tree.rb
ADDED
@@ -0,0 +1,75 @@
|
|
1
|
+
=begin
|
2
|
+
* **Install**: gem(rubytree)
|
3
|
+
=end
|
4
|
+
module Tree
|
5
|
+
Fatal = Class.new Exception
|
6
|
+
Error = Class.new Exception
|
7
|
+
ENoNode = Class.new Error
|
8
|
+
|
9
|
+
class TreeNode
|
10
|
+
|
11
|
+
# get a Node name
|
12
|
+
def get name
|
13
|
+
return name if self.class===name
|
14
|
+
treetage = Array===name ? name : name.split(/ +/)
|
15
|
+
|
16
|
+
treetage.gach self.root do |n,i,m|
|
17
|
+
if m[n]
|
18
|
+
m[n]
|
19
|
+
else
|
20
|
+
raise ENoNode, "'#{n}` node doesn't exists for root `#{root.name}'"
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
# set a Node name
|
26
|
+
def name= name
|
27
|
+
old = @name
|
28
|
+
@name = name
|
29
|
+
children_hash = parent.instance_variable.get :@children_hash
|
30
|
+
children_hash.delete old
|
31
|
+
children_hash[@name] = self
|
32
|
+
end
|
33
|
+
|
34
|
+
alias original_parentage parentage
|
35
|
+
# * default return nil for root
|
36
|
+
# * now return [] for root
|
37
|
+
def parentage
|
38
|
+
is_root? ? [] : original_parentage
|
39
|
+
end
|
40
|
+
|
41
|
+
# parentage in reverse
|
42
|
+
# @see parentage
|
43
|
+
def treetage
|
44
|
+
([self.name] + self.parentage.map{|v| v.name}).reverse[1..-1]
|
45
|
+
end
|
46
|
+
|
47
|
+
# return "a b c"
|
48
|
+
def treename
|
49
|
+
self.treetage.join(" ")
|
50
|
+
end
|
51
|
+
|
52
|
+
def __compare other
|
53
|
+
raise ArgumentError, "comparison '{self}` with '{other}` failed"
|
54
|
+
.format(self.class, other) unless self.class === other
|
55
|
+
|
56
|
+
a = self.treetage
|
57
|
+
b = other.treetage
|
58
|
+
|
59
|
+
if a.length==b.length
|
60
|
+
return 0 if a==b
|
61
|
+
elsif a.length < b.length
|
62
|
+
return 1 if a==b[0...a.length]
|
63
|
+
elsif a.length>b.length
|
64
|
+
return -1 if a[0...b.length]==b
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
# is same node ?
|
69
|
+
def same?(other) __compare(other)==0 ? true : false end
|
70
|
+
def ancestor_of?(other) __compare(other)==1 ? true : false end
|
71
|
+
def descendant_of?(other) __compare(other)==-1 ? true : false end
|
72
|
+
def ancestor_in?(other) [0, 1].include?(__compare(other)) ? true : false end
|
73
|
+
def descendant_in?(other) [0,-1].include?(__compare(other)) ? true : false end
|
74
|
+
end
|
75
|
+
end
|
data/lib/tagen/vim.rb
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
=begin
|
2
|
+
used by VimL(Vim Script)
|
3
|
+
=end
|
4
|
+
|
5
|
+
# in vim
|
6
|
+
# print "guten" => guten\n
|
7
|
+
# print "guten\ntag" => guten\n
|
8
|
+
# each_str.split("\n")
|
9
|
+
def vimprint *args
|
10
|
+
args.each do |arg|
|
11
|
+
arg = arg.to_s
|
12
|
+
arg.split("\n").each {|v| print v}
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
# fix bug
|
17
|
+
class <<$stdout
|
18
|
+
def flush; end
|
19
|
+
end
|
data/lib/tagen/xmpp4r.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative "xmpp4r/roster"
|
@@ -0,0 +1,20 @@
|
|
1
|
+
=begin
|
2
|
+
* **Install**: gem(xmpp4r)
|
3
|
+
added:
|
4
|
+
#unsubscribe
|
5
|
+
=end
|
6
|
+
|
7
|
+
module Jabber
|
8
|
+
module Roster
|
9
|
+
class Helper
|
10
|
+
class RosterItem
|
11
|
+
|
12
|
+
# unsubscribe an item
|
13
|
+
def unsubscribe
|
14
|
+
pres = Presence.new.set_type(:unsubscribe).set_to(jid.strip)
|
15
|
+
@stream.send(pres)
|
16
|
+
end
|
17
|
+
end # class RosterItem
|
18
|
+
end # Helper
|
19
|
+
end # module Roster
|
20
|
+
end # module Jabber
|
data/spec/cairo_spec.rb
ADDED
@@ -0,0 +1,137 @@
|
|
1
|
+
=begin
|
2
|
+
require "tagen/cairo"
|
3
|
+
|
4
|
+
include Cairo
|
5
|
+
|
6
|
+
tmpdir = Gile.dirname(__FILE__)+"/tmp"
|
7
|
+
Gile.rmdir!(tmpdir)
|
8
|
+
Gile.mkdir(tmpdir)
|
9
|
+
Gile.chdir(tmpdir)
|
10
|
+
#}}}1
|
11
|
+
DEBUG[0] = true
|
12
|
+
|
13
|
+
Test.skip do
|
14
|
+
skip :table
|
15
|
+
end
|
16
|
+
|
17
|
+
class Test_Context < Test
|
18
|
+
def test_du #{{{1
|
19
|
+
# (x_str,nil) (nil,y_str) (x_str, y_str), (x,y)
|
20
|
+
cr = Context.new(ImageSurface.new(200,200))
|
21
|
+
cr.scale(2,4)
|
22
|
+
cr.translate(10,10)
|
23
|
+
|
24
|
+
assert_equal 1, cr.tdu(2)
|
25
|
+
assert_equal 1, cr.tdu(nil, 4)
|
26
|
+
assert_equal [1,1], cr.tdu(2,4)
|
27
|
+
assert_equal [0,0], cr.du(20, 40)
|
28
|
+
end # test_du
|
29
|
+
#}}}1
|
30
|
+
def test___pos #< du #{{{1
|
31
|
+
cr = Context.new(ImageSurface.new(200,200))
|
32
|
+
cr.translate(2,4)
|
33
|
+
cr.scale(2,4)
|
34
|
+
__pos = cr.method(:__pos)
|
35
|
+
|
36
|
+
cr.xy 10,10
|
37
|
+
assert_equal [0, 10], __pos.call(0, 10)
|
38
|
+
assert_equal __pos.call(0, cr.du(nil,0)), __pos.call(0, :d0)
|
39
|
+
|
40
|
+
cr.xy 10,10
|
41
|
+
assert_equal [0, 20], __pos.call(0, "10")
|
42
|
+
assert_equal [0, 10+cr.tdu(nil,10)], __pos.call(0, :r10)
|
43
|
+
end
|
44
|
+
#}}}1
|
45
|
+
def test__angle #{{{1
|
46
|
+
cr = Context.new(ImageSurface.new(200,200))
|
47
|
+
__angle = cr.method(:__angle)
|
48
|
+
|
49
|
+
assert_equal 10 , __angle.call("10")
|
50
|
+
assert_equal [10, 10], __angle.call("10", "10")
|
51
|
+
assert_equal [10*Math::PI/180.0, 10], __angle.call(10, "10")
|
52
|
+
end
|
53
|
+
#}}}1
|
54
|
+
def test_bak #{{{1
|
55
|
+
cr = Context.new(ImageSurface.new(200,200))
|
56
|
+
# xy
|
57
|
+
cr.xy 0,0
|
58
|
+
cr.bak(:xy) do
|
59
|
+
cr.xy 10,10
|
60
|
+
end
|
61
|
+
assert_equal [0,0], cr.xy
|
62
|
+
|
63
|
+
# translate
|
64
|
+
cr.translate(3,3)
|
65
|
+
cr.bak(:translate) do
|
66
|
+
cr.translate(10,10)
|
67
|
+
end
|
68
|
+
assert_equal [0,0], cr.du(3,3)
|
69
|
+
cr.btranslate
|
70
|
+
|
71
|
+
# scale
|
72
|
+
cr.scale(2,4)
|
73
|
+
cr.bak(:scale) do
|
74
|
+
cr.scale(2,4)
|
75
|
+
end
|
76
|
+
assert_equal [1,1], cr.tdu(2, 4)
|
77
|
+
cr.dscale 1,1
|
78
|
+
|
79
|
+
# matrix
|
80
|
+
cr.scale(2,4)
|
81
|
+
cr.translate(10,10)
|
82
|
+
cr.bak(:matrix) do
|
83
|
+
cr.scale(2,4)
|
84
|
+
cr.translate(10,10)
|
85
|
+
end
|
86
|
+
assert_equal [0,0], cr.du(20,40)
|
87
|
+
assert_equal [1,1], cr.tdu(2,4)
|
88
|
+
cr.dscale 1,1
|
89
|
+
cr.btranslate
|
90
|
+
|
91
|
+
# size
|
92
|
+
cr.size=10
|
93
|
+
cr.bak(:size) do
|
94
|
+
cr.size=12
|
95
|
+
end
|
96
|
+
assert_equal 10, cr.size
|
97
|
+
|
98
|
+
# all
|
99
|
+
cr.size=10
|
100
|
+
cr.xy 0,0
|
101
|
+
cr.translate(3,3)
|
102
|
+
cr.bak(:all) do
|
103
|
+
cr.xy 10,10
|
104
|
+
cr.translate(10,10)
|
105
|
+
cr.size=12
|
106
|
+
end
|
107
|
+
assert_equal [0,0], cr.xy
|
108
|
+
assert_equal [0,0], cr.du(3,3)
|
109
|
+
assert_equal 10, cr.size
|
110
|
+
end # def test_bak
|
111
|
+
#}}}1
|
112
|
+
def test_table #{{{1
|
113
|
+
wh=[400,400]
|
114
|
+
img = Cairo::ImageSurface.new(*wh)
|
115
|
+
cr = Cairo::Context.new(img)
|
116
|
+
cr.scale(*wh)
|
117
|
+
cr.rectangle(0,0,1,1); cr.stroke
|
118
|
+
cr.font= "iYahei"
|
119
|
+
#============
|
120
|
+
|
121
|
+
datas = [
|
122
|
+
["你好","tag"],
|
123
|
+
["你好","tag"],
|
124
|
+
]
|
125
|
+
|
126
|
+
cr.dxy 20,20
|
127
|
+
cr.table(datas[0], border:1)
|
128
|
+
cr.dry 20
|
129
|
+
cr.table(datas, border:1)
|
130
|
+
#============
|
131
|
+
img.write("a.png")
|
132
|
+
`pic a.png`
|
133
|
+
end
|
134
|
+
#}}}1
|
135
|
+
end
|
136
|
+
|
137
|
+
=end
|
@@ -0,0 +1,251 @@
|
|
1
|
+
require "tagen/core"
|
2
|
+
require "fileutils"
|
3
|
+
require "tmpdir"
|
4
|
+
|
5
|
+
describe Pa do
|
6
|
+
before :all do
|
7
|
+
$tmpdir = Dir.mktmpdir
|
8
|
+
Dir.chdir($tmpdir)
|
9
|
+
end
|
10
|
+
|
11
|
+
after(:all) do
|
12
|
+
FileUtils.rm_r $tmpdir
|
13
|
+
end
|
14
|
+
|
15
|
+
describe "#_rmdir" do
|
16
|
+
# dir/
|
17
|
+
# a
|
18
|
+
# dira/
|
19
|
+
# aa
|
20
|
+
before(:all) do
|
21
|
+
@_rmdir = Pa.method(:_rmdir)
|
22
|
+
FileUtils.mkdir_p(%w(dir/dira))
|
23
|
+
FileUtils.touch(%w(dir/a dir/dira/aa))
|
24
|
+
end
|
25
|
+
|
26
|
+
it "remove directory" do
|
27
|
+
@_rmdir.call Pa("dir")
|
28
|
+
File.exists?("dir").should be_false
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
# rm family
|
33
|
+
describe "" do
|
34
|
+
# a
|
35
|
+
# dir/
|
36
|
+
# dira/
|
37
|
+
# a
|
38
|
+
before :each do
|
39
|
+
FileUtils.mkdir_p(%w(dir/dira))
|
40
|
+
FileUtils.touch(%w(a dir/a))
|
41
|
+
end
|
42
|
+
|
43
|
+
describe "#rm" do
|
44
|
+
it "remove file" do
|
45
|
+
Pa.rm "a"
|
46
|
+
File.exists?("a").should be_false
|
47
|
+
lambda{Pa.rm("dir")}.should raise_error(Errno::EISDIR)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#rmdir" do
|
52
|
+
it "remove directory" do
|
53
|
+
Pa.rmdir "dir"
|
54
|
+
File.exists?("dir").should be_false
|
55
|
+
lambda{Pa.rmdir("a")}.should raise_error(Errno::ENOTDIR)
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
describe "#rm_r" do
|
60
|
+
it "remove both file and directory" do
|
61
|
+
Pa.rm "a"
|
62
|
+
File.exists?("a").should be_false
|
63
|
+
Pa.rm_r "dir"
|
64
|
+
File.exists?("dir").should be_false
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
describe "#rm_if" do
|
69
|
+
it "remove if condition" do
|
70
|
+
Pa.rm_if "." do |pa|
|
71
|
+
next if pa.p=="a"
|
72
|
+
yield if pa.b=="a"
|
73
|
+
end
|
74
|
+
|
75
|
+
File.exists?("a").should be_true
|
76
|
+
File.exists?("dir/dira/a").should be_false
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
end
|
81
|
+
|
82
|
+
describe "#mkdir" do
|
83
|
+
after :each do
|
84
|
+
FileUtils.rm_r Dir["*"]-%w(. ..)
|
85
|
+
end
|
86
|
+
|
87
|
+
it "mkdir" do
|
88
|
+
Pa.mkdir("guten/tag")
|
89
|
+
File.exists?("guten/tag").should be_true
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
93
|
+
|
94
|
+
describe "#_copy" do
|
95
|
+
# a symfile
|
96
|
+
# ab
|
97
|
+
# ac
|
98
|
+
# dir/
|
99
|
+
# b # guten
|
100
|
+
# dira/
|
101
|
+
# c
|
102
|
+
# destdir/
|
103
|
+
# b # tag
|
104
|
+
# dir/
|
105
|
+
before :all do
|
106
|
+
@_copy = Pa.method(:_copy)
|
107
|
+
FileUtils.mkdir_p(%w(dir/dira destdir/dir))
|
108
|
+
FileUtils.touch(%w(a ab ac dir/b dir/dira/c destdir/dir/b))
|
109
|
+
File.symlink("a", "symfile")
|
110
|
+
open("dir/b", "w"){|f|f.write "guten"}
|
111
|
+
open("destdir/dir/b", "w"){|f|f.write "tag"}
|
112
|
+
end
|
113
|
+
|
114
|
+
it "_copy file" do
|
115
|
+
@_copy.call Pa('a'), Pa('b')
|
116
|
+
File.exists?('b').should be_true
|
117
|
+
end
|
118
|
+
|
119
|
+
it "_copy directory" do
|
120
|
+
@_copy.call Pa('dir'), Pa('dirc')
|
121
|
+
Dir.entries('dirc').should == Dir.entries('dir')
|
122
|
+
end
|
123
|
+
|
124
|
+
context "with :symlink" do
|
125
|
+
|
126
|
+
it "_copy" do
|
127
|
+
@_copy.call Pa('symfile'), Pa('symfilea')
|
128
|
+
File.symlink?('symfilea').should be_true
|
129
|
+
end
|
130
|
+
|
131
|
+
it "_copy with :folsymlink" do
|
132
|
+
@_copy.call Pa('symfile'), Pa('folsymlink'), folsymlink:true
|
133
|
+
File.symlink?('folsymlink').should be_false
|
134
|
+
File.file?('folsymlink').should be_true
|
135
|
+
end
|
136
|
+
|
137
|
+
end
|
138
|
+
|
139
|
+
context "with :mkdir" do
|
140
|
+
it "_copy" do
|
141
|
+
lambda{Pa.cp "a", "destdir/mkdir/dir"}.should raise_error(Errno::ENOENT)
|
142
|
+
end
|
143
|
+
|
144
|
+
it "_copy with :mkdir" do
|
145
|
+
lambda{Pa.cp "a", "destdir/mkdir/dir", mkdir:true}.should_not raise_error(Errno::ENOENT)
|
146
|
+
File.exists?("destdir/mkdir/dir/a").should be_true
|
147
|
+
end
|
148
|
+
|
149
|
+
it "_copy with :mkdir" do
|
150
|
+
lambda{Pa.cp "a", "destdir/mkdira", mkdir:true}.should_not raise_error(Errno::ENOENT)
|
151
|
+
File.exists?("destdir/mkdira/a").should be_true
|
152
|
+
end
|
153
|
+
end
|
154
|
+
|
155
|
+
context "with :overwrite" do
|
156
|
+
it "_copy" do
|
157
|
+
File.open("destdir/overwrite","w"){|f|f.write("")}
|
158
|
+
lambda{Pa.cp "a", "destdir/overwrite"}.should raise_error(Errno::EEXIST)
|
159
|
+
end
|
160
|
+
|
161
|
+
it "_copy with :overwrite" do
|
162
|
+
lambda{Pa.cp "a", "destdir/overwrite", overwrite:true}.should_not raise_error(Errno::EEXIST)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
|
166
|
+
end
|
167
|
+
|
168
|
+
describe "#cp" do
|
169
|
+
it "cp file destdir/file" do
|
170
|
+
Pa.cp "a", "destdir/aa"
|
171
|
+
File.exists?("destdir/aa").should be_true
|
172
|
+
end
|
173
|
+
|
174
|
+
it "cp file destdir/" do
|
175
|
+
Pa.cp "a", "destdir"
|
176
|
+
File.exists?("destdir/a").should be_true
|
177
|
+
end
|
178
|
+
|
179
|
+
it "cp file1 file2 .. dest_file" do
|
180
|
+
lambda{Pa.cp(%w(a ab), "ac")}.should raise_error(Errno::ENOTDIR)
|
181
|
+
end
|
182
|
+
|
183
|
+
it "cp file1 file2 .. dird/" do
|
184
|
+
Dir.mkdir 'dird'
|
185
|
+
Pa.cp %w(a ab), "dird"
|
186
|
+
File.exists?("dird/a").should be_true
|
187
|
+
File.exists?("dird/ab").should be_true
|
188
|
+
end
|
189
|
+
end
|
190
|
+
|
191
|
+
describe "#_move" do
|
192
|
+
# a
|
193
|
+
# dir/ b
|
194
|
+
before :each do
|
195
|
+
@_move = Pa.method(:_move)
|
196
|
+
FileUtils.mkdir_p(%w(dir))
|
197
|
+
FileUtils.touch(%w(a dir/b))
|
198
|
+
end
|
199
|
+
after :each do
|
200
|
+
FileUtils.rm_r Dir["*"]-%w(. ..)
|
201
|
+
end
|
202
|
+
|
203
|
+
it "mv a dir/a" do
|
204
|
+
ino = File.stat('a').ino
|
205
|
+
@_move.call Pa("a"), Pa("dir/a"), {}
|
206
|
+
File.stat('dir/a').ino.should == ino
|
207
|
+
File.exists?("a").should be_false
|
208
|
+
end
|
209
|
+
|
210
|
+
context "with :overwrite" do
|
211
|
+
it "mv a dir/b" do
|
212
|
+
lambda{@_move.call Pa("a"), Pa("dir/b"), {}}.should raise_error Errno::EEXIST
|
213
|
+
end
|
214
|
+
|
215
|
+
it "mv a dir/b :overwrite" do
|
216
|
+
ino = File.stat('a').ino
|
217
|
+
@_move.call Pa("a"), Pa("dir/b"), overwrite:true
|
218
|
+
File.stat("dir/b").ino.should == ino
|
219
|
+
end
|
220
|
+
end
|
221
|
+
end
|
222
|
+
|
223
|
+
describe "#mv" do
|
224
|
+
# a b c
|
225
|
+
# dir/ aa
|
226
|
+
before :each do
|
227
|
+
@_move = Pa.method(:_move)
|
228
|
+
FileUtils.mkdir_p(%w(dir))
|
229
|
+
FileUtils.touch(%w(a b c dir/aa))
|
230
|
+
end
|
231
|
+
after :each do
|
232
|
+
FileUtils.rm_r Dir["*"]-%w(. ..)
|
233
|
+
end
|
234
|
+
|
235
|
+
it "mv a dir/" do
|
236
|
+
Pa.mv "a", "dir"
|
237
|
+
File.exists?("dir/a").should be_true
|
238
|
+
end
|
239
|
+
|
240
|
+
it "mv a b .. file" do
|
241
|
+
lambda{Pa.mv(%w(a b), "c")}.should raise_error(Errno::ENOTDIR)
|
242
|
+
end
|
243
|
+
|
244
|
+
it "mv file1 file2 .. dir/" do
|
245
|
+
Pa.mv %w(a b), "dir"
|
246
|
+
File.exists?("dir/a").should be_true
|
247
|
+
File.exists?("dir/b").should be_true
|
248
|
+
end
|
249
|
+
end
|
250
|
+
|
251
|
+
end
|