Skip to content
Merged
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
Fix ValueFactoryTest
  • Loading branch information
xerial committed May 12, 2021
commit 28c7843b3aa737f5975b0ece142d9bdfbdcf2b2f
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
//
package org.msgpack.value

import org.scalacheck.Gen
import wvlet.airspec.AirSpec
import wvlet.airspec.spi.PropertyCheck

Expand Down Expand Up @@ -53,35 +54,63 @@ class ValueFactoryTest extends AirSpec with PropertyCheck {
}

test("ValueFactory") {
test("create valid type values") {
test("nil") {
isValid(ValueFactory.newNil(), expected = ValueType.NIL, isNil = true)
}

test("boolean") {
forAll { (v: Boolean) =>
isValid(ValueFactory.newBoolean(v), expected = ValueType.BOOLEAN, isBoolean = true)
}
}

test("int") {
forAll { (v: Int) =>
isValid(ValueFactory.newInteger(v), expected = ValueType.INTEGER, isInteger = true, isNumber = true)
}
}

test("float") {
forAll { (v: Float) =>
isValid(ValueFactory.newFloat(v), expected = ValueType.FLOAT, isFloat = true, isNumber = true)
}
}
test("string") {
forAll { (v: String) =>
isValid(ValueFactory.newString(v), expected = ValueType.STRING, isString = true, isRaw = true)
}
}

test("array") {
forAll { (v: Array[Byte]) =>
isValid(ValueFactory.newBinary(v), expected = ValueType.BINARY, isBinary = true, isRaw = true)
}
}

test("empty array") {
isValid(ValueFactory.emptyArray(), expected = ValueType.ARRAY, isArray = true)
}

test("empty map") {
isValid(ValueFactory.emptyMap(), expected = ValueType.MAP, isMap = true)
}

test("ext") {
forAll { (v: Array[Byte]) =>
isValid(ValueFactory.newExtension(0, v), expected = ValueType.EXTENSION, isExtension = true, isRaw = false)
}
}

test("timestamp") {
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) =>
}

test("timestamp sec/nano") {
val posLong = Gen.chooseNum[Long](-31557014167219200L, 31556889864403199L)
val posInt = Gen.chooseNum(0, 1000000000 - 1) // NANOS_PER_SECOND
forAll(posLong, posInt) { (sec: Long, nano: Int) =>
isValid(ValueFactory.newTimestamp(sec, nano), expected = ValueType.EXTENSION, isExtension = true, isTimestamp = true)
}
}
Expand Down