-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #40 from CSBiology/xlsxlIOfix
test and fix writeAndReadSpreadsheet
- Loading branch information
Showing
13 changed files
with
145 additions
and
20 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
module FsWorkbook | ||
|
||
open Expecto | ||
open FsSpreadsheet | ||
open FsSpreadsheet.ExcelIO | ||
|
||
open TestingUtils | ||
|
||
let writeAndReadBytes = | ||
testList "WriteAndReadBytes" [ | ||
testCase "Empty" (fun () -> | ||
let wb = new FsWorkbook() | ||
let bytes = wb.ToBytes() | ||
let wb2 = FsWorkbook.fromBytes(bytes) | ||
Expect.equal (wb.GetWorksheets() |> List.length) (wb2.GetWorksheets() |> List.length) "Worksheet count should be equal" | ||
) | ||
testCase "SingleWorksheet" (fun () -> | ||
let wb = new FsWorkbook() | ||
let ws = TestObjects.sheet1() | ||
wb.AddWorksheet(ws) | ||
let bytes = wb.ToBytes() | ||
let wb2 = FsWorkbook.fromBytes(bytes) | ||
Expect.equal (wb.GetWorksheets() |> List.length) (wb2.GetWorksheets() |> List.length) "Worksheet count should be equal" | ||
Expect.workSheetEqual (wb.GetWorksheetByName(TestObjects.sheet1Name)) (wb2.GetWorksheetByName(TestObjects.sheet1Name)) "Worksheet did not match" | ||
) | ||
testCase "MultipleWorksheets" (fun () -> | ||
let wb = new FsWorkbook() | ||
wb.AddWorksheet(TestObjects.sheet1()) | ||
wb.AddWorksheet(TestObjects.sheet2()) | ||
let bytes = wb.ToBytes() | ||
let wb2 = FsWorkbook.fromBytes(bytes) | ||
Expect.equal (wb.GetWorksheets() |> List.length) (wb2.GetWorksheets() |> List.length) "Worksheet count should be equal" | ||
Expect.workSheetEqual (wb.GetWorksheetByName(TestObjects.sheet1Name)) (wb2.GetWorksheetByName(TestObjects.sheet1Name)) "First Worksheet did not match" | ||
Expect.workSheetEqual (wb.GetWorksheetByName(TestObjects.sheet2Name)) (wb2.GetWorksheetByName(TestObjects.sheet2Name)) "Second Worksheet did not match" | ||
) | ||
] | ||
|
||
|
||
|
||
[<Tests>] | ||
let tests = | ||
testList "FsWorkbook" [ | ||
writeAndReadBytes | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
module TestObjects | ||
|
||
open FsSpreadsheet | ||
|
||
let sheet1Name = "Sheet1" | ||
let sheet2Name = "Sheet2" | ||
|
||
let sheet1() = | ||
let ws = new FsWorksheet(sheet1Name) | ||
[ | ||
FsCell.createWithDataType DataType.String 1 1 "A1" | ||
FsCell.createWithDataType DataType.String 1 2 "B1" | ||
FsCell.createWithDataType DataType.String 1 3 "C1" | ||
|
||
FsCell.createWithDataType DataType.String 2 1 "A2" | ||
FsCell.createWithDataType DataType.String 2 2 "B2" | ||
FsCell.createWithDataType DataType.String 2 3 "C2" | ||
|
||
FsCell.createWithDataType DataType.String 3 1 "A3" | ||
FsCell.createWithDataType DataType.String 3 2 "B3" | ||
FsCell.createWithDataType DataType.String 3 3 "C3" | ||
] | ||
|> List.iter (fun c -> ws.Row(c.RowNumber).[c.ColumnNumber].SetValueAs c.Value) | ||
ws | ||
|
||
let sheet2() = | ||
let ws = new FsWorksheet(sheet2Name) | ||
[ | ||
FsCell.createWithDataType DataType.Number 1 1 1 | ||
FsCell.createWithDataType DataType.Number 1 2 2 | ||
FsCell.createWithDataType DataType.Number 1 3 3 | ||
FsCell.createWithDataType DataType.Number 1 4 4 | ||
|
||
FsCell.createWithDataType DataType.Number 2 1 5 | ||
FsCell.createWithDataType DataType.Number 2 2 6 | ||
FsCell.createWithDataType DataType.Number 2 3 7 | ||
FsCell.createWithDataType DataType.Number 2 4 8 | ||
] | ||
|> List.iter (fun c -> ws.Row(c.RowNumber).[c.ColumnNumber].SetValueAs c.Value) | ||
ws |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
module TestingUtils | ||
|
||
open FsSpreadsheet | ||
open Expecto | ||
|
||
module Expect = | ||
|
||
let workSheetEqual (actual : FsWorksheet) (expected : FsWorksheet) message = | ||
let f (ws : FsWorksheet) = | ||
ws.RescanRows() | ||
ws.Rows | ||
|> Seq.map (fun r -> r.Cells |> Seq.map (fun c -> c.Value) |> Seq.reduce (fun a b -> a + b)) | ||
if actual.Name <> expected.Name then | ||
failwithf $"{message}. Worksheet names do not match. Expected {expected.Name} but got {actual.Name}" | ||
Expect.sequenceEqual (f actual) (f expected) $"{message}. Worksheet does not match" | ||
|
||
let columnsEqual (actual : FsCell seq seq) (expected : FsCell seq seq) message = | ||
let f (cols : FsCell seq seq) = | ||
cols | ||
|> Seq.map (fun r -> r |> Seq.map (fun c -> c.Value) |> Seq.reduce (fun a b -> a + b)) | ||
Expect.sequenceEqual (f actual) (f expected) $"{message}. Columns do not match" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters