Skip to content

Commit 919ab70

Browse files
committed
added tests for integer value range checks and casts
1 parent 382845b commit 919ab70

1 file changed

Lines changed: 30 additions & 1 deletion

File tree

msgpack-core/src/test/scala/org/msgpack/value/ValueTest.scala

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.msgpack.value
1717

1818
import java.math.BigInteger
19-
2019
import org.msgpack.core._
2120

2221
import scala.util.parsing.json.JSON
@@ -97,5 +96,35 @@ class ValueTest extends MessagePackSpec
9796

9897
}
9998

99+
"check appropriate range for integers" in {
100+
import ValueFactory._
101+
import java.lang.Byte
102+
import java.lang.Short
103+
104+
newInteger(Byte.MAX_VALUE).asByte() shouldBe Byte.MAX_VALUE
105+
newInteger(Byte.MIN_VALUE).asByte() shouldBe Byte.MIN_VALUE
106+
newInteger(Short.MAX_VALUE).asShort() shouldBe Short.MAX_VALUE
107+
newInteger(Short.MIN_VALUE).asShort() shouldBe Short.MIN_VALUE
108+
newInteger(Integer.MAX_VALUE).asInt() shouldBe Integer.MAX_VALUE
109+
newInteger(Integer.MIN_VALUE).asInt() shouldBe Integer.MIN_VALUE
110+
intercept[MessageIntegerOverflowException] {
111+
newInteger(Byte.MAX_VALUE+1).asByte()
112+
}
113+
intercept[MessageIntegerOverflowException] {
114+
newInteger(Byte.MIN_VALUE-1).asByte()
115+
}
116+
intercept[MessageIntegerOverflowException] {
117+
newInteger(Short.MAX_VALUE+1).asShort()
118+
}
119+
intercept[MessageIntegerOverflowException] {
120+
newInteger(Short.MIN_VALUE-1).asShort()
121+
}
122+
intercept[MessageIntegerOverflowException] {
123+
newInteger(Integer.MAX_VALUE+1).asInt()
124+
}
125+
intercept[MessageIntegerOverflowException] {
126+
newInteger(Integer.MIN_VALUE-1).asInt()
127+
}
128+
}
100129
}
101130
}

0 commit comments

Comments
 (0)