Skip to content

Commit

Permalink
make ArcTables construction fail for duplicate table names
Browse files Browse the repository at this point in the history
  • Loading branch information
HLWeil committed May 29, 2024
1 parent 8182d52 commit f565309
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
8 changes: 6 additions & 2 deletions src/Core/Table/ArcTables.fs
Original file line number Diff line number Diff line change
Expand Up @@ -145,8 +145,12 @@ open Fable.Core
/// This type only includes mutable options and only static members, the MUST be referenced and used in all record types implementing `ResizeArray<ArcTable>`
[<AttachMembers>]
type ArcTables(initTables:ResizeArray<ArcTable>) =

let mutable tables = initTables

let mutable tables =
initTables
|> Seq.map (fun t -> t.Name)
|> ArcTablesAux.SanityChecks.validateNamesUnique
initTables
member this.Tables
with get() = tables
and set(newTables) = tables <- newTables
Expand Down
7 changes: 7 additions & 0 deletions tests/Core/ArcAssay.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,13 @@ let private test_create =
Expect.equal actual.Tables tables "Tables"
Expect.equal actual.Performers performers "Performers"
Expect.equal actual.Comments comments "Comments"
testCase "createDuplicateTablesNames" <| fun _ ->
let table1 = ArcTable.init("Table 1")
let table2 = ArcTable.init("Table 1")
let tables = ResizeArray([table1; table2])
let createAssay =
fun () -> ArcAssay.create("MyAssay", tables = tables) |> ignore
Expect.throws createAssay "throws, duplicate table names"
]

let private tests_AddTable =
Expand Down
16 changes: 15 additions & 1 deletion tests/Core/ArcTables.Tests.fs
Original file line number Diff line number Diff line change
Expand Up @@ -357,10 +357,24 @@ let updateReferenceWithSheet =
)
]

let tests_constructor =

testList "Constructor" [

testCase "DuplicateNames" (fun () ->
let table1 = ArcTable.init("Table 1")
let table2 = ArcTable.init("Table 1")
let createTables =
fun () -> ArcTables(ResizeArray [table1;table2]) |> ignore
Expect.throws createTables "Should throw an exception"
)
]

let main =
testList "ArcTablesTests" [
tests_Item
tests_IEnumberable
tests_member
updateReferenceWithSheet
updateReferenceWithSheet
tests_constructor
]

0 comments on commit f565309

Please sign in to comment.