brittany icon indicating copy to clipboard operation
brittany copied to clipboard

Large case pattern should respect line lengths

Open chreekat opened this issue 7 years ago • 2 comments

A new corner case for you. :)

With default options, 0.11 produces

test_examples :: [TestTree]
test_examples =
  [ testCase
      "buildParticipantRecordAction-all"
      (  (case buildParticipantRecordAction participantRecordAll Create of
           ParticipantRecordAction Create [Upsert m1 "1", Upsert m2 "infoval", Upsert m3 "descval", Upsert m4 "2011-06-17", Upsert m5 "Male", Upsert m6 "White", Upsert m7 "Hispanic or Latino", Upsert m8 "2.5", Upsert m9 "Preterm", Upsert m10 "10.5", Upsert m11 "normal", Upsert m12 "English", Upsert m13 "USA", Upsert m14 "MA", Upsert m15 "Lab"]
             -> m1
               == participantMetricId
               && m2
               == participantMetricInfo
               && m3
               == participantMetricDescription
               && m4
               == participantMetricBirthdate
               && m5
               == participantMetricGender
               && m6
               == participantMetricRace
               && m7
               == participantMetricEthnicity
               && m8
               == participantMetricGestationalAge
               && m9
               == participantMetricPregnancyTerm
               && m10
               == participantMetricBirthWeight
               && m11
               == participantMetricDisability
               && m12
               == participantMetricLanguage
               && m13
               == participantMetricCountry
               && m14
               == participantMetricState
               && m15
               == participantMetricSetting
           _ -> False
         )
      @? "Expected create with upsert for each metric"
      )
  ]

chreekat avatar May 16 '18 14:05 chreekat

Yeah, i know. Pattern layouting is not complete for any non-single-line cases. And unfortunately this has somewhat low priority for me, as such patterns usually are best avoided. Although I don't see any workaround for your example there.

(If you want to have a go at improving this, the relevant brittany module is Language.Haskell.Brittany.Internal.Layouters.Pattern. Although some other code might be affected as well which currently relies on the "patterns are single-line" assumption.)

At least you now have the option of making use of -- brittany-disable-next-binding and layout this one by hand. Presuming that you only have a few of these cases.

lspitzner avatar May 16 '18 19:05 lspitzner

Maybe @kanishka-azimi has an opinion on the size of the pattern in this particular case. But anyway, that brittany directive shall certainly come in handy!

chreekat avatar May 19 '18 18:05 chreekat