fix(xanthous): Fix display of square/cubic units
Previously this'd display `5 m m³`, because it'd show the underlying value then add the unit suffix on at the end Change-Id: Idd240ddfebc212460f9fb529eff72732a5dafe2a Reviewed-on: https://cl.tvl.fyi/c/depot/+/3241 Reviewed-by: grfn <grfn@gws.fyi> Tested-by: BuildkiteCI
This commit is contained in:
parent
e62f578687
commit
ad8d38c64c
2 changed files with 11 additions and 4 deletions
|
@ -557,7 +557,6 @@ newtype Square a = Square a
|
|||
, Scalar
|
||||
)
|
||||
via a
|
||||
deriving Show via ShowUnitSuffix (Square a) a
|
||||
deriving via (a :: Type)
|
||||
instance ( Distribution d a
|
||||
, forall xx yy. Coercible xx yy => Coercible (d xx) (d yy)
|
||||
|
@ -567,6 +566,9 @@ deriving via (a :: Type)
|
|||
instance Unit a => Unit (Square a) where
|
||||
unitSuffix = unitSuffix @a <> "²"
|
||||
|
||||
instance Show a => Show (Square a) where
|
||||
show (Square n) = show n <> "²"
|
||||
|
||||
newtype Cubic a = Cubic a
|
||||
deriving stock (Eq, Generic)
|
||||
deriving anyclass (NFData, CoArbitrary, Function)
|
||||
|
@ -574,7 +576,6 @@ newtype Cubic a = Cubic a
|
|||
, Scalar
|
||||
)
|
||||
via a
|
||||
deriving Show via ShowUnitSuffix (Cubic a) a
|
||||
deriving via (a :: Type)
|
||||
instance ( Distribution d a
|
||||
, forall xx yy. Coercible xx yy => Coercible (d xx) (d yy)
|
||||
|
@ -584,6 +585,9 @@ deriving via (a :: Type)
|
|||
instance Unit a => Unit (Cubic a) where
|
||||
unitSuffix = unitSuffix @a <> "³"
|
||||
|
||||
instance Show a => Show (Cubic a) where
|
||||
show (Cubic n) = show n <> "³"
|
||||
|
||||
|
||||
--------------------------------------------------------------------------------
|
||||
|
||||
|
|
|
@ -99,8 +99,11 @@ test = testGroup "Xanthous.Data"
|
|||
, testGroup "units"
|
||||
[ testGroup "unit suffixes"
|
||||
[ testCase "density"
|
||||
$ tshow (10000 :: Grams `Per` Cubic Meters)
|
||||
@?= "10000.0 g/m³"
|
||||
$ tshow (10000 :: Grams `Per` Cubic Meters) @?= "10000.0 g/m³"
|
||||
, testCase "volume"
|
||||
$ tshow (5 :: Cubic Meters) @?= "5.0 m³"
|
||||
, testCase "area"
|
||||
$ tshow (5 :: Square Meters) @?= "5.0 m²"
|
||||
]
|
||||
]
|
||||
]
|
||||
|
|
Loading…
Reference in a new issue