Skip to content

Commit

Permalink
Merge pull request #479 from codacy/big-int-fix
Browse files Browse the repository at this point in the history
fix: Use `BigInt` instead of `Long` in `toIntOrMaxValue` TS-549
  • Loading branch information
lolgab authored Nov 8, 2023
2 parents 3cca982 + 15df687 commit 2f2561b
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,9 @@ object CoberturaParser extends CoverageParser with XmlReportParser {
} {
val key = (line \@ "number").toInt
val value = (line \@ "hits").toIntOrMaxValue
val sum = map.get(key).getOrElse(0) + BigInt(value)

map(key) = map.get(key).getOrElse(0) + value
map(key) = sum.toIntOrMaxValue
}

CoverageFileReport(sourceFilename, fileHit, map.toMap)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@ object MathUtils {
}

implicit class ParseIntOps(val s: String) extends AnyVal {
def toIntOrMaxValue: Int = BigInt(s).toIntOrMaxValue
}

implicit class BigIntOps(val bigInt: BigInt) extends AnyVal {

def toIntOrMaxValue: Int = {
val long = s.toLong
if (long > Int.MaxValue) Int.MaxValue
else long.toInt
}
def toIntOrMaxValue: Int =
if (bigInt.isValidInt) bigInt.toInt
else Int.MaxValue
}
}
1 change: 1 addition & 0 deletions coverage-parser/src/test/resources/test_cobertura.xml
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<line number="7" hits="0"/>
<line number="8" hits="1"/>
<line number="8" hits="2"/>
<line number="9" hits="9999999999999999"/>
</lines>
</class>
<class line-rate="0.87" name="TestSourceFile" filename="coverage-parser/src/test/resources/TestSourceFile.scala">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ class CoberturaParserTest extends WordSpec with BeforeAndAfterAll with Matchers
CoverageFileReport(
"coverage-parser/src/test/resources/TestSourceFile.scala",
87,
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1, 7 -> 1, 8 -> 3)
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> Int.MaxValue, 3 -> 0, 4 -> 1, 7 -> 1, 8 -> 3)
)
)
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class CoverageParserFactoryTest extends WordSpec with BeforeAndAfterAll with Mat
CoverageFileReport(
"coverage-parser/src/test/resources/TestSourceFile.scala",
87,
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1, 7 -> 1, 8 -> 3)
Map(5 -> 1, 10 -> 1, 6 -> 2, 9 -> 1, 3 -> 0, 4 -> 1, 7 -> 1, 8 -> 3, 9 -> Int.MaxValue)
)
)
)
Expand Down

0 comments on commit 2f2561b

Please sign in to comment.