diff --git a/message_test.go b/message_test.go index fa60b3fd1..392690f92 100644 --- a/message_test.go +++ b/message_test.go @@ -146,6 +146,29 @@ func (s *MessageSuite) TestReBuild() { s.True(bytes.Equal(s.msg.bodyBytes, expectedBodyBytes), "Incorrect body bytes, got %s", string(s.msg.bodyBytes)) } +func (s *MessageSuite) TestRebuildWithRepeatingGroup() { + + dict, dictErr := datadictionary.Parse("spec/FIX44.xml") + s.Nil(dictErr) + + // Given message bytes from a valid string + rawMsg := bytes.NewBufferString("8=FIX.4.49=21035=D34=2347=UTF-852=20231231-20:19:4149=0100150=01001a56=TEST44=1211=139761=1010040021=1386=1336=NOPL55=SYMABC54=160=20231231-20:19:4138=140=259=0453=1448=4501447=D452=28354=6355=Public10=104") + + // When we parse it into a message + s.Nil(ParseMessageWithDataDictionary(s.msg, rawMsg, dict, dict)) + + // And then rebuild the message bytes + rebuildBytes := s.msg.build() + + // this method does result in test passing. + //s.msg.buildWithBodyBytes(s.msg.bodyBytes) + + expectedBytes := []byte("8=FIX.4.49=21035=D34=249=0100150=01001a52=20231231-20:19:4156=TEST347=UTF-844=1211=139761=1010040021=1386=1336=NOPL55=SYMABC54=160=20231231-20:19:4138=140=259=0453=1448=4501447=D452=28354=6355=Public10=104") + + // Then the bytes should be the same with repeating group properly ordered + s.True(bytes.Equal(expectedBytes, rebuildBytes), "Unexpected bytes,\n +%s\n -%s", rebuildBytes, expectedBytes) +} + func (s *MessageSuite) TestReBuildWithRepeatingGroupForResend() { // Given the following message with a repeating group origHeader := "8=FIXT.1.19=16135=834=349=ISLD52=20240415-03:43:17.92356=TW"