test/test_basic_parsing.rb in ruby-hl7-0.1.23 vs test/test_basic_parsing.rb in ruby-hl7-0.2.44

- old
+ new

@@ -1,13 +1,15 @@ -# $Id: test_basic_parsing.rb 21 2007-03-17 04:49:50Z segfault $ +# $Id: test_basic_parsing.rb 41 2007-06-30 08:06:04Z segfault $ $: << '../lib' require 'test/unit' require 'ruby-hl7' class BasicParsing < Test::Unit::TestCase def setup @simple_msh_txt = open( './test_data/test.hl7' ).readlines.first + @empty_txt = open( './test_data/empty.hl7' ).readlines.first + @empty_segments_txt = open( './test_data/empty_segments.hl7' ).readlines.first @base_msh = "MSH|^~\\&|LAB1||DESTINATION||19910127105114||ORU^R03|LAB1003929" end def test_simple_msh msg = HL7::Message.new @@ -29,14 +31,18 @@ assert_raise( HL7::ParseError ) do msg = HL7::Message.parse( :MSHthis_shouldnt_parse_at_all ) end end + def test_parse_empty + msg = HL7::Message.new @empty_txt + end + def test_message_to_string msg = HL7::Message.new msg.parse @simple_msh_txt - orig = @simple_msh_txt.gsub( /\r/, '\n' ) + orig = @simple_msh_txt.gsub( /\r/, "\n" ) assert_equal( orig, msg.to_s ) end def test_to_s_vs_to_hl7 msg = HL7::Message.new( @simple_msh_txt ) @@ -71,10 +77,18 @@ assert_raise( HL7::Exception ) do msg[2] = Class.new end end + def test_segment_missing_accessor + msg = HL7::Message.new + msg.parse @simple_msh_txt + assert_nothing_raised do + assert_equal( nil, msg[:does_not_exist] ) + end + end + def test_segment_string_mutator msg = HL7::Message.new msg.parse @simple_msh_txt inp = HL7::Message::Segment::NTE.new msg["NTE"] = inp @@ -260,10 +274,11 @@ def test_grouped_sequenced_segments #multible obr's with multiple obx's msg = HL7::Message.parse( @simple_msh_txt ) orig_output = msg.to_hl7 + orig_obx_cnt = msg[:OBX].length (1..10).each do |obr_id| obr = HL7::Message::Segment::OBR.new msg << obr (1..10).each do |obx_id| obx = HL7::Message::Segment::OBX.new @@ -272,11 +287,11 @@ end assert_not_nil( msg[:OBR] ) assert_equal( 11, msg[:OBR].length ) assert_not_nil( msg[:OBX] ) - assert_equal( 2, msg[:OBX].length ) + assert_equal( 102, msg[:OBX].length ) assert_equal( "2", msg[:OBR][4].children[1].set_id ) # confirm the id's assert_equal( "2", msg[:OBR][5].children[1].set_id ) # confirm the id's final_output = msg.to_hl7 assert_not_equal( orig_output, final_output ) @@ -299,8 +314,13 @@ pid.admin_sex = "TEST" end assert_nothing_raised do pid.admin_sex = "F" end + end + + def test_empty_segment + msg = HL7::Message.new @empty_segments_txt + end end