Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Use AirSpec for integration with ScalaCheck
  • Loading branch information
xerial committed May 12, 2021
commit d8bb62d12ad97395df3925290ae3ed775f933578
15 changes: 9 additions & 6 deletions build.sbt
Original file line number Diff line number Diff line change
Expand Up @@ -71,15 +71,18 @@ lazy val msgpackCore = Project(id = "msgpack-core", base = file("msgpack-core"))
"org.msgpack.value",
"org.msgpack.value.impl"
),
testFrameworks += new TestFramework("wvlet.airspec.Framework"),
libraryDependencies ++= Seq(
// msgpack-core should have no external dependencies
junitInterface,
"org.scalatest" %% "scalatest" % "3.2.8" % "test",
"org.scalacheck" %% "scalacheck" % "1.15.4" % "test",
"org.xerial" %% "xerial-core" % "3.6.0" % "test",
"org.msgpack" % "msgpack" % "0.6.12" % "test",
"commons-codec" % "commons-codec" % "1.12" % "test",
"com.typesafe.akka" %% "akka-actor" % "2.5.23" % "test"
"org.scalatest" %% "scalatest" % "3.2.8" % "test",
"org.scalacheck" %% "scalacheck" % "1.15.4" % "test",
"org.xerial" %% "xerial-core" % "3.6.0" % "test",
"org.msgpack" % "msgpack" % "0.6.12" % "test",
"commons-codec" % "commons-codec" % "1.12" % "test",
"com.typesafe.akka" %% "akka-actor" % "2.5.23" % "test",
"org.wvlet.airframe" %% "airspec" % "20.4.1" % "test",
"org.scala-lang.modules" %% "scala-collection-compat" % "2.4.3" % "test"
)
)

Expand Down
6 changes: 6 additions & 0 deletions msgpack-core/src/main/java/org/msgpack/value/ValueType.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ public enum ValueType
MAP(false, false),
EXTENSION(false, false);

/**
* Design note: We do not add Timestamp as a ValueType here because
* detecting Timestamp values requires reading 1-3 bytes ahead while the other
* value types can be determined just by reading the first one byte.
*/

private final boolean numberType;
private final boolean rawType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package org.msgpack.core
import java.io.ByteArrayOutputStream
import org.scalatest._
import org.scalatest.matchers.should.Matchers
import org.scalatest.prop.TableDrivenPropertyChecks
import org.scalatest.wordspec.AnyWordSpec
import xerial.core.log.{LogLevel, Logger}
import xerial.core.util.{TimeReport, Timer}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,9 @@ class MessagePackTest extends MessagePackSpec {
check(v, _.packTimestamp(second, nano), _.unpackTimestamp())
}

// Corner cases for u
// sign uint32 nanoseq (out of int32 range)
// Corner-cases around uint32 boundaries
for (v <- Seq(
Instant.ofEpochSecond(Instant.now().getEpochSecond, 123456789L),
Instant.ofEpochSecond(Instant.now().getEpochSecond, 123456789L), // uint32 nanoseq (out of int32 range)
Instant.ofEpochSecond(-1302749144L, 0), // 1928-09-19T21:14:16Z
Instant.ofEpochSecond(-747359729L, 0), // 1946-04-27T00:04:31Z
Instant.ofEpochSecond(4257387427L, 0) // 2104-11-29T07:37:07Z
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,28 +15,28 @@
//
package org.msgpack.value

import org.msgpack.core.MessagePackSpec
import org.scalacheck.Prop.forAll
import wvlet.airspec.AirSpec
import wvlet.airspec.spi.PropertyCheck

/**
*
*/
class ValueFactoryTest extends MessagePackSpec {
class ValueFactoryTest extends AirSpec with PropertyCheck {

def isValid(v: Value,
expected: ValueType,
isNil: Boolean = false,
isBoolean: Boolean = false,
isInteger: Boolean = false,
isString: Boolean = false,
isFloat: Boolean = false,
isBinary: Boolean = false,
isArray: Boolean = false,
isMap: Boolean = false,
isExtension: Boolean = false,
isRaw: Boolean = false,
isNumber: Boolean = false,
isTimestamp: Boolean = false): Boolean = {
private def isValid(v: Value,
expected: ValueType,
isNil: Boolean = false,
isBoolean: Boolean = false,
isInteger: Boolean = false,
isString: Boolean = false,
isFloat: Boolean = false,
isBinary: Boolean = false,
isArray: Boolean = false,
isMap: Boolean = false,
isExtension: Boolean = false,
isRaw: Boolean = false,
isNumber: Boolean = false,
isTimestamp: Boolean = false): Boolean = {
v.isNilValue shouldBe isNil
v.isBooleanValue shouldBe isBoolean
v.isIntegerValue shouldBe isInteger
Expand All @@ -52,9 +52,8 @@ class ValueFactoryTest extends MessagePackSpec {
true
}

"ValueFactory" should {

"create valid type values" in {
test("ValueFactory") {
test("create valid type values") {
isValid(ValueFactory.newNil(), expected = ValueType.NIL, isNil = true)
forAll { (v: Boolean) =>
isValid(ValueFactory.newBoolean(v), expected = ValueType.BOOLEAN, isBoolean = true)
Expand All @@ -79,6 +78,12 @@ class ValueFactoryTest extends MessagePackSpec {
forAll { (millis: Long) =>
isValid(ValueFactory.newTimestamp(millis), expected = ValueType.EXTENSION, isExtension = true, isTimestamp = true)
}
forAll { (millis: Long) =>
isValid(ValueFactory.newTimestamp(millis), expected = ValueType.EXTENSION, isExtension = true, isTimestamp = true)
}
forAll { (sec: Long, nano: Int) =>
isValid(ValueFactory.newTimestamp(sec, nano), expected = ValueType.EXTENSION, isExtension = true, isTimestamp = true)
}
}
}
}
Loading