diff --git a/src/Core/Table/ArcTableAux.fs b/src/Core/Table/ArcTableAux.fs index 04434e61..7a1d99e1 100644 --- a/src/Core/Table/ArcTableAux.fs +++ b/src/Core/Table/ArcTableAux.fs @@ -310,12 +310,12 @@ module Unchecked = let rowKeys = Array.map snd col |> Set.ofArray for rowIndex = 0 to rowCount - 1 do if not <| rowKeys.Contains rowIndex then - addCellAt (columnIndex,rowIndex,defaultCell) values + addCellAt (columnIndex,rowIndex,defaultCell.Copy()) values // No values existed in this column. Fill with default cells | None -> let defaultCell = getEmptyCellForHeader header None for rowIndex = 0 to rowCount - 1 do - addCellAt (columnIndex,rowIndex,defaultCell) values + addCellAt (columnIndex,rowIndex,defaultCell.Copy()) values /// Increases the table size to the given new row count and fills the new rows with the last value of the column diff --git a/src/Core/Table/CompositeCell.fs b/src/Core/Table/CompositeCell.fs index 2a5dd8fa..25429883 100644 --- a/src/Core/Table/CompositeCell.fs +++ b/src/Core/Table/CompositeCell.fs @@ -153,6 +153,13 @@ type CompositeCell = | Unitized (v,oa) -> $"{v} {oa.NameText}" | Data d -> $"{d.NameText}" + member this.Copy() = + match this with + | Term oa -> Term (oa.Copy()) + | FreeText s -> FreeText s + | Unitized (v,oa) -> Unitized (v, oa.Copy()) + | Data d -> Data (d.Copy()) + #if FABLE_COMPILER //[] static member term (oa:OntologyAnnotation) = CompositeCell.Term(oa) diff --git a/src/Json/Table/CellTable.fs b/src/Json/Table/CellTable.fs index 31b42369..7b4cce1e 100644 --- a/src/Json/Table/CellTable.fs +++ b/src/Json/Table/CellTable.fs @@ -42,5 +42,5 @@ module CellTable = let decodeCell (ot : CellTableArray) : Decoder = Decode.object (fun get -> let i = get.Required.Raw Decode.int - ot.[i] + ot.[i].Copy() ) \ No newline at end of file diff --git a/tests/Core/ArcTable.Tests.fs b/tests/Core/ArcTable.Tests.fs index 541be694..04a4e648 100644 --- a/tests/Core/ArcTable.Tests.fs +++ b/tests/Core/ArcTable.Tests.fs @@ -2337,9 +2337,26 @@ let private tests_equality = testList "equality" [ ] -//let private tests_fillMissing = testList "fillMissing" [ +let private tests_fillMissing = testList "fillMissing" [ + testCase "OntologyAnnotationCopied" <| fun _ -> + let table = ArcTable.init "My Table" -// ] + table.AddColumn(CompositeHeader.Input IOType.Source, [|for i in 0 .. 4 do CompositeCell.FreeText $"Source {i}"|]) + + table.AddColumn(CompositeHeader.Component (OntologyAnnotation.create("instrument model", "MS", "MS:424242"))) + + let cell = table.Values.[(1,0)] + + match cell with + | CompositeCell.Term oa -> + oa.Name <- Some "New Name" + | _ -> failwith "Expected a term" + + let otherCell = table.Values.[(1,1)] + + Expect.equal (table.Values.[(1,1)]) (table.Values.[(1,2)]) "Should be the same cell" + Expect.notEqual cell otherCell "Should not be the same cell" + ] let main = testList "ArcTable" [ @@ -2365,5 +2382,5 @@ let main = tests_IterColumns tests_GetHashCode tests_equality - //tests_fillMissing + tests_fillMissing ] \ No newline at end of file diff --git a/tests/Json/ArcTable.Tests.fs b/tests/Json/ArcTable.Tests.fs index 2c40486e..447d479e 100644 --- a/tests/Json/ArcTable.Tests.fs +++ b/tests/Json/ArcTable.Tests.fs @@ -66,8 +66,7 @@ let private tests_compressedFilled = None None -let private tests = testList "extended" [ - testList "compressed" [ +let private tests_compressedExtended = testList "compressed_extended" [ testCase "rangeColumnSize" <| fun _ -> // testTable column should be saved as range column, this should make it smaller than the IO column even though it has more cells let testTable = ArcTable.init("Test") @@ -88,8 +87,33 @@ let private tests = testList "extended" [ let encoded = testTable.ToCompressedJsonString() let decoded = ArcTable.fromCompressedJsonString encoded Expect.arcTableEqual decoded testTable "decompressed table should be equal to original table" + testCase "SeparateOntologyAnnotations" <| fun _ -> + let table = ArcTable.init "My Table" + + table.AddColumn( + CompositeHeader.Component (OntologyAnnotation.create("instrument model", "MS", "MS:424242")), + [|for i in 0 .. 2 do CompositeCell.createTermFromString $"Term"|] + ) + + let encoded = table.ToCompressedJsonString() + let decoded = ArcTable.fromCompressedJsonString encoded + + Expect.equal (table.Values.[(0,1)]) (decoded.Values.[(0,1)]) "Should be the same cell" + + let cell = decoded.Values.[(0,0)] + + match cell with + | CompositeCell.Term oa -> + oa.Name <- Some "New Name" + | _ -> failwith "Expected a term" + + let otherCell = decoded.Values.[(0,1)] + + Expect.equal (table.Values.[(0,1)]) (decoded.Values.[(0,1)]) "Should still be the same cell" + Expect.equal (decoded.Values.[(0,1)]) (decoded.Values.[(0,2)]) "Should also be the same cell" + Expect.notEqual cell otherCell "Should not be the same cell" ] -] + let private tests_dataColumns = testList "dataColumns" [ @@ -125,7 +149,7 @@ let private tests_commentColumns = let main = testList "ArcTable" [ - tests + tests_compressedExtended tests_core tests_coreEmpty tests_compressedEmpty