tagen 1.1.7 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -1
- data/.travis.yml +5 -0
- data/CHANGELOG +6 -0
- data/Gemfile +2 -3
- data/Gemfile.lock +13 -15
- data/README.md +20 -39
- data/Rakefile +2 -1
- data/benchmark/a.rb +14 -0
- data/lib/tagen/core.rb +17 -22
- data/lib/tagen/core/array.rb +5 -109
- data/lib/tagen/core/array/append.rb +3 -0
- data/lib/tagen/core/array/delete_values.rb +43 -0
- data/lib/tagen/core/array/extract_options.rb +35 -94
- data/lib/tagen/core/class.rb +1 -0
- data/lib/tagen/core/enumerable.rb +15 -18
- data/lib/tagen/core/enumerator.rb +22 -12
- data/lib/tagen/core/exception.rb +5 -3
- data/lib/tagen/core/file.rb +1 -0
- data/lib/tagen/core/hash.rb +4 -39
- data/lib/tagen/core/integer.rb +2 -0
- data/lib/tagen/core/io.rb +59 -26
- data/lib/tagen/core/kernel.rb +5 -64
- data/lib/tagen/core/kernel/deprecate.rb +5 -0
- data/lib/tagen/core/kernel/platform.rb +46 -0
- data/lib/tagen/core/kernel/shell.rb +45 -0
- data/lib/tagen/core/module.rb +9 -11
- data/lib/tagen/core/numeric.rb +4 -2
- data/lib/tagen/core/object.rb +6 -21
- data/lib/tagen/core/process.rb +6 -4
- data/lib/tagen/core/re.rb +2 -2
- data/lib/tagen/core/string.rb +12 -47
- data/lib/tagen/core/time.rb +30 -38
- data/lib/tagen/erb.rb +10 -8
- data/lib/tagen/net/http.rb +33 -29
- data/lib/tagen/pathname.rb +1 -5
- data/lib/tagen/rbconfig.rb +8 -0
- data/lib/tagen/socket.rb +8 -2
- data/lib/tagen/uri.rb +9 -0
- data/lib/tagen/version.rb +1 -1
- data/lib/tagen/vim.rb +8 -8
- data/lib/tagen/xmpp4r.rb +23 -23
- data/spec/spec_helper.rb +23 -17
- data/spec/tagen/core/array/delete_values_spec.rb +19 -0
- data/spec/tagen/core/array/extract_options_spec.rb +9 -29
- data/spec/tagen/core/enumerable_spec.rb +9 -0
- data/spec/tagen/core/enumerator_spec.rb +10 -12
- data/spec/tagen/core/exception_spec.rb +14 -9
- data/spec/tagen/core/io_spec.rb +20 -0
- data/spec/tagen/core/kernel/platform_spec.rb +92 -0
- data/spec/tagen/core/kernel/shell_spec.rb +27 -0
- data/spec/tagen/core/numeric_spec.rb +10 -0
- data/spec/tagen/core/process_spec.rb +14 -0
- data/spec/tagen/core/re_spec.rb +9 -0
- data/spec/tagen/core/string_spec.rb +9 -0
- data/spec/tagen/core/time_spec.rb +6 -51
- data/spec/tagen/erb_spec.rb +3 -10
- data/spec/tagen/pathname_spec.rb +11 -0
- data/spec/tagen/rbconfig_spec.rb +11 -0
- data/spec/tagen/socket_spec.rb +7 -5
- data/spec/tagen/uri_spec.rb +13 -0
- data/tagen.gemspec +3 -4
- metadata +45 -51
- data/TODO +0 -1
- data/docs/Architecture.md +0 -17
- data/docs/CoreExtensions.md +0 -40
- data/docs/ExtraExtensions.md +0 -20
- data/lib/tagen/RMagick.rb +0 -12
- data/lib/tagen/audioinfo.rb +0 -22
- data/lib/tagen/cairo.rb +0 -811
- data/lib/tagen/core/extend_hash.rb +0 -46
- data/lib/tagen/core/marshal.rb +0 -34
- data/lib/tagen/core/open_option.rb +0 -161
- data/lib/tagen/core/string/pyformat.rb +0 -336
- data/lib/tagen/core/symbol.rb +0 -8
- data/lib/tagen/date.rb +0 -80
- data/lib/tagen/gdk_pixbuf2.rb +0 -26
- data/lib/tagen/gtk2.rb +0 -122
- data/lib/tagen/ncurses.rb +0 -246
- data/lib/tagen/poppler.rb +0 -48
- data/lib/tagen/tree.rb +0 -77
- data/lib/tagen/xmpp4r/roster.rb +0 -20
- data/lib/tagen/yaml.rb +0 -38
- data/spec/tagen/cairo_spec.rb +0 -137
- data/spec/tagen/core/array_spec.rb +0 -42
- data/spec/tagen/core/extend_hash_spec.rb +0 -54
- data/spec/tagen/core/hash_spec.rb +0 -10
- data/spec/tagen/core/module_spec.rb +0 -14
- data/spec/tagen/core/open_option_spec.rb +0 -83
- data/spec/tagen/core/string/pyformat_spec.rb +0 -98
- data/spec/tagen/core/symbol_spec.rb +0 -15
- data/spec/tagen/core_spec.rb +0 -6
- data/spec/tagen/date_spec.rb +0 -146
data/spec/spec_helper.rb
CHANGED
@@ -1,8 +1,13 @@
|
|
1
|
+
require "pd"
|
1
2
|
require "tagen/core"
|
2
3
|
|
4
|
+
$spec_dir = File.expand_path("..", __FILE__)
|
5
|
+
$spec_data = File.join($spec_dir, "data")
|
6
|
+
$spec_tmp = File.join($spec_dir, "tmp")
|
7
|
+
|
3
8
|
class Dir
|
4
9
|
class << self
|
5
|
-
def empty?
|
10
|
+
def empty?(path)
|
6
11
|
Dir.entries(path).sort == %w(. ..)
|
7
12
|
end
|
8
13
|
end
|
@@ -25,24 +30,25 @@ RSpec.configure do |config|
|
|
25
30
|
alias :silence :capture
|
26
31
|
end
|
27
32
|
|
28
|
-
module
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
33
|
+
module RSpec
|
34
|
+
module Core
|
35
|
+
module DSL
|
36
|
+
def xdescribe(*args, &blk)
|
37
|
+
describe *args do
|
38
|
+
pending
|
39
|
+
end
|
40
|
+
end
|
36
41
|
|
37
|
-
|
38
|
-
context *args do
|
39
|
-
pending "xxxxxxxxx"
|
42
|
+
alias xcontext xdescribe
|
40
43
|
end
|
41
44
|
end
|
45
|
+
end
|
42
46
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
47
|
+
def public_all_methods(*klasses)
|
48
|
+
klasses.each {|klass|
|
49
|
+
klass.class_eval {
|
50
|
+
public *(self.protected_instance_methods(false) + self.private_instance_methods(false))
|
51
|
+
public_class_method *(self.protected_methods(false) + self.private_methods(false))
|
52
|
+
}
|
53
|
+
}
|
48
54
|
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Array do
|
4
|
+
describe "#delete_values" do
|
5
|
+
it do
|
6
|
+
a = (1..4).to_a
|
7
|
+
expect(a.delete_values(1, 3)).to eq([1, 3])
|
8
|
+
expect(a).to eq([2, 4])
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe "#delete_values_at" do
|
13
|
+
it do
|
14
|
+
a = (1..4).to_a
|
15
|
+
expect(a.delete_values_at(0, 2)).to eq([1, 3])
|
16
|
+
expect(a).to eq([2, 4])
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
@@ -2,41 +2,21 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Array do
|
4
4
|
describe "#extract_options" do
|
5
|
-
it
|
6
|
-
args = [1, a:1, b:2]
|
5
|
+
it do
|
6
|
+
args = [1, {a: 1}, {b: 2}]
|
7
7
|
nums, o = args.extract_options
|
8
|
-
nums.
|
9
|
-
|
10
|
-
|
8
|
+
expect(nums).to eq([1, {a: 1}])
|
9
|
+
expect(o).to eq({b: 2})
|
10
|
+
expect(args).to eq([1, {a: 1}, {b: 2}])
|
11
11
|
end
|
12
12
|
end
|
13
13
|
|
14
14
|
describe "#extract_options!" do
|
15
|
-
it
|
16
|
-
args = [1, a:1, b:2]
|
15
|
+
it do
|
16
|
+
args = [1, {a: 1}, {b: 2}]
|
17
17
|
o = args.extract_options!
|
18
|
-
o.
|
19
|
-
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "#extract_extend_options" do
|
24
|
-
|
25
|
-
it "returns [args, option]" do
|
26
|
-
args = [1, :a, :_b, c:2]
|
27
|
-
nums, o = args.extract_extend_options
|
28
|
-
nums.should == [1]
|
29
|
-
o.should == {a:true, b:false, c:2}
|
30
|
-
args.should == [1, :a, :_b, c:2]
|
31
|
-
end
|
32
|
-
end
|
33
|
-
|
34
|
-
describe "#extract_extend_options!" do
|
35
|
-
it "modify args and returns option only" do
|
36
|
-
args = [1, :a, :_b, c:2]
|
37
|
-
o = args.extract_extend_options!
|
38
|
-
args.should == [1]
|
39
|
-
o.should == {a:true, b:false, c:2}
|
18
|
+
expect(o).to eq({b: 2})
|
19
|
+
expect(args).to eq([1, {a: 1}])
|
40
20
|
end
|
41
21
|
end
|
42
22
|
end
|
@@ -2,20 +2,18 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Enumerator do
|
4
4
|
describe "#with_iobject" do
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
ret.should == [1,2]
|
5
|
+
it "has memo" do
|
6
|
+
ret = [1, 2].each.with_iobject([]) { |v, i, m|
|
7
|
+
m << v + i
|
8
|
+
}
|
9
|
+
expect(ret).to eq([1, 3])
|
11
10
|
end
|
12
11
|
|
13
|
-
it "
|
14
|
-
ret = [1,2].each.with_iobject
|
15
|
-
m << i
|
16
|
-
|
17
|
-
ret.
|
12
|
+
it "has offset and memo" do
|
13
|
+
ret = [1, 2].each.with_iobject(1, []) { |v, i, m|
|
14
|
+
m << v + i
|
15
|
+
}
|
16
|
+
expect(ret).to eq([2, 4])
|
18
17
|
end
|
19
|
-
|
20
18
|
end
|
21
19
|
end
|
@@ -1,18 +1,23 @@
|
|
1
1
|
require "spec_helper"
|
2
|
-
require "tagen/core/exception"
|
3
2
|
|
4
3
|
describe "Exception" do
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
describe ".exit_code,=" do
|
5
|
+
it do
|
6
|
+
MyError = Class.new Exception
|
7
|
+
MyError.exit_code = 1
|
8
8
|
|
9
|
-
|
9
|
+
expect(MyError.new.exit_code).to eq(1)
|
10
|
+
end
|
10
11
|
end
|
11
12
|
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
describe "@@exit_code" do
|
14
|
+
it do
|
15
|
+
class MyError2 < Exception
|
16
|
+
@@exit_code = 1
|
17
|
+
end
|
16
18
|
|
19
|
+
expect(MyError2.new.exit_code).to eq(1)
|
20
|
+
end
|
21
|
+
end
|
17
22
|
end
|
18
23
|
|
@@ -0,0 +1,20 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe IO do
|
4
|
+
describe ".write" do
|
5
|
+
it do
|
6
|
+
IO.should_receive(:write_without_tagen).with("foo", "content", nil, {mkdir: true})
|
7
|
+
|
8
|
+
IO.write("foo", "content", mkdir: true)
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
describe ".append" do
|
13
|
+
it do
|
14
|
+
IO.should_receive(:write).with("foo", "content", nil, {mode: "a"})
|
15
|
+
|
16
|
+
IO.append("foo", "content")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
@@ -0,0 +1,92 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Kernel do
|
4
|
+
def stub2(platform)
|
5
|
+
RbConfig::CONFIG["host_os"] = platform
|
6
|
+
end
|
7
|
+
|
8
|
+
describe "#linux?" do
|
9
|
+
it "is linux" do
|
10
|
+
stub2("linux")
|
11
|
+
expect(linux?).to be_true
|
12
|
+
end
|
13
|
+
|
14
|
+
it "is cygwin" do
|
15
|
+
stub2("cygwin")
|
16
|
+
expect(linux?).to be_true
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
describe "#mac?" do
|
21
|
+
it "is mac" do
|
22
|
+
stub2("mac")
|
23
|
+
expect(mac?).to be_true
|
24
|
+
end
|
25
|
+
|
26
|
+
it "is darwin" do
|
27
|
+
stub2("darwin")
|
28
|
+
expect(mac?).to be_true
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
describe "#bsd?" do
|
33
|
+
it "is bsd" do
|
34
|
+
stub2("bsd")
|
35
|
+
expect(bsd?).to be_true
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
describe "#windows?" do
|
40
|
+
it "is mswin" do
|
41
|
+
stub2("mswin")
|
42
|
+
expect(windows?).to be_true
|
43
|
+
end
|
44
|
+
|
45
|
+
it "is mingw" do
|
46
|
+
stub2("mingw")
|
47
|
+
expect(windows?).to be_true
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
describe "#solaris?" do
|
52
|
+
it "is solaris" do
|
53
|
+
stub2("solaris")
|
54
|
+
expect(solaris?).to be_true
|
55
|
+
end
|
56
|
+
|
57
|
+
it "is sunos" do
|
58
|
+
stub2("sunos")
|
59
|
+
expect(solaris?).to be_true
|
60
|
+
end
|
61
|
+
end
|
62
|
+
|
63
|
+
describe "#symbian?" do
|
64
|
+
it "is symbian" do
|
65
|
+
stub2("symbian")
|
66
|
+
expect(symbian?).to be_true
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
describe "#posix?" do
|
71
|
+
it "is linux" do
|
72
|
+
stub2("linux")
|
73
|
+
expect(posix?).to be_true
|
74
|
+
end
|
75
|
+
|
76
|
+
it "is mac" do
|
77
|
+
stub2("mac")
|
78
|
+
expect(posix?).to be_true
|
79
|
+
end
|
80
|
+
|
81
|
+
it "is bsd" do
|
82
|
+
stub2("bsd")
|
83
|
+
expect(posix?).to be_true
|
84
|
+
end
|
85
|
+
|
86
|
+
it "is solaris" do
|
87
|
+
stub2("solaris")
|
88
|
+
expect(posix?).to be_true
|
89
|
+
end
|
90
|
+
end
|
91
|
+
end
|
92
|
+
|
@@ -0,0 +1,27 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Kernel do
|
4
|
+
describe "#system" do
|
5
|
+
it "" do
|
6
|
+
should_receive(:system_without_tagen).with("foo -l", {})
|
7
|
+
|
8
|
+
output = capture :stdout do
|
9
|
+
system("foo -l", show_cmd: true)
|
10
|
+
end
|
11
|
+
|
12
|
+
expect(output).to eq("foo -l\n")
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
describe "#sh" do
|
17
|
+
it "" do
|
18
|
+
should_receive(:`).with("foo -l")
|
19
|
+
|
20
|
+
output = capture :stdout do
|
21
|
+
sh("foo -l", show_cmd: true)
|
22
|
+
end
|
23
|
+
|
24
|
+
expect(output).to eq("foo -l\n")
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,14 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Process do
|
4
|
+
describe ".exists?" do
|
5
|
+
it do
|
6
|
+
if linux?
|
7
|
+
expect(Process.exists?(Process.pid)).to be_true
|
8
|
+
expect(Process.exists?(-1)).to be_false
|
9
|
+
else
|
10
|
+
expect{ Process.exists?(Process.pid) }.to raise_error(NotImplementedError)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
@@ -2,63 +2,18 @@ require "spec_helper"
|
|
2
2
|
|
3
3
|
describe Time do
|
4
4
|
describe ".time" do
|
5
|
-
it
|
5
|
+
it do
|
6
6
|
Time.stub_chain("now.to_f") { 1 }
|
7
7
|
Time.time.should == 1
|
8
8
|
end
|
9
9
|
end
|
10
10
|
end
|
11
11
|
|
12
|
-
|
13
|
-
describe
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
d.years.should == 1
|
19
|
-
d.months.should == 2
|
20
|
-
d.days.should == 3
|
21
|
-
d.hours.should == 4
|
22
|
-
d.minutes.should == 5
|
23
|
-
d.seconds.should == 6
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
describe "#display" do
|
28
|
-
it "works for 1 years 2 months 3 days 4 hours 5 minutes 6 seconds" do
|
29
|
-
d = Deta.new(36561906)
|
30
|
-
|
31
|
-
d.display.should == "1 years 2 months 3 days 4 hours 5 minutes 6 seconds"
|
32
|
-
end
|
33
|
-
|
34
|
-
it "works for 0 second" do
|
35
|
-
d = Deta.new(0)
|
36
|
-
|
37
|
-
d.display.should == "0 seconds"
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
describe "#to_a" do
|
42
|
-
it "works" do
|
43
|
-
d = Deta.new(1)
|
44
|
-
d.stub(:years) { 1 }
|
45
|
-
d.stub(:months) { 2 }
|
46
|
-
d.stub(:days) { 3 }
|
47
|
-
d.stub(:hours) { 4 }
|
48
|
-
d.stub(:minutes) { 5 }
|
49
|
-
d.stub(:seconds) { 6 }
|
50
|
-
|
51
|
-
|
52
|
-
d.to_a.should == [ 1, 2, 3, 4, 5, 6 ]
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
describe ".deta" do
|
57
|
-
it "works" do
|
58
|
-
a = Deta.deta(Time.new(2011, 1, 1, 1, 1, 2), Time.new(2011, 1, 1, 1, 1, 1)).to_a
|
59
|
-
b = [ 0, 0, 0, 0, 0, 1 ]
|
60
|
-
|
61
|
-
a.should == b
|
12
|
+
describe Numeric do
|
13
|
+
describe "#time_humanize" do
|
14
|
+
it do
|
15
|
+
expect(36561906.time_humanize).to eq("1 years 2 months 3 days 4 hours 5 minutes")
|
16
|
+
expect(0.time_humanize(true)).to eq("0 seconds")
|
62
17
|
end
|
63
18
|
end
|
64
19
|
end
|