-
Notifications
You must be signed in to change notification settings - Fork 5
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Migrate tests to MUnit + other improvements #210
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
e1937e5
Migrate metarpheus to munit
gabro b2ca485
Use Scala.js 1.0
gabro 93afeec
Migrate enumero to munit
gabro 0a14c7a
Migrate toctoc to munit
gabro de91c7b
Migrate mailo to munit
gabro 9d94c95
Resolve all mailo warnings
gabro 5dcef68
Update dependencies
gabro 57bc7fa
New sbt and scala version
gabro e2e37e4
Shutdown actor system in mailo tests
gabro 66c0566
Update akka deps
gabro aea31ff
Fix mailo test
gabro File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,66 +1,61 @@ | ||
import io.buildo.enumero._ | ||
import scala.language.reflectiveCalls | ||
|
||
import org.scalatest.{Matchers, WordSpec} | ||
|
||
class CaseEnumIndexSpec extends WordSpec with Matchers { | ||
class CaseEnumIndexSuite extends munit.FunSuite { | ||
sealed trait Planet extends IndexedCaseEnum { type Index = Int } | ||
object Planet { | ||
case object Mercury extends Planet { val index = 1 } | ||
case object Venus extends Planet { val index = 2 } | ||
case object Earth extends Planet { val index = 3 } | ||
} | ||
|
||
"CaseEnumIndexMacro" should { | ||
"construct a sensible CaseEnumIndex" in { | ||
val converter = CaseEnumIndex.caseEnumIndex[Planet] | ||
test("CaseEnumIndexMacro should construct a sensible CaseEnumIndex") { | ||
val converter = CaseEnumIndex.caseEnumIndex[Planet] | ||
|
||
val pairs = List(Planet.Mercury -> 1, Planet.Venus -> 2, Planet.Earth -> 3) | ||
val pairs = List(Planet.Mercury -> 1, Planet.Venus -> 2, Planet.Earth -> 3) | ||
|
||
for ((co, index) <- pairs) { | ||
converter.caseToIndex(co).shouldBe(index) | ||
converter.caseFromIndex(index).shouldBe(Some(co)) | ||
} | ||
for ((co, index) <- pairs) { | ||
assertEquals(converter.caseToIndex(co), index) | ||
assertEquals(converter.caseFromIndex(index), Some(co)) | ||
} | ||
} | ||
|
||
"CaseEnumIndex" should { | ||
"provide the typeclass instance" in { | ||
trait FakeBinaryPickler[T] { | ||
def pickle(c: T)(picklerState: { def writeInt(int: Int) }): Unit | ||
def unpickle(unpicklerState: { def getInt(): Int }): Option[T] | ||
} | ||
test("CaseEnumIndex should provide the typeclass instance") { | ||
trait FakeBinaryPickler[T] { | ||
def pickle(c: T)(picklerState: { def writeInt(int: Int): Unit }): Unit | ||
def unpickle(unpicklerState: { def getInt(): Int }): Option[T] | ||
} | ||
|
||
implicit def fakeBinaryPickler[T <: IndexedCaseEnum { type Index = Int }]( | ||
implicit instance: CaseEnumIndex[T] | ||
) = new FakeBinaryPickler[T] { | ||
implicit def fakeBinaryPickler[T <: IndexedCaseEnum { type Index = Int }]( | ||
implicit instance: CaseEnumIndex[T], | ||
) = new FakeBinaryPickler[T] { | ||
|
||
def pickle(c: T)(picklerState: { def writeInt(int: Int) }): Unit = { | ||
picklerState.writeInt(instance.caseToIndex(c)) | ||
} | ||
def unpickle(unpicklerState: { def getInt(): Int }): Option[T] = { | ||
instance.caseFromIndex(unpicklerState.getInt()) | ||
} | ||
def pickle(c: T)(picklerState: { def writeInt(int: Int): Unit }): Unit = { | ||
picklerState.writeInt(instance.caseToIndex(c)) | ||
} | ||
|
||
object picklerState { | ||
var value: Int = 0 | ||
def writeInt(int: Int): Unit = { | ||
value = int | ||
} | ||
def unpickle(unpicklerState: { def getInt(): Int }): Option[T] = { | ||
instance.caseFromIndex(unpicklerState.getInt()) | ||
} | ||
val binaryPickler = implicitly[FakeBinaryPickler[Planet]] | ||
binaryPickler.pickle(Planet.Venus)(picklerState) | ||
picklerState.value.shouldBe(2) | ||
} | ||
|
||
object unpicklerState { | ||
def getInt(): Int = 3 | ||
object picklerState { | ||
var value: Int = 0 | ||
def writeInt(int: Int): Unit = { | ||
value = int | ||
} | ||
binaryPickler.unpickle(unpicklerState).shouldBe(Some(Planet.Earth)) | ||
} | ||
val binaryPickler = implicitly[FakeBinaryPickler[Planet]] | ||
binaryPickler.pickle(Planet.Venus)(picklerState) | ||
assertEquals(picklerState.value, 2) | ||
|
||
"retrieve a typeclass instance using apply" in { | ||
CaseEnumIndex[Planet].caseFromIndex(1) shouldBe Some(Planet.Mercury) | ||
object unpicklerState { | ||
def getInt(): Int = 3 | ||
} | ||
assertEquals(binaryPickler.unpickle(unpicklerState), Some(Planet.Earth)) | ||
} | ||
|
||
test("CaseEnumIndex should retrieve a typeclass instance using apply") { | ||
assertEquals(CaseEnumIndex[Planet].caseFromIndex(1), Some(Planet.Mercury)) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we lost an assertion here (Beer.Ale)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it was intentional, when I tried to rewrite the assertion it wouldn't even compile ("fruitless type test") and it's such an obvious test that I preferred to drop it.