kat 1.0.0 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,136 @@
1
+ require 'minitest/autorun'
2
+ require File.dirname(__FILE__) + '/../../lib/kat/colour'
3
+
4
+ describe Kat::Colour do
5
+ let(:colours) { %i(black red green yellow blue magenta cyan white) }
6
+
7
+ describe 'colour' do
8
+ it 'has working flag methods' do
9
+ Kat::Colour.capable?.must_equal true
10
+ Kat::Colour.colour = false
11
+ Kat::Colour.colour?.must_equal false
12
+ Kat::Colour.colour = true
13
+ Kat::Colour.colour?.must_equal true
14
+ end
15
+
16
+ it 'has colour methods' do
17
+ colours.each { |c|
18
+ ''.respond_to?(c).must_equal true
19
+ :s.respond_to?(c).must_equal true
20
+ [].respond_to?(c).must_equal true
21
+ {}.respond_to?(c).wont_equal true
22
+ }
23
+ end
24
+
25
+ it 'colours strings' do
26
+ colours.each_with_index { |c, i|
27
+ str = 'foobar'
28
+ result = "\e[0;#{ 30 + i }mfoobar\e[0m"
29
+ intense_result = "\e[1;#{ 30 + i }mfoobar\e[0m"
30
+
31
+ str.send(c).must_equal result
32
+ str.must_equal 'foobar'
33
+
34
+ str.send(c, true).must_equal intense_result
35
+ str.must_equal 'foobar'
36
+
37
+ str.send("#{ c }!").must_equal result
38
+ str.must_equal result
39
+
40
+ str = 'foobar'
41
+ str.send("#{ c }!", true).must_equal intense_result
42
+ str.must_equal intense_result
43
+ }
44
+ end
45
+
46
+ it 'uncolour strings' do
47
+ str = "\e[0;30mfoobar\e[0m"
48
+ result = str.dup
49
+
50
+ str.uncolour.must_equal 'foobar'
51
+ str.must_equal result
52
+
53
+ str.uncolour!.must_equal 'foobar'
54
+ str.must_equal 'foobar'
55
+ end
56
+
57
+ it 'colours symbols' do
58
+ colours.each_with_index { |c, i|
59
+ sym = :foobar
60
+ result = "\e[0;#{ 30 + i }mfoobar\e[0m"
61
+ intense_result = "\e[1;#{ 30 + i }mfoobar\e[0m"
62
+
63
+ sym.send(c).must_equal result
64
+ sym.must_equal :foobar
65
+
66
+ sym.send(c, true).must_equal intense_result
67
+ sym.must_equal :foobar
68
+
69
+ sym.send("#{ c }!").must_equal :foobar
70
+ sym.must_equal :foobar
71
+
72
+ sym.send("#{ c }!", true).must_equal :foobar
73
+ sym.must_equal :foobar
74
+ }
75
+ end
76
+
77
+ it 'does not uncolour symbols' do
78
+ sym = :foobar
79
+
80
+ sym.uncolour.must_equal :foobar
81
+ sym.must_equal :foobar
82
+
83
+ sym.uncolour!.must_equal :foobar
84
+ sym.must_equal :foobar
85
+ end
86
+
87
+ it 'colours arrays of strings and symbols' do
88
+ colours.each_with_index { |c, i|
89
+ s = ['foobar', :foobar, nil, ['foobar', :foobar, nil]]
90
+ t = ['foobar', :foobar, nil, ['foobar', :foobar, nil]]
91
+ result = [
92
+ "\e[0;#{ 30 + i }mfoobar\e[0m",
93
+ "\e[0;#{ 30 + i }mfoobar\e[0m",
94
+ nil,
95
+ ["\e[0;#{ 30 + i }mfoobar\e[0m",
96
+ "\e[0;#{ 30 + i }mfoobar\e[0m",
97
+ nil]
98
+ ]
99
+
100
+ s.send(c).must_equal result
101
+ s.must_equal t
102
+
103
+ result[1] = :foobar
104
+ result[3][1] = :foobar
105
+ s.send("#{ c }!").must_equal result
106
+ s.must_equal result
107
+ }
108
+ end
109
+
110
+ it 'uncolours arrays of strings' do
111
+ s = [
112
+ "\e[0;30mfoobar\e[0m",
113
+ :foobar,
114
+ nil,
115
+ ["\e[0;30mfoobar\e[0m",
116
+ :foobar,
117
+ nil]
118
+ ]
119
+ t = [
120
+ "\e[0;30mfoobar\e[0m",
121
+ :foobar,
122
+ nil,
123
+ ["\e[0;30mfoobar\e[0m",
124
+ :foobar,
125
+ nil]
126
+ ]
127
+ result = ['foobar', :foobar, nil, ['foobar', :foobar, nil]]
128
+
129
+ s.uncolour.must_equal result
130
+ s.must_equal t
131
+
132
+ s.uncolour!.must_equal result
133
+ s.must_equal result
134
+ end
135
+ end
136
+ end
@@ -0,0 +1,46 @@
1
+ require 'minitest/autorun'
2
+ require File.dirname(__FILE__) + '/../../lib/kat/field_map'
3
+
4
+ describe Kat do
5
+ describe 'field map' do
6
+ let(:f) { Kat::FIELD_MAP }
7
+
8
+ it 'is a hash' do
9
+ f.must_be_instance_of Hash
10
+ end
11
+
12
+ it 'has symbolised keys' do
13
+ f.keys.wont_be_empty
14
+ f.keys.each { |key|
15
+ key.must_be_instance_of Symbol
16
+ }
17
+ end
18
+
19
+ it 'has a hash for values' do
20
+ f.values.wont_be_empty
21
+ f.values.each { |value|
22
+ value.must_be_instance_of Hash
23
+ }
24
+ end
25
+
26
+ it 'has symbolised keys in each value' do
27
+ f.values.each { |value|
28
+ value.keys.wont_be_empty
29
+ value.keys.each { |key|
30
+ key.must_be_instance_of Symbol
31
+ case key
32
+ when :desc
33
+ value[key].must_be_instance_of String
34
+ when :multi, :check, :input
35
+ value[key].must_equal true
36
+ when :short
37
+ value[key].must_be_instance_of Symbol
38
+ value[key].must_match /\A([a-z]|none)\Z/
39
+ else
40
+ value[key].must_be_instance_of Symbol
41
+ end
42
+ }
43
+ }
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,77 @@
1
+ require 'minitest/autorun'
2
+ require File.dirname(__FILE__) + '/../../lib/kat/options'
3
+
4
+ describe Kat::Options do
5
+
6
+ describe 'options map' do
7
+ let(:opts) { Kat::Options.options_map }
8
+
9
+ it 'is a hash' do
10
+ opts.must_be_instance_of Hash
11
+ opts.keys.wont_be_empty
12
+ opts.values.wont_be_empty
13
+ end
14
+
15
+ it 'has symbolised keys' do
16
+ opts.keys.each { |key|
17
+ key.must_be_instance_of Symbol
18
+ key.wont_equal :size
19
+ }
20
+ end
21
+
22
+ it 'has a hash for values, each with a description' do
23
+ opts.values.each { |value|
24
+ value.must_be_instance_of Hash
25
+ value.keys.must_include :desc
26
+ }
27
+ end
28
+
29
+ it 'has symbolised keys in each value' do
30
+ opts.each { |key, value|
31
+ value.each { |k, v|
32
+ k.must_be_instance_of Symbol
33
+ case k
34
+ when :desc
35
+ v.must_be_instance_of String
36
+ when :multi
37
+ v.must_equal true
38
+ when :short
39
+ v.must_be_instance_of Symbol
40
+ v.must_match /\A([a-z]|none)\Z/
41
+ else
42
+ v.must_be_instance_of Symbol
43
+ end
44
+ }
45
+ }
46
+ end
47
+ end
48
+
49
+ describe 'parse options' do
50
+ it 'returns an options hash with everything off' do
51
+ args = ['foobar']
52
+ opts = Kat::Options.parse args
53
+
54
+ args.must_equal ['foobar']
55
+
56
+ opts.must_be_instance_of Hash
57
+ opts.wont_be_empty
58
+ opts.values.each { |value|
59
+ [[], nil, false].must_include value
60
+ }
61
+ end
62
+
63
+ it 'returns an options hash with some options switched on' do
64
+ args = %w(foobar --or baz --colour -t age)
65
+ opts = Kat::Options.parse args
66
+
67
+ args.must_equal ['foobar']
68
+
69
+ opts[:or].must_equal %w(baz)
70
+ opts[:sort].must_equal 'age'
71
+ %i(colour colour_given or_given sort_given).each { |key|
72
+ opts[key].must_equal true
73
+ }
74
+ end
75
+ end
76
+
77
+ end
@@ -1,17 +1,17 @@
1
1
  require 'minitest/autorun'
2
- require 'kat'
2
+ require File.dirname(__FILE__) + '/../../lib/kat/search'
3
3
 
4
- blue_peter = Kat.new
5
- blue_peter.do_search.do_search 1
4
+ blue_peter = Kat.search
5
+ blue_peter.go.go 1
6
6
 
7
- describe Kat do
7
+ describe Kat::Search do
8
8
 
9
- let(:kat) { Kat.new 'test' }
10
- let(:kat_opts) { Kat.new 'test', { :category => 'books' } }
9
+ let(:kat) { Kat.search 'test' }
10
+ let(:kat_opts) { Kat.search 'test', { category: 'books' } }
11
11
 
12
12
  describe 'basic search' do
13
13
  it 'returns a full result set' do
14
- Kat.search('test').size.must_equal 25
14
+ Kat.quick_search('test').size.must_equal 25
15
15
  end
16
16
  end
17
17
 
@@ -23,25 +23,25 @@ describe Kat do
23
23
  kat_opts.query_str(1).must_equal 'usearch/test category:books/2/'
24
24
  kat_opts.query = :foobar
25
25
  kat_opts.query_str(1).must_equal 'usearch/foobar category:books/2/'
26
- kat_opts.query = [ 0, {}, [ :test, 0..1, [ 'user:foo' ] ] ]
26
+ kat_opts.query = [0, {}, [:test, 0..1, ['user:foo']]]
27
27
  kat_opts.query_str(1).must_equal 'usearch/test user:foo category:books/2/'
28
28
  end
29
29
 
30
30
  it 'returns a valid query string based on many options' do
31
- kat_opts.options = { :files => 2, :safe => true, :language => 2, :sort => :files_count, :asc => true, :seeds => 2 }
32
- kat_opts.query_str(1).must_equal 'usearch/test seeds:2 files:2 safe:1 category:books lang_id:2/2/?field=files_count&sorder=asc'
31
+ kat_opts.options = { files: 2, safe: true, language: 2, sort: :files_count, asc: true, seeds: 2 }
32
+ kat_opts.query_str(1).must_equal 'usearch/test files:2 seeds:2 safe:1 category:books lang_id:2/2/?field=files_count&sorder=asc'
33
33
  end
34
34
 
35
35
  it 'wont respond to result fields before a search' do
36
- [ :titles, :files ].each do |s|
36
+ %i(titles files).each { |s|
37
37
  kat.respond_to?(s).must_equal false
38
- end
38
+ }
39
39
  end
40
40
 
41
41
  it 'responds to result fields after a search' do
42
- [ :titles, :files ].each do |s|
42
+ %i(titles files).each { |s|
43
43
  blue_peter.respond_to?(s).must_equal true
44
- end
44
+ }
45
45
  end
46
46
 
47
47
  it 'returns identical result sets' do
@@ -55,8 +55,8 @@ describe Kat do
55
55
 
56
56
  it 'returns a valid query string with options' do
57
57
  bp = blue_peter.dup
58
- bp.options = { :user => :foobar }
59
- bp.options.must_equal({ :user => :foobar })
58
+ bp.options = { user: :foobar }
59
+ bp.options.must_equal({ user: :foobar })
60
60
  bp.query_str(1).must_equal 'usearch/user:foobar/2/'
61
61
  bp.results.must_be_empty
62
62
  bp.pages.must_equal(-1)
@@ -71,7 +71,7 @@ describe Kat do
71
71
  end
72
72
 
73
73
  it 'works when there are fewer than 25 results' do
74
- kat.options = { :category => :wallpapers }
74
+ kat.options = { category: :wallpapers }
75
75
  kat.search.wont_be_nil
76
76
  kat.search.size.wont_equal 0
77
77
  kat.pages.must_equal 1
@@ -80,43 +80,41 @@ describe Kat do
80
80
  it 'can return 0 results, set an error and set pages to 0' do
81
81
  kat.query = 'owijefbvoweivf'
82
82
  kat.search.must_be_nil
83
- kat.error[:error].must_be_instance_of OpenURI::HTTPError
84
- kat.error[:error].message.must_equal '404 Not Found'
85
83
  kat.pages.must_equal 0
86
84
  end
87
85
  end
88
86
 
89
87
  describe 'field options' do
90
88
  it 'returns a list of time added options' do
91
- times = Kat.times
89
+ times = Kat::Search.times
92
90
  times.must_be_instance_of Hash
93
91
  times.wont_be_empty
94
92
  times[:error].must_be_nil
95
93
  end
96
94
 
97
95
  it 'returns a list of categories' do
98
- categories = Kat.categories
96
+ categories = Kat::Search.categories
99
97
  categories.must_be_instance_of Hash
100
98
  categories.wont_be_empty
101
99
  categories[:error].must_be_nil
102
100
  end
103
101
 
104
102
  it 'returns a list of languages' do
105
- languages = Kat.languages
103
+ languages = Kat::Search.languages
106
104
  languages.must_be_instance_of Hash
107
105
  languages.wont_be_empty
108
106
  languages[:error].must_be_nil
109
107
  end
110
108
 
111
109
  it 'returns a list of platforms' do
112
- platforms = Kat.platforms
110
+ platforms = Kat::Search.platforms
113
111
  platforms.must_be_instance_of Hash
114
112
  platforms.wont_be_empty
115
113
  platforms[:error].must_be_nil
116
114
  end
117
115
 
118
116
  it 'returns an error' do
119
- Kat.field_options(:foobar)[:error].must_be_instance_of RuntimeError
117
+ Kat::Search.class_exec { field_options :foobar }[:error].must_be_instance_of RuntimeError
120
118
  end
121
119
  end
122
120
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: kat
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Fission Xuiptz
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-14 00:00:00.000000000 Z
11
+ date: 2013-09-18 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: nokogiri
@@ -68,8 +68,17 @@ files:
68
68
  - bin/kat
69
69
  - kat.gemspec
70
70
  - lib/kat.rb
71
+ - lib/kat/app.rb
72
+ - lib/kat/colour.rb
73
+ - lib/kat/field_map.rb
74
+ - lib/kat/options.rb
75
+ - lib/kat/search.rb
71
76
  - lib/kat/version.rb
72
- - test/kat_test.rb
77
+ - test/kat/test_app.rb
78
+ - test/kat/test_colour.rb
79
+ - test/kat/test_field_map.rb
80
+ - test/kat/test_options.rb
81
+ - test/kat/test_search.rb
73
82
  homepage: http://github.com/fissionxuiptz/kat
74
83
  licenses:
75
84
  - MIT
@@ -95,4 +104,8 @@ signing_key:
95
104
  specification_version: 4
96
105
  summary: Kickass Torrents Interface
97
106
  test_files:
98
- - test/kat_test.rb
107
+ - test/kat/test_app.rb
108
+ - test/kat/test_colour.rb
109
+ - test/kat/test_field_map.rb
110
+ - test/kat/test_options.rb
111
+ - test/kat/test_search.rb