Skip to content

Commit

Permalink
add json io tests
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed Mar 14, 2024
1 parent 13dbca2 commit 514c204
Show file tree
Hide file tree
Showing 12 changed files with 81 additions and 10 deletions.
2 changes: 1 addition & 1 deletion tests/FsSpreadsheet.Js.Tests/DefaultIO.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let private tests_Write = testList "Write" [
testCaseAsync "default" (Async.AwaitPromise <| promise {
let wb = DefaultTestObject.defaultTestObject()
let p = DefaultTestObject.WriteTestFiles.FsSpreadsheetJS.asRelativePathNode
do! FsWorkbook.toFile p wb
do! FsWorkbook.toXlsxFile p wb
let! wb_read = FsWorkbook.fromXlsxFile p
Expect.isDefaultTestObject wb_read
})
Expand Down
1 change: 1 addition & 0 deletions tests/FsSpreadsheet.Js.Tests/FsSpreadsheet.Js.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
<ItemGroup>
<Compile Include="DefaultIO.Tests.fs" />
<Compile Include="Workbook.Tests.fs" />
<Compile Include="Json.Tests.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
22 changes: 22 additions & 0 deletions tests/FsSpreadsheet.Js.Tests/Json.Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Json.Tests

open FsSpreadsheet
open FsSpreadsheet.Js
open Fable.Pyxpecto

let defaultTestObject =
testList "defaultTestObject" [

testCase "Read-Write DefaultTestObject" <| fun _ ->
let dto = DefaultTestObject.defaultTestObject()
let s = dto.ToJsonString()
let dto2 = FsWorkbook.fromJsonString(s)
TestingUtils.Expect.isDefaultTestObject dto2

testCase "Should Fail" <| fun _ ->
Expect.isTrue false "is not the expected DataType.Boolean"
]

let main = testList "Json" [
defaultTestObject
]
1 change: 1 addition & 0 deletions tests/FsSpreadsheet.Js.Tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ let all =
[
Workbook.Tests.main
DefaultIO.Tests.main
Json.Tests.main
]

// This is possibly the most magic used to make this work.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
<Compile Include="OpenXml\Spreadsheet.fs" />
<Compile Include="Table.fs" />
<Compile Include="FsWorkbook.fs" />
<Compile Include="Json.Tests.fs" />
<Compile Include="Main.fs" />
</ItemGroup>

Expand Down
12 changes: 6 additions & 6 deletions tests/FsSpreadsheet.Net.Tests/FsWorkbook.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module FsWorkbook
module FsWorkbookTests

open Expecto
open FsSpreadsheet
Expand All @@ -10,7 +10,7 @@ let writeAndReadBytes =
testList "WriteAndReadBytes" [
testCase "Empty" (fun () ->
let wb = new FsWorkbook()
let f() = wb.ToBytes()
let f() = wb.ToXlsxBytes()
try
f() |> ignore
failwith "Should throw an exception"
Expand All @@ -35,8 +35,8 @@ let writeAndReadBytes =
let expected = new FsWorkbook()
let ws = TestObjects.sheet1()
expected.AddWorksheet(ws)
let bytes = expected.ToBytes()
let actual = FsWorkbook.fromBytes(bytes)
let bytes = expected.ToXlsxBytes()
let actual = FsWorkbook.fromXlsxBytes(bytes)
Expect.equal (expected.GetWorksheets().Count) (actual.GetWorksheets().Count) "Worksheet count should be equal"
Expect.equal (expected.GetWorksheetByName(TestObjects.sheet1Name).Name) TestObjects.sheet1Name "excpected sheetname"
Expect.equal (actual.GetWorksheetByName(TestObjects.sheet1Name).Name) TestObjects.sheet1Name "actual sheetname"
Expand All @@ -46,8 +46,8 @@ let writeAndReadBytes =
let wb = new FsWorkbook()
wb.AddWorksheet(TestObjects.sheet1())
wb.AddWorksheet(TestObjects.sheet2())
let bytes = wb.ToBytes()
let wb2 = FsWorkbook.fromBytes(bytes)
let bytes = wb.ToXlsxBytes()
let wb2 = FsWorkbook.fromXlsxBytes(bytes)
Expect.equal (wb.GetWorksheets().Count) (wb2.GetWorksheets().Count) "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"
Expand Down
22 changes: 22 additions & 0 deletions tests/FsSpreadsheet.Net.Tests/Json.Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Json.Tests

open FsSpreadsheet
open FsSpreadsheet.Net
open Fable.Pyxpecto

let defaultTestObject =
testList "defaultTestObject" [

testCase "Read-Write DefaultTestObject" <| fun _ ->
let dto = DefaultTestObject.defaultTestObject()
let s = dto.ToJsonString()
let dto2 = FsWorkbook.fromJsonString(s)
TestingUtils.Expect.isDefaultTestObject dto2

testCase "Should Fail" <| fun _ ->
Expect.isTrue false "is not the expected DataType.Boolean"
]

let main = testList "Json" [
defaultTestObject
]
4 changes: 2 additions & 2 deletions tests/FsSpreadsheet.Net.Tests/Table.fs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module FsTable
module FsTableTests

open Expecto
open FsSpreadsheet
Expand Down Expand Up @@ -31,7 +31,7 @@ let transformTable =

// --- Function of interest ---

let bytes = wb.ToBytes()
let bytes = wb.ToXlsxBytes()

// --- Get Tables ---

Expand Down
2 changes: 1 addition & 1 deletion tests/FsSpreadsheet.Py.Tests/DefaultIO.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ let private tests_Write = testList "Write" [
testCase "default" <| fun _ ->
let wb = DefaultTestObject.defaultTestObject()
let p = DefaultTestObject.WriteTestFiles.FsSpreadsheetPY.asRelativePathNode
do FsWorkbook.toFile p wb
do FsWorkbook.toXlsxFile p wb
let wb_read = FsWorkbook.fromXlsxFile p
Expect.isDefaultTestObject wb_read

Expand Down
1 change: 1 addition & 0 deletions tests/FsSpreadsheet.Py.Tests/FsSpreadsheet.Py.Tests.fsproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<Compile Include="Worksheet.Tests.fs" />
<Compile Include="Workbook.Tests.fs" />
<Compile Include="DefaultIO.Tests.fs" />
<Compile Include="Json.Tests.fs" />
<Compile Include="Main.fs" />
</ItemGroup>
<ItemGroup>
Expand Down
22 changes: 22 additions & 0 deletions tests/FsSpreadsheet.Py.Tests/Json.Tests.fs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
module Json.Tests

open FsSpreadsheet
open FsSpreadsheet.Py
open Fable.Pyxpecto

let defaultTestObject =
testList "defaultTestObject" [

testCase "Read-Write DefaultTestObject" <| fun _ ->
let dto = DefaultTestObject.defaultTestObject()
let s = dto.ToJsonString()
let dto2 = FsWorkbook.fromJsonString(s)
TestingUtils.Expect.isDefaultTestObject dto2

//testCase "Should Fail" <| fun _ ->
// Expect.isTrue false "is not the expected DataType.Boolean"
]

let main = testList "Json" [
defaultTestObject
]
1 change: 1 addition & 0 deletions tests/FsSpreadsheet.Py.Tests/Main.fs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ let all =
Worksheet.Tests.main
Workbook.Tests.main
DefaultIO.Tests.main
Json.Tests.main
]

//// This is possibly the most magic used to make this work.
Expand Down

0 comments on commit 514c204

Please sign in to comment.