I'm just getting started with Scala, and I'm wondering which language feature allows you to do this:
"PersistentQueue" should {
"add and remove one item" in {
withTempFolder {
val q = new PersistentQueue(folderName, "work", Config.fromMap(Map.empty))
q.setup
q.length mustEqual 0
q.totalItems mustEqual 0
q.bytes mustEqual 0
q.journalSize mustEqual 0
q.add("hello kitty".getBytes)
q.length mustEqual 1
q.totalItems mustEqual 1
q.bytes mustEqual 11
q.journalSize mustEqual 32
new String(q.remove.get.data) mustEqual "hello kitty"
q.length mustEqual 0
q.totalItems mustEqual 1
q.bytes mustEqual 0
q.journalSize mustEqual 33
q.close
dumpJournal("work") mustEqual "add(11:0:hello kitty), remove"
}
}
}
That's from the unit tests for Kestrel.
What's going on here? Does "PersistentQueue" should
mean that the Scala string class has been extended with a "should" method, or is something else happening here? I had a quick look through the Scala documentation but couldn't see which language features are being used for this code sample.
It looks like implicit methods being added to the String class to me. This post has a demonstration.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With