boson 0.2.2 → 0.2.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -7,51 +7,47 @@ module Boson
7
7
  Ab = Struct.new(:a, :b) unless PipeTest.const_defined?(:Ab)
8
8
  @objects = [Ab.new('some', 'thing'), Ab.new(:more, :yep)]
9
9
  }
10
- context "search_object" do
10
+ context "query_pipe" do
11
11
 
12
12
  test "searches one query" do
13
13
  [@hashes, @objects].each {|e|
14
- Pipe.search_object(e, :a=>'some').should == e[0,1]
14
+ Pipes.query_pipe(e, :a=>'some').should == e[0,1]
15
15
  }
16
16
  end
17
17
 
18
18
  test "searches non-string values" do
19
19
  [@hashes, @objects].each {|e|
20
- Pipe.search_object(e, :a=>'more').should == e[1,1]
20
+ Pipes.query_pipe(e, :a=>'more').should == e[1,1]
21
21
  }
22
22
  end
23
23
 
24
24
  test "searches multiple search terms" do
25
25
  [@hashes, @objects].each {|e|
26
- Pipe.search_object(e, :a=>'some', :b=>'yep').size.should == 2
26
+ Pipes.query_pipe(e, :a=>'some', :b=>'yep').size.should == 2
27
27
  }
28
28
  end
29
29
 
30
30
  test "prints error for invalid search field" do
31
- capture_stderr { Pipe.search_object(@objects, :blah=>'blah') }.should =~ /failed.*'blah'/
31
+ capture_stderr { Pipes.query_pipe(@objects, :blah=>'blah') }.should =~ /failed.*'blah'/
32
32
  end
33
33
  end
34
34
 
35
- context "sort_object" do
35
+ context "sort_pipe" do
36
36
  test "sorts objects with values of different types" do
37
- Pipe.sort_object(@objects, :a).should == @objects.reverse
37
+ Pipes.sort_pipe(@objects, :a).should == @objects.reverse
38
38
  end
39
39
 
40
40
  test "sorts hashes with values of different types" do
41
- Pipe.sort_object(@hashes, :a).should == @hashes.reverse
41
+ Pipes.sort_pipe(@hashes, :a).should == @hashes.reverse
42
42
  end
43
43
 
44
44
  test "sorts numeric values" do
45
45
  hashes = [{:a=>10, :b=>4}, {:a=>5, :b=>3}]
46
- Pipe.sort_object(hashes, :a).should == hashes.reverse
47
- end
48
-
49
- test "sorts and reverses sort" do
50
- Pipe.sort_object(@hashes, :a, true).should == @hashes
46
+ Pipes.sort_pipe(hashes, :a).should == hashes.reverse
51
47
  end
52
48
 
53
49
  test "prints error for invalid sort field" do
54
- capture_stderr { Pipe.sort_object(@objects, :blah)}.should =~ /failed.*'blah'/
50
+ capture_stderr { Pipes.sort_pipe(@objects, :blah)}.should =~ /failed.*'blah'/
55
51
  end
56
52
  end
57
53
  end
@@ -322,6 +322,10 @@ module Boson
322
322
  local_and_global("doh -r -f - --dude").should == [{:foo=>true}, {:dude=>true, :render=>true}]
323
323
  end
324
324
 
325
+ test "conflicting global option after -" do
326
+ local_and_global('doh - -f=1,2').should == [{}, {:fields=>["1", "2"]}]
327
+ end
328
+
325
329
  test "no options parsed after --" do
326
330
  local_and_global('doh -f -- -r').should == [{:foo=>true}, {}]
327
331
  local_and_global('doh -- -r -f').should == [{}, {}]
data/test/test_helper.rb CHANGED
@@ -130,4 +130,15 @@ class Test::Unit::TestCase
130
130
  Boson::Manager.add_library(lib); lib
131
131
  }
132
132
  end
133
+
134
+ module OptionTestHelper
135
+ def create(opts)
136
+ @opt = Boson::OptionParser.new(opts)
137
+ end
138
+
139
+ def parse(*args)
140
+ @non_opts = []
141
+ @opt.parse(args.flatten)
142
+ end
143
+ end
133
144
  end
data/test/util_test.rb ADDED
@@ -0,0 +1,58 @@
1
+ require File.join(File.dirname(__FILE__), 'test_helper')
2
+
3
+ module Boson
4
+ class UtilTest < Test::Unit::TestCase
5
+ test "underscore converts camelcase to underscore" do
6
+ Util.underscore('Boson::MethodInspector').should == 'boson/method_inspector'
7
+ end
8
+
9
+ test "constantize converts string to class" do
10
+ Util.constantize("Boson").should == ::Boson
11
+ end
12
+
13
+ context "underscore_search" do
14
+ def search(query, list)
15
+ Util.underscore_search(query, list).sort {|a,b| a.to_s <=> b.to_s }
16
+ end
17
+
18
+ def first_search(query, list)
19
+ Util.underscore_search(query, list, true)
20
+ end
21
+
22
+ test "matches non underscore strings" do
23
+ search('som', %w{some words match sometimes}).should == %w{some sometimes}
24
+ end
25
+
26
+ test "matches first non underscore string" do
27
+ first_search('wo', %w{some work wobbles}).should == 'work'
28
+ end
29
+
30
+ test "matches non underscore symbols" do
31
+ search(:som, [:some, :words, :match, :sometimes]).should == [:some, :sometimes]
32
+ search('som', [:some, :words, :match, :sometimes]).should == [:some, :sometimes]
33
+ end
34
+
35
+ test "matches underscore strings" do
36
+ search('s_l', %w{some_long some_short some_lame}).should == %w{some_lame some_long}
37
+ end
38
+
39
+ test "matches first underscore string" do
40
+ first_search('s_l', %w{some_long some_short some_lame}).should == 'some_long'
41
+ end
42
+
43
+ test "matches underscore symbols" do
44
+ search(:s_l, [:some_long, :some_short, :some_lame]).should == [:some_lame, :some_long]
45
+ search('s_l', [:some_long, :some_short, :some_lame]).should == [:some_lame, :some_long]
46
+ end
47
+
48
+ test "matches full underscore string" do
49
+ search('some_long_name', %w{some_long_name some_short some_lame}).should == %w{some_long_name}
50
+ end
51
+
52
+ test "only matches exact match if multiple matches that start with exact match" do
53
+ search('bl', %w{bl blang bling}).should == ['bl']
54
+ first_search('bl', %w{bl blang bling}).should == 'bl'
55
+ end
56
+ end
57
+ end
58
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: boson
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Gabriel Horner
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2010-01-23 00:00:00 -05:00
12
+ date: 2010-02-16 00:00:00 -05:00
13
13
  default_executable: boson
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -20,7 +20,7 @@ dependencies:
20
20
  requirements:
21
21
  - - ">="
22
22
  - !ruby/object:Gem::Version
23
- version: 0.2.8
23
+ version: 0.2.10
24
24
  version:
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: alias
@@ -70,6 +70,7 @@ files:
70
70
  - lib/boson/option_parser.rb
71
71
  - lib/boson/options.rb
72
72
  - lib/boson/pipe.rb
73
+ - lib/boson/pipes.rb
73
74
  - lib/boson/repo.rb
74
75
  - lib/boson/repo_index.rb
75
76
  - lib/boson/runner.rb
@@ -86,12 +87,14 @@ files:
86
87
  - test/manager_test.rb
87
88
  - test/method_inspector_test.rb
88
89
  - test/option_parser_test.rb
89
- - test/pipe_test.rb
90
+ - test/options_test.rb
91
+ - test/pipes_test.rb
90
92
  - test/repo_index_test.rb
91
93
  - test/repo_test.rb
92
94
  - test/runner_test.rb
93
95
  - test/scientist_test.rb
94
96
  - test/test_helper.rb
97
+ - test/util_test.rb
95
98
  has_rdoc: true
96
99
  homepage: http://tagaholic.me/boson/
97
100
  licenses: []
@@ -129,9 +132,11 @@ test_files:
129
132
  - test/manager_test.rb
130
133
  - test/method_inspector_test.rb
131
134
  - test/option_parser_test.rb
132
- - test/pipe_test.rb
135
+ - test/options_test.rb
136
+ - test/pipes_test.rb
133
137
  - test/repo_index_test.rb
134
138
  - test/repo_test.rb
135
139
  - test/runner_test.rb
136
140
  - test/scientist_test.rb
137
141
  - test/test_helper.rb
142
+ - test/util_test.rb