Skip to content

Commit

Permalink
replace CellDouble by CellDecimal in some tests
Browse files Browse the repository at this point in the history
  • Loading branch information
olafklinke authored May 31, 2024
1 parent 345ba78 commit 99b8d68
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 32 deletions.
8 changes: 4 additions & 4 deletions test/Main.hs
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,10 @@ floatsParsingTests parser = do
let xlsx = parser bs
parsedCells = maybe mempty (_wsCells . snd) $ listToMaybe $ xlsx ^. xlSheets
expectedCells = M.fromList
[ ((1,1), def & cellValue ?~ CellDouble 12.0)
, ((2,1), def & cellValue ?~ CellDouble 13.0)
, ((3,1), def & cellValue ?~ CellDouble 14.0 & cellStyle ?~ 1)
, ((4,1), def & cellValue ?~ CellDouble 15.0)
[ ((1,1), def & cellValue ?~ CellDecimal 12.0)
, ((2,1), def & cellValue ?~ CellDecimal 13.0)
, ((3,1), def & cellValue ?~ CellDecimal 14.0 & cellStyle ?~ 1)
, ((4,1), def & cellValue ?~ CellDecimal 15.0)
]
expectedCells @==? parsedCells

Expand Down
14 changes: 7 additions & 7 deletions test/PivotTableTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -106,24 +106,24 @@ testPivotSrcCells =
where
cellMap =
[ [CellText "Color", CellText "Year", CellText "Price", CellText "Count"]
, [CellText "green", CellDouble 2012, CellDouble 12.23, CellDouble 17]
, [CellText "white", CellDouble 2011, CellDouble 73.99, CellDouble 21]
, [CellText "red", CellDouble 2012, CellDouble 10.19, CellDouble 172]
, [CellText "white", CellDouble 2012, CellDouble 34.99, CellDouble 49]
, [CellText "green", CellDecimal 2012, CellDecimal 12.23, CellDecimal 17]
, [CellText "white", CellDecimal 2011, CellDecimal 73.99, CellDecimal 21]
, [CellText "red", CellDecimal 2012, CellDecimal 10.19, CellDecimal 172]
, [CellText "white", CellDecimal 2012, CellDecimal 34.99, CellDecimal 49]
]

testPivotCacheFields :: [CacheField]
testPivotCacheFields =
[ CacheField
(PivotFieldName "Color")
[CellText "green", CellText "white", CellText "red"]
, CacheField (PivotFieldName "Year") [CellDouble 2012, CellDouble 2011]
, CacheField (PivotFieldName "Year") [CellDecimal 2012, CellDecimal 2011]
, CacheField
(PivotFieldName "Price")
[CellDouble 12.23, CellDouble 73.99, CellDouble 10.19, CellDouble 34.99]
[CellDecimal 12.23, CellDecimal 73.99, CellDecimal 10.19, CellDecimal 34.99]
, CacheField
(PivotFieldName "Count")
[CellDouble 17, CellDouble 21, CellDouble 172, CellDouble 49]
[CellDecimal 17, CellDecimal 21, CellDecimal 172, CellDecimal 49]
]

testPivotTableDefinition :: ByteString
Expand Down
12 changes: 6 additions & 6 deletions test/StreamTests.hs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ smallWorkbook = def & atSheet "Sheet1" ?~ sheet
[((row,1), a1)
, ((row,2), def & cellValue ?~ CellText ("text at B"<> tshow row <> " Sheet1"))
, ((row,3), def & cellValue ?~ CellText "text at C1 Sheet1")
, ((row,4), def & cellValue ?~ CellDouble (0.2 + 0.1))
, ((row,4), def & cellValue ?~ CellDecimal (0.2 + 0.1))
, ((row,5), def & cellValue ?~ CellBool False)
]
-- sheets = [("Sheet1" , toWs $ [1..2] >>= \row ->
Expand All @@ -170,7 +170,7 @@ smallWorkbook = def & atSheet "Sheet1" ?~ sheet
-- , ((RowIndex row, ColumnIndex 3),
-- def & cellValue ?~ CellText "text at C1 Sheet1")
-- , ((RowIndex row, ColumnIndex 4),
-- def & cellValue ?~ CellDouble (0.2 + 0.1))
-- def & cellValue ?~ CellDecimal (0.2 + 0.1))
-- , ((RowIndex row, ColumnIndex 5),
-- def & cellValue ?~ CellBool False)
-- ]
Expand Down Expand Up @@ -224,13 +224,13 @@ untypedCellsAreParsedAsFloats = do
-- as numbers explicitly in `t` attribute.
items <- runXlsxM "data/floats.xlsx" $ collectItems $ makeIndex 1
let expected =
[ IM.fromList [ (1, def & cellValue ?~ CellDouble 12.0) ]
, IM.fromList [ (1, def & cellValue ?~ CellDouble 13.0) ]
[ IM.fromList [ (1, def & cellValue ?~ CellDecimal 12.0) ]
, IM.fromList [ (1, def & cellValue ?~ CellDecimal 13.0) ]
-- cell below has explicit `Numeric` type, while others are all `General`,
-- but sometimes excel does not add a `t="n"` attr even to numeric cells
-- but it should be default as number in any cases if `t` is missing
, IM.fromList [ (1, def & cellValue ?~ CellDouble 14.0 & cellStyle ?~ 1 ) ]
, IM.fromList [ (1, def & cellValue ?~ CellDouble 15.0) ]
, IM.fromList [ (1, def & cellValue ?~ CellDecimal 14.0 & cellStyle ?~ 1 ) ]
, IM.fromList [ (1, def & cellValue ?~ CellDecimal 15.0) ]
]
expected @==? (_ri_cell_row . _si_row <$> items)

Expand Down
30 changes: 15 additions & 15 deletions test/TestXlsx.hs
Original file line number Diff line number Diff line change
Expand Up @@ -146,16 +146,16 @@ testCellMap1 = M.fromList [ ((1, 2), cd1_2), ((1, 5), cd1_5), ((1, 10), cd1_10)
where
cd v = def {_cellValue=Just v}
cd1_2 = cd (CellText "just a text, fließen, русский <> и & \"in quotes\"")
cd1_5 = cd (CellDouble 42.4567)
cd1_5 = cd (CellDecimal 42.4567)
cd1_10 = cd (CellText "")
cd3_1 = cd (CellText "another text")
cd3_2 = def -- shouldn't it be skipped?
cd3_3 = def & cellValue ?~ CellError ErrorDiv0
& cellFormula ?~ simpleCellFormula "1/0"
cd3_7 = cd (CellBool True)
cd4_1 = cd (CellDouble 1)
cd4_2 = cd (CellDouble 123456789012345)
cd4_3 = (cd (CellDouble (1+2))) { _cellFormula =
cd4_1 = cd (CellDecimal 1)
cd4_2 = cd (CellDecimal 123456789012345)
cd4_3 = (cd (CellDecimal (1+2))) { _cellFormula =
Just $ simpleCellFormula "A4+B4<>11"
}
cd5_1 = def & cellFormula ?~ sharedFormulaByIndex (SharedFormulaIndex 0)
Expand All @@ -169,16 +169,16 @@ cellRangeDvSourceMap = M.fromList [ ((1, 1), def & cellValue ?~ CellText "A-A-A"
, ((2, 1), def & cellValue ?~ CellText "B-B-B")
, ((1, 2), def & cellValue ?~ CellText "C-C-C")
, ((2, 2), def & cellValue ?~ CellText "D-D-D")
, ((1, 3), def & cellValue ?~ CellDouble 6)
, ((2, 3), def & cellValue ?~ CellDouble 7)
, ((3, 1), def & cellValue ?~ CellDouble 5)
, ((1, 3), def & cellValue ?~ CellDecimal 6)
, ((2, 3), def & cellValue ?~ CellDecimal 7)
, ((3, 1), def & cellValue ?~ CellDecimal 5)
, ((3, 2), def & cellValue ?~ CellText "numbers!")
, ((3, 3), def & cellValue ?~ CellDouble 5)
, ((3, 3), def & cellValue ?~ CellDecimal 5)
]

testCellMap2 :: CellMap
testCellMap2 = M.fromList [ ((1, 2), def & cellValue ?~ CellText "something here")
, ((3, 5), def & cellValue ?~ CellDouble 123.456)
, ((3, 5), def & cellValue ?~ CellDecimal 123.456)
, ((2, 4),
def & cellValue ?~ CellText "value"
& cellComment ?~ comment1
Expand Down Expand Up @@ -401,12 +401,12 @@ testFormattedResult = Formatted cm styleSheet merges
, _cellFormula = Nothing }
cell12 = Cell
{ _cellStyle = Just 2
, _cellValue = Just (CellDouble 1.23)
, _cellValue = Just (CellDecimal 1.23)
, _cellComment = Nothing
, _cellFormula = Nothing }
cell25 = Cell
{ _cellStyle = Just 3
, _cellValue = Just (CellDouble 1.23456)
, _cellValue = Just (CellDecimal 1.23456)
, _cellComment = Nothing
, _cellFormula = Nothing }
merges = []
Expand Down Expand Up @@ -441,10 +441,10 @@ testRunFormatted = formatted formattedCellMap minimalStyleSheet
& fontName ?~ "Calibri"
at (1, 1) ?= (def & formattedCell . cellValue ?~ CellText "text at A1"
& formattedFormat . formatFont ?~ font1)
at (1, 2) ?= (def & formattedCell . cellValue ?~ CellDouble 1.23
at (1, 2) ?= (def & formattedCell . cellValue ?~ CellDecimal 1.23
& formattedFormat . formatFont . non def . fontItalic ?~ True
& formattedFormat . formatNumberFormat ?~ fmtDecimalsZeroes 4)
at (2, 5) ?= (def & formattedCell . cellValue ?~ CellDouble 1.23456
at (2, 5) ?= (def & formattedCell . cellValue ?~ CellDecimal 1.23456
& formattedFormat . formatNumberFormat ?~ StdNumberFormat Nf2Decimal)

testFormatWorkbookResult :: Xlsx
Expand All @@ -456,7 +456,7 @@ testFormatWorkbookResult = def & xlSheets .~ sheets
, _cellComment = Nothing
, _cellFormula = Nothing })]
cellMap2 = M.fromList [((2, 3), Cell { _cellStyle = Just 1
, _cellValue = Just (CellDouble 1.23456)
, _cellValue = Just (CellDecimal 1.23456)
, _cellComment = Nothing
, _cellFormula = Nothing })]
sheets = [ ("Sheet1", def & wsCells .~ cellMap1) , ("Sheet2", def & wsCells .~ cellMap2) ]
Expand All @@ -476,7 +476,7 @@ testFormatWorkbook = formatWorkbook sheets minimalStyleSheet
sheetNames = ["Sheet1", "Sheet2"]
testFormattedCellMap1 = M.fromList [((1,1), (def & formattedCell . cellValue ?~ CellText "text at A1 Sheet1"))]

testFormattedCellMap2 = M.fromList [((2,3), (def & formattedCell . cellValue ?~ CellDouble 1.23456
testFormattedCellMap2 = M.fromList [((2,3), (def & formattedCell . cellValue ?~ CellDecimal 1.23456
& formattedFormat . formatNumberFormat ?~ (UserNumberFormat "DD.MM.YYYY")))]
sheets = zip sheetNames [testFormattedCellMap1, testFormattedCellMap2]

Expand Down

0 comments on commit 99b8d68

Please sign in to comment.