ndr_support 5.10.4 → 5.10.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +7 -0
- data/LICENSE.txt +1 -1
- data/README.md +3 -3
- data/lib/ndr_support/concerns/working_days.rb +12 -1
- data/lib/ndr_support/string/clean_methodable.rb +4 -4
- data/lib/ndr_support/version.rb +1 -1
- data/ndr_support.gemspec +8 -6
- metadata +10 -73
- data/.gitignore +0 -19
- data/.rubocop.yml +0 -1
- data/Gemfile +0 -4
- data/Guardfile +0 -24
- data/Rakefile +0 -12
- data/code_safety.yml +0 -294
- data/gemfiles/Gemfile.rails70 +0 -6
- data/gemfiles/Gemfile.rails71 +0 -6
- data/gemfiles/Gemfile.rails72 +0 -6
- data/gemfiles/Gemfile.rails80 +0 -6
- data/test/array_test.rb +0 -20
- data/test/concerns/working_days_test.rb +0 -148
- data/test/date_and_time_extensions_test.rb +0 -82
- data/test/daterange_test.rb +0 -303
- data/test/hash_test.rb +0 -84
- data/test/integer/calculations_test.rb +0 -28
- data/test/integer/rounding_test.rb +0 -14
- data/test/integer/working_days_test.rb +0 -14
- data/test/nil_test.rb +0 -40
- data/test/obfuscator_test.rb +0 -26
- data/test/ourdate_test.rb +0 -26
- data/test/ourtime_test.rb +0 -45
- data/test/password_test.rb +0 -129
- data/test/regexp_range_test.rb +0 -136
- data/test/resources/filesystem_paths.yml +0 -37
- data/test/safe_file_test.rb +0 -670
- data/test/safe_path_test.rb +0 -168
- data/test/string/cleaning_test.rb +0 -247
- data/test/string/conversions_test.rb +0 -371
- data/test/test_helper.rb +0 -42
- data/test/threat_scanner_test.rb +0 -77
- data/test/utf8_encoding/control_characters_test.rb +0 -84
- data/test/utf8_encoding/force_binary_test.rb +0 -64
- data/test/utf8_encoding_test.rb +0 -170
- data/test/yaml/serialization_test.rb +0 -200
data/test/safe_path_test.rb
DELETED
|
@@ -1,168 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
# Switch on the patientlimiter as though in external environment
|
|
4
|
-
|
|
5
|
-
class SafePathTest < Minitest::Test
|
|
6
|
-
def setup
|
|
7
|
-
@sp = SafePath.new('dbs_outbox').join!('/usr/lib')
|
|
8
|
-
end
|
|
9
|
-
|
|
10
|
-
def test_reconfiguring_exception
|
|
11
|
-
# We need SafePath to be well-configured for testing already:
|
|
12
|
-
SafePath.fs_paths # force configuration
|
|
13
|
-
assert_raises(SecurityError) { SafePath.configure! 'dodgy_config.yml' }
|
|
14
|
-
end
|
|
15
|
-
|
|
16
|
-
test 'path passed to the constructor is always relative to the root of the path space' do
|
|
17
|
-
assert_equal @sp.to_s, '/mounts/ron/dbs_outbox/usr/lib'
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
test 'permissions are combination of w or r or x' do
|
|
21
|
-
assert_equal Array, @sp.permissions.class
|
|
22
|
-
assert_equal %w(r w x), @sp.permissions
|
|
23
|
-
|
|
24
|
-
@sp.permissions = 'r'
|
|
25
|
-
assert_equal ['r'], @sp.permissions
|
|
26
|
-
|
|
27
|
-
# The assignment of the permissions preserves the order, although this is not
|
|
28
|
-
# necessary.
|
|
29
|
-
@sp.permissions = %w(w r)
|
|
30
|
-
assert_equal %w(w r), @sp.permissions
|
|
31
|
-
|
|
32
|
-
# The class shouldn't keep duplicates and should flattent the arrays
|
|
33
|
-
@sp.permissions = ['w', 'r', 'x', 'w', 'r', %w(x r)]
|
|
34
|
-
assert_equal %w(w r x), @sp.permissions
|
|
35
|
-
end
|
|
36
|
-
|
|
37
|
-
test 'safe path raises exception if parmission different from rwx is passed' do
|
|
38
|
-
@sp.permissions = 'w'
|
|
39
|
-
assert_raises ArgumentError do
|
|
40
|
-
@sp.permissions = %w(r w potato)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
# The class sould keep it's old permissions in case of raised exception
|
|
44
|
-
assert_equal ['w'], @sp.permissions
|
|
45
|
-
end
|
|
46
|
-
|
|
47
|
-
test 'safe path should remember the pathspace' do
|
|
48
|
-
assert_equal 'dbs_outbox', @sp.path_space
|
|
49
|
-
end
|
|
50
|
-
|
|
51
|
-
test 'safe path should remember root and return another instance of safe path rather than string' do
|
|
52
|
-
@sp.permissions = %w(w x)
|
|
53
|
-
root = @sp.root
|
|
54
|
-
assert_equal SafePath, @sp.root.class
|
|
55
|
-
assert_equal '/mounts/ron/dbs_outbox', root.to_s
|
|
56
|
-
|
|
57
|
-
assert_equal @sp.permissions, root.permissions
|
|
58
|
-
assert_equal @sp.path_space, root.path_space
|
|
59
|
-
end
|
|
60
|
-
|
|
61
|
-
test 'safe path should raise exception if unsafe path passed to constructor' do
|
|
62
|
-
assert_raises SecurityError do
|
|
63
|
-
SafePath.new('dbs_outbox').join!('../../../evil_path')
|
|
64
|
-
end
|
|
65
|
-
end
|
|
66
|
-
|
|
67
|
-
test 'safe path should raise expecption if incorrect path is assigned' do
|
|
68
|
-
assert_raises SecurityError do
|
|
69
|
-
@sp.path = '/etc/passwd'
|
|
70
|
-
end
|
|
71
|
-
|
|
72
|
-
assert_raises SecurityError do
|
|
73
|
-
@sp.path = '/mounts/ron/dbs_outbox/../../../evil_path'
|
|
74
|
-
end
|
|
75
|
-
end
|
|
76
|
-
|
|
77
|
-
test 'join should return SafePath' do
|
|
78
|
-
assert_equal SafePath, @sp.join('/test').class
|
|
79
|
-
end
|
|
80
|
-
|
|
81
|
-
test 'join sould raise exception if insecure path constructed' do
|
|
82
|
-
assert_raises SecurityError do
|
|
83
|
-
@sp.join('../../../evil_path')
|
|
84
|
-
end
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
test 'join should create new object' do
|
|
88
|
-
refute_equal @sp.object_id, @sp.join('test').object_id
|
|
89
|
-
end
|
|
90
|
-
|
|
91
|
-
test 'join! should return SafePath' do
|
|
92
|
-
assert_equal SafePath, @sp.join!('/test').class
|
|
93
|
-
end
|
|
94
|
-
|
|
95
|
-
test 'join! sould raise exception if insecure path constructed' do
|
|
96
|
-
path = @sp.to_s
|
|
97
|
-
|
|
98
|
-
assert_raises SecurityError do
|
|
99
|
-
@sp.join!('/../../../evil_path')
|
|
100
|
-
end
|
|
101
|
-
|
|
102
|
-
# if join is unsuccessful then it shouldn't alter the path
|
|
103
|
-
assert_equal path, @sp.to_s
|
|
104
|
-
end
|
|
105
|
-
|
|
106
|
-
test 'join! should work in-place' do
|
|
107
|
-
assert_equal @sp.object_id, @sp.join!('test').object_id
|
|
108
|
-
end
|
|
109
|
-
|
|
110
|
-
test '+ should return SafePath' do
|
|
111
|
-
assert_equal SafePath, (@sp + '/test').class
|
|
112
|
-
end
|
|
113
|
-
|
|
114
|
-
test '+ sould raise exception if insecure path constructed' do
|
|
115
|
-
assert_raises SecurityError do
|
|
116
|
-
@sp + '../../../evil_path'
|
|
117
|
-
end
|
|
118
|
-
end
|
|
119
|
-
|
|
120
|
-
test '+ should create new object' do
|
|
121
|
-
refute_equal @sp.object_id, (@sp + 'test').object_id
|
|
122
|
-
end
|
|
123
|
-
|
|
124
|
-
test "constructor should raise exception if the path space doesn't exist" do
|
|
125
|
-
assert_raises ArgumentError do
|
|
126
|
-
SafePath.new('potato_space')
|
|
127
|
-
end
|
|
128
|
-
end
|
|
129
|
-
|
|
130
|
-
test 'constructor should raise exception if path space is broken' do
|
|
131
|
-
assert_raises ArgumentError do
|
|
132
|
-
SafePath.new('broken_space')
|
|
133
|
-
end
|
|
134
|
-
end
|
|
135
|
-
|
|
136
|
-
test 'should reject root paths that are not subpath of the root specified in the yaml file' do
|
|
137
|
-
assert_raises SecurityError do
|
|
138
|
-
SafePath.new('dbs_outbox', '../../evil_path')
|
|
139
|
-
end
|
|
140
|
-
end
|
|
141
|
-
|
|
142
|
-
test 'should accept root paths that are subpath of the root specified in the yaml file' do
|
|
143
|
-
assert_equal '/mounts/ron/dbs_outbox/nice_path/path',
|
|
144
|
-
SafePath.new('dbs_outbox', 'nice_path/path').root.to_s
|
|
145
|
-
end
|
|
146
|
-
|
|
147
|
-
test 'should restrict the access only to the subpath specified in the contructor rather than the root in the yaml file' do
|
|
148
|
-
assert_raises SecurityError do
|
|
149
|
-
SafePath.new('dbs_outbox', 'nice_path/path').join!('../evil_path_under_the_root')
|
|
150
|
-
end
|
|
151
|
-
|
|
152
|
-
assert_raises SecurityError do
|
|
153
|
-
sp = SafePath.new('dbs_outbox', 'nice_path/path')
|
|
154
|
-
sp.path = '/mounts/ron/dbs_outbox/evil_path'
|
|
155
|
-
end
|
|
156
|
-
|
|
157
|
-
assert_raises SecurityError do
|
|
158
|
-
SafePath.new('dbs_outbox', 'nice_path/path').join('../../evil_path')
|
|
159
|
-
end
|
|
160
|
-
|
|
161
|
-
assert_raises SecurityError do
|
|
162
|
-
SafePath.new('dbs_outbox', 'nice_path/path') + '../../evil_path'
|
|
163
|
-
end
|
|
164
|
-
end
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
# TODO:
|
|
168
|
-
# Alternative .
|
|
@@ -1,247 +0,0 @@
|
|
|
1
|
-
require 'test_helper'
|
|
2
|
-
|
|
3
|
-
class String
|
|
4
|
-
class CleaningTest < Minitest::Test
|
|
5
|
-
# squash
|
|
6
|
-
|
|
7
|
-
test 'postcodeize' do
|
|
8
|
-
assert_equal 'CB22 3AD', 'CB223AD'.postcodeize
|
|
9
|
-
assert_equal 'NOTCB223AD', 'NOTCB223AD'.postcodeize
|
|
10
|
-
assert_equal 'CB2 2QQ', 'CB22QQ'.postcodeize
|
|
11
|
-
assert_equal 'CB2 2QQ', 'CB22QQ '.postcodeize
|
|
12
|
-
assert_equal 'CB2 2QQ', 'C B 22QQ '.postcodeize
|
|
13
|
-
assert_equal 'CB2 2QQ', "CB2\u00a02QQ".postcodeize # Unicode non-breaking space
|
|
14
|
-
assert_equal 'CB22QQ', 'CB2 2QQ'.postcodeize(:compact)
|
|
15
|
-
assert_equal 'CB2 2QQ', 'CB22QQ '.postcodeize(:db)
|
|
16
|
-
assert_equal 'CB2A2QQ', 'CB2A 2QQ '.postcodeize(:db)
|
|
17
|
-
assert_equal '', ''.postcodeize
|
|
18
|
-
assert_equal 'CB2 2QQ', 'cb22qq'.postcodeize(:db)
|
|
19
|
-
# Database storage format for all major UK postcode formats:
|
|
20
|
-
assert_equal 'A9 9AA', 'A9 9AA'.postcodeize(:db)
|
|
21
|
-
assert_equal 'A99 9AA', 'A99 9AA'.postcodeize(:db)
|
|
22
|
-
assert_equal 'A9A 9AA', 'A9A 9AA'.postcodeize(:db)
|
|
23
|
-
assert_equal 'AA9 9AA', 'AA9 9AA'.postcodeize(:db)
|
|
24
|
-
assert_equal 'AA999AA', 'AA99 9AA'.postcodeize(:db)
|
|
25
|
-
assert_equal 'AA9A9AA', 'AA9A 9AA'.postcodeize(:db)
|
|
26
|
-
# Old Newport postcodes until end 1984
|
|
27
|
-
assert_equal 'NPT 1AA' , 'NPT 1AA'.postcodeize(:db)
|
|
28
|
-
assert_equal 'NPT 1AA' , 'NPT 1AA'.postcodeize(:db)
|
|
29
|
-
# Examples of legacy postcodes, that should be unchanged
|
|
30
|
-
assert_equal 'IP222', 'IP222'.postcodeize(:db)
|
|
31
|
-
assert_equal 'IP222E', 'IP222E'.postcodeize(:db)
|
|
32
|
-
assert_equal 'HANTS', 'HANTS'.postcodeize(:db)
|
|
33
|
-
end
|
|
34
|
-
|
|
35
|
-
test 'clean_log10' do
|
|
36
|
-
assert_equal '0.0', '0'.clean(:log10)
|
|
37
|
-
assert_equal '-10.1', '-10.1'.clean(:log10)
|
|
38
|
-
assert_match(/\A0.041392685158225[0-9]*\z/, '1.1'.clean(:log10),
|
|
39
|
-
"Different ruby versions give '0.04139268515822507' or '0.04139268515822508'")
|
|
40
|
-
assert_equal 'BILBO', 'BILBO'.clean(:log10)
|
|
41
|
-
end
|
|
42
|
-
|
|
43
|
-
test 'clean_roman5' do
|
|
44
|
-
assert_equal '12345', 'I2345'.clean(:roman5)
|
|
45
|
-
assert_equal '12345', '1II345'.clean(:roman5)
|
|
46
|
-
assert_equal '12345', '12III45'.clean(:roman5)
|
|
47
|
-
assert_equal '12345', '123IIII5'.clean(:roman5)
|
|
48
|
-
assert_equal '12345', '123IIII5'.clean(:roman5)
|
|
49
|
-
assert_equal '12345', '123IV5'.clean(:roman5)
|
|
50
|
-
assert_equal '12345', '1234V'.clean(:roman5)
|
|
51
|
-
assert_equal '12345', '1II34V'.clean(:roman5)
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
test 'xml_unsafe?' do
|
|
55
|
-
without_control = 'hello world!'
|
|
56
|
-
refute without_control.xml_unsafe?
|
|
57
|
-
|
|
58
|
-
with_safe_control = "increase: 100\045"
|
|
59
|
-
refute with_safe_control.xml_unsafe?
|
|
60
|
-
|
|
61
|
-
with_unsafe_control = "Lorem \000Ipsum\000"
|
|
62
|
-
assert with_unsafe_control.xml_unsafe?
|
|
63
|
-
end
|
|
64
|
-
|
|
65
|
-
test 'strip_xml_unsafe_characters' do
|
|
66
|
-
without_control = 'hello world!'
|
|
67
|
-
assert_equal without_control, without_control.strip_xml_unsafe_characters
|
|
68
|
-
|
|
69
|
-
with_safe_control = "increase: 100\045"
|
|
70
|
-
assert_equal 'increase: 100%', with_safe_control.strip_xml_unsafe_characters
|
|
71
|
-
|
|
72
|
-
with_unsafe_control = "Lorem \000Ipsum\000"
|
|
73
|
-
assert_equal 'Lorem Ipsum', with_unsafe_control.strip_xml_unsafe_characters
|
|
74
|
-
end
|
|
75
|
-
|
|
76
|
-
test 'clean xmlsafe' do
|
|
77
|
-
without_control = 'hello world!'
|
|
78
|
-
assert_equal without_control, without_control.clean(:xmlsafe)
|
|
79
|
-
|
|
80
|
-
with_safe_control = "increase: 100\045"
|
|
81
|
-
assert_equal 'increase: 100%', with_safe_control.clean(:xmlsafe)
|
|
82
|
-
|
|
83
|
-
with_unsafe_control = "Lorem \007Ipsum\006"
|
|
84
|
-
assert_equal 'Lorem Ipsum', with_unsafe_control.clean(:xmlsafe)
|
|
85
|
-
end
|
|
86
|
-
|
|
87
|
-
test 'clean make_xml_safe' do
|
|
88
|
-
without_control = 'hello world!'
|
|
89
|
-
assert_equal without_control, without_control.clean(:make_xml_safe)
|
|
90
|
-
|
|
91
|
-
with_safe_control = "increase: 100\045"
|
|
92
|
-
assert_equal 'increase: 100%', with_safe_control.clean(:make_xml_safe)
|
|
93
|
-
|
|
94
|
-
with_unsafe_control = "Lorem \000Ipsum\000"
|
|
95
|
-
assert_equal 'Lorem Ipsum', with_unsafe_control.clean(:make_xml_safe)
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
test 'clean nhsnumber' do
|
|
99
|
-
assert_equal '1234567890', '123 456 7890'.clean(:nhsnumber)
|
|
100
|
-
assert_equal '1234567890', ' 123-456-7890123'.clean(:nhsnumber)
|
|
101
|
-
assert_equal '', 'unknown'.clean(:nhsnumber)
|
|
102
|
-
assert_equal '', ''.clean(:nhsnumber)
|
|
103
|
-
end
|
|
104
|
-
|
|
105
|
-
test 'clean postcode' do
|
|
106
|
-
assert_equal 'CB4 3ND', 'cb4 3ND '.clean(:postcode)
|
|
107
|
-
assert_equal 'CB223AD', ' CB22 3AD'.clean(:postcode)
|
|
108
|
-
assert_equal '', ''.clean(:postcode)
|
|
109
|
-
end
|
|
110
|
-
|
|
111
|
-
test 'clean lpi' do
|
|
112
|
-
# self.upcase.delete('^0-9A-Z')
|
|
113
|
-
assert_equal '007', '007?!?'.clean(:lpi)
|
|
114
|
-
assert_equal 'A0000001', 'a0000001'.clean(:lpi)
|
|
115
|
-
assert_equal 'UNKNOWN', 'UNKNOWN'.clean(:lpi)
|
|
116
|
-
assert_equal '', ''.clean(:lpi)
|
|
117
|
-
end
|
|
118
|
-
|
|
119
|
-
test 'clean gender' do
|
|
120
|
-
assert_equal '1', 'M'.clean(:gender)
|
|
121
|
-
assert_equal '1', 'male'.clean(:gender)
|
|
122
|
-
assert_equal '1', '1'.clean(:gender)
|
|
123
|
-
assert_equal '2', 'F'.clean(:gender)
|
|
124
|
-
assert_equal '2', 'Female'.clean(:gender)
|
|
125
|
-
assert_equal '2', '2'.clean(:gender)
|
|
126
|
-
assert_equal '4000', '4000'.clean(:gender)
|
|
127
|
-
assert_equal '9', '9'.clean(:gender)
|
|
128
|
-
assert_equal 'UNK', 'UNK'.clean(:gender)
|
|
129
|
-
assert_equal '', ''.clean(:gender)
|
|
130
|
-
end
|
|
131
|
-
|
|
132
|
-
test 'clean sex' do
|
|
133
|
-
assert_equal '1', 'male'.clean(:sex)
|
|
134
|
-
assert_equal '1', '1'.clean(:sex)
|
|
135
|
-
assert_equal '2', 'F'.clean(:sex)
|
|
136
|
-
assert_equal '2', '2'.clean(:sex)
|
|
137
|
-
assert_equal '0', ''.clean(:sex)
|
|
138
|
-
assert_equal '0', 'unknown'.clean(:sex)
|
|
139
|
-
end
|
|
140
|
-
|
|
141
|
-
test 'clean sex_c' do
|
|
142
|
-
assert_equal 'M', 'male'.clean(:sex_c)
|
|
143
|
-
assert_equal 'M', '1'.clean(:sex_c)
|
|
144
|
-
assert_equal 'F', 'F'.clean(:sex_c)
|
|
145
|
-
assert_equal 'F', '2'.clean(:sex_c)
|
|
146
|
-
assert_equal '', ''.clean(:sex_c)
|
|
147
|
-
assert_equal '', 'unknown'.clean(:sex_c)
|
|
148
|
-
end
|
|
149
|
-
|
|
150
|
-
test 'clean name' do
|
|
151
|
-
assert_equal 'MAKE A NAME', ' Make A. Name '.clean(:name)
|
|
152
|
-
assert_equal 'PUNCTUATE A NAME', 'PUNCTUATE,A;NAME'.clean(:name)
|
|
153
|
-
assert_equal 'SPREAD A NAME', 'spread a name'.clean(:name)
|
|
154
|
-
assert_equal "O'NAME", 'O`NAME'.clean(:name)
|
|
155
|
-
assert_equal "JOHN MIDDLE O'NAME", 'John, Middle. O`NAME'.clean(:name)
|
|
156
|
-
assert_equal '', ''.clean(:name)
|
|
157
|
-
end
|
|
158
|
-
|
|
159
|
-
test 'clean ethniccategory' do
|
|
160
|
-
assert_equal 'M', '1'.clean(:ethniccategory)
|
|
161
|
-
assert_equal 'X', '99'.clean(:ethniccategory)
|
|
162
|
-
assert_equal 'A', 'A'.clean(:ethniccategory)
|
|
163
|
-
assert_equal 'INVALID', 'InValid'.clean(:ethniccategory)
|
|
164
|
-
assert_equal '', ''.clean(:ethniccategory)
|
|
165
|
-
end
|
|
166
|
-
|
|
167
|
-
test 'clean code' do
|
|
168
|
-
assert_equal 'a123 B456', ' a12.3,,B45.6;'.clean(:code)
|
|
169
|
-
assert_equal 'A123 B456', 'A12.3 B.456'.clean(:code)
|
|
170
|
-
assert_equal 'UNKNOWN', 'UNKNOWN'.clean(:code)
|
|
171
|
-
assert_equal '', ''.clean(:code)
|
|
172
|
-
end
|
|
173
|
-
|
|
174
|
-
test 'clean code_icd' do
|
|
175
|
-
assert_equal 'C449 Q123A Q455', 'C449,Q123,A,Q455'.clean(:code_icd)
|
|
176
|
-
assert_equal 'C449 Q123D Q455', 'C449,Q123,D,Q455'.clean(:code_icd)
|
|
177
|
-
end
|
|
178
|
-
|
|
179
|
-
test 'clean icd' do
|
|
180
|
-
assert_equal 'C509', ' c50.9; '.clean(:icd)
|
|
181
|
-
assert_equal 'C50 C509', ' C50X, c50.9; '.clean(:icd)
|
|
182
|
-
assert_equal 'D04', 'd04'.clean(:icd)
|
|
183
|
-
assert_equal 'C32', ';C32.X'.clean(:icd)
|
|
184
|
-
assert_equal 'C32', ';C32X'.clean(:icd)
|
|
185
|
-
assert_equal 'X32 X901A', ';X32.X;x90.1.a'.clean(:icd)
|
|
186
|
-
end
|
|
187
|
-
|
|
188
|
-
test 'clean code_opcs' do
|
|
189
|
-
assert_equal 'B274 Z943', ' b27.4,Z94.3;'.clean(:code_opcs)
|
|
190
|
-
assert_equal 'B274 Z943', 'B27.4 Z94.3'.clean(:code_opcs)
|
|
191
|
-
assert_equal 'CZ001', 'CZ001'.clean(:code_opcs)
|
|
192
|
-
assert_equal 'B274 CZ002', 'B27.4 cz00.2'.clean(:code_opcs)
|
|
193
|
-
assert_equal '', 'CZ003'.clean(:code_opcs)
|
|
194
|
-
assert_equal '', 'UNKNOWN'.clean(:code_opcs)
|
|
195
|
-
assert_equal '', ''.clean(:code_opcs)
|
|
196
|
-
end
|
|
197
|
-
|
|
198
|
-
test 'clean hospitalnumber' do
|
|
199
|
-
assert_equal 'a0000001', 'a0000001'.clean(:hospitalnumber)
|
|
200
|
-
assert_equal 'A0000001', 'A0000001B'.clean(:hospitalnumber)
|
|
201
|
-
assert_equal 'UNKNOW', 'UNKNOWN'.clean(:hospitalnumber)
|
|
202
|
-
assert_equal '', ''.clean(:hospitalnumber)
|
|
203
|
-
end
|
|
204
|
-
|
|
205
|
-
test 'clean tnmcategory' do
|
|
206
|
-
assert_equal '', ''.clean(:tnmcategory)
|
|
207
|
-
assert_equal 'X', 'X'.clean(:tnmcategory)
|
|
208
|
-
assert_equal 'X', 'x'.clean(:tnmcategory)
|
|
209
|
-
assert_equal '1a', '1A'.clean(:tnmcategory)
|
|
210
|
-
assert_equal '1a', '1a'.clean(:tnmcategory)
|
|
211
|
-
assert_equal '1a', 'T1A'.clean(:tnmcategory)
|
|
212
|
-
assert_equal '1a', 't1a'.clean(:tnmcategory)
|
|
213
|
-
assert_equal 'X', 'TX'.clean(:tnmcategory)
|
|
214
|
-
assert_equal 'X', 'tx'.clean(:tnmcategory)
|
|
215
|
-
assert_equal 'X', 'Tx'.clean(:tnmcategory)
|
|
216
|
-
assert_equal 'X', 'tX'.clean(:tnmcategory)
|
|
217
|
-
end
|
|
218
|
-
|
|
219
|
-
test 'clean upcase' do
|
|
220
|
-
assert_equal '', ''.clean(:upcase)
|
|
221
|
-
assert_equal 'DOWNCASE', 'downcase'.clean(:upcase)
|
|
222
|
-
assert_equal 'MIXEDCASE', 'mIxEdCaSe'.clean(:upcase)
|
|
223
|
-
assert_equal 'UPCASE', 'UPCASE'.clean(:upcase)
|
|
224
|
-
end
|
|
225
|
-
|
|
226
|
-
test 'clean strip' do
|
|
227
|
-
assert_equal '', ''.clean(:strip)
|
|
228
|
-
assert_equal 'no leading or trailing spaces', 'no leading or trailing spaces'.clean(:strip)
|
|
229
|
-
assert_equal 'leading and trailing spaces', ' leading and trailing spaces '.clean(:strip)
|
|
230
|
-
assert_equal 'leading spaces', ' leading spaces'.clean(:strip)
|
|
231
|
-
assert_equal 'trailing spaces', 'trailing spaces '.clean(:strip)
|
|
232
|
-
end
|
|
233
|
-
|
|
234
|
-
test 'clean itself' do
|
|
235
|
-
assert_equal ' leading & trailing spaces ', ' leading & trailing spaces '.clean(:itself)
|
|
236
|
-
assert_equal 'no leading or trailing spaces', 'no leading or trailing spaces'.clean(:itself)
|
|
237
|
-
assert_equal ' ', ' '.clean(:itself)
|
|
238
|
-
assert_equal '', ''.clean(:itself)
|
|
239
|
-
end
|
|
240
|
-
|
|
241
|
-
test 'clean fallback' do
|
|
242
|
-
assert_equal 'UN KNOWN', 'UN ?KNOWN'.clean(:somethingorother)
|
|
243
|
-
assert_equal 'UNKNOWN', 'UNKNOWN'.clean(:somethingorother)
|
|
244
|
-
assert_equal '', ''.clean(:somethingorother)
|
|
245
|
-
end
|
|
246
|
-
end
|
|
247
|
-
end
|