Skip to content

Commit 2f2561b

Browse files
authored
Merge pull request #479 from codacy/big-int-fix
fix: Use `BigInt` instead of `Long` in `toIntOrMaxValue` TS-549
2 parents 3cca982 + 15df687 commit 2f2561b

File tree

5 files changed

+12
-8
lines changed

5 files changed

+12
-8
lines changed

coverage-parser/src/main/scala/com/codacy/parsers/implementation/CoberturaParser.scala

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,9 @@ object CoberturaParser extends CoverageParser with XmlReportParser {
5959
} {
6060
val key = (line \@ "number").toInt
6161
val value = (line \@ "hits").toIntOrMaxValue
62+
val sum = map.get(key).getOrElse(0) + BigInt(value)
6263

63-
map(key) = map.get(key).getOrElse(0) + value
64+
map(key) = sum.toIntOrMaxValue
6465
}
6566

6667
CoverageFileReport(sourceFilename, fileHit, map.toMap)

coverage-parser/src/main/scala/com/codacy/parsers/util/MathUtils.scala

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,13 @@ object MathUtils {
77
}
88

99
implicit class ParseIntOps(val s: String) extends AnyVal {
10+
def toIntOrMaxValue: Int = BigInt(s).toIntOrMaxValue
11+
}
12+
13+
implicit class BigIntOps(val bigInt: BigInt) extends AnyVal {
1014

11-
def toIntOrMaxValue: Int = {
12-
val long = s.toLong
13-
if (long > Int.MaxValue) Int.MaxValue
14-
else long.toInt
15-
}
15+
def toIntOrMaxValue: Int =
16+
if (bigInt.isValidInt) bigInt.toInt
17+
else Int.MaxValue
1618
}
1719
}

coverage-parser/src/test/resources/test_cobertura.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
<line number="7" hits="0"/>
1414
<line number="8" hits="1"/>
1515
<line number="8" hits="2"/>
16+
<line number="9" hits="9999999999999999"/>
1617
</lines>
1718
</class>
1819
<class line-rate="0.87" name="TestSourceFile" filename="coverage-parser/src/test/resources/TestSourceFile.scala">

coverage-parser/src/test/scala/com/codacy/parsers/CoberturaParserTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ class CoberturaParserTest extends WordSpec with BeforeAndAfterAll with Matchers
3636
CoverageFileReport(
3737
"coverage-parser/src/test/resources/TestSourceFile.scala",
3838
87,
39-
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1, 7 -> 1, 8 -> 3)
39+
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> Int.MaxValue, 3 -> 0, 4 -> 1, 7 -> 1, 8 -> 3)
4040
)
4141
)
4242
)

coverage-parser/src/test/scala/com/codacy/parsers/CoverageParserFactoryTest.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ class CoverageParserFactoryTest extends WordSpec with BeforeAndAfterAll with Mat
2121
CoverageFileReport(
2222
"coverage-parser/src/test/resources/TestSourceFile.scala",
2323
87,
24-
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1, 7 -> 1, 8 -> 3)
24+
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1, 7 -> 1, 8 -> 3, 9 -> Int.MaxValue)
2525
)
2626
)
2727
)

0 commit comments

Comments
 (0)