added enum pretty printing tests

This commit is contained in:
macocianradu
2022-01-12 14:41:28 +02:00
parent a8c5438d79
commit 07d4cc73e0
10 changed files with 122 additions and 13 deletions

View File

@@ -79,6 +79,7 @@ test-suite RosettaParser-test
Parser.EnumSpec
Parser.ExpressionSpec
Parser.TypeSpec
PrettyPrinter.EnumSpec
Paths_RosettaParser
hs-source-dirs:
test

View File

@@ -0,0 +1,13 @@
{-The enumerated values to specified the period, e.g. day, week.-}
data PeriodEnum =
{-Day-}
D
{-Month-}
| M
{-Year-}
| Y
instance Show PeriodEnum where
show D = "day"
show M = "month"
show Y = "year"

View File

@@ -0,0 +1,13 @@
{-The enumerated values to specified the period, e.g. day, week.-}
data EnumWithoutDisplay =
{-Day-}
D
{-Month-}
| M
{-Year-}
| Y
instance Show EnumWithoutDisplay where
show D = "D"
show M = "M"
show Y = "Y"

View File

@@ -0,0 +1,7 @@
data EnumWithoutDescription =
X
| Y
instance Show EnumWithoutDescription where
show X = "xs"
show Y = "ys"

View File

@@ -35,9 +35,9 @@ func EquityPriceObservation: <"Function specification for the observation of an
func Something: <"asd">
inputs:
equity1 boolean (1..1)
determinationMethod ObservationPrimitive (1..1)
equity1 boolean (1..1)
valuationTime ObservationPrimitive (1..1)
output:
valuation ObservationPrimitive (0..1)
valuation ObservationPrimitive (0..*)
assign-output: if True and False then determinationMethod
assign-output: if True and False then valuationTime

View File

@@ -1,11 +1,44 @@
func EquityPriceObservation: <"Function specification for the observation of an equity price, based on the attributes of the 'EquityValuation' class.">
inputs:
equity Equity (1..1)
valuationDate AdjustableOrRelativeDate (1..1)
valuationTime BusinessCenterTime (0..1)
timeType TimeTypeEnum (0..1)
determinationMethod DeterminationMethodEnum (1..*)
equity int (1..1)
determinationMethod ObservationPrimitive (1..1)
output:
observation ObservationPrimitive (1..1)
observation ObservationPrimitive (0..1)
assign-output: if asd exists then var2
assign-output: if True and False then valuationDate
func EquityPriceObservation: <"Function specification for the observation of an equity price, based on the attributes of the 'EquityValuation' class.">
inputs:
equity int (1..1)
determinationMethod ObservationPrimitive (1..1)
output:
observation ObservationPrimitive (0..*)
assign-output: if True and False then valuationDate
func EquityPriceObservation: <"Function specification for the observation of an equity price, based on the attributes of the 'EquityValuation' class.">
inputs:
equity int (1..1)
determinationMethod ObservationPrimitive (1..1)
output:
observation ObservationPrimitive (1..1)
assign-output: if True and False then valuationDate
func EquityPriceObservation: <"Function specification for the observation of an equity price, based on the attributes of the 'EquityValuation' class.">
inputs:
equity int (1..1)
determinationMethod ObservationPrimitive (1..1)
output:
observation ObservationPrimitive (1..*)
assign-output: if True and False then valuationDate
func EquityPriceObservation: <"Function specification for the observation of an equity price, based on the attributes of the 'EquityValuation' class.">
inputs:
equity int (1..1)
determinationMethod ObservationPrimitive (1..1)
output:
observation ObservationPrimitive (*..*)
assign-output: if True and False then valuationDate

View File

@@ -34,10 +34,13 @@ printExpression (PostfixExp "multiple exists" ex) = "length" <+> printExpression
printExpression (PostfixExp "count" ex) = "length" <+> printExpression ex
printExpression (PostfixExp name ex) = pretty name <+> printExpression ex
-- Equality expressions
-- [a] a all =
-- any <>
printExpression (InfixExp "=" ex1 ex2) = printExpression ex1 <+> "==" <+> printExpression ex2
printExpression (InfixExp "<>" ex1 ex2) = printExpression ex1 <+> "/=" <+> printExpression ex2
printExpression (InfixExp "any =" ex1 ex2) = printExpression ex2 <+> "`elem`" <+> printExpression ex1
printExpression (InfixExp "all <>" ex1 ex2) = printExpression ex2 <+> "`notElem`" <+> printExpression ex1
--printExpression (InfixExp "all =" ex1 ex2) = "all (Eq)" <+> printExpression ex2 <+> printExpression ex1
printExpression (InfixExp "and" ex1 ex2) = printExpression ex1 <+> "&&" <+> printExpression ex2
printExpression (InfixExp "or" ex1 ex2) = printExpression ex1 <+> "||" <+> printExpression ex2
printExpression (InfixExp name ex1 ex2) = printExpression ex1 <+> pretty name <+> printExpression ex2

View File

@@ -0,0 +1,39 @@
module PrettyPrinter.EnumSpec where
import Test.Hspec
import Model.Enum
import PrettyPrinter.Enum
spec :: Spec
spec = do
describe "Testing enum parsing" $ do
it "[Test 1]" $ do
plainText <- readFile "resources/Enums/haskellEnum1.hs"
printEnum (head enums) `shouldBe` plainText
it "[Test 2]" $ do
plainText <- readFile "resources/Enums/haskellEnum2.hs"
printEnum (enums !! 1) `shouldBe` plainText
it "[Test 3]" $ do
plainText <- readFile "resources/Enums/haskellEnum3.hs"
printEnum (enums !! 2) `shouldBe` plainText
enums :: [EnumType]
enums = [
MakeEnum {enumName = "PeriodEnum",
enumDescription = Just "The enumerated values to specified the period, e.g. day, week.",
enumValues = [MakeEnumValue {enumValueName = "D", enumValueDescription = Just "Day", enumValueDisplayName = Just "day"},
MakeEnumValue {enumValueName = "M", enumValueDescription = Just "Month", enumValueDisplayName = Just "month"},
MakeEnumValue {enumValueName = "Y", enumValueDescription = Just "Year", enumValueDisplayName = Just "year"}]},
MakeEnum {enumName = "EnumWithoutDisplay",
enumDescription = Just "The enumerated values to specified the period, e.g. day, week.",
enumValues = [MakeEnumValue {enumValueName = "D", enumValueDescription = Just "Day", enumValueDisplayName = Nothing},
MakeEnumValue {enumValueName = "M", enumValueDescription = Just "Month", enumValueDisplayName = Nothing},
MakeEnumValue {enumValueName = "Y", enumValueDescription = Just "Year", enumValueDisplayName = Nothing}]},
MakeEnum {enumName = "EnumWithoutDescription",
enumDescription = Nothing,
enumValues = [MakeEnumValue {enumValueName = "X", enumValueDescription = Nothing, enumValueDisplayName = Just "xs"},
MakeEnumValue {enumValueName = "Y", enumValueDescription = Nothing, enumValueDisplayName = Just "ys"}]}]