tagen 1.1.7 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (92) hide show
  1. data/.gitignore +4 -1
  2. data/.travis.yml +5 -0
  3. data/CHANGELOG +6 -0
  4. data/Gemfile +2 -3
  5. data/Gemfile.lock +13 -15
  6. data/README.md +20 -39
  7. data/Rakefile +2 -1
  8. data/benchmark/a.rb +14 -0
  9. data/lib/tagen/core.rb +17 -22
  10. data/lib/tagen/core/array.rb +5 -109
  11. data/lib/tagen/core/array/append.rb +3 -0
  12. data/lib/tagen/core/array/delete_values.rb +43 -0
  13. data/lib/tagen/core/array/extract_options.rb +35 -94
  14. data/lib/tagen/core/class.rb +1 -0
  15. data/lib/tagen/core/enumerable.rb +15 -18
  16. data/lib/tagen/core/enumerator.rb +22 -12
  17. data/lib/tagen/core/exception.rb +5 -3
  18. data/lib/tagen/core/file.rb +1 -0
  19. data/lib/tagen/core/hash.rb +4 -39
  20. data/lib/tagen/core/integer.rb +2 -0
  21. data/lib/tagen/core/io.rb +59 -26
  22. data/lib/tagen/core/kernel.rb +5 -64
  23. data/lib/tagen/core/kernel/deprecate.rb +5 -0
  24. data/lib/tagen/core/kernel/platform.rb +46 -0
  25. data/lib/tagen/core/kernel/shell.rb +45 -0
  26. data/lib/tagen/core/module.rb +9 -11
  27. data/lib/tagen/core/numeric.rb +4 -2
  28. data/lib/tagen/core/object.rb +6 -21
  29. data/lib/tagen/core/process.rb +6 -4
  30. data/lib/tagen/core/re.rb +2 -2
  31. data/lib/tagen/core/string.rb +12 -47
  32. data/lib/tagen/core/time.rb +30 -38
  33. data/lib/tagen/erb.rb +10 -8
  34. data/lib/tagen/net/http.rb +33 -29
  35. data/lib/tagen/pathname.rb +1 -5
  36. data/lib/tagen/rbconfig.rb +8 -0
  37. data/lib/tagen/socket.rb +8 -2
  38. data/lib/tagen/uri.rb +9 -0
  39. data/lib/tagen/version.rb +1 -1
  40. data/lib/tagen/vim.rb +8 -8
  41. data/lib/tagen/xmpp4r.rb +23 -23
  42. data/spec/spec_helper.rb +23 -17
  43. data/spec/tagen/core/array/delete_values_spec.rb +19 -0
  44. data/spec/tagen/core/array/extract_options_spec.rb +9 -29
  45. data/spec/tagen/core/enumerable_spec.rb +9 -0
  46. data/spec/tagen/core/enumerator_spec.rb +10 -12
  47. data/spec/tagen/core/exception_spec.rb +14 -9
  48. data/spec/tagen/core/io_spec.rb +20 -0
  49. data/spec/tagen/core/kernel/platform_spec.rb +92 -0
  50. data/spec/tagen/core/kernel/shell_spec.rb +27 -0
  51. data/spec/tagen/core/numeric_spec.rb +10 -0
  52. data/spec/tagen/core/process_spec.rb +14 -0
  53. data/spec/tagen/core/re_spec.rb +9 -0
  54. data/spec/tagen/core/string_spec.rb +9 -0
  55. data/spec/tagen/core/time_spec.rb +6 -51
  56. data/spec/tagen/erb_spec.rb +3 -10
  57. data/spec/tagen/pathname_spec.rb +11 -0
  58. data/spec/tagen/rbconfig_spec.rb +11 -0
  59. data/spec/tagen/socket_spec.rb +7 -5
  60. data/spec/tagen/uri_spec.rb +13 -0
  61. data/tagen.gemspec +3 -4
  62. metadata +45 -51
  63. data/TODO +0 -1
  64. data/docs/Architecture.md +0 -17
  65. data/docs/CoreExtensions.md +0 -40
  66. data/docs/ExtraExtensions.md +0 -20
  67. data/lib/tagen/RMagick.rb +0 -12
  68. data/lib/tagen/audioinfo.rb +0 -22
  69. data/lib/tagen/cairo.rb +0 -811
  70. data/lib/tagen/core/extend_hash.rb +0 -46
  71. data/lib/tagen/core/marshal.rb +0 -34
  72. data/lib/tagen/core/open_option.rb +0 -161
  73. data/lib/tagen/core/string/pyformat.rb +0 -336
  74. data/lib/tagen/core/symbol.rb +0 -8
  75. data/lib/tagen/date.rb +0 -80
  76. data/lib/tagen/gdk_pixbuf2.rb +0 -26
  77. data/lib/tagen/gtk2.rb +0 -122
  78. data/lib/tagen/ncurses.rb +0 -246
  79. data/lib/tagen/poppler.rb +0 -48
  80. data/lib/tagen/tree.rb +0 -77
  81. data/lib/tagen/xmpp4r/roster.rb +0 -20
  82. data/lib/tagen/yaml.rb +0 -38
  83. data/spec/tagen/cairo_spec.rb +0 -137
  84. data/spec/tagen/core/array_spec.rb +0 -42
  85. data/spec/tagen/core/extend_hash_spec.rb +0 -54
  86. data/spec/tagen/core/hash_spec.rb +0 -10
  87. data/spec/tagen/core/module_spec.rb +0 -14
  88. data/spec/tagen/core/open_option_spec.rb +0 -83
  89. data/spec/tagen/core/string/pyformat_spec.rb +0 -98
  90. data/spec/tagen/core/symbol_spec.rb +0 -15
  91. data/spec/tagen/core_spec.rb +0 -6
  92. data/spec/tagen/date_spec.rb +0 -146
@@ -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? path
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 Kernel
29
- private
30
-
31
- def xdescribe(*args, &blk)
32
- describe *args do
33
- pending "xxxxxxxxx"
34
- end
35
- end
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
- def xcontext(*args, &blk)
38
- context *args do
39
- pending "xxxxxxxxx"
42
+ alias xcontext xdescribe
40
43
  end
41
44
  end
45
+ end
42
46
 
43
- def xit(*args, &blk)
44
- it *args do
45
- pending "xxxxxxxx"
46
- end
47
- end
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 "returns [args, option]" do
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.should == [1]
9
- o.should == {a:1, b:2}
10
- args.should == [1, a:1, b:2]
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 "returns option" do
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.should == {a:1, b:2}
19
- args.should == [1]
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
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe Enumerable do
4
+ describe "#grep_values" do
5
+ it do
6
+ expect(%w[ab ac bb cc].grep_values(/a./, /bb/)).to eq(%w[ab ac bb])
7
+ end
8
+ end
9
+ end
@@ -2,20 +2,18 @@ require "spec_helper"
2
2
 
3
3
  describe Enumerator do
4
4
  describe "#with_iobject" do
5
-
6
- it "support mem_obj" do
7
- ret = [1,2].each.with_iobject [] do |v,i, m|
8
- m << v
9
- end
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 "support offset" do
14
- ret = [1,2].each.with_iobject 2, [] do |v,i, m|
15
- m << i
16
- end
17
- ret.should == [2,3]
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
- it "works with syntax 1" do
6
- MyError = Class.new Exception
7
- MyError.exit_code = 1
4
+ describe ".exit_code,=" do
5
+ it do
6
+ MyError = Class.new Exception
7
+ MyError.exit_code = 1
8
8
 
9
- MyError.new.exit_code.should == 1
9
+ expect(MyError.new.exit_code).to eq(1)
10
+ end
10
11
  end
11
12
 
12
- it "works with syntax 2" do
13
- class MyError2 < Exception; @@exit_code = 1 end
14
- MyError2.new.exit_code.should == 1
15
- end
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,10 @@
1
+ require "spec_helper"
2
+
3
+ describe Numeric do
4
+ describe "#div2" do
5
+ it do
6
+ expect(3.div2(2)).to eq(2)
7
+ expect(4.div2(2)).to eq(2)
8
+ end
9
+ end
10
+ 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
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe MatchData do
4
+ describe "#to_hash" do
5
+ it do
6
+ expect("guten".match(/(?<a>.)(?<b>.)/).to_hash).to eq({a: "g", b: "u"})
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ require "spec_helper"
2
+
3
+ describe String do
4
+ describe "#ascii" do
5
+ it do
6
+ expect("a".ascii).to eq(97)
7
+ end
8
+ end
9
+ end
@@ -2,63 +2,18 @@ require "spec_helper"
2
2
 
3
3
  describe Time do
4
4
  describe ".time" do
5
- it "works" do
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
- Deta = Time::Deta
13
- describe Deta do
14
- describe "#initialize" do
15
- it "works for 36561906 seconds" do
16
- d = Deta.new(36561906)
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