cw_sort_order 1.0.1 → 1.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (4) hide show
  1. data/LICENSE +8 -0
  2. data/Rakefile +7 -0
  3. data/test/test_sort_order.rb +108 -0
  4. metadata +6 -3
data/LICENSE ADDED
@@ -0,0 +1,8 @@
1
+ Copyright 2011 Christopher Richard Wojno. All rights reserved.
2
+
3
+ Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
4
+
5
+ 1. Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
6
+ 2. Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
7
+
8
+ THIS SOFTWARE IS PROVIDED BY CHRISTOPHER WOJNO ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL CHRISTOPHER WOJNO OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
data/Rakefile ADDED
@@ -0,0 +1,7 @@
1
+ require 'rake/testtask'
2
+ Rake::TestTask.new do |t|
3
+ t.libs << 'test'
4
+ end
5
+
6
+ desc "Run Tests"
7
+ task :default => :test
@@ -0,0 +1,108 @@
1
+ require 'test/unit'
2
+ require 'cw_sort_order'
3
+
4
+ class PaginationOrderTest < Test::Unit::TestCase
5
+
6
+ def test_basic_creation
7
+ o = CW::SortOrder.asc('1').desc('2').desc('3').asc('4')
8
+ assert_equal 4, o.size
9
+ v = o.at(0)
10
+ assert_equal '1', v.first
11
+ assert_equal :asc, v.last
12
+ v = o.at(1)
13
+ assert_equal '2', v.first
14
+ assert_equal :desc, v.last
15
+ v = o.at(2)
16
+ assert_equal '3', v.first
17
+ assert_equal :desc, v.last
18
+ v = o.at(3)
19
+ assert_equal '4', v.first
20
+ assert_equal :asc, v.last
21
+ end
22
+
23
+ def test_short_hand_creation
24
+ o = CW::SortOrder.up('1').dn('2').dn('3').up('4')
25
+ assert_equal 4, o.size
26
+ v = o.at(0)
27
+ assert_equal '1', v.first
28
+ assert_equal :asc, v.last
29
+ v = o.at(1)
30
+ assert_equal '2', v.first
31
+ assert_equal :desc, v.last
32
+ v = o.at(2)
33
+ assert_equal '3', v.first
34
+ assert_equal :desc, v.last
35
+ v = o.at(3)
36
+ assert_equal '4', v.first
37
+ assert_equal :asc, v.last
38
+ end
39
+
40
+ def test_operator_creation
41
+ o = CW::SortOrder.new + '1' - '2' - '3' + '4'
42
+ assert_equal 4, o.size
43
+ v = o.at(0)
44
+ assert_equal '1', v.first
45
+ assert_equal :asc, v.last
46
+ v = o.at(1)
47
+ assert_equal '2', v.first
48
+ assert_equal :desc, v.last
49
+ v = o.at(2)
50
+ assert_equal '3', v.first
51
+ assert_equal :desc, v.last
52
+ v = o.at(3)
53
+ assert_equal '4', v.first
54
+ assert_equal :asc, v.last
55
+ end
56
+
57
+
58
+
59
+ def test_basic_columns_and_directions
60
+ o = CW::SortOrder.new + '1' - '2' - '3' + '4'
61
+ assert_equal %w(1 2 3 4), o.columns
62
+ assert_equal [:asc,:desc,:desc,:asc], o.directions
63
+ end
64
+
65
+ def test_basic_reverse_columns
66
+ o = CW::SortOrder.new + '1' - '2' - '3' - '4'
67
+ o = o.reverse
68
+ assert_equal %w(1 2 3 4).reverse, o.columns
69
+ assert_equal [:asc,:desc,:desc,:desc].reverse, o.directions
70
+ end
71
+
72
+ def test_basic_invert
73
+ o = CW::SortOrder.new + '1' - '2' - '3' + '4'
74
+ o = o.invert
75
+ assert_equal %w(1 2 3 4), o.columns
76
+ assert_equal [:desc,:asc,:asc,:desc], o.directions
77
+ end
78
+
79
+ def test_basic_select
80
+ o = CW::SortOrder.new + '1' - '2' - '3' + '4'
81
+ o = o.select{|col,dir| dir.eql?(:asc) }
82
+ assert_equal %w(1 4), o.columns
83
+ end
84
+ def test_basic_reject
85
+ o = CW::SortOrder.new + '1' - '2' - '3' + '4'
86
+ o = o.reject{|col,dir| dir.eql?(:asc) }
87
+ assert_equal %w(2 3), o.columns
88
+ end
89
+
90
+ def test_concat
91
+ a = CW::SortOrder.new + '1' - '2' - '3' + '4'
92
+ b = CW::SortOrder.new + '5' + '6' + '7' - '8'
93
+ c = CW::SortOrder.new - '9' - '10' + '11' + '12'
94
+ o = a.concat( b ).concat( c )
95
+ assert_equal %w(1 2 3 4 5 6 7 8 9 10 11 12), o.columns
96
+ assert_equal [:asc,:desc,:desc,:asc,:asc,:asc,:asc,:desc,:desc,:desc,:asc,:asc], o.directions
97
+ end
98
+
99
+ def test_shift
100
+ a = CW::SortOrder.new + '1' - '2' - '3' + '4'
101
+ assert_equal ['1',:asc], a.shift
102
+ assert_equal ['2',:desc], a.shift
103
+ assert_equal ['3',:desc], a.shift
104
+ assert_equal ['4',:asc], a.shift
105
+ assert_nil a.shift
106
+ end
107
+
108
+ end
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: cw_sort_order
3
3
  version: !ruby/object:Gem::Version
4
- hash: 21
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 1
8
8
  - 0
9
- - 1
10
- version: 1.0.1
9
+ - 2
10
+ version: 1.0.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Christopher Wojno
@@ -29,6 +29,9 @@ extra_rdoc_files: []
29
29
  files:
30
30
  - lib/cw_sort_order.rb
31
31
  - .gemtest
32
+ - LICENSE
33
+ - Rakefile
34
+ - test/test_sort_order.rb
32
35
  homepage: http://www.wojnosystems.com
33
36
  licenses: []
34
37