Skip to content

Commit 5c72681

Browse files
committed
Make number attributes parsed as number objects
1 parent cff7494 commit 5c72681

File tree

2 files changed

+25
-7
lines changed

2 files changed

+25
-7
lines changed

integration/vscode/ada/src/gnatcov.ts

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import { X2jOptions, XMLParser } from 'fast-xml-parser';
2+
import { number } from 'fp-ts';
23
import * as fs from 'fs';
34

45
/**
@@ -75,7 +76,7 @@ type metric_type = {
7576
* should be 'number' but we don't want to ask the XML parser to parse
7677
* numbers
7778
*/
78-
'@_count': string;
79+
'@_count': number;
7980
'@_ratio': number;
8081
};
8182
type metric_kind_type =
@@ -170,6 +171,21 @@ type message_kind_type =
170171
| 'undetermined_cov'
171172
| 'exclusion';
172173

174+
/**
175+
* Process attribute values to convert certain attributes to number values.
176+
*
177+
* @param name - attribute name
178+
* @param value - unprocessed value
179+
* @returns processed value
180+
*/
181+
function attributeValueProcessor(name: string, value: string): unknown {
182+
return ['scope_line', 'count', 'ratio', 'num', 'column_begin', 'column_end', 'id'].includes(
183+
name,
184+
)
185+
? Number.parseInt(value)
186+
: value;
187+
}
188+
173189
/**
174190
*
175191
* @param path - path to GNATcoverage index.xml report
@@ -188,6 +204,8 @@ export function parseGnatcovIndexXml(path: string): CovIndex {
188204
isArray: (_, jPath) => {
189205
return ([] as string[]).indexOf(jPath) !== -1;
190206
},
207+
trimValues: false,
208+
attributeValueProcessor: attributeValueProcessor,
191209
};
192210
const parser = new XMLParser(options);
193211
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
@@ -225,7 +243,9 @@ export function parseGnatcovFileXml(path: string): source_type {
225243
* original content.
226244
*/
227245
trimValues: false,
246+
attributeValueProcessor: attributeValueProcessor,
228247
};
248+
229249
const parser = new XMLParser(options);
230250
// eslint-disable-next-line @typescript-eslint/no-unsafe-assignment
231251
const parseResult = parser.parse(fileContentAsBuffer);

integration/vscode/ada/src/gnattest.ts

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1207,12 +1207,10 @@ async function addCoverageData(run: vscode.TestRun, covDir: string) {
12071207
if (found.length == 0) continue;
12081208

12091209
const srcUri = found[0];
1210-
const total = Number.parseInt(
1211-
file.metric.find((m) => m['@_kind'] == 'total_lines_of_relevance')!['@_count'],
1212-
);
1213-
const covered = Number.parseInt(
1214-
file.metric.find((m) => m['@_kind'] == 'fully_covered')!['@_count'],
1215-
);
1210+
const total = file.metric.find((m) => m['@_kind'] == 'total_lines_of_relevance')![
1211+
'@_count'
1212+
];
1213+
const covered = file.metric.find((m) => m['@_kind'] == 'fully_covered')!['@_count'];
12161214

12171215
const fileReportBasename = data.coverage_report.sources!['xi:include'].find(
12181216
(inc) => inc['@_href'] == `${file['@_name']!}.xml`,

0 commit comments

Comments
 (0)