Skip to content

Commit b8368dd

Browse files
authored
Fix for Scala 2.13 syntax (#577)
1 parent fc791f1 commit b8368dd

File tree

11 files changed

+175
-135
lines changed

11 files changed

+175
-135
lines changed

msgpack-core/src/test/scala/org/msgpack/core/InvalidDataReadTest.scala

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ import org.msgpack.core.MessagePackSpec.createMessagePackData
44
import wvlet.airspec.AirSpec
55

66
/**
7-
*
87
*/
98
class InvalidDataReadTest extends AirSpec {
109

msgpack-core/src/test/scala/org/msgpack/core/MessageFormatTest.scala

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ import scala.util.Random
2828
class MessageFormatTest extends AirSpec with Benchmark {
2929
test("MessageFormat") {
3030
test("cover all byte codes") {
31-
def checkV(b: Byte, tpe: ValueType) {
31+
def checkV(b: Byte, tpe: ValueType): Unit = {
3232
try MessageFormat.valueOf(b).getValueType shouldBe tpe
3333
catch {
3434
case e: AirSpecException =>
@@ -37,11 +37,11 @@ class MessageFormatTest extends AirSpec with Benchmark {
3737
}
3838
}
3939

40-
def checkF(b: Byte, f: MessageFormat) {
40+
def checkF(b: Byte, f: MessageFormat): Unit = {
4141
MessageFormat.valueOf(b) shouldBe f
4242
}
4343

44-
def check(b: Byte, tpe: ValueType, f: MessageFormat) {
44+
def check(b: Byte, tpe: ValueType, f: MessageFormat): Unit = {
4545
checkV(b, tpe)
4646
checkF(b, f)
4747
}

msgpack-core/src/test/scala/org/msgpack/core/MessagePackTest.scala

Lines changed: 114 additions & 75 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
8282
Code.isPosFixInt(i.toByte) shouldBe true
8383
}
8484

85-
for (i <- 0x80 until 0xFF) {
85+
for (i <- 0x80 until 0xff) {
8686
Code.isPosFixInt(i.toByte) shouldBe false
8787
}
8888
}
@@ -166,7 +166,7 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
166166
Code.isNegFixInt(i.toByte) shouldBe false
167167
}
168168

169-
for (i <- 0xe0 until 0xFF) {
169+
for (i <- 0xe0 until 0xff) {
170170
Code.isNegFixInt(i.toByte) shouldBe true
171171
}
172172

@@ -223,7 +223,7 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
223223
fail("cannot not reach here")
224224
}
225225

226-
private def checkOverflow[A](v: A, pack: MessagePacker => Unit, unpack: MessageUnpacker => A) {
226+
private def checkOverflow[A](v: A, pack: MessagePacker => Unit, unpack: MessageUnpacker => A): Unit = {
227227
try {
228228
checkException[A](v, pack, unpack)
229229
} catch {
@@ -253,63 +253,80 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
253253
forAll { (v: Double) =>
254254
check(v, _.packDouble(v), _.unpackDouble)
255255
}
256-
check(null, _.packNil, { unpacker =>
257-
unpacker.unpackNil(); null
258-
})
256+
check(
257+
null,
258+
_.packNil,
259+
{ unpacker =>
260+
unpacker.unpackNil(); null
261+
}
262+
)
259263
}
260264

261265
test("skipping a nil value") {
262266
check(true, _.packNil, _.tryUnpackNil)
263-
check(false, { packer =>
264-
packer.packString("val")
265-
}, { unpacker =>
266-
unpacker.tryUnpackNil()
267-
})
268-
check("val", { packer =>
269-
packer.packString("val")
270-
}, { unpacker =>
271-
unpacker.tryUnpackNil(); unpacker.unpackString()
272-
})
273-
check("val", { packer =>
274-
packer.packNil(); packer.packString("val")
275-
}, { unpacker =>
276-
unpacker.tryUnpackNil(); unpacker.unpackString()
277-
})
267+
check(
268+
false,
269+
{ packer =>
270+
packer.packString("val")
271+
},
272+
{ unpacker =>
273+
unpacker.tryUnpackNil()
274+
}
275+
)
276+
check(
277+
"val",
278+
{ packer =>
279+
packer.packString("val")
280+
},
281+
{ unpacker =>
282+
unpacker.tryUnpackNil(); unpacker.unpackString()
283+
}
284+
)
285+
check(
286+
"val",
287+
{ packer =>
288+
packer.packNil(); packer.packString("val")
289+
},
290+
{ unpacker =>
291+
unpacker.tryUnpackNil(); unpacker.unpackString()
292+
}
293+
)
278294
try {
279-
checkException(null, { _ =>
280-
}, _.tryUnpackNil)
295+
checkException(null, { _ => }, _.tryUnpackNil)
281296
} catch {
282297
case e: MessageInsufficientBufferException => // OK
283298
}
284299
}
285300

286301
test("pack/unpack integer values") {
287-
val sampleData = Seq[Long](Int.MinValue.toLong -
288-
10,
289-
-65535,
290-
-8191,
291-
-1024,
292-
-255,
293-
-127,
294-
-63,
295-
-31,
296-
-15,
297-
-7,
298-
-3,
299-
-1,
300-
0,
301-
2,
302-
4,
303-
8,
304-
16,
305-
32,
306-
64,
307-
128,
308-
256,
309-
1024,
310-
8192,
311-
65536,
312-
Int.MaxValue.toLong + 10)
302+
val sampleData = Seq[Long](
303+
Int.MinValue.toLong -
304+
10,
305+
-65535,
306+
-8191,
307+
-1024,
308+
-255,
309+
-127,
310+
-63,
311+
-31,
312+
-15,
313+
-7,
314+
-3,
315+
-1,
316+
0,
317+
2,
318+
4,
319+
8,
320+
16,
321+
32,
322+
64,
323+
128,
324+
256,
325+
1024,
326+
8192,
327+
65536,
328+
Int.MaxValue.toLong + 10
329+
)
313330
for (v <- sampleData) {
314331
check(v, _.packLong(v), _.unpackLong)
315332

@@ -399,10 +416,14 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
399416
}
400417

401418
try {
402-
checkException(malformed, { packer =>
403-
packer.packRawStringHeader(malformedBytes.length)
404-
packer.writePayload(malformedBytes)
405-
}, _.unpackString())
419+
checkException(
420+
malformed,
421+
{ packer =>
422+
packer.packRawStringHeader(malformedBytes.length)
423+
packer.writePayload(malformedBytes)
424+
},
425+
_.unpackString()
426+
)
406427
} catch {
407428
case e: MessageStringCodingException => // OK
408429
}
@@ -421,10 +442,16 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
421442

422443
for (bytes <- Seq(unmappable)) {
423444
try {
424-
checkException(bytes, { packer =>
425-
packer.packRawStringHeader(bytes.length)
426-
packer.writePayload(bytes)
427-
}, _.unpackString(), new PackerConfig(), unpackerConfig)
445+
checkException(
446+
bytes,
447+
{ packer =>
448+
packer.packRawStringHeader(bytes.length)
449+
packer.writePayload(bytes)
450+
},
451+
_.unpackString(),
452+
new PackerConfig(),
453+
unpackerConfig
454+
)
428455
} catch {
429456
case e: MessageStringCodingException => // OK
430457
}
@@ -434,9 +461,11 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
434461
test("pack/unpack binary") {
435462
forAll { (v: Array[Byte]) =>
436463
check(
437-
v, { packer =>
464+
v,
465+
{ packer =>
438466
packer.packBinaryHeader(v.length); packer.writePayload(v)
439-
}, { unpacker =>
467+
},
468+
{ unpacker =>
440469
val len = unpacker.unpackBinaryHeader()
441470
val out = new Array[Byte](len)
442471
unpacker.readPayload(out, 0, len)
@@ -450,9 +479,11 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
450479
val v = new Array[Byte](l)
451480
Random.nextBytes(v)
452481
check(
453-
v, { packer =>
482+
v,
483+
{ packer =>
454484
packer.packBinaryHeader(v.length); packer.writePayload(v)
455-
}, { unpacker =>
485+
},
486+
{ unpacker =>
456487
val len = unpacker.unpackBinaryHeader()
457488
val out = new Array[Byte](len)
458489
unpacker.readPayload(out, 0, len)
@@ -467,10 +498,12 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
467498
test("pack/unpack arrays") {
468499
forAll { (v: Array[Int]) =>
469500
check(
470-
v, { packer =>
501+
v,
502+
{ packer =>
471503
packer.packArrayHeader(v.length)
472504
v.map(packer.packInt(_))
473-
}, { unpacker =>
505+
},
506+
{ unpacker =>
474507
val len = unpacker.unpackArrayHeader()
475508
val out = new Array[Int](len)
476509
for (i <- 0 until v.length) {
@@ -498,20 +531,22 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
498531
val m = v.map(i => (i, i.toString)).toSeq
499532

500533
check(
501-
m, { packer =>
534+
m,
535+
{ packer =>
502536
packer.packMapHeader(v.length)
503537
m.map {
504538
case (k: Int, v: String) =>
505539
packer.packInt(k)
506540
packer.packString(v)
507541
}
508-
}, { unpacker =>
542+
},
543+
{ unpacker =>
509544
val len = unpacker.unpackMapHeader()
510545
val b = Seq.newBuilder[(Int, String)]
511546
for (i <- 0 until len) {
512547
b += ((unpacker.unpackInt, unpacker.unpackString))
513548
}
514-
b.result
549+
b.result()
515550
}
516551
)
517552
}
@@ -549,7 +584,8 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
549584
val aMap = List(Map("f" -> "x"))
550585

551586
check(
552-
aMap, { packer =>
587+
aMap,
588+
{ packer =>
553589
packer.packArrayHeader(aMap.size)
554590
for (m <- aMap) {
555591
packer.packMapHeader(m.size)
@@ -558,10 +594,11 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
558594
packer.packString(v)
559595
}
560596
}
561-
}, { unpacker =>
597+
},
598+
{ unpacker =>
562599
val v = new Variable()
563600
unpacker.unpackValue(v)
564-
import scala.collection.JavaConverters._
601+
import scala.jdk.CollectionConverters._
565602
v.asArrayValue().asScala
566603
.map { m =>
567604
val mv = m.asMapValue()
@@ -605,12 +642,14 @@ class MessagePackTest extends AirSpec with PropertyCheck with Benchmark {
605642
}
606643

607644
// Corner-cases around uint32 boundaries
608-
for (v <- Seq(
609-
Instant.ofEpochSecond(Instant.now().getEpochSecond, 123456789L), // uint32 nanoseq (out of int32 range)
610-
Instant.ofEpochSecond(-1302749144L, 0), // 1928-09-19T21:14:16Z
611-
Instant.ofEpochSecond(-747359729L, 0), // 1946-04-27T00:04:31Z
612-
Instant.ofEpochSecond(4257387427L, 0) // 2104-11-29T07:37:07Z
613-
)) {
645+
for (
646+
v <- Seq(
647+
Instant.ofEpochSecond(Instant.now().getEpochSecond, 123456789L), // uint32 nanoseq (out of int32 range)
648+
Instant.ofEpochSecond(-1302749144L, 0), // 1928-09-19T21:14:16Z
649+
Instant.ofEpochSecond(-747359729L, 0), // 1946-04-27T00:04:31Z
650+
Instant.ofEpochSecond(4257387427L, 0) // 2104-11-29T07:37:07Z
651+
)
652+
) {
614653
check(v, _.packTimestamp(v), _.unpackTimestamp())
615654
}
616655
}

msgpack-core/src/test/scala/org/msgpack/core/MessagePackerTest.scala

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -25,17 +25,16 @@ import java.io.{ByteArrayOutputStream, File, FileInputStream, FileOutputStream}
2525
import scala.util.Random
2626

2727
/**
28-
*
2928
*/
3029
class MessagePackerTest extends AirSpec with Benchmark {
3130

32-
private def verifyIntSeq(answer: Array[Int], packed: Array[Byte]) {
31+
private def verifyIntSeq(answer: Array[Int], packed: Array[Byte]): Unit = {
3332
val unpacker = MessagePack.newDefaultUnpacker(packed)
3433
val b = Array.newBuilder[Int]
3534
while (unpacker.hasNext) {
3635
b += unpacker.unpackInt()
3736
}
38-
val result = b.result
37+
val result = b.result()
3938
result.size shouldBe answer.size
4039
result shouldBe answer
4140
}
@@ -61,7 +60,7 @@ class MessagePackerTest extends AirSpec with Benchmark {
6160
test("MessagePacker") {
6261

6362
test("reset the internal states") {
64-
val intSeq = (0 until 100).map(i => Random.nextInt).toArray
63+
val intSeq = (0 until 100).map(i => Random.nextInt()).toArray
6564

6665
val b = new ByteArrayOutputStream
6766
val packer = MessagePack.newDefaultPacker(b)
@@ -239,12 +238,12 @@ class MessagePackerTest extends AirSpec with Benchmark {
239238
val packerTotalWrittenBytes =
240239
withResource(MessagePack.newDefaultPacker(out)) { packer =>
241240
packer
242-
.packByte(0) // 1
243-
.packBoolean(true) // 1
244-
.packShort(12) // 1
245-
.packInt(1024) // 3
241+
.packByte(0) // 1
242+
.packBoolean(true) // 1
243+
.packShort(12) // 1
244+
.packInt(1024) // 3
246245
.packLong(Long.MaxValue) // 5
247-
.packString("foobar") // 7
246+
.packString("foobar") // 7
248247
.flush()
249248

250249
packer.getTotalWrittenBytes

0 commit comments

Comments
 (0)