edi4r 0.9.4.1 → 0.9.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (50) hide show
  1. checksums.yaml +7 -0
  2. data/AuthorCopyright +3 -3
  3. data/{ChangeLog → Changelog} +60 -0
  4. data/README +15 -10
  5. data/Tutorial +2 -3
  6. data/VERSION +1 -1
  7. data/bin/edi2xml.rb +12 -16
  8. data/bin/editool.rb +9 -5
  9. data/bin/sedas2eancom02.rb +1385 -0
  10. data/bin/xml2edi.rb +7 -12
  11. data/data/edifact/iso9735/SDCD.20000.csv +1 -0
  12. data/data/edifact/iso9735/SDCD.3for2.csv +1 -0
  13. data/data/edifact/iso9735/SDED.20000.csv +6 -0
  14. data/data/edifact/iso9735/SDED.30000.csv +43 -43
  15. data/data/edifact/iso9735/SDED.3for2.csv +6 -0
  16. data/data/edifact/iso9735/SDED.40000.csv +129 -129
  17. data/data/edifact/iso9735/SDED.40100.csv +130 -130
  18. data/data/edifact/iso9735/SDMD.20000.csv +6 -0
  19. data/data/edifact/iso9735/SDMD.30000.csv +6 -6
  20. data/data/edifact/iso9735/SDMD.3for2.csv +6 -0
  21. data/data/edifact/iso9735/SDMD.40000.csv +17 -17
  22. data/data/edifact/iso9735/SDMD.40100.csv +17 -17
  23. data/data/edifact/iso9735/SDSD.20000.csv +5 -0
  24. data/data/edifact/iso9735/SDSD.3for2.csv +5 -0
  25. data/data/edifact/untdid/EDMD.d01b.csv +1 -1
  26. data/data/sedas/EDCD..csv +0 -0
  27. data/data/sedas/EDED..csv +859 -0
  28. data/data/sedas/EDMD..csv +16 -0
  29. data/data/sedas/EDSD..csv +44 -0
  30. data/lib/edi4r.rb +147 -67
  31. data/lib/edi4r/ansi_x12-rexml.rb +91 -0
  32. data/lib/edi4r/ansi_x12.rb +1684 -0
  33. data/lib/edi4r/diagrams.rb +75 -14
  34. data/lib/edi4r/edifact-rexml.rb +4 -3
  35. data/lib/edi4r/edifact.rb +505 -202
  36. data/lib/edi4r/rexml.rb +13 -7
  37. data/lib/edi4r/sedas.rb +854 -0
  38. data/lib/edi4r/standards.rb +150 -33
  39. data/test/damaged_file.edi +1 -0
  40. data/test/eancom2webedi.rb +1 -0
  41. data/test/groups.edi +1 -1
  42. data/test/test_basics.rb +16 -9
  43. data/test/test_edi_split.rb +30 -0
  44. data/test/test_loopback.rb +7 -2
  45. data/test/test_rexml.rb +34 -2
  46. data/test/test_service_messages.rb +190 -0
  47. data/test/test_streaming.rb +167 -0
  48. data/test/test_tut_examples.rb +3 -1
  49. data/test/webedi2eancom.rb +1 -0
  50. metadata +121 -77
@@ -1,3 +1,4 @@
1
+ # -*- encoding: iso-8859-1 -*-
1
2
  # Classes providing access to directories of EDI standards like
2
3
  # the UN Trade Data Interchange Directories (UNTDID) and Subsets,
3
4
  # or ISO7389, or SAP IDoc definitions.
@@ -7,9 +8,15 @@
7
8
  #
8
9
  # :include: ../../AuthorCopyright
9
10
  #
10
- # $Id: standards.rb,v 1.9 2006/08/01 11:00:35 werntges Exp $
11
+ # $Id: standards.rb,v 1.11 2007/08/21 17:11:13 werntges Exp werntges $
11
12
  #--
12
13
  # $Log: standards.rb,v $
14
+ # Revision 1.11 2007/08/21 17:11:13 werntges
15
+ # Now with some SEDAS support; moving on to support ANSI X12
16
+ #
17
+ # Revision 1.10 2007/03/19 08:52:44 werntges
18
+ # Intermediate check-in: Basic subset support added, now going to add SEDAS
19
+ #
13
20
  # Revision 1.9 2006/08/01 11:00:35 werntges
14
21
  # EDI_NDB_PATH: Now platform independent
15
22
  #
@@ -48,11 +55,11 @@
48
55
  module EDI
49
56
  module Dir
50
57
 
51
- DE_Properties = Struct.new( :name, :format, :status, :dummy, :description)
58
+ DE_Properties = Struct.new( :name, :format, :status, :dummy, :description )
52
59
 
53
60
  # Common structure of B)ranch (of a msg), C)DE, D)E, S)egment
54
61
  #
55
- BCDS_entry = Struct.new( :item_no, :name, :status, :maxrep)
62
+ BCDS_entry = Struct.new( :item_no, :name, :status, :maxrep )
56
63
 
57
64
  # Named_list:
58
65
  #
@@ -99,7 +106,7 @@ module EDI
99
106
  # As long as we employ plain CSV files to store directories, a Directory
100
107
  # can become quite memory-consuming.
101
108
  # Therefore Directorys are cached after creation, so that they
102
- # need to be created and maintained only once when there areeseveral
109
+ # need to be created and maintained only once when there are several
103
110
  # messages of the same type in an interchange.
104
111
  #
105
112
  # Turns off this caching mechanism, saving memory but costing time.
@@ -132,14 +139,17 @@ module EDI
132
139
  # existing directory when already in cache.
133
140
  #
134
141
  # std:: The syntax standard key. Currently supported:
142
+ # - 'A' (ANSI X12),
135
143
  # - 'E' (EDIFACT),
136
144
  # - 'I' (SAP IDOC)
145
+ # - 'S' (SEDAS)
137
146
  # params:: A hash of parameters that uniquely identify the selected dir.
138
147
  # Hash parameters use following alternative key sets:
139
148
  #
140
149
  # ISO9735:: :d0002, :d0076 (default: "", nil)
141
150
  # UN/TDID:: :d0065, :d0052, :d0054, :d0051, :d0057; :is_iedi
142
151
  # SAP IDOC:: :IDOCTYPE, :SAPTYPE, :EXTENSION (see EDI_DC fields)
152
+ # SEDAS:: (none so far)
143
153
  #
144
154
  # UN/TDID: Elements of S009 or S320 are used:
145
155
  # d0065:: Message type like "INVOIC"
@@ -151,15 +161,20 @@ module EDI
151
161
  # Interactive EDI (only limited supported so far):
152
162
  # is_iedi:: Flag, +true+ or +false+. Assumed +false+ if missing.
153
163
  #
154
- def Directory.create( std, params )
164
+ def Directory.create( std, params={} )
155
165
 
156
166
  case std
167
+ when 'A' # ANSI X12
168
+ # par = { :ISA12 => '00401', :is_iedi => false }.update( params )
169
+ par = { }.update( params )
157
170
  when 'E' # UN/EDIFACT
158
- par = {:d0051 => '',
171
+ par = {:d0051 => '',
159
172
  :d0057 => '',
160
173
  :is_iedi => false }.update( params )
161
174
  when 'I' # SAP IDocs
162
175
  par = { }.update( params )
176
+ when 'S' # SEDAS
177
+ par = { }.update( params )
163
178
  else
164
179
  raise "Unsupported syntax standard: #{std}"
165
180
  end
@@ -170,9 +185,11 @@ module EDI
170
185
  #
171
186
  key = par.sort {|a,b| a.to_s <=> b.to_s}.hash
172
187
  obj = @@cache[key]
188
+ # warn "Looking up #{par.inspect} with key=#{key}"
173
189
  return obj unless obj.nil?
174
190
 
175
191
  obj = new( std, par )
192
+ # warn "Caching for #{par.inspect} with key=#{key}"
176
193
  @@cache[key] = obj # cache & return it
177
194
 
178
195
  else
@@ -213,7 +230,7 @@ module EDI
213
230
  end
214
231
 
215
232
  when 'E' # UN/EDIFACT
216
- prefix = '/edifact'
233
+ prefix, subset_prefix = '/edifact', nil
217
234
  if par[:d0002] # ISO9735 requested?
218
235
  case par[:d0002]
219
236
  when 1
@@ -232,16 +249,67 @@ module EDI
232
249
  prefix += '/iso9735/SD'
233
250
  ext += '.csv'
234
251
 
252
+ # Service messages? (AUTACK, CONTRL, KEYMAN): 2/2, D/3, 4/1 ok
253
+ elsif %w/2 D 4/.include?(par[:d0052]) && %w/2 3 1/.include?(par[:d0054])
254
+ if par[:d0052] == '2' && par[:d0054] == '2'
255
+ ext = '20000'
256
+ elsif par[:d0052] == 'D' && par[:d0054] == '3'
257
+ ext = '30000'
258
+ elsif par[:d0052] == '4' && par[:d0054] == '1'
259
+ ext = (par[:d0076] == nil) ? '40000' : '40100'
260
+ else
261
+ raise "Invalid syntax version: #{par[:d0002]}"
262
+ end
263
+ prefix += '/iso9735/SD'
264
+ ext += '.csv'
265
+
235
266
  else # UN/TDID requested?
236
267
  prefix += par[:is_iedi] ? '/untdid/ID' : '/untdid/ED'
237
- ext = (par[:d0052]+par[:d0054]).downcase + '.csv'
268
+ ext = (par[:d0052].to_s+par[:d0054].to_s).downcase + '.csv'
269
+ case par[:d0057]
270
+ when /EAN\d\d\d/, /EDIT\d\d/
271
+ subset_prefix = '/edifact/eancom/ED'
272
+ when '', nil
273
+ else
274
+ # raise "Subset not supported: #{par[:d0057]}"
275
+ EDI::logger.warn "Subset not supported: #{par[:d0057]}"
276
+ end
277
+ end
278
+ when 'S' # SEDAS
279
+ prefix, subset_prefix, ext = '/sedas/ED', nil, '.csv'
280
+
281
+ when 'A' # ANSI X12
282
+ prefix, subset_prefix = '/ansi', nil
283
+ if par[:ISA12] # control segments requested?
284
+ msg = "Syntax version not supported: #{par[:ISA12]}"
285
+ case par[:ISA12]
286
+ when /00[1-5]0\d/ # , '00401', '00501' etc.
287
+ EDI::logger.warn msg if par[:ISA12] !~ /^00[45]01$/
288
+ ext = par[:ISA12]
289
+ else
290
+ raise msg
291
+ end
292
+ prefix += '/x12/SD'
293
+ ext += '.csv'
294
+
295
+ else # Standards directory requested?
296
+ prefix += '/dir/ED'
297
+ ext = par[:GS08][0,6] + '.csv' # Subset not supported
298
+ case par[:GS08][6..-1]
299
+ when 'X098', 'X098A1', 'X096A1', 'X093', 'X092', 'X091A1', 'X222A1', 'X223A2', /^X2\d\d(A[12])?/
300
+ # Conceivable support of a major subset (like HIPAA)
301
+ # subset_prefix = '/ansi/hipaa/ED'
302
+ when '', nil
303
+ else
304
+ raise "Subset not supported: <<#{par[:GS08][6..-1]}>>"
305
+ end
238
306
  end
239
307
 
240
308
  else
241
309
  raise "Unsupported syntax standard: #{std}"
242
310
  end
243
311
 
244
- return prefix, ext
312
+ return prefix, subset_prefix, ext
245
313
  end
246
314
 
247
315
 
@@ -251,14 +319,30 @@ module EDI
251
319
  # Will be generalized to a lookup scheme!
252
320
  #
253
321
  def Directory.path_finder( prefix, ext, selector )
254
- filename = prefix + selector + '.' + ext
255
- searchpath = ENV['EDI_NDB_PATH']
322
+ #
323
+ # Subset requested:
324
+ # Try subset first, warn & fall back on standard before giving up
325
+ #
326
+ if prefix.is_a? Array
327
+ raise "Only subset and regular prefix expected" if prefix.size != 2
328
+ begin
329
+ Directory.path_finder( prefix[0], ext, selector )
330
+ rescue EDILookupError
331
+ # warn "Subset data not found - falling back on standard"
332
+ # $stderr.puts prefix.inspect, ext.inspect, selector.inspect
333
+ Directory.path_finder( prefix[1], ext, selector )
334
+ end
335
+ else
336
+ filename = prefix + selector + '.' + ext
337
+ searchpath = ENV['EDI_NDB_PATH']
256
338
 
257
- searchpath.split(/#{File::PATH_SEPARATOR}/).each do |datadir|
258
- path = datadir + filename
259
- return path if File.readable? path
339
+ searchpath.split(/#{File::PATH_SEPARATOR}/).each do |datadir|
340
+ path = datadir + filename
341
+ # warn "Looking for #{path}"
342
+ return path if File.readable? path
343
+ end
344
+ raise EDILookupError, "No readable file '." + filename + "' found below any dir on '" + searchpath + "'"
260
345
  end
261
- raise "No readable file '." + filename + "' found below any dir on '" + searchpath + "'"
262
346
  end
263
347
 
264
348
  #
@@ -266,17 +350,19 @@ module EDI
266
350
  #
267
351
  def initialize ( std, par ) # :nodoc:
268
352
 
269
- prefix, ext = Directory.prefix_ext_finder( std, par )
353
+ prefix, subset_prefix, ext = Directory.prefix_ext_finder( std, par )
270
354
 
271
355
  # Build DE directory
272
356
 
273
357
  prefix_ed = prefix.sub(/ID$/, 'ED') # There is no IDED.*.csv!
274
- csvFileName = Directory.path_finder(prefix_ed, ext, 'ED' )
358
+ _prefix = subset_prefix.nil? ? prefix_ed : [subset_prefix, prefix_ed]
359
+
360
+ csvFileName = Directory.path_finder(_prefix, ext, 'ED' )
275
361
  @de_dir = Hash.new
276
362
  IO.foreach(csvFileName) do |line|
277
363
  d = DE_Properties.new
278
364
  d.name, d.format, d.dummy, d.description = line.strip.split(/;/)
279
- $stderr.puts "ERR DE line", line if d.description.nil?
365
+ EDI::logger.warn "ERR DE line: "+line if d.description.nil?
280
366
  @de_dir[d.name] = d
281
367
  end
282
368
 
@@ -287,9 +373,9 @@ module EDI
287
373
  IO.foreach(csvFileName) do |line|
288
374
  c = Named_list.new
289
375
  c.name, c.desc, list = line.split(/;/, 3)
290
- $stderr.puts "ERR CDE line", line if list.nil?
376
+ EDI::logger.warn "ERR CDE line: "+line if list.nil?
291
377
  list.sub(/;\s*$/,'').split(/;/).each_slice(4) do |item, code, status, fmt|
292
- $stderr.puts "ERR CDE list", line if fmt.nil?
378
+ EDI::logger.warn "ERR CDE list: "+line if fmt.nil?
293
379
  c << BCDS_entry.new( item, code, status, 1 )
294
380
  end
295
381
  @cde_dir[c.name] = c
@@ -297,36 +383,44 @@ module EDI
297
383
 
298
384
  # Build Segment directory
299
385
 
300
- csvFileName = Directory.path_finder(prefix, ext, 'SD' )
386
+ _prefix = subset_prefix.nil? ? prefix : [subset_prefix, prefix]
387
+ csvFileName = Directory.path_finder( _prefix, ext, 'SD' )
301
388
  @seg_dir = Hash.new
302
389
  IO.foreach(csvFileName) do |line|
303
390
  c = Named_list.new
304
391
  c.name, c.desc, list = line.split(/;/, 3)
305
- $stderr.puts "ERR SEG line", line if list.nil?
392
+ EDI::logger.warn "ERR SEG line: "+line if list.nil?
306
393
  list.sub(/;\s*$/,'').split(/;/).each_slice(4) do |item, code, status, maxrep|
307
- $stderr.puts "ERR SEG list", line if maxrep.nil?
308
- c << BCDS_entry.new( item, code, status, maxrep.to_i )
394
+ EDI::logger.warn "ERR SEG list: "+line if maxrep.nil?
395
+ maxrep = maxrep=='>1' ? 1 << 30 : maxrep.to_i # Use 2**30 instead of Infinity
396
+ c << BCDS_entry.new( item, code, status, maxrep )
309
397
  end
310
398
  @seg_dir[c.name] = c
311
399
  end
312
400
 
313
401
  # Build Message directory
314
-
315
- csvFileName = Directory.path_finder(prefix, ext, 'MD' )
402
+
403
+ _prefix = subset_prefix.nil? ? prefix : [subset_prefix, prefix]
404
+ csvFileName = Directory.path_finder( _prefix, ext,'MD' )
316
405
  @msg_dir = Hash.new
317
406
  re = if par[:d0065] and par[:d0065] =~ /([A-Z]{6})/
318
- then Regexp.new($1) else nil end
407
+ then Regexp.new($1) else nil end # UN/EDIFACT
408
+ re = if par[:ST01] and par[:ST01] =~ /(\d{3})/
409
+ then Regexp.new('^'+$1) else nil end unless re # ANSI - Try again
410
+
319
411
  IO.foreach(csvFileName) do |line|
320
412
  next if re and line !~ re # Only lines matching message type if given
321
413
  c = Named_list.new
322
414
  c.name, c.desc, list = line.split(/;/, 3)
323
- $stderr.puts "ERR MSG line", line if list.nil?
415
+ EDI::logger.warn "ERR MSG line: "+line if list.nil?
324
416
  list.sub(/;\s*$/,'').split(/;/).each_slice(3) do |code, status, maxrep|
325
- $stderr.puts "ERR MSG list", line if maxrep.nil?
326
- c << BCDS_entry.new( "0000", code, status, maxrep.to_i )
417
+ EDI::logger.warn "ERR MSG list: "+line if maxrep.nil?
418
+ maxrep = maxrep=='>1' ? 1 << 30 : maxrep.to_i # Use 2**30 instead of Infinity
419
+ c << BCDS_entry.new( "0000", code, status, maxrep )
327
420
  end
328
421
  @msg_dir[c.name] = c
329
422
  end
423
+
330
424
  end # initialize
331
425
 
332
426
 
@@ -382,8 +476,16 @@ module EDI
382
476
  # Returns CSV line of top branch for message called +name+.
383
477
  #
384
478
  def message( name ) # Actually, only one branch!
385
- # $stderr.puts name
386
- @msg_dir[name]
479
+ # p name
480
+ # p @msg_dir# [name]
481
+ rc = @msg_dir[name]
482
+ return rc unless rc.nil?
483
+ # Try without subset if nil:
484
+ # ex.: CONTRL:D:3:UN:1.3c:SG1, CONTRL:D:3:UN::
485
+ return nil unless name =~ /(.*:)([^:]{1,6})(:[^:]*)/
486
+ EDI::logger.warn "Subset not supported: #$2 - falling back on standard}" if $3==':' # warn only at top branch
487
+ # $stderr.puts "Using fallback name: #{$1+$3}"
488
+ @msg_dir[$1+$3]
387
489
  end
388
490
 
389
491
  # Returns a sorted list of names of available messages
@@ -407,7 +509,7 @@ module EDI
407
509
  case id
408
510
  when /^[CES]\d{3}$/ # C)omposite
409
511
  list = cde(id)
410
-
512
+
411
513
  when /^\d{4}$/ # Simple D)E
412
514
  list = de(id)
413
515
 
@@ -481,6 +583,21 @@ if __FILE__ == $0
481
583
 
482
584
  puts d.message_names; gets
483
585
 
586
+ # SEDAS tests
587
+
588
+ s = EDI::Dir::Directory.create('S')#,
589
+ # :d0052 =>'D',
590
+ # :d0054 =>'96A')
591
+
592
+ puts s.message_names; gets
593
+
594
+ # ANSI X12 tests
595
+
596
+ s = EDI::Dir::Directory.create('A', :ISA12 =>'00401' )
597
+ puts s.message_names; gets
598
+ s = EDI::Dir::Directory.create('A', :GS08 =>'004010X098' )
599
+ puts s.message_names; gets
600
+
484
601
  # SAP IDOC tests (should fail now!)
485
602
 
486
603
  s = EDI::Dir::Directory.create('I',
@@ -0,0 +1 @@
1
+ UNA:+.? 'UNB+UNOC:3+2965197100002:14+2165197000009:14+060501:1611+1146492687.229+++++EANCOM+1'UNH+1+ORDERS:D:01B:UN:EAN010'BGM+220+12345+9'DTM+137:20040712:102'DTM+2:200404141245200404141420:719'RFF+PD:4712'NAD+SU+2165197000009::9'RFF+YC1:23456'RFF+VA:DE1234512345'NAD+BY+2965197100002::9'RFF+VA:DE1234512345'CTA+PD+1144'NAD+IV+2965197400003::9'RFF+VA:DE1234512346'CTA+OC+223'NAD+DP+2965197200009::9'CTA+DL+6677'NAD+UC+2965197300006::9'CTA+GR+9876'CUX+2:EUR:9'LIN+1++2165197000016:SRV'PIA+1+JEBL5023:SA::91+BLJE50:IN::92'IMD+A++:::Jeans?+mehr'IMD+F+35+:::Blau'IMD+F+98+:::50'QTY+21:10'PRI+AAA:30.0::LIU'PRI+AAE:99,0::SRP:1'LIN+2++2165197000023:SRV'PIA+1+JEBL5223:SA::91+BLJE52:IN::92'IMD+A++:::Jeans'IMD+F+35+:::Blau'IMD+F+98+:::52'QTY+21:10'PRi+AAA:40::LIU'PRI+AAE:120::SRP:1'UNS+S'UNT+37+1'UNZ+1+1146492687.229'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- encoding: iso-8859-1 -*-
2
3
  #
3
4
  # Mapping demo: Inbound, from EANCOM to inhouse
4
5
  #
@@ -1 +1 @@
1
- UNA:+.? 'UNB+UNOB:3+sender+recipient+060801:1327+1'UNG+ORDERS+sender-g+recipient-g+060801:1327+1+UN+D:96A'UNE+0+1'UNG+ORDERS+sender+recipient+060801:1327+5+UN+D:96A'UNH+1+ORDERS:D:96A:UN'BGM++220'DTM+137:20060703:102'UNS+S'UNT+5+1'UNE+1+5'UNG+INVOIC+sender+recipient+060801:1327+3+UN+D:01B:EAN010'UNH+1+INVOIC:D:01B:UN:EAN010'BGM+380'DTM+137:20060801132728:204'UNS+S'MOA+86:0'UNT+6+1'UNE+1+3'UNZ+3+1'
1
+ UNA:+.? 'UNB+UNOB:3+sender+recipient+150331:1913+1'UNG+ORDERS+sender-g+recipient-g+150331:1913+1+UN+D:96A'UNE+0+1'UNG+ORDERS+sender+recipient+150331:1913+5+UN+D:96A'UNH+1+ORDERS:D:96A:UN'BGM++220'DTM+137:20060703:102'UNS+S'UNT+5+1'UNE+1+5'UNG+INVOIC+sender+recipient+150331:1913+3+UN+D:01B:EAN010'UNH+1+INVOIC:D:01B:UN:EAN010'BGM+380'DTM+137:20150331191342:204'UNS+S'MOA+86:0'UNT+6+1'UNE+1+3'UNZ+3+1'
@@ -1,4 +1,5 @@
1
1
  #!/usr/bin/env ruby
2
+ # -*- encoding: iso-8859-1 -*-
2
3
  # :include: ../AuthorCopyright
3
4
 
4
5
  # Load path magic...
@@ -21,7 +22,8 @@ class EDIFACT_Tests < Test::Unit::TestCase
21
22
  seg = msg.new_segment('DTM')
22
23
  msg.add seg
23
24
  seg.cC507.d2005 = '137'
24
- t = Time.edifact('20060703', 102)
25
+ t = EDI::Time.edifact('20060703', 102)
26
+ assert_equal('20060703', t.to_s)
25
27
  seg.cC507.d2380 = t
26
28
  seg.cC507.d2379 = t.format
27
29
 
@@ -41,7 +43,7 @@ class EDIFACT_Tests < Test::Unit::TestCase
41
43
  seg = msg.new_segment('DTM')
42
44
  msg.add seg
43
45
  seg.cC507.d2005 = '137'
44
- t = Time.new
46
+ t = EDI::Time.new
45
47
  t.format = 204
46
48
  seg.cC507.d2380 = t
47
49
  seg.cC507.d2379 = t.format
@@ -191,19 +193,24 @@ class EDIFACT_Tests < Test::Unit::TestCase
191
193
  assert_equal( 'PRI+AAA-\\-30.1--LIU', pri.to_s)
192
194
  end
193
195
 
194
- begin
195
196
  def test_interchange_parsing
197
+ mode = RUBY_VERSION >= '1.9' ? 'rb:iso-8859-15' : 'rb'
196
198
  assert_nothing_raised {
197
- ic = EDI::E::Interchange.parse( File.open( './O0002248720','r' ), false )
199
+ # ic = EDI::E::Interchange.parse( File.open( './marius1.edi','r' ), true )
200
+ file = File.open './O0002248720', mode
201
+ ic = EDI::E::Interchange.parse file, false
202
+ file.close
198
203
  ic.output_mode = :indented
199
204
  File.open("invoic.out", "w") {|hnd| hnd.print ic}
200
205
  }
201
- assert_nothing_raised {
202
- ic = EDI::E::Interchange.parse( File.open( './remadv101.edi', 'r' ) )
203
- ic.output_mode = :indented
206
+ # assert_nothing_raised {
207
+ file = File.open './remadv101.edi', mode
208
+ ic = EDI::E::Interchange.parse file
209
+ # ic.output_mode = :indented
210
+ file.close
204
211
  File.open("remadv.out", "w") {|hnd| hnd.print ic}
205
212
  # $stdout.write ic
206
- }
213
+ ic.validate
214
+ # }
207
215
  end
208
- end
209
216
  end
@@ -19,6 +19,7 @@ include EDI::E
19
19
 
20
20
  class TestClass < Test::Unit::TestCase
21
21
 
22
+ =begin
22
23
  def test_cde_sep
23
24
  assert_equal(['a','b'], edi_split('a:b', ?:, ??) )
24
25
  assert_equal(['a:b'], edi_split('a?:b', ?:, ??) )
@@ -45,6 +46,35 @@ class TestClass < Test::Unit::TestCase
45
46
  assert_equal( ['TAG','SOME TEXT?', 'MORE TEXT', 'PENDING ESC ?'], edi_split('TAG+SOME TEXT??+MORE TEXT+PENDING ESC ??', ?+, ??) )
46
47
  assert_raise(EDISyntaxError){edi_split('TAG+SOME TEXT??+MORE TEXT+PENDING ESC! ???', ?+, ??)}
47
48
  end
49
+ =end
50
+ # New concept: Leave the unescaping to the last step (at DE level)
51
+ # to avoid accidental multiple unescaping
52
+ def test_cde_sep
53
+ assert_equal(['a','b'], edi_split('a:b', ?:, ??) )
54
+ assert_equal(['a?:b'], edi_split('a?:b', ?:, ??) )
55
+ assert_equal(['a??','b'],edi_split('a??:b', ?:, ??) )
56
+ assert_equal(['a???:b'], edi_split('a???:b', ?:, ??) )
57
+ assert_raise( EDISyntaxError) { edi_split('a:b?', ?:, ??)}
58
+
59
+ assert_equal(['a','', 'b'], edi_split('a::b', ?:, ??) )
60
+ assert_equal(['a','', '', 'b'], edi_split('a:::b', ?:, ??) )
61
+ assert_equal(['a','b'], edi_split('a:b:', ?:, ??) )
62
+ assert_equal(['a','', 'b'], edi_split('a::b::', ?:, ??) )
63
+
64
+ assert_equal(['','a','b'], edi_split(':a:b', ?:, ??) )
65
+ assert_equal(['','','', 'a','', 'b'], edi_split(':::a::b::', ?:, ??) )
66
+
67
+ assert_equal( ['123456780', 'A + B LTD' ], edi_split('123456780:A + B LTD', ?:, ??) )
68
+ assert_equal( ['', '', '', '10010099', '25', '131' ], edi_split(':::10010099:25:131', ?:, ??) )
69
+ end
70
+
71
+ def test_de_sep
72
+ assert_equal( ['IMD', 'A','', ':::JEANS'], edi_split('IMD+A++:::JEANS', ?+, ??))
73
+ assert_equal( ['FII', 'OR','123456780:A ?+ B LTD', ':::10010099:25:131' ], edi_split('FII+OR+123456780:A ?+ B LTD+:::10010099:25:131', ?+, ??) )
74
+ assert_raise(EDISyntaxError){edi_split('TAG+SOME TEXT??+MORE TEXT+PENDING ESC! ?', ?+, ??)}
75
+ assert_equal( ['TAG','SOME TEXT??', 'MORE TEXT', 'PENDING ESC ??'], edi_split('TAG+SOME TEXT??+MORE TEXT+PENDING ESC ??', ?+, ??) )
76
+ assert_raise(EDISyntaxError){edi_split('TAG+SOME TEXT??+MORE TEXT+PENDING ESC! ???', ?+, ??)}
77
+ end
48
78
 
49
79
  def test_seg_term
50
80
  assert_equal( ['RFF+ACK:12345/678', 'FII+BF+000000000:::EUR+:::10010099:25:131', 'SEQ++1', 'FII+OR+123456780:A ?+ B LTD+:::10010099:25:131', 'RFF+RA:YOUR ACCOUNT 1234-5678 9'], edi_split('RFF+ACK:12345/678\'FII+BF+000000000:::EUR+:::10010099:25:131\'SEQ++1\'FII+OR+123456780:A ?+ B LTD+:::10010099:25:131\'RFF+RA:YOUR ACCOUNT 1234-5678 9\'', ?', ??))