ascii-data-tools 0.9
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +3 -0
- data/.rvmrc +1 -0
- data/.travis.yml +4 -0
- data/Gemfile +3 -0
- data/Gemfile.lock +40 -0
- data/LICENSE.GPL2 +339 -0
- data/README.rdoc +52 -0
- data/Rakefile +42 -0
- data/TODO +4 -0
- data/ascii-data-tools.gemspec +30 -0
- data/bin/ascii-data-cat +13 -0
- data/bin/ascii-data-edit +13 -0
- data/bin/ascii-data-norm +13 -0
- data/bin/ascii-data-qdiff +13 -0
- data/bin/ascii-data-tools-config +9 -0
- data/examples/big +10000 -0
- data/examples/built_in_records.gz +0 -0
- data/examples/slightly_modified_built_in_records.gz +0 -0
- data/features/ascii-data-cat.feature +110 -0
- data/features/ascii-data-edit.feature +91 -0
- data/features/ascii-data-qdiff.feature +54 -0
- data/features/encoding_decoding.feature +68 -0
- data/features/normaliser.feature +27 -0
- data/features/plugins.feature +73 -0
- data/features/record_recognition.feature +61 -0
- data/features/step_definitions/ascii-data-cat_steps.rb +48 -0
- data/features/step_definitions/ascii-data-edit_steps.rb +38 -0
- data/features/step_definitions/ascii-data-norm_steps.rb +7 -0
- data/features/step_definitions/ascii-data-qdiff_steps.rb +43 -0
- data/features/step_definitions/encoding_decoding_steps.rb +23 -0
- data/features/step_definitions/plugins_steps.rb +11 -0
- data/features/step_definitions/record_recognition_steps.rb +10 -0
- data/features/support/env.rb +5 -0
- data/lib/ascii-data-tools.rb +8 -0
- data/lib/ascii-data-tools/configuration.rb +169 -0
- data/lib/ascii-data-tools/configuration_printer.rb +38 -0
- data/lib/ascii-data-tools/controller.rb +123 -0
- data/lib/ascii-data-tools/discover.rb +19 -0
- data/lib/ascii-data-tools/external_programs.rb +23 -0
- data/lib/ascii-data-tools/filter.rb +148 -0
- data/lib/ascii-data-tools/filter/diffing.rb +139 -0
- data/lib/ascii-data-tools/formatting.rb +109 -0
- data/lib/ascii-data-tools/global_autodiscovery.rb +21 -0
- data/lib/ascii-data-tools/record.rb +50 -0
- data/lib/ascii-data-tools/record_type.rb +139 -0
- data/lib/ascii-data-tools/record_type/builder.rb +50 -0
- data/lib/ascii-data-tools/record_type/decoder.rb +77 -0
- data/lib/ascii-data-tools/record_type/encoder.rb +17 -0
- data/lib/ascii-data-tools/record_type/field.rb +168 -0
- data/lib/ascii-data-tools/record_type/normaliser.rb +38 -0
- data/lib/ascii-data-tools/ruby_extensions.rb +7 -0
- data/lib/ascii-data-tools/version.rb +3 -0
- data/spec/ascii-data-tools/configuration_printer_spec.rb +51 -0
- data/spec/ascii-data-tools/configuration_spec.rb +153 -0
- data/spec/ascii-data-tools/discover_spec.rb +8 -0
- data/spec/ascii-data-tools/filter/diffing_spec.rb +82 -0
- data/spec/ascii-data-tools/filter_spec.rb +107 -0
- data/spec/ascii-data-tools/formatting_spec.rb +106 -0
- data/spec/ascii-data-tools/record_spec.rb +49 -0
- data/spec/ascii-data-tools/record_type/builder_spec.rb +69 -0
- data/spec/ascii-data-tools/record_type/decoder_spec.rb +73 -0
- data/spec/ascii-data-tools/record_type/encoder_spec.rb +32 -0
- data/spec/ascii-data-tools/record_type/field_spec.rb +160 -0
- data/spec/ascii-data-tools/record_type/normaliser_spec.rb +25 -0
- data/spec/ascii-data-tools/record_type_spec.rb +175 -0
- data/spec/filter_helper.rb +24 -0
- data/spec/record_type_helpers.rb +8 -0
- data/spec/spec.opts +2 -0
- data/spec/spec_helper.rb +5 -0
- metadata +196 -0
Binary file
|
Binary file
|
@@ -0,0 +1,110 @@
|
|
1
|
+
Feature: ascii-data-cat support
|
2
|
+
In order to understand the contents of ascii-encoded record streams quicker
|
3
|
+
As a tester
|
4
|
+
I want to decode and pretty print the streams
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given the following configuration:
|
8
|
+
"""
|
9
|
+
record_type("ABC") do
|
10
|
+
field "RECORD_TYPE", :length => 3, :constrained_to => "ABC"
|
11
|
+
field "RECORD_SIZE", :length => 5
|
12
|
+
field "END_OF_RECORD", :length => 1
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
|
16
|
+
Scenario: two fixed-length records
|
17
|
+
When ascii-data-cat is invoked on a record stream containing
|
18
|
+
"""
|
19
|
+
ABC12345
|
20
|
+
ABC67890
|
21
|
+
|
22
|
+
"""
|
23
|
+
Then the following is printed out:
|
24
|
+
"""
|
25
|
+
Record 01 (ABC)
|
26
|
+
01 RECORD_TYPE : [ABC]-------
|
27
|
+
02 RECORD_SIZE : [12345]-----
|
28
|
+
03 END_OF_RECORD : [\n]--------
|
29
|
+
|
30
|
+
Record 02 (ABC)
|
31
|
+
01 RECORD_TYPE : [ABC]-------
|
32
|
+
02 RECORD_SIZE : [67890]-----
|
33
|
+
03 END_OF_RECORD : [\n]--------
|
34
|
+
|
35
|
+
|
36
|
+
"""
|
37
|
+
|
38
|
+
Scenario: an unknown record
|
39
|
+
When ascii-data-cat is invoked on a record stream containing
|
40
|
+
"""
|
41
|
+
XYZ123456789
|
42
|
+
|
43
|
+
"""
|
44
|
+
Then the following is printed out:
|
45
|
+
"""
|
46
|
+
Record 01 (unknown)
|
47
|
+
01 UNKNOWN : [XYZ123456789\n]-----
|
48
|
+
|
49
|
+
|
50
|
+
"""
|
51
|
+
|
52
|
+
Scenario: record types can be limited to apply only to records contained in particular filenames
|
53
|
+
# In this example, the record should not be recognised with type XYZ because the source filename does not match /records[.]XYZ[.]gz/
|
54
|
+
Given the following configuration:
|
55
|
+
"""
|
56
|
+
record_type("XYZ", :applies_for_filenames_matching => /records[.]XYZ[.]gz/) do
|
57
|
+
field "RECORD_TYPE", :length => 3
|
58
|
+
field "RECORD_SIZE", :length => 6
|
59
|
+
field "END_OF_RECORD", :length => 1
|
60
|
+
end
|
61
|
+
"""
|
62
|
+
When ascii-data-cat is invoked on a file "records.ABC.gz" containing
|
63
|
+
"""
|
64
|
+
ABC123456
|
65
|
+
|
66
|
+
"""
|
67
|
+
Then the following is printed out:
|
68
|
+
"""
|
69
|
+
Record 01 (unknown)
|
70
|
+
01 UNKNOWN : [ABC123456\n]-----
|
71
|
+
|
72
|
+
|
73
|
+
"""
|
74
|
+
|
75
|
+
Scenario: out-of-the-box example record types defined and configured
|
76
|
+
When ascii-data-cat is invoked on a file "records.gz" containing
|
77
|
+
"""
|
78
|
+
EXAMPLE01MO 4912345678 442012345678 0012
|
79
|
+
EXAMPLE02internet 2010010112000007220156
|
80
|
+
EXAMPLE01SMS4998765432 55555 0099
|
81
|
+
|
82
|
+
"""
|
83
|
+
Then the following is printed out:
|
84
|
+
"""
|
85
|
+
Record 01 (EXAMPLE01)
|
86
|
+
01 RECORD_TYPE : [EXAMPLE01]------------
|
87
|
+
02 USAGE : [MO ]------------------
|
88
|
+
03 A_NUMBER : [4912345678 ]-----
|
89
|
+
04 B_NUMBER : [442012345678 ]-----
|
90
|
+
05 CHARGEABLE_UNITS : [0012]-----------------
|
91
|
+
06 END_OF_RECORD : [\n]-------------------
|
92
|
+
|
93
|
+
Record 02 (EXAMPLE02)
|
94
|
+
01 RECORD_TYPE : [EXAMPLE02]----------
|
95
|
+
02 APN : [internet ]-------
|
96
|
+
03 TIMESTAMP : [20100101120000]-----
|
97
|
+
04 SESSION_DURATION : [0722]---------------
|
98
|
+
05 CHARGEABLE_UNITS : [0156]---------------
|
99
|
+
06 END_OF_RECORD : [\n]-----------------
|
100
|
+
|
101
|
+
Record 03 (EXAMPLE01)
|
102
|
+
01 RECORD_TYPE : [EXAMPLE01]------------
|
103
|
+
02 USAGE : [SMS]------------------
|
104
|
+
03 A_NUMBER : [4998765432 ]-----
|
105
|
+
04 B_NUMBER : [55555 ]-----
|
106
|
+
05 CHARGEABLE_UNITS : [0099]-----------------
|
107
|
+
06 END_OF_RECORD : [\n]-------------------
|
108
|
+
|
109
|
+
|
110
|
+
"""
|
@@ -0,0 +1,91 @@
|
|
1
|
+
Feature: ascii-data-edit support
|
2
|
+
In order to create and edit test data efficiently
|
3
|
+
As a tester
|
4
|
+
I want a tool to edit the streams in a readable form
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given the following configuration:
|
8
|
+
"""
|
9
|
+
record_type("ABC") do
|
10
|
+
field "RECORD_TYPE", :length => 3, :constrained_to => "ABC"
|
11
|
+
field "RECORD_SIZE", :length => 5
|
12
|
+
field "END_OF_RECORD", :length => 1
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
|
16
|
+
Scenario: two fixed-length records opened
|
17
|
+
When ascii-data-edit is invoked on a record stream containing
|
18
|
+
"""
|
19
|
+
ABC12345
|
20
|
+
ABC67890
|
21
|
+
|
22
|
+
"""
|
23
|
+
Then the editor shows:
|
24
|
+
"""
|
25
|
+
Record 01 (ABC)
|
26
|
+
01 RECORD_TYPE : [ABC]-------
|
27
|
+
02 RECORD_SIZE : [12345]-----
|
28
|
+
03 END_OF_RECORD : [\n]--------
|
29
|
+
|
30
|
+
Record 02 (ABC)
|
31
|
+
01 RECORD_TYPE : [ABC]-------
|
32
|
+
02 RECORD_SIZE : [67890]-----
|
33
|
+
03 END_OF_RECORD : [\n]--------
|
34
|
+
|
35
|
+
|
36
|
+
"""
|
37
|
+
|
38
|
+
Scenario: two fixed-length records changed
|
39
|
+
Given a record stream containing
|
40
|
+
"""
|
41
|
+
ABC12345
|
42
|
+
ABC67890
|
43
|
+
|
44
|
+
"""
|
45
|
+
When the output is successfully ascii-edited to the following:
|
46
|
+
"""
|
47
|
+
Record 01 (ABC)
|
48
|
+
01 RECORD_TYPE : [ABC]-------
|
49
|
+
02 RECORD_SIZE : [45678]-----
|
50
|
+
03 END_OF_RECORD : [\n]--------
|
51
|
+
|
52
|
+
Record 02 (ABC)
|
53
|
+
01 RECORD_TYPE : [ABC]-------
|
54
|
+
02 RECORD_SIZE : [XXXXX]-----
|
55
|
+
03 END_OF_RECORD : [\n]--------
|
56
|
+
|
57
|
+
|
58
|
+
"""
|
59
|
+
Then the encoded record stream contains:
|
60
|
+
"""
|
61
|
+
ABC45678
|
62
|
+
ABCXXXXX
|
63
|
+
|
64
|
+
"""
|
65
|
+
|
66
|
+
Scenario: files not resaved unless they are modified during editing
|
67
|
+
Given a record stream containing
|
68
|
+
"""
|
69
|
+
ABC12345
|
70
|
+
ABC67890
|
71
|
+
|
72
|
+
"""
|
73
|
+
When the output is ascii-edited without alteration
|
74
|
+
Then the user receives the following feedback:
|
75
|
+
"""
|
76
|
+
The file is unmodified.
|
77
|
+
|
78
|
+
"""
|
79
|
+
Scenario: editing an unknown record
|
80
|
+
When ascii-data-edit is invoked on a record stream containing
|
81
|
+
"""
|
82
|
+
XYZ123456789
|
83
|
+
|
84
|
+
"""
|
85
|
+
Then the editor shows:
|
86
|
+
"""
|
87
|
+
Record 01 (unknown)
|
88
|
+
01 UNKNOWN : [XYZ123456789\n]-----
|
89
|
+
|
90
|
+
|
91
|
+
"""
|
@@ -0,0 +1,54 @@
|
|
1
|
+
Feature: ascii-data-qdiff support
|
2
|
+
In order to see the difference between the contents of ascii-encoded record streams
|
3
|
+
As a tester
|
4
|
+
I want a tool to decode, normalise, sort, pretty print the streams and show them in a diffing editor
|
5
|
+
|
6
|
+
Scenario: comparing identical files
|
7
|
+
When ascii-data-qdiff is invoked on files containing:
|
8
|
+
"""
|
9
|
+
EXAMPLE01MO 1112345678 442012345678 0012\n || EXAMPLE01MO 1112345678 442012345678 0012\n
|
10
|
+
"""
|
11
|
+
Then the user receives the following feedback:
|
12
|
+
"""
|
13
|
+
The files are identical.
|
14
|
+
|
15
|
+
"""
|
16
|
+
|
17
|
+
Scenario: normal execution
|
18
|
+
When ascii-data-qdiff is invoked on files containing:
|
19
|
+
"""
|
20
|
+
EXAMPLE01MO 1112345678 442012345678 0012\n || EXAMPLE01MO 9954321098 442012345678 0012\n
|
21
|
+
EXAMPLE01MO 9992345678 442012345678 0012\n || EXAMPLE01MO 9992345678 442012345678 0012\n
|
22
|
+
EXAMPLE02internet 2010010112000007220156\n || EXAMPLE02internet 2010010112000007220156\n
|
23
|
+
EXAMPLE02internet 2010010113000001500000\n || EXAMPLE02internet 2010010113000001500156\n
|
24
|
+
EXAMPLE01SMS4998765432 55555 0099\n || --------------------------------------------------
|
25
|
+
"""
|
26
|
+
Then the diffed result should be:
|
27
|
+
"""
|
28
|
+
Record (EXAMPLE01) || Record (EXAMPLE01)
|
29
|
+
01 RECORD_TYPE : [EXAMPLE01]------------ || 01 RECORD_TYPE : [EXAMPLE01]------------
|
30
|
+
02 USAGE : [MO ]------------------ || 02 USAGE : [MO ]------------------
|
31
|
+
03 A_NUMBER : [1112345678 ]----- || 03 A_NUMBER : [9954321098 ]-----
|
32
|
+
04 B_NUMBER : [442012345678 ]----- || 04 B_NUMBER : [442012345678 ]-----
|
33
|
+
05 CHARGEABLE_UNITS : [0012]----------------- || 05 CHARGEABLE_UNITS : [0012]-----------------
|
34
|
+
06 END_OF_RECORD : [\n]------------------- || 06 END_OF_RECORD : [\n]-------------------
|
35
|
+
||
|
36
|
+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~|| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
|
37
|
+
|| -----------------------------------------------
|
38
|
+
Record (EXAMPLE01) || -----------------------------------------------
|
39
|
+
01 RECORD_TYPE : [EXAMPLE01]------------ || -----------------------------------------------
|
40
|
+
02 USAGE : [SMS]------------------ || -----------------------------------------------
|
41
|
+
03 A_NUMBER : [4998765432 ]----- || -----------------------------------------------
|
42
|
+
04 B_NUMBER : [55555 ]----- || -----------------------------------------------
|
43
|
+
05 CHARGEABLE_UNITS : [0099]----------------- || -----------------------------------------------
|
44
|
+
06 END_OF_RECORD : [\n]------------------- || -----------------------------------------------
|
45
|
+
||
|
46
|
+
Record (EXAMPLE02) || Record (EXAMPLE02)
|
47
|
+
01 RECORD_TYPE : [EXAMPLE02]---------- || 01 RECORD_TYPE : [EXAMPLE02]----------
|
48
|
+
02 APN : [internet ]------- || 02 APN : [internet ]-------
|
49
|
+
03 TIMESTAMP : [XXXXXXXXXXXXXX]----- || 03 TIMESTAMP : [XXXXXXXXXXXXXX]-----
|
50
|
+
04 SESSION_DURATION : [0150]--------------- || 04 SESSION_DURATION : [0150]---------------
|
51
|
+
05 CHARGEABLE_UNITS : [0000]--------------- || 05 CHARGEABLE_UNITS : [0156]---------------
|
52
|
+
06 END_OF_RECORD : [\n]----------------- || 06 END_OF_RECORD : [\n]-----------------
|
53
|
+
||
|
54
|
+
"""
|
@@ -0,0 +1,68 @@
|
|
1
|
+
Feature: encoding and decoding of records
|
2
|
+
In order to understand the contents of ascii-encoded record streams quicker
|
3
|
+
As a tester
|
4
|
+
I want a tool to be able to handle different types of records
|
5
|
+
|
6
|
+
Scenario: decoding fixed-length records
|
7
|
+
Given the following configuration:
|
8
|
+
"""
|
9
|
+
record_type("ABC") do
|
10
|
+
field "RECORD_TYPE", :length => 3
|
11
|
+
field "RECORD_SIZE", :length => 5
|
12
|
+
field "END_OF_RECORD", :length => 1
|
13
|
+
end
|
14
|
+
"""
|
15
|
+
When I decode an encoded record "ABC12345\n" of type "ABC"
|
16
|
+
Then I should have a decoded record of type "ABC" and contents:
|
17
|
+
| field name | field value |
|
18
|
+
| RECORD_TYPE | ABC |
|
19
|
+
| RECORD_SIZE | 12345 |
|
20
|
+
| END_OF_RECORD | \n |
|
21
|
+
|
22
|
+
Scenario: encoding fixed-length records
|
23
|
+
Given the following configuration:
|
24
|
+
"""
|
25
|
+
record_type("ABC") do
|
26
|
+
field "RECORD_TYPE", :length => 3
|
27
|
+
field "RECORD_SIZE", :length => 5
|
28
|
+
field "END_OF_RECORD", :length => 1
|
29
|
+
end
|
30
|
+
"""
|
31
|
+
When I encode a record of type "ABC" and contents:
|
32
|
+
| field name | field value |
|
33
|
+
| RECORD_TYPE | ABC |
|
34
|
+
| RECORD_SIZE | 12345 |
|
35
|
+
| END_OF_RECORD | \n |
|
36
|
+
Then I should have a encoded record "ABC12345\n"
|
37
|
+
|
38
|
+
Scenario: decoding csv records
|
39
|
+
Given the following configuration:
|
40
|
+
"""
|
41
|
+
record_type("ABC", :family => "csv", :divider => ",") do
|
42
|
+
field "RECORD_TYPE"
|
43
|
+
field "RECORD_SIZE"
|
44
|
+
field "UNITS"
|
45
|
+
end
|
46
|
+
"""
|
47
|
+
When I decode an encoded record "ABC,12345,123\n" of type "ABC"
|
48
|
+
Then I should have a decoded record of type "ABC" and contents:
|
49
|
+
| field name | field value |
|
50
|
+
| RECORD_TYPE | ABC |
|
51
|
+
| RECORD_SIZE | 12345 |
|
52
|
+
| UNITS | 123 |
|
53
|
+
|
54
|
+
Scenario: encoding csv records
|
55
|
+
Given the following configuration:
|
56
|
+
"""
|
57
|
+
record_type("ABC", :family => "csv", :divider => ",") do
|
58
|
+
field "RECORD_TYPE"
|
59
|
+
field "RECORD_SIZE"
|
60
|
+
field "UNITS"
|
61
|
+
end
|
62
|
+
"""
|
63
|
+
When I encode a record of type "ABC" and contents:
|
64
|
+
| field name | field value |
|
65
|
+
| RECORD_TYPE | ABC |
|
66
|
+
| RECORD_SIZE | 12345 |
|
67
|
+
| UNITS | XX |
|
68
|
+
Then I should have a encoded record "ABC,12345,XX\n"
|
@@ -0,0 +1,27 @@
|
|
1
|
+
Feature: normalisation
|
2
|
+
In order to see differences between two streams of record streams with variable parameters like timestamps
|
3
|
+
As a tester
|
4
|
+
I want a tool to normalise which outputs normalised raw records
|
5
|
+
|
6
|
+
Scenario: two fixed-length records
|
7
|
+
Given the following configuration:
|
8
|
+
"""
|
9
|
+
record_type("ABC") do
|
10
|
+
field "RECORD_TYPE", :length => 3, :constrained_to => "ABC"
|
11
|
+
field "RECORD_SIZE", :length => 5
|
12
|
+
field "TIMESTAMP", :length => 14, :normalised => true
|
13
|
+
field "END_OF_RECORD", :length => 1
|
14
|
+
end
|
15
|
+
"""
|
16
|
+
When ascii-data-norm is invoked on a record stream containing
|
17
|
+
"""
|
18
|
+
ABC1234520100101120000
|
19
|
+
ABC6789020100415180005
|
20
|
+
|
21
|
+
"""
|
22
|
+
Then the following is printed out:
|
23
|
+
"""
|
24
|
+
ABC12345XXXXXXXXXXXXXX
|
25
|
+
ABC67890XXXXXXXXXXXXXX
|
26
|
+
|
27
|
+
"""
|
@@ -0,0 +1,73 @@
|
|
1
|
+
Feature: tools for plugins
|
2
|
+
In order to create a plugin that adds custom functionality to the ascii tools
|
3
|
+
As a plugin writer
|
4
|
+
I want tools which support readable, compact configurations and configuration debugging
|
5
|
+
|
6
|
+
Scenario: defining new record types and printing the record type summary
|
7
|
+
Given the following configuration:
|
8
|
+
"""
|
9
|
+
record_type("ABC") do
|
10
|
+
field "RECORD_TYPE", :length => 3
|
11
|
+
field "RECORD_SIZE", :length => 5
|
12
|
+
field "END_OF_RECORD", :length => 1
|
13
|
+
end
|
14
|
+
|
15
|
+
record_type("DEF") do
|
16
|
+
field "RECORD_TYPE", :length => 3
|
17
|
+
field "RECORD_SIZE", :length => 3
|
18
|
+
field "END_OF_RECORD", :length => 1
|
19
|
+
end
|
20
|
+
"""
|
21
|
+
When the record type configuration is printed
|
22
|
+
Then it should look like this:
|
23
|
+
"""
|
24
|
+
+-----------+--------------+-------------------------+-------------------+
|
25
|
+
| type name | total length | constraints | normalised fields |
|
26
|
+
+-----------+--------------+-------------------------+-------------------+
|
27
|
+
| DEF | 7 | | |
|
28
|
+
| ABC | 9 | | |
|
29
|
+
| EXAMPLE02 | 44 | RECORD_TYPE = EXAMPLE02 | TIMESTAMP |
|
30
|
+
| EXAMPLE01 | 49 | RECORD_TYPE = EXAMPLE01 | |
|
31
|
+
+-----------+--------------+-------------------------+-------------------+
|
32
|
+
|
33
|
+
"""
|
34
|
+
|
35
|
+
Scenario: defining constraints on record types
|
36
|
+
Given the following configuration:
|
37
|
+
"""
|
38
|
+
record_type("XYZ") do
|
39
|
+
field "RECORD_TYPE", :length => 5, :constrained_to => "REC01"
|
40
|
+
field "A_NUMBER", :length => 16, :constrained_to => /44123/
|
41
|
+
field "END_OF_RECORD", :length => 1
|
42
|
+
end
|
43
|
+
"""
|
44
|
+
When the record type configuration is printed
|
45
|
+
Then it should look like this:
|
46
|
+
"""
|
47
|
+
+-----------+--------------+------------------------------------------+-------------------+
|
48
|
+
| type name | total length | constraints | normalised fields |
|
49
|
+
+-----------+--------------+------------------------------------------+-------------------+
|
50
|
+
| XYZ | 22 | RECORD_TYPE = REC01, A_NUMBER =~ /44123/ | |
|
51
|
+
| EXAMPLE02 | 44 | RECORD_TYPE = EXAMPLE02 | TIMESTAMP |
|
52
|
+
| EXAMPLE01 | 49 | RECORD_TYPE = EXAMPLE01 | |
|
53
|
+
+-----------+--------------+------------------------------------------+-------------------+
|
54
|
+
|
55
|
+
"""
|
56
|
+
|
57
|
+
Scenario: normalising and grepping record types
|
58
|
+
Given the following configuration:
|
59
|
+
"""
|
60
|
+
for_names_matching(/EXAMPLE\d/) {|type| type.fields_with {|field| field.name =~ /RECORD_/}.should_be_normalised }
|
61
|
+
type("EXAMPLE01").field_with_index(2).should_be_normalised
|
62
|
+
"""
|
63
|
+
When the record type configuration is printed
|
64
|
+
Then it should look like this:
|
65
|
+
"""
|
66
|
+
+-----------+--------------+-------------------------+------------------------+
|
67
|
+
| type name | total length | constraints | normalised fields |
|
68
|
+
+-----------+--------------+-------------------------+------------------------+
|
69
|
+
| EXAMPLE02 | 44 | RECORD_TYPE = EXAMPLE02 | RECORD_TYPE, TIMESTAMP |
|
70
|
+
| EXAMPLE01 | 49 | RECORD_TYPE = EXAMPLE01 | RECORD_TYPE, USAGE |
|
71
|
+
+-----------+--------------+-------------------------+------------------------+
|
72
|
+
|
73
|
+
"""
|
@@ -0,0 +1,61 @@
|
|
1
|
+
Feature: intelligent record recognition
|
2
|
+
In order to understand the contents of ascii-encoded record streams quicker
|
3
|
+
As a tester
|
4
|
+
I want a tool to correctly recognise the record type without user intervention
|
5
|
+
|
6
|
+
Background:
|
7
|
+
Given the following configuration:
|
8
|
+
"""
|
9
|
+
record_type("ABC") do
|
10
|
+
field "RECORD_TYPE", :length => 3, :constrained_to => "ABC"
|
11
|
+
field "RECORD_SIZE", :length => 5
|
12
|
+
field "END_OF_RECORD", :length => 1
|
13
|
+
end
|
14
|
+
|
15
|
+
record_type("DEF") do
|
16
|
+
field "RECORD_TYPE", :length => 3, :constrained_to => "DEF"
|
17
|
+
field "RECORD_SIZE", :length => 5
|
18
|
+
field "END_OF_RECORD", :length => 1
|
19
|
+
end
|
20
|
+
|
21
|
+
record_type("GXX") do
|
22
|
+
field "RECORD_TYPE", :length => 3, :constrained_to => ["G01", "G02"]
|
23
|
+
field "RECORD_SIZE", :length => 5
|
24
|
+
field "END_OF_RECORD", :length => 1
|
25
|
+
end
|
26
|
+
|
27
|
+
record_type("XYZ") do
|
28
|
+
field "RECORD_TYPE", :length => 3
|
29
|
+
field "RECORD_SIZE", :length => 3
|
30
|
+
field "END_OF_RECORD", :length => 1
|
31
|
+
end
|
32
|
+
|
33
|
+
record_type("TXX_A", :applies_for_filenames_matching => /TXX_A/) do
|
34
|
+
field "RECORD_TYPE", :length => 3, :constrained_to => "TXX"
|
35
|
+
field "RECORD_SIZE", :length => 4
|
36
|
+
field "END_OF_RECORD", :length => 1
|
37
|
+
end
|
38
|
+
|
39
|
+
record_type("TXX_B", :applies_for_filenames_matching => /TXX_B/) do
|
40
|
+
field "RECORD_TYPE", :length => 3, :constrained_to => "TXX"
|
41
|
+
field "RECORD_SIZE", :length => 4
|
42
|
+
field "END_OF_RECORD", :length => 1
|
43
|
+
end
|
44
|
+
"""
|
45
|
+
|
46
|
+
Scenario Outline: fixed length record recognition
|
47
|
+
When record "<record>" coming from <filename> is analysed
|
48
|
+
Then its type should be recognised as "<expected type>"
|
49
|
+
|
50
|
+
Examples:
|
51
|
+
| record | filename | expected type |
|
52
|
+
| ABC | unspecified | unknown |
|
53
|
+
| XYZ123\n | unspecified | XYZ |
|
54
|
+
| ABC12345\n | unspecified | ABC |
|
55
|
+
| DEF12345\n | unspecified | DEF |
|
56
|
+
| G0112345\n | unspecified | GXX |
|
57
|
+
| G0212345\n | unspecified | GXX |
|
58
|
+
| G0312345\n | unspecified | unknown |
|
59
|
+
| TXX1234\n | TXX_A.gz | TXX_A |
|
60
|
+
| TXX1234\n | TXX_B.gz | TXX_B |
|
61
|
+
| TXX1234\n | TXX_Z.gz | unknown |
|