normatron 0.2.1 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.textile +35 -48
- data/Rakefile +6 -7
- data/lib/generators/normatron/install_generator.rb +23 -0
- data/lib/generators/normatron/templates/normatron.rb +4 -0
- data/lib/normatron.rb +22 -8
- data/lib/normatron/configuration.rb +26 -22
- data/lib/normatron/extensions.rb +8 -0
- data/lib/normatron/extensions/active_record.rb +20 -15
- data/lib/normatron/filters.rb +26 -379
- data/lib/normatron/filters/blank_filter.rb +29 -0
- data/lib/normatron/filters/camelize_filter.rb +50 -0
- data/lib/normatron/filters/capitalize_filter.rb +29 -0
- data/lib/normatron/filters/chomp_filter.rb +34 -0
- data/lib/normatron/filters/dasherize_filter.rb +25 -0
- data/lib/normatron/filters/downcase_filter.rb +29 -0
- data/lib/normatron/filters/dump_filter.rb +27 -0
- data/lib/normatron/filters/helpers.rb +44 -0
- data/lib/normatron/filters/keep_filter.rb +100 -0
- data/lib/normatron/filters/remove_filter.rb +37 -0
- data/lib/normatron/filters/squeeze_filter.rb +30 -0
- data/lib/normatron/filters/squish_filter.rb +28 -0
- data/lib/normatron/filters/strip_filter.rb +33 -0
- data/lib/normatron/filters/swapcase_filter.rb +30 -0
- data/lib/normatron/filters/titleize_filter.rb +29 -0
- data/lib/normatron/filters/underscore_filter.rb +45 -0
- data/lib/normatron/filters/upcase_filter.rb +29 -0
- data/lib/normatron/version.rb +3 -0
- data/spec/normatron/configuration_spec.rb +60 -0
- data/spec/normatron/extensions/active_record_spec.rb +96 -0
- data/spec/normatron/filters/blank_filter_spec.rb +15 -0
- data/spec/normatron/filters/camelize_filter_spec.rb +42 -0
- data/spec/normatron/filters/capitalize_filter_spec.rb +14 -0
- data/spec/normatron/filters/chomp_filter_spec.rb +15 -0
- data/spec/normatron/filters/dasherize_filter_spec.rb +9 -0
- data/spec/normatron/filters/downcase_filter_spec.rb +10 -0
- data/spec/normatron/filters/dump_filter_spec.rb +10 -0
- data/spec/normatron/filters/keep_filter_spec.rb +86 -0
- data/spec/normatron/filters/remove_filter_spec.rb +86 -0
- data/spec/normatron/filters/squeeze_filter_spec.rb +10 -0
- data/spec/normatron/filters/squish_filter_spec.rb +12 -0
- data/spec/normatron/filters/strip_filter_spec.rb +12 -0
- data/spec/normatron/filters/swapcase_filter_spec.rb +12 -0
- data/spec/normatron/filters/titleize_filter_spec.rb +12 -0
- data/spec/normatron/filters/underscore_filter_spec.rb +26 -0
- data/spec/normatron/filters/upcase_filter_spec.rb +10 -0
- data/spec/normatron_spec.rb +28 -2
- data/spec/spec_helper.rb +37 -4
- data/spec/support/my_filters.rb +7 -0
- data/spec/support/user_model.rb +14 -0
- metadata +64 -13
- data/spec/configuration_spec.rb +0 -53
- data/spec/extensions/active_record_spec.rb +0 -114
- data/spec/filters_spec.rb +0 -442
- data/spec/support/model_model.rb +0 -3
- data/spec/support/schema.rb +0 -7
data/spec/configuration_spec.rb
DELETED
@@ -1,53 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Normatron::Configuration do
|
4
|
-
before :each do
|
5
|
-
@instance = described_class.new
|
6
|
-
end
|
7
|
-
|
8
|
-
subject { @instance }
|
9
|
-
|
10
|
-
describe "#default_filters" do
|
11
|
-
it "should initializate" do
|
12
|
-
subject.default_filters.should == { squish: [], blank: [] }
|
13
|
-
end
|
14
|
-
it "should parse and set filters properly" do
|
15
|
-
subject.default_filters = :upcase, :blank, { keep: [:L, :N] }, [:remove, :S, :Z]
|
16
|
-
subject.default_filters.should == { upcase: [], blank: [], keep: [:L, :N], remove: [:S, :Z] }
|
17
|
-
end
|
18
|
-
it "should raise error for empty filters" do
|
19
|
-
lambda{ subject.default_filters = [] }.should raise_error
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
describe "::clean_filters" do
|
24
|
-
context "with wrong arguments" do
|
25
|
-
it { expect{ described_class.clean_filters(nil) }.to raise_error }
|
26
|
-
it { expect{ described_class.clean_filters([]) }.to raise_error }
|
27
|
-
it { expect{ described_class.clean_filters(1) }.to raise_error }
|
28
|
-
it { expect{ described_class.clean_filters([1]) }.to raise_error }
|
29
|
-
it { expect{ described_class.clean_filters([:a, 1]) }.to raise_error }
|
30
|
-
it { expect{ described_class.clean_filters([[1]]) }.to raise_error }
|
31
|
-
end
|
32
|
-
|
33
|
-
context "with single filter hash" do
|
34
|
-
it { described_class.clean_filters(:a ).should == { a:[] } }
|
35
|
-
it { described_class.clean_filters([:a] ).should == { a:[] } }
|
36
|
-
it { described_class.clean_filters([[:a]] ).should == { a:[] } }
|
37
|
-
it { described_class.clean_filters([[:a, :b]] ).should == { a:[:b] } }
|
38
|
-
it { described_class.clean_filters([a: [:b]] ).should == { a:[:b] } }
|
39
|
-
end
|
40
|
-
|
41
|
-
context "with double filters hash" do
|
42
|
-
it { described_class.clean_filters([:a, :b] ).should == { a:[], b:[] } }
|
43
|
-
it { described_class.clean_filters([:a, b:[:c, :d]] ).should == { a:[], b:[:c, :d] } }
|
44
|
-
it { described_class.clean_filters([:a, [:b, :c, :d]] ).should == { a:[], b:[:c, :d] } }
|
45
|
-
end
|
46
|
-
|
47
|
-
context "with trible filters hash" do
|
48
|
-
it { described_class.clean_filters([:a, [:b, :c, :d], { e: [:f, :g] }] ).should == { a:[], b:[:c, :d], e: [:f, :g] } }
|
49
|
-
it { described_class.clean_filters([:a, { b: [:c, :d] }, { e: [:f, :g] }] ).should == { a:[], b:[:c, :d], e: [:f, :g] } }
|
50
|
-
it { described_class.clean_filters([:a, { b: [:c, :d], e: [:f, :g] }] ).should == { a:[], b:[:c, :d], e: [:f, :g] } }
|
51
|
-
end
|
52
|
-
end
|
53
|
-
end
|
@@ -1,114 +0,0 @@
|
|
1
|
-
require "spec_helper"
|
2
|
-
|
3
|
-
describe Normatron::Extensions::ActiveRecord do
|
4
|
-
let(:model) { Model }
|
5
|
-
before(:each) { model.normalize_options = nil }
|
6
|
-
|
7
|
-
describe "::normalize" do
|
8
|
-
subject { model.normalize_options }
|
9
|
-
|
10
|
-
specify("unknown attribute") { expect { model.normalize :abcdef }.to raise_error }
|
11
|
-
specify("nil attribute") { expect { model.normalize nil }.to raise_error }
|
12
|
-
|
13
|
-
context "with no filters" do
|
14
|
-
it "should use default filters" do
|
15
|
-
model.normalize :field_a
|
16
|
-
should == { field_a: { squish: [], blank: [] } }
|
17
|
-
end
|
18
|
-
|
19
|
-
it "should assoc to multiple attributes" do
|
20
|
-
model.normalize :field_a, :field_b, :field_c
|
21
|
-
should == { field_a: { squish: [], blank: [] },
|
22
|
-
field_b: { squish: [], blank: [] },
|
23
|
-
field_c: { squish: [], blank: [] } }
|
24
|
-
end
|
25
|
-
|
26
|
-
it "should stack attributes for multiple calls" do
|
27
|
-
model.normalize :field_a, :field_b
|
28
|
-
model.normalize :field_c
|
29
|
-
should == { field_a: { squish: [], blank: [] },
|
30
|
-
field_b: { squish: [], blank: [] },
|
31
|
-
field_c: { squish: [], blank: [] } }
|
32
|
-
end
|
33
|
-
end
|
34
|
-
|
35
|
-
context "with single filter" do
|
36
|
-
it "should set it" do
|
37
|
-
model.normalize :field_a, with: :upcase
|
38
|
-
should == { field_a: { upcase: [] } }
|
39
|
-
end
|
40
|
-
|
41
|
-
it "should set it as an array" do
|
42
|
-
model.normalize :field_a, with: [:upcase]
|
43
|
-
should == { field_a: { upcase: [] } }
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should set it as an array" do
|
47
|
-
model.normalize :field_a, with: [[:keep, :L, :Z, :N]]
|
48
|
-
should == { field_a: { keep: [:L, :Z, :N] } }
|
49
|
-
end
|
50
|
-
end
|
51
|
-
|
52
|
-
context "with multiple filters" do
|
53
|
-
it "should set it" do
|
54
|
-
model.normalize :field_a, with: [:upcase, :dasherize]
|
55
|
-
should == { field_a: { upcase: [], dasherize: [] } }
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should stack filters for multiple calls" do
|
59
|
-
model.normalize :field_a, with: :upcase
|
60
|
-
model.normalize :field_a, :field_b, with: [:blank, :squish]
|
61
|
-
should == { field_a: { upcase: [], blank: [], squish: [] },
|
62
|
-
field_b: { blank: [], squish: []} }
|
63
|
-
end
|
64
|
-
|
65
|
-
it "should use filters with arguments passed as an array" do
|
66
|
-
model.normalize :field_a, with: [:upcase, [:keep, :L, :N], :blank]
|
67
|
-
should == { field_a: { upcase: [], keep: [:L, :N], blank: [] } }
|
68
|
-
end
|
69
|
-
|
70
|
-
it "should use filters with arguments passed as a hash" do
|
71
|
-
model.normalize :field_a, with: [:upcase, { keep: [:L, :N] }, :blank]
|
72
|
-
should == { field_a: { upcase: [], keep: [:L, :N], blank: [] } }
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
describe "#normalize_attributes" do
|
78
|
-
before(:each) { @instance = model.new }
|
79
|
-
let(:instance) { @instance }
|
80
|
-
|
81
|
-
it "should run instance method filter" do
|
82
|
-
model.class_eval do
|
83
|
-
define_method :test_filter do |value, glue, size|
|
84
|
-
v = value.gsub(/\p{Z}/u, '').split(//) * glue
|
85
|
-
v[0..size-1]
|
86
|
-
end
|
87
|
-
end
|
88
|
-
|
89
|
-
model.normalize :field_a, with: [[:test_filter, ".", 5]]
|
90
|
-
instance.field_a = " bla bla bla"
|
91
|
-
instance.normalize_attributes
|
92
|
-
instance.field_a.should == "b.l.a"
|
93
|
-
end
|
94
|
-
|
95
|
-
it "should run native filter" do
|
96
|
-
model.normalize :field_a, with: [keep: [:N]]
|
97
|
-
instance.field_a = "abc123"
|
98
|
-
instance.normalize_attributes
|
99
|
-
instance.field_a.should == "123"
|
100
|
-
end
|
101
|
-
|
102
|
-
it "should be called before validation" do
|
103
|
-
model.normalize :field_a, with: :downcase
|
104
|
-
instance.field_a = "XXXXXX"
|
105
|
-
instance.valid?
|
106
|
-
instance.field_a.should == "xxxxxx"
|
107
|
-
end
|
108
|
-
|
109
|
-
it "should raise error for wrong filters" do
|
110
|
-
model.normalize :field_a, with: :down
|
111
|
-
expect { instance.normalize_attributes }.to raise_error "Filter 'down' wasn't found."
|
112
|
-
end
|
113
|
-
end
|
114
|
-
end
|
data/spec/filters_spec.rb
DELETED
@@ -1,442 +0,0 @@
|
|
1
|
-
# encoding: UTF-8
|
2
|
-
|
3
|
-
require 'spec_helper'
|
4
|
-
|
5
|
-
describe Normatron::Filters do
|
6
|
-
|
7
|
-
subject { described_class }
|
8
|
-
let(:mb_chars) { ActiveSupport::Multibyte::Chars }
|
9
|
-
|
10
|
-
#
|
11
|
-
# BLANK
|
12
|
-
###################################################################################################################
|
13
|
-
describe "::blank" do
|
14
|
-
it { subject.blank(" . " ).should eq " . " }
|
15
|
-
it { subject.blank(" . ".mb_chars).should eq " . ".mb_chars }
|
16
|
-
|
17
|
-
it { subject.blank(" . " ).should be_a String }
|
18
|
-
it { subject.blank(" " ).should be_nil }
|
19
|
-
it { subject.blank("\n \t \r \f" ).should be_nil }
|
20
|
-
|
21
|
-
it { subject.blank(" . ".mb_chars).should be_a mb_chars }
|
22
|
-
it { subject.blank(" ".mb_chars).should be_nil }
|
23
|
-
it { subject.blank("\n \t \r \f".mb_chars).should be_nil }
|
24
|
-
|
25
|
-
it { subject.blank(100 ).should eq 100 }
|
26
|
-
it { subject.blank(nil ).should be_nil }
|
27
|
-
end
|
28
|
-
|
29
|
-
#
|
30
|
-
# CAMELIZE
|
31
|
-
###################################################################################################################
|
32
|
-
describe "::camelize" do
|
33
|
-
it { subject.camelize("active_record/errors" ).should eq "ActiveRecord::Errors" }
|
34
|
-
it { subject.camelize("áctivé_record/érrórs" ).should eq "ÁctivéRecord::Érrórs" }
|
35
|
-
it { subject.camelize("ActivE_record/ErrOrs" ).should eq "ActiveRecord::Errors" }
|
36
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs" ).should eq "ÁctivéRecord::Érrórs" }
|
37
|
-
it { subject.camelize("active_record/errors", :upper ).should eq "ActiveRecord::Errors" }
|
38
|
-
it { subject.camelize("áctivé_record/érrórs", :upper ).should eq "ÁctivéRecord::Érrórs" }
|
39
|
-
it { subject.camelize("ActivE_record/ErrOrs", :upper ).should eq "ActiveRecord::Errors" }
|
40
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs", :upper ).should eq "ÁctivéRecord::Érrórs" }
|
41
|
-
it { subject.camelize("active_record/errors", :lower ).should eq "activeRecord::Errors" }
|
42
|
-
it { subject.camelize("áctivé_record/érrórs", :lower ).should eq "áctivéRecord::Érrórs" }
|
43
|
-
it { subject.camelize("ActivE_record/ErrOrs", :lower ).should eq "activeRecord::Errors" }
|
44
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs", :lower ).should eq "áctivéRecord::Érrórs" }
|
45
|
-
|
46
|
-
it { subject.camelize("active_record/errors".mb_chars ).should eq "ActiveRecord::Errors".mb_chars }
|
47
|
-
it { subject.camelize("áctivé_record/érrórs".mb_chars ).should eq "ÁctivéRecord::Érrórs".mb_chars }
|
48
|
-
it { subject.camelize("ActivE_record/ErrOrs".mb_chars ).should eq "ActiveRecord::Errors".mb_chars }
|
49
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs".mb_chars ).should eq "ÁctivéRecord::Érrórs".mb_chars }
|
50
|
-
it { subject.camelize("active_record/errors".mb_chars, :upper).should eq "ActiveRecord::Errors".mb_chars }
|
51
|
-
it { subject.camelize("áctivé_record/érrórs".mb_chars, :upper).should eq "ÁctivéRecord::Érrórs".mb_chars }
|
52
|
-
it { subject.camelize("ActivE_record/ErrOrs".mb_chars, :upper).should eq "ActiveRecord::Errors".mb_chars }
|
53
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs".mb_chars, :upper).should eq "ÁctivéRecord::Érrórs".mb_chars }
|
54
|
-
it { subject.camelize("active_record/errors".mb_chars, :lower).should eq "activeRecord::Errors".mb_chars }
|
55
|
-
it { subject.camelize("áctivé_record/érrórs".mb_chars, :lower).should eq "áctivéRecord::Érrórs".mb_chars }
|
56
|
-
it { subject.camelize("ActivE_record/ErrOrs".mb_chars, :lower).should eq "activeRecord::Errors".mb_chars }
|
57
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs".mb_chars, :lower).should eq "áctivéRecord::Érrórs".mb_chars }
|
58
|
-
|
59
|
-
it { subject.camelize("active_record/errors" ).should be_a String }
|
60
|
-
it { subject.camelize("áctivé_record/érrórs" ).should be_a String }
|
61
|
-
it { subject.camelize("ActivE_record/ErrOrs" ).should be_a String }
|
62
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs" ).should be_a String }
|
63
|
-
it { subject.camelize("active_record/errors", :upper ).should be_a String }
|
64
|
-
it { subject.camelize("áctivé_record/érrórs", :upper ).should be_a String }
|
65
|
-
it { subject.camelize("ActivE_record/ErrOrs", :upper ).should be_a String }
|
66
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs", :upper ).should be_a String }
|
67
|
-
it { subject.camelize("active_record/errors", :lower ).should be_a String }
|
68
|
-
it { subject.camelize("áctivé_record/érrórs", :lower ).should be_a String }
|
69
|
-
it { subject.camelize("ActivE_record/ErrOrs", :lower ).should be_a String }
|
70
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs", :lower ).should be_a String }
|
71
|
-
|
72
|
-
it { subject.camelize("active_record/errors".mb_chars ).should be_a mb_chars }
|
73
|
-
it { subject.camelize("áctivé_record/érrórs".mb_chars ).should be_a mb_chars }
|
74
|
-
it { subject.camelize("ActivE_record/ErrOrs".mb_chars ).should be_a mb_chars }
|
75
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs".mb_chars ).should be_a mb_chars }
|
76
|
-
it { subject.camelize("active_record/errors".mb_chars, :upper).should be_a mb_chars }
|
77
|
-
it { subject.camelize("áctivé_record/érrórs".mb_chars, :upper).should be_a mb_chars }
|
78
|
-
it { subject.camelize("ActivE_record/ErrOrs".mb_chars, :upper).should be_a mb_chars }
|
79
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs".mb_chars, :upper).should be_a mb_chars }
|
80
|
-
it { subject.camelize("active_record/errors".mb_chars, :lower).should be_a mb_chars }
|
81
|
-
it { subject.camelize("áctivé_record/érrórs".mb_chars, :lower).should be_a mb_chars }
|
82
|
-
it { subject.camelize("ActivE_record/ErrOrs".mb_chars, :lower).should be_a mb_chars }
|
83
|
-
it { subject.camelize("ÁctivÉ_record/ÉrrÓrs".mb_chars, :lower).should be_a mb_chars }
|
84
|
-
|
85
|
-
it { subject.camelize(100 ).should eq 100 }
|
86
|
-
it { subject.camelize(100, :upper ).should eq 100 }
|
87
|
-
it { subject.camelize(100, :lower ).should eq 100 }
|
88
|
-
it { subject.camelize(nil ).should be_nil }
|
89
|
-
it { subject.camelize(nil, :upper ).should be_nil }
|
90
|
-
it { subject.camelize(nil, :lower ).should be_nil }
|
91
|
-
|
92
|
-
it { expect { subject.camelize("ÁctivÉ_record/ÉrrÓrs", :other) }.to raise_error }
|
93
|
-
|
94
|
-
context "should affect acronyms" do
|
95
|
-
let(:inflections) { ActiveSupport::Inflector::Inflections.instance }
|
96
|
-
|
97
|
-
before(:all) do
|
98
|
-
inflections.acronym 'HTTP'
|
99
|
-
inflections.acronym 'SSL'
|
100
|
-
end
|
101
|
-
|
102
|
-
it { subject.camelize("http_address/ssl", :upper).should eq "HTTPAddress::SSL" }
|
103
|
-
it { subject.camelize("http_address/ssl", :lower).should eq "httpAddress::SSL" }
|
104
|
-
|
105
|
-
after(:all) do
|
106
|
-
inflections.acronyms = {}
|
107
|
-
end
|
108
|
-
end
|
109
|
-
end
|
110
|
-
|
111
|
-
describe "::capitalize" do
|
112
|
-
it { subject.capitalize("abcDEF GhI" ).should eq "Abcdef ghi" }
|
113
|
-
it { subject.capitalize("ébcDEF GhI" ).should eq "Ébcdef ghi" }
|
114
|
-
it { subject.capitalize(" bcDEF GhI" ).should eq " bcdef ghi" }
|
115
|
-
it { subject.capitalize("abcDEF GhI" ).should be_a String }
|
116
|
-
it { subject.capitalize("abcDEF GhI".mb_chars).should be_a mb_chars }
|
117
|
-
it { subject.capitalize(100 ).should eq 100 }
|
118
|
-
it { subject.capitalize(nil ).should be_nil }
|
119
|
-
end
|
120
|
-
|
121
|
-
#
|
122
|
-
# CHOMP
|
123
|
-
###################################################################################################################
|
124
|
-
describe "::chomp" do
|
125
|
-
it { subject.chomp("abcdef ghijkl" ).should eq "abcdef ghijkl" }
|
126
|
-
it { subject.chomp("abcdef ghij\n" ).should eq "abcdef ghij" }
|
127
|
-
it { subject.chomp("abc\nd efghij" ).should eq "abc\nd efghij" }
|
128
|
-
it { subject.chomp("abc\nd ef\n\r" ).should eq "abc\nd ef\n" }
|
129
|
-
it { subject.chomp("abc\nd ef\r\n" ).should eq "abc\nd ef" }
|
130
|
-
it { subject.chomp("abcdef ghijkl", "jkl" ).should eq "abcdef ghi" }
|
131
|
-
it { subject.chomp("abcdef ghij\n", "j\n" ).should eq "abcdef ghi" }
|
132
|
-
it { subject.chomp("abc\nd efghij", " efghij" ).should eq "abc\nd" }
|
133
|
-
it { subject.chomp("abc\nd ef\n\r", "\n\r" ).should eq "abc\nd ef" }
|
134
|
-
it { subject.chomp("abc\nd ef\r\n", "\n" ).should eq "abc\nd ef" }
|
135
|
-
|
136
|
-
it { subject.chomp("abcdef ghijkl" ).should eq "abcdef ghijkl" }
|
137
|
-
it { subject.chomp("abcdef ghij\n" ).should eq "abcdef ghij" }
|
138
|
-
it { subject.chomp("abc\nd efghij" ).should eq "abc\nd efghij" }
|
139
|
-
it { subject.chomp("abc\nd ef\n\r" ).should eq "abc\nd ef\n" }
|
140
|
-
it { subject.chomp("abc\nd ef\r\n" ).should eq "abc\nd ef" }
|
141
|
-
it { subject.chomp("abcdef ghijkl", "jkl" .mb_chars ).should eq "abcdef ghi" }
|
142
|
-
it { subject.chomp("abcdef ghij\n", "j\n" .mb_chars ).should eq "abcdef ghi" }
|
143
|
-
it { subject.chomp("abc\nd efghij", " efghij".mb_chars ).should eq "abc\nd" }
|
144
|
-
it { subject.chomp("abc\nd ef\n\r", "\n\r" .mb_chars ).should eq "abc\nd ef" }
|
145
|
-
it { subject.chomp("abc\nd ef\r\n", "\n" .mb_chars ).should eq "abc\nd ef" }
|
146
|
-
|
147
|
-
it { subject.chomp("abcdef ghijkl".mb_chars ).should eq "abcdef ghijkl".mb_chars }
|
148
|
-
it { subject.chomp("abcdef ghij\n".mb_chars ).should eq "abcdef ghij" .mb_chars }
|
149
|
-
it { subject.chomp("abc\nd efghij".mb_chars ).should eq "abc\nd efghij".mb_chars }
|
150
|
-
it { subject.chomp("abc\nd ef\n\r".mb_chars ).should eq "abc\nd ef\n" .mb_chars }
|
151
|
-
it { subject.chomp("abc\nd ef\r\n".mb_chars ).should eq "abc\nd ef" .mb_chars }
|
152
|
-
it { subject.chomp("abcdef ghijkl".mb_chars, "jkl" ).should eq "abcdef ghi" .mb_chars }
|
153
|
-
it { subject.chomp("abcdef ghij\n".mb_chars, "j\n" ).should eq "abcdef ghi" .mb_chars }
|
154
|
-
it { subject.chomp("abc\nd efghij".mb_chars, " efghij" ).should eq "abc\nd" .mb_chars }
|
155
|
-
it { subject.chomp("abc\nd ef\n\r".mb_chars, "\n\r" ).should eq "abc\nd ef" .mb_chars }
|
156
|
-
it { subject.chomp("abc\nd ef\r\n".mb_chars, "\n" ).should eq "abc\nd ef" .mb_chars }
|
157
|
-
|
158
|
-
it { subject.chomp("abcdef ghijkl".mb_chars ).should eq "abcdef ghijkl".mb_chars }
|
159
|
-
it { subject.chomp("abcdef ghij\n".mb_chars ).should eq "abcdef ghij" .mb_chars }
|
160
|
-
it { subject.chomp("abc\nd efghij".mb_chars ).should eq "abc\nd efghij".mb_chars }
|
161
|
-
it { subject.chomp("abc\nd ef\n\r".mb_chars ).should eq "abc\nd ef\n" .mb_chars }
|
162
|
-
it { subject.chomp("abc\nd ef\r\n".mb_chars ).should eq "abc\nd ef" .mb_chars }
|
163
|
-
it { subject.chomp("abcdef ghijkl".mb_chars, "jkl" .mb_chars).should eq "abcdef ghi" .mb_chars }
|
164
|
-
it { subject.chomp("abcdef ghij\n".mb_chars, "j\n" .mb_chars).should eq "abcdef ghi" .mb_chars }
|
165
|
-
it { subject.chomp("abc\nd efghij".mb_chars, " efghij".mb_chars).should eq "abc\nd" .mb_chars }
|
166
|
-
it { subject.chomp("abc\nd ef\n\r".mb_chars, "\n\r" .mb_chars).should eq "abc\nd ef" .mb_chars }
|
167
|
-
it { subject.chomp("abc\nd ef\r\n".mb_chars, "\n" .mb_chars).should eq "abc\nd ef" .mb_chars }
|
168
|
-
|
169
|
-
it { subject.chomp("abcdef ghijkl" ).should be_a String }
|
170
|
-
it { subject.chomp("abcdef ghij\n" ).should be_a String }
|
171
|
-
it { subject.chomp("abc\nd efghij" ).should be_a String }
|
172
|
-
it { subject.chomp("abc\nd ef\n\r" ).should be_a String }
|
173
|
-
it { subject.chomp("abc\nd ef\r\n" ).should be_a String }
|
174
|
-
it { subject.chomp("abcdef ghijkl", "jkl" ).should be_a String }
|
175
|
-
it { subject.chomp("abcdef ghij\n", "j\n" ).should be_a String }
|
176
|
-
it { subject.chomp("abc\nd efghij", " efghij" ).should be_a String }
|
177
|
-
it { subject.chomp("abc\nd ef\n\r", "\n\r" ).should be_a String }
|
178
|
-
it { subject.chomp("abc\nd ef\r\n", "\n" ).should be_a String }
|
179
|
-
|
180
|
-
it { subject.chomp("abcdef ghijkl" ).should be_a String }
|
181
|
-
it { subject.chomp("abcdef ghij\n" ).should be_a String }
|
182
|
-
it { subject.chomp("abc\nd efghij" ).should be_a String }
|
183
|
-
it { subject.chomp("abc\nd ef\n\r" ).should be_a String }
|
184
|
-
it { subject.chomp("abc\nd ef\r\n" ).should be_a String }
|
185
|
-
it { subject.chomp("abcdef ghijkl", "jkl" .mb_chars ).should be_a String }
|
186
|
-
it { subject.chomp("abcdef ghij\n", "j\n" .mb_chars ).should be_a String }
|
187
|
-
it { subject.chomp("abc\nd efghij", " efghij".mb_chars ).should be_a String }
|
188
|
-
it { subject.chomp("abc\nd ef\n\r", "\n\r" .mb_chars ).should be_a String }
|
189
|
-
it { subject.chomp("abc\nd ef\r\n", "\n" .mb_chars ).should be_a String }
|
190
|
-
|
191
|
-
it { subject.chomp("abcdef ghijkl".mb_chars ).should be_a mb_chars }
|
192
|
-
it { subject.chomp("abcdef ghij\n".mb_chars ).should be_a mb_chars }
|
193
|
-
it { subject.chomp("abc\nd efghij".mb_chars ).should be_a mb_chars }
|
194
|
-
it { subject.chomp("abc\nd ef\n\r".mb_chars ).should be_a mb_chars }
|
195
|
-
it { subject.chomp("abc\nd ef\r\n".mb_chars ).should be_a mb_chars }
|
196
|
-
it { subject.chomp("abcdef ghijkl".mb_chars, "jkl" ).should be_a mb_chars }
|
197
|
-
it { subject.chomp("abcdef ghij\n".mb_chars, "j\n" ).should be_a mb_chars }
|
198
|
-
it { subject.chomp("abc\nd efghij".mb_chars, " efghij" ).should be_a mb_chars }
|
199
|
-
it { subject.chomp("abc\nd ef\n\r".mb_chars, "\n\r" ).should be_a mb_chars }
|
200
|
-
it { subject.chomp("abc\nd ef\r\n".mb_chars, "\n" ).should be_a mb_chars }
|
201
|
-
|
202
|
-
it { subject.chomp("abcdef ghijkl".mb_chars ).should be_a mb_chars }
|
203
|
-
it { subject.chomp("abcdef ghij\n".mb_chars ).should be_a mb_chars }
|
204
|
-
it { subject.chomp("abc\nd efghij".mb_chars ).should be_a mb_chars }
|
205
|
-
it { subject.chomp("abc\nd ef\n\r".mb_chars ).should be_a mb_chars }
|
206
|
-
it { subject.chomp("abc\nd ef\r\n".mb_chars ).should be_a mb_chars }
|
207
|
-
it { subject.chomp("abcdef ghijkl".mb_chars, "jkl" .mb_chars).should be_a mb_chars }
|
208
|
-
it { subject.chomp("abcdef ghij\n".mb_chars, "j\n" .mb_chars).should be_a mb_chars }
|
209
|
-
it { subject.chomp("abc\nd efghij".mb_chars, " efghij".mb_chars).should be_a mb_chars }
|
210
|
-
it { subject.chomp("abc\nd ef\n\r".mb_chars, "\n\r" .mb_chars).should be_a mb_chars }
|
211
|
-
it { subject.chomp("abc\nd ef\r\n".mb_chars, "\n" .mb_chars).should be_a mb_chars }
|
212
|
-
|
213
|
-
it { subject.chomp(100 ).should eq 100 }
|
214
|
-
it { subject.chomp(nil ).should be_nil }
|
215
|
-
end
|
216
|
-
|
217
|
-
describe "::dasherize" do
|
218
|
-
it { subject.dasherize("string_inflections" ).should eq "string-inflections" }
|
219
|
-
it { subject.dasherize("string_inflections" ).should be_a String }
|
220
|
-
it { subject.dasherize("string_inflections".mb_chars).should be_a mb_chars }
|
221
|
-
it { subject.dasherize(100 ).should eq 100 }
|
222
|
-
it { subject.dasherize(nil ).should be_nil }
|
223
|
-
end
|
224
|
-
|
225
|
-
describe "::downcase" do
|
226
|
-
it { subject.downcase("ÇSDF !@# JHAS" ).should eq "çsdf !@# jhas" }
|
227
|
-
it { subject.downcase("ÇSDF !@# JHAS" ).should be_a String }
|
228
|
-
it { subject.downcase("ÇSDF !@# JHAS".mb_chars).should be_a mb_chars }
|
229
|
-
it { subject.downcase(100 ).should eq 100 }
|
230
|
-
it { subject.downcase(nil ).should be_nil }
|
231
|
-
end
|
232
|
-
|
233
|
-
#
|
234
|
-
# DUMP
|
235
|
-
###################################################################################################################
|
236
|
-
describe "::dump" do
|
237
|
-
it { subject.dump("abc\ndef" ).should eq '"abc\ndef"' }
|
238
|
-
it { subject.dump('abc\ndef' ).should eq '"abc\\\ndef"' }
|
239
|
-
|
240
|
-
it { subject.dump("abc\ndef".mb_chars).should eq '"abc\ndef"' .mb_chars }
|
241
|
-
it { subject.dump('abc\ndef'.mb_chars).should eq '"abc\\\ndef"'.mb_chars }
|
242
|
-
|
243
|
-
it { subject.dump("abc\ndef" ).should be_a String }
|
244
|
-
it { subject.dump('abc\ndef' ).should be_a String }
|
245
|
-
|
246
|
-
it { subject.dump("abc\ndef".mb_chars).should be_a mb_chars }
|
247
|
-
it { subject.dump('abc\ndef'.mb_chars).should be_a mb_chars }
|
248
|
-
|
249
|
-
it { subject.dump(100 ).should eq 100 }
|
250
|
-
it { subject.dump(nil ).should be_nil }
|
251
|
-
end
|
252
|
-
|
253
|
-
describe "::keep" do
|
254
|
-
it { subject.keep("1111aaaa", :L ).should eq "aaaa" }
|
255
|
-
it { subject.keep("1111ܑܑܑܑ", :M ).should eq "ܑܑܑܑ" }
|
256
|
-
it { subject.keep("1111!!!!", :P ).should eq "!!!!" }
|
257
|
-
it { subject.keep("1111££££", :S ).should eq "££££" }
|
258
|
-
it { subject.keep("11 ££", :Z ).should eq " " }
|
259
|
-
it { subject.keep("11\n\n££", :C ).should eq "\n\n" }
|
260
|
-
it { subject.keep("1111aaaa", :L ).should be_a String }
|
261
|
-
it { subject.keep("1111aaaa".mb_chars, :L).should be_a mb_chars }
|
262
|
-
it { subject.keep(1, :L ).should eq 1 }
|
263
|
-
it { subject.keep(1, :M ).should eq 1 }
|
264
|
-
it { subject.keep(1, :P ).should eq 1 }
|
265
|
-
it { subject.keep(1, :S ).should eq 1 }
|
266
|
-
it { subject.keep(1, :Z ).should eq 1 }
|
267
|
-
it { subject.keep(1, :C ).should eq 1 }
|
268
|
-
it { subject.keep(nil, :L ).should be_nil }
|
269
|
-
it { subject.keep(nil, :M ).should be_nil }
|
270
|
-
it { subject.keep(nil, :P ).should be_nil }
|
271
|
-
it { subject.keep(nil, :S ).should be_nil }
|
272
|
-
it { subject.keep(nil, :Z ).should be_nil }
|
273
|
-
it { subject.keep(nil, :C ).should be_nil }
|
274
|
-
|
275
|
-
context "with multiple options" do
|
276
|
-
it { subject.keep("1111aaaa!!!!", [:L, :N]).should eq "1111aaaa" }
|
277
|
-
it { subject.keep("1111ܑܑܑܑ!!!!", [:M, :N]).should eq "1111ܑܑܑܑ" }
|
278
|
-
it { subject.keep("1111!!!!aaaa", [:P, :L]).should eq "!!!!aaaa" }
|
279
|
-
it { subject.keep("1111££££aaaa", [:S, :N]).should eq "1111££££" }
|
280
|
-
it { subject.keep("11 ££aaaa", [:Z, :S]).should eq " ££" }
|
281
|
-
it { subject.keep("11\n\n££aaaa", [:C, :N]).should eq "11\n\n" }
|
282
|
-
end
|
283
|
-
|
284
|
-
context "with wrong option" do
|
285
|
-
it { lambda { subject.keep("1111aaaa", :J) }.should raise_error }
|
286
|
-
it { lambda { subject.keep("1111ܑܑܑܑ", :J) }.should raise_error }
|
287
|
-
it { lambda { subject.keep("1111!!!!", :J) }.should raise_error }
|
288
|
-
it { lambda { subject.keep("1111££££", :J) }.should raise_error }
|
289
|
-
it { lambda { subject.keep("11 ££", :J) }.should raise_error }
|
290
|
-
it { lambda { subject.keep("11\n\n££", :J) }.should raise_error }
|
291
|
-
end
|
292
|
-
|
293
|
-
context "with wrong option inside multiple options array" do
|
294
|
-
it { lambda { subject.keep("1111aaaa", [:J, :N]) }.should raise_error }
|
295
|
-
it { lambda { subject.keep("1111ܑܑܑܑ", [:J, :N]) }.should raise_error }
|
296
|
-
it { lambda { subject.keep("1111!!!!", [:J, :N]) }.should raise_error }
|
297
|
-
it { lambda { subject.keep("1111££££", [:J, :N]) }.should raise_error }
|
298
|
-
it { lambda { subject.keep("11 ££", [:J, :N]) }.should raise_error }
|
299
|
-
it { lambda { subject.keep("11\n\n££", [:J, :N]) }.should raise_error }
|
300
|
-
end
|
301
|
-
end
|
302
|
-
|
303
|
-
describe "::lstrip" do
|
304
|
-
it { subject.lstrip(" 1111 " ).should eq "1111 " }
|
305
|
-
it { subject.lstrip(" 1111 " ).should be_a String }
|
306
|
-
it { subject.lstrip(" 1111 ".mb_chars).should be_a mb_chars }
|
307
|
-
it { subject.lstrip(1).should eq 1 }
|
308
|
-
it { subject.lstrip(nil).should be_nil }
|
309
|
-
end
|
310
|
-
|
311
|
-
describe "::remove" do
|
312
|
-
it { subject.remove("1111aaaa", :L ).should eq "1111" }
|
313
|
-
it { subject.remove("1111ܑܑܑܑ", :M ).should eq "1111" }
|
314
|
-
it { subject.remove("1111!!!!", :P ).should eq "1111" }
|
315
|
-
it { subject.remove("1111££££", :S ).should eq "1111" }
|
316
|
-
it { subject.remove("11 ££", :Z ).should eq "11££" }
|
317
|
-
it { subject.remove("11\n\n££", :C ).should eq "11££" }
|
318
|
-
it { subject.remove("1111aaaa", :L ).should be_a String }
|
319
|
-
it { subject.remove("1111aaaa".mb_chars, :L).should be_a mb_chars }
|
320
|
-
it { subject.remove(1, :L ).should eq 1 }
|
321
|
-
it { subject.remove(1, :M ).should eq 1 }
|
322
|
-
it { subject.remove(1, :P ).should eq 1 }
|
323
|
-
it { subject.remove(1, :S ).should eq 1 }
|
324
|
-
it { subject.remove(1, :Z ).should eq 1 }
|
325
|
-
it { subject.remove(1, :C ).should eq 1 }
|
326
|
-
it { subject.remove(nil, :L ).should be_nil }
|
327
|
-
it { subject.remove(nil, :M ).should be_nil }
|
328
|
-
it { subject.remove(nil, :P ).should be_nil }
|
329
|
-
it { subject.remove(nil, :S ).should be_nil }
|
330
|
-
it { subject.remove(nil, :Z ).should be_nil }
|
331
|
-
it { subject.remove(nil, :C ).should be_nil }
|
332
|
-
|
333
|
-
context "with multiple options" do
|
334
|
-
it { subject.remove("1111aaaa!!!!", [:L, :N]).should eq "!!!!" }
|
335
|
-
it { subject.remove("1111ܑܑܑܑ!!!!", [:M, :N]).should eq "!!!!" }
|
336
|
-
it { subject.remove("1111!!!!aaaa", [:P, :L]).should eq "1111" }
|
337
|
-
it { subject.remove("1111££££aaaa", [:S, :N]).should eq "aaaa" }
|
338
|
-
it { subject.remove("11 ££aaaa", [:Z, :S]).should eq "11aaaa" }
|
339
|
-
it { subject.remove("11\n\n££aaaa", [:C, :N]).should eq "££aaaa" }
|
340
|
-
end
|
341
|
-
|
342
|
-
context "with wrong option" do
|
343
|
-
it { lambda { subject.remove("1111aaaa", :J) }.should raise_error }
|
344
|
-
it { lambda { subject.remove("1111ܑܑܑܑ", :J) }.should raise_error }
|
345
|
-
it { lambda { subject.remove("1111!!!!", :J) }.should raise_error }
|
346
|
-
it { lambda { subject.remove("1111££££", :J) }.should raise_error }
|
347
|
-
it { lambda { subject.remove("11 ££", :J) }.should raise_error }
|
348
|
-
it { lambda { subject.remove("11\n\n££", :J) }.should raise_error }
|
349
|
-
end
|
350
|
-
|
351
|
-
context "with wrong option inside multiple options array" do
|
352
|
-
it { lambda { subject.remove("1111aaaa", [:J, :N]) }.should raise_error }
|
353
|
-
it { lambda { subject.remove("1111ܑܑܑܑ", [:J, :N]) }.should raise_error }
|
354
|
-
it { lambda { subject.remove("1111!!!!", [:J, :N]) }.should raise_error }
|
355
|
-
it { lambda { subject.remove("1111££££", [:J, :N]) }.should raise_error }
|
356
|
-
it { lambda { subject.remove("11 ££", [:J, :N]) }.should raise_error }
|
357
|
-
it { lambda { subject.remove("11\n\n££", [:J, :N]) }.should raise_error }
|
358
|
-
end
|
359
|
-
end
|
360
|
-
|
361
|
-
describe "::rstrip" do
|
362
|
-
it { subject.rstrip(" 1111 " ).should eq " 1111" }
|
363
|
-
it { subject.rstrip(" 1111 " ).should be_a String }
|
364
|
-
it { subject.rstrip(" 1111 ".mb_chars).should be_a mb_chars }
|
365
|
-
it { subject.rstrip(1 ).should eq 1 }
|
366
|
-
it { subject.rstrip(nil ).should be_nil }
|
367
|
-
end
|
368
|
-
|
369
|
-
describe "::squeeze" do
|
370
|
-
it { subject.squeeze(" 1 22 333 4444 " ).should eq " 1 2 3 4 " }
|
371
|
-
it { subject.squeeze(" 1 22 333 4444 " ).should be_a String }
|
372
|
-
it { subject.squeeze(" 1 22 333 4444 ".mb_chars).should be_a mb_chars }
|
373
|
-
it { subject.squeeze(1 ).should eq 1 }
|
374
|
-
it { subject.squeeze(nil ).should be_nil }
|
375
|
-
|
376
|
-
context "with options" do
|
377
|
-
it { subject.squeeze("aaabbbcccdddeeefff", "b-d" ).should eq "aaabcdeeefff" }
|
378
|
-
it { subject.squeeze("aaabbbcccdddeeefff".mb_chars, "b-d").should eq "aaabcdeeefff".mb_chars }
|
379
|
-
end
|
380
|
-
end
|
381
|
-
|
382
|
-
describe "::squish" do
|
383
|
-
it { subject.squish(" 11 11 " ).should eq "11 11" }
|
384
|
-
it { subject.squish(" 11\n\n11 " ).should eq "11 11" }
|
385
|
-
it { subject.squish(" 11 11 " ).should be_a String }
|
386
|
-
it { subject.squish(" 11 11 ".mb_chars).should be_a mb_chars }
|
387
|
-
it { subject.squish(1 ).should eq 1 }
|
388
|
-
it { subject.squish(nil ).should be_nil }
|
389
|
-
end
|
390
|
-
|
391
|
-
describe "::strip" do
|
392
|
-
it { subject.strip(" 1111 " ).should eq "1111" }
|
393
|
-
it { subject.strip(" 1111 " ).should be_a String }
|
394
|
-
it { subject.strip(" 1111 ".mb_chars).should be_a mb_chars }
|
395
|
-
it { subject.strip(1 ).should eq 1 }
|
396
|
-
it { subject.strip(nil ).should be_nil }
|
397
|
-
end
|
398
|
-
|
399
|
-
#
|
400
|
-
# SWAPCASE
|
401
|
-
###################################################################################################################
|
402
|
-
describe "::swapcase" do
|
403
|
-
it { subject.swapcase("aeiouáéíóú" ).should eq "AEIOUÁÉÍÓÚ" }
|
404
|
-
it { subject.swapcase("AEIOUÁÉÍÓÚ" ).should eq "aeiouáéíóú" }
|
405
|
-
it { subject.swapcase("aEiOuÁéÍóÚ" ).should eq "AeIoUáÉíÓú" }
|
406
|
-
it { subject.swapcase("AeIoUáÉíÓú" ).should eq "aEiOuÁéÍóÚ" }
|
407
|
-
|
408
|
-
it { subject.swapcase("aeiouáéíóú".mb_chars).should eq "AEIOUÁÉÍÓÚ".mb_chars }
|
409
|
-
it { subject.swapcase("AEIOUÁÉÍÓÚ".mb_chars).should eq "aeiouáéíóú".mb_chars }
|
410
|
-
it { subject.swapcase("aEiOuÁéÍóÚ".mb_chars).should eq "AeIoUáÉíÓú".mb_chars }
|
411
|
-
it { subject.swapcase("AeIoUáÉíÓú".mb_chars).should eq "aEiOuÁéÍóÚ".mb_chars }
|
412
|
-
|
413
|
-
it { subject.swapcase("aeiouáéíóú" ).should be_a String }
|
414
|
-
it { subject.swapcase("AEIOUÁÉÍÓÚ" ).should be_a String }
|
415
|
-
it { subject.swapcase("aEiOuÁéÍóÚ" ).should be_a String }
|
416
|
-
it { subject.swapcase("AeIoUáÉíÓú" ).should be_a String }
|
417
|
-
|
418
|
-
it { subject.swapcase("aeiouáéíóú".mb_chars).should be_a mb_chars }
|
419
|
-
it { subject.swapcase("AEIOUÁÉÍÓÚ".mb_chars).should be_a mb_chars }
|
420
|
-
it { subject.swapcase("aEiOuÁéÍóÚ".mb_chars).should be_a mb_chars }
|
421
|
-
it { subject.swapcase("AeIoUáÉíÓú".mb_chars).should be_a mb_chars }
|
422
|
-
|
423
|
-
it { subject.swapcase(100 ).should eq 100 }
|
424
|
-
it { subject.swapcase(nil ).should be_nil }
|
425
|
-
end
|
426
|
-
|
427
|
-
describe "::titleize" do
|
428
|
-
pending
|
429
|
-
end
|
430
|
-
|
431
|
-
describe "::underscore" do
|
432
|
-
pending
|
433
|
-
end
|
434
|
-
|
435
|
-
describe "::upcase" do
|
436
|
-
it { subject.upcase("Çsdf !@# éhas" ).should eq "ÇSDF !@# ÉHAS" }
|
437
|
-
it { subject.upcase("Çsdf !@# éhas" ).should be_a String }
|
438
|
-
it { subject.upcase("Çsdf !@# éhas".mb_chars).should be_a mb_chars }
|
439
|
-
it { subject.upcase(100 ).should eq 100 }
|
440
|
-
it { subject.upcase(nil ).should be_nil }
|
441
|
-
end
|
442
|
-
end
|