mirror of
https://github.com/macocianradu/RosettaHaskellCompiler.git
synced 2026-03-18 13:00:08 +00:00
added enum pretty printing tests
This commit is contained in:
@@ -79,6 +79,7 @@ test-suite RosettaParser-test
|
|||||||
Parser.EnumSpec
|
Parser.EnumSpec
|
||||||
Parser.ExpressionSpec
|
Parser.ExpressionSpec
|
||||||
Parser.TypeSpec
|
Parser.TypeSpec
|
||||||
|
PrettyPrinter.EnumSpec
|
||||||
Paths_RosettaParser
|
Paths_RosettaParser
|
||||||
hs-source-dirs:
|
hs-source-dirs:
|
||||||
test
|
test
|
||||||
|
|||||||
13
resources/Enums/haskellEnum1.hs
Normal file
13
resources/Enums/haskellEnum1.hs
Normal 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"
|
||||||
13
resources/Enums/haskellEnum2.hs
Normal file
13
resources/Enums/haskellEnum2.hs
Normal 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"
|
||||||
7
resources/Enums/haskellEnum3.hs
Normal file
7
resources/Enums/haskellEnum3.hs
Normal file
@@ -0,0 +1,7 @@
|
|||||||
|
data EnumWithoutDescription =
|
||||||
|
X
|
||||||
|
| Y
|
||||||
|
|
||||||
|
instance Show EnumWithoutDescription where
|
||||||
|
show X = "xs"
|
||||||
|
show Y = "ys"
|
||||||
@@ -35,9 +35,9 @@ func EquityPriceObservation: <"Function specification for the observation of an
|
|||||||
|
|
||||||
func Something: <"asd">
|
func Something: <"asd">
|
||||||
inputs:
|
inputs:
|
||||||
equity1 boolean (1..1)
|
equity1 boolean (1..1)
|
||||||
determinationMethod ObservationPrimitive (1..1)
|
valuationTime ObservationPrimitive (1..1)
|
||||||
output:
|
output:
|
||||||
valuation ObservationPrimitive (0..1)
|
valuation ObservationPrimitive (0..*)
|
||||||
|
|
||||||
assign-output: if True and False then determinationMethod
|
assign-output: if True and False then valuationTime
|
||||||
@@ -1,11 +1,44 @@
|
|||||||
func EquityPriceObservation: <"Function specification for the observation of an equity price, based on the attributes of the 'EquityValuation' class.">
|
func EquityPriceObservation: <"Function specification for the observation of an equity price, based on the attributes of the 'EquityValuation' class.">
|
||||||
inputs:
|
inputs:
|
||||||
equity Equity (1..1)
|
equity int (1..1)
|
||||||
valuationDate AdjustableOrRelativeDate (1..1)
|
determinationMethod ObservationPrimitive (1..1)
|
||||||
valuationTime BusinessCenterTime (0..1)
|
|
||||||
timeType TimeTypeEnum (0..1)
|
|
||||||
determinationMethod DeterminationMethodEnum (1..*)
|
|
||||||
output:
|
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
|
||||||
@@ -34,10 +34,13 @@ printExpression (PostfixExp "multiple exists" ex) = "length" <+> printExpression
|
|||||||
printExpression (PostfixExp "count" ex) = "length" <+> printExpression ex
|
printExpression (PostfixExp "count" ex) = "length" <+> printExpression ex
|
||||||
printExpression (PostfixExp name ex) = pretty name <+> printExpression ex
|
printExpression (PostfixExp name ex) = pretty name <+> printExpression ex
|
||||||
-- Equality expressions
|
-- Equality expressions
|
||||||
|
-- [a] a all =
|
||||||
|
-- any <>
|
||||||
printExpression (InfixExp "=" ex1 ex2) = printExpression ex1 <+> "==" <+> printExpression ex2
|
printExpression (InfixExp "=" ex1 ex2) = printExpression ex1 <+> "==" <+> printExpression ex2
|
||||||
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 "any =" ex1 ex2) = printExpression ex2 <+> "`elem`" <+> printExpression ex1
|
||||||
printExpression (InfixExp "all <>" ex1 ex2) = printExpression ex2 <+> "`notElem`" <+> 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 "and" ex1 ex2) = printExpression ex1 <+> "&&" <+> printExpression ex2
|
||||||
printExpression (InfixExp "or" 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
|
printExpression (InfixExp name ex1 ex2) = printExpression ex1 <+> pretty name <+> printExpression ex2
|
||||||
|
|||||||
@@ -28,7 +28,7 @@ printAttributes (at : ats) = (printAttribute at <> ",") : printAttributes ats
|
|||||||
printAttribute :: TypeAttribute -> Doc a
|
printAttribute :: TypeAttribute -> Doc a
|
||||||
printAttribute (MakeTypeAttribute name typ crd description) =
|
printAttribute (MakeTypeAttribute name typ crd description) =
|
||||||
printDescription description
|
printDescription description
|
||||||
(pretty name <+> "::" <+> printCardinality (MakeTypeAttribute name typ crd description))
|
(pretty name <+> "::" <+> printCardinality (MakeTypeAttribute name typ crd description))
|
||||||
|
|
||||||
-- |Converts a Cardinality into a haskell valid Doc
|
-- |Converts a Cardinality into a haskell valid Doc
|
||||||
printCardinality :: TypeAttribute -> Doc a
|
printCardinality :: TypeAttribute -> Doc a
|
||||||
|
|||||||
@@ -175,7 +175,7 @@ cardinalityIncluded (Bounds (x1, x2)) (Bounds (y1, y2))
|
|||||||
-- |Looks in the symbol map for the type of a variable
|
-- |Looks in the symbol map for the type of a variable
|
||||||
findVarType :: String -> [Symbol] -> Either TypeCheckError (Type, Cardinality)
|
findVarType :: String -> [Symbol] -> Either TypeCheckError (Type, Cardinality)
|
||||||
findVarType var [] = Left $ UndefinedVariable var
|
findVarType var [] = Left $ UndefinedVariable var
|
||||||
findVarType x ((Var name typ crd):symbols)
|
findVarType x ((Var name typ crd):symbols)
|
||||||
| x == name = Right (typ, crd)
|
| x == name = Right (typ, crd)
|
||||||
| otherwise = findVarType x symbols
|
| otherwise = findVarType x symbols
|
||||||
findVarType x (_:symbols) = findVarType x symbols
|
findVarType x (_:symbols) = findVarType x symbols
|
||||||
39
test/PrettyPrinter/EnumSpec.hs
Normal file
39
test/PrettyPrinter/EnumSpec.hs
Normal 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"}]}]
|
||||||
Reference in New Issue
Block a user