Skip to content

Commit 61ea221

Browse files
committed
datamap comment headers now contain "Comment" prefix
#515
1 parent 8d97118 commit 61ea221

3 files changed

Lines changed: 82 additions & 1 deletion

File tree

src/Spreadsheet/DataMapTable/DataMapHeader.fs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -199,5 +199,5 @@ let toFsCells (commentKeys : string list) : list<FsCell> =
199199
FsCell(DataMapAux.labelShortHand)
200200
]
201201
for ck in commentKeys do
202-
yield FsCell(ck)
202+
yield FsCell($"Comment [{ck}]")
203203
]

tests/Spreadsheet/DataMapTests.fs

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,70 @@ let private simpleTable =
6565
)
6666
]
6767

68+
let private commentTable =
69+
testList "commentTable" [
70+
let wsName = "isa_datamap"
71+
let ws =
72+
initWorksheet wsName
73+
[
74+
Data.appendDataColumn 1
75+
Explication.appendMeanColumn 1
76+
Unit.appendPPMColumn 1
77+
ObjectType.appendFloatColumn 1
78+
Description.appendDescriptionColumn 1
79+
GeneratedBy.appendGeneratedByColumn 1
80+
Label.appendLabelColumn 1
81+
Comment.appendCommentColumn 1
82+
]
83+
testCase "Read" (fun () ->
84+
85+
let table = DataMapTable.tryFromFsWorksheet ws
86+
87+
Expect.isSome table "Table was not created"
88+
let table = table.Value
89+
90+
Expect.equal table.DataContexts.Count 1 "Wrong number of rows"
91+
92+
let dc = table.GetDataContext(0)
93+
94+
let expectedComment = Comment(Comment.commentHeader, Comment.commentValue)
95+
let expectedData = Data.dataValue.Copy()
96+
expectedData.Comments <- ResizeArray [| expectedComment |]
97+
98+
Expect.equal (dc.AsData()) expectedData "Data did not match"
99+
100+
let explication = Expect.wantSome dc.Explication "Explication was not set"
101+
Expect.equal explication Explication.meanValue "Explication did not match"
102+
103+
let unit = Expect.wantSome dc.Unit "Unit was not set"
104+
Expect.equal unit Unit.ppmValue "Unit did not match"
105+
106+
let objectType = Expect.wantSome dc.ObjectType "ObjectType was not set"
107+
Expect.equal objectType ObjectType.floatValue "ObjectType did not match"
108+
109+
let description = Expect.wantSome dc.Description "Description was not set"
110+
Expect.equal description Description.descriptionValue "Description did not match"
111+
112+
let generatedBy = Expect.wantSome dc.GeneratedBy "GeneratedBy was not set"
113+
Expect.equal generatedBy GeneratedBy.generatedByValue "GeneratedBy did not match"
114+
115+
let label = Expect.wantSome dc.Label "Label was not set"
116+
Expect.equal label Label.labelValue "Label did not match"
117+
118+
Expect.hasLength dc.Comments 1 "Comments should have one entry"
119+
let comment = dc.Comments.[0]
120+
Expect.equal comment.Name (Some Comment.commentHeader) "Comment key did not match"
121+
Expect.equal comment.Value (Some Comment.commentValue) "Comment value did not match"
122+
)
123+
testCase "Write" (fun () ->
124+
let table = DataMapTable.tryFromFsWorksheet ws
125+
Expect.isSome table "Table was not created"
126+
let out = DataMapTable.toFsWorksheet table.Value
127+
Expect.workSheetEqual out ws "Worksheet was not correctly written"
128+
129+
)
130+
]
131+
68132
let private valuelessTable =
69133
testList "valuelessTable" [
70134
let wsName = "isa_datamap"
@@ -188,6 +252,7 @@ let private emptyDatamap =
188252
let main =
189253
testList "DataMapTableTests" [
190254
simpleTable
255+
commentTable
191256
valuelessTable
192257
emptyTable
193258
simpleFile

tests/TestingUtils/TestObjects.Spreadsheet/Spreadsheet.DataMap.fs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,22 @@ module Label =
164164
for i = 2 to l + 1 do
165165
t.Cell(FsAddress(i, colCount + 1),c).SetValueAs labelValueV1
166166

167+
module Comment =
168+
169+
let commentHeader = "Kommend"
170+
171+
let commentValue = "This is a comment"
172+
173+
let commentHeaderV1 = "Comment [Kommend]"
174+
175+
let commentValueV1 = "This is a comment"
176+
177+
let appendCommentColumn l (c : FsCellsCollection) (t : FsTable) =
178+
let colCount = if t.IsEmpty(c) then 0 else t.ColumnCount()
179+
t.Cell(FsAddress(1, colCount + 1),c).SetValueAs commentHeaderV1
180+
for i = 2 to l + 1 do
181+
t.Cell(FsAddress(i, colCount + 1),c).SetValueAs commentValueV1
182+
167183
let initWorksheet (name : string) (appendOperations : (FsCellsCollection -> FsTable -> unit) list) =
168184
let w = FsWorksheet(name)
169185
let t = w.Table(DataMapTable.datamapTablePrefix, FsRangeAddress("A1:A1"))

0 commit comments

Comments
 (0)