@@ -6,129 +6,107 @@ import org.scalatest.matchers.should.Matchers
66class ChannelTryTest extends AnyFlatSpec with Matchers :
77 // trySend
88
9- " trySend" should " return true when there is space in the buffer" in {
9+ " trySend" should " return true when there is space in the buffer" in :
1010 val c = Channel .buffered[Int ](2 )
1111 c.trySend(1 ) shouldBe true
1212 c.trySend(2 ) shouldBe true
13- }
1413
15- it should " return false when the buffer is full" in {
14+ it should " return false when the buffer is full" in :
1615 val c = Channel .buffered[Int ](1 )
1716 c.trySend(1 ) shouldBe true
1817 c.trySend(2 ) shouldBe false
19- }
2018
21- it should " return true for an unlimited channel" in {
19+ it should " return true for an unlimited channel" in :
2220 val c = Channel .unlimited[Int ]
2321 c.trySend(1 ) shouldBe true
2422 c.trySend(2 ) shouldBe true
25- }
2623
27- it should " throw ChannelClosedException.Done when the channel is done" in {
24+ it should " throw ChannelClosedException.Done when the channel is done" in :
2825 val c = Channel .buffered[Int ](2 )
2926 c.done()
30- assertThrows[ChannelClosedException .Done ] {
27+ assertThrows[ChannelClosedException .Done ]:
3128 c.trySend(1 )
32- }
33- }
3429
35- it should " throw ChannelClosedException.Error when the channel is in error" in {
30+ it should " throw ChannelClosedException.Error when the channel is in error" in :
3631 val c = Channel .buffered[Int ](2 )
3732 c.error(new RuntimeException (" test" ))
38- assertThrows[ChannelClosedException .Error ] {
33+ assertThrows[ChannelClosedException .Error ]:
3934 c.trySend(1 )
40- }
41- }
4235
4336 // trySendOrClosed
4437
45- " trySendOrClosed" should " return true when there is space in the buffer" in {
38+ " trySendOrClosed" should " return true when there is space in the buffer" in :
4639 val c = Channel .buffered[Int ](2 )
4740 c.trySendOrClosed(1 ) shouldBe true
4841 c.trySendOrClosed(2 ) shouldBe true
49- }
5042
51- it should " return false when the buffer is full" in {
43+ it should " return false when the buffer is full" in :
5244 val c = Channel .buffered[Int ](1 )
5345 c.trySendOrClosed(1 ) shouldBe true
5446 c.trySendOrClosed(2 ) shouldBe false
55- }
5647
57- it should " return ChannelClosed.Done when the channel is done" in {
48+ it should " return ChannelClosed.Done when the channel is done" in :
5849 val c = Channel .buffered[Int ](2 )
5950 c.done()
6051 c.trySendOrClosed(1 ) shouldBe ChannelClosed .Done
61- }
6252
63- it should " return ChannelClosed.Error when the channel is in error" in {
53+ it should " return ChannelClosed.Error when the channel is in error" in :
6454 val c = Channel .buffered[Int ](2 )
6555 val ex = new RuntimeException (" test" )
6656 c.error(ex)
6757 c.trySendOrClosed(1 ) should matchPattern { case ChannelClosed .Error (_) => }
68- }
6958
7059 // tryReceive
7160
72- " tryReceive" should " return Some with the value when one is available" in {
61+ " tryReceive" should " return Some with the value when one is available" in :
7362 val c = Channel .buffered[Int ](2 )
7463 c.send(1 )
7564 c.send(2 )
7665 c.tryReceive() shouldBe Some (1 )
7766 c.tryReceive() shouldBe Some (2 )
78- }
7967
80- it should " return None when the buffer is empty" in {
68+ it should " return None when the buffer is empty" in :
8169 val c = Channel .buffered[Int ](2 )
8270 c.tryReceive() shouldBe None
83- }
8471
85- it should " throw ChannelClosedException.Done when the channel is done and empty" in {
72+ it should " throw ChannelClosedException.Done when the channel is done and empty" in :
8673 val c = Channel .buffered[Int ](2 )
8774 c.done()
88- assertThrows[ChannelClosedException .Done ] {
75+ assertThrows[ChannelClosedException .Done ]:
8976 c.tryReceive()
90- }
91- }
9277
93- it should " throw ChannelClosedException.Error when the channel is in error" in {
78+ it should " throw ChannelClosedException.Error when the channel is in error" in :
9479 val c = Channel .buffered[Int ](2 )
9580 c.send(1 )
9681 c.error(new RuntimeException (" test" ))
97- assertThrows[ChannelClosedException .Error ] {
82+ assertThrows[ChannelClosedException .Error ]:
9883 c.tryReceive()
99- }
100- }
10184
10285 // tryReceiveOrClosed
10386
104- " tryReceiveOrClosed" should " return Some with the value when one is available" in {
87+ " tryReceiveOrClosed" should " return Some with the value when one is available" in :
10588 val c = Channel .buffered[Int ](2 )
10689 c.send(1 )
10790 c.tryReceiveOrClosed() shouldBe Some (1 )
108- }
10991
110- it should " return None when the buffer is empty" in {
92+ it should " return None when the buffer is empty" in :
11193 val c = Channel .buffered[Int ](2 )
11294 c.tryReceiveOrClosed() shouldBe None
113- }
11495
115- it should " return ChannelClosed.Done when the channel is done and empty" in {
96+ it should " return ChannelClosed.Done when the channel is done and empty" in :
11697 val c = Channel .buffered[Int ](2 )
11798 c.done()
11899 c.tryReceiveOrClosed() shouldBe ChannelClosed .Done
119- }
120100
121- it should " return ChannelClosed.Error when the channel is in error" in {
101+ it should " return ChannelClosed.Error when the channel is in error" in :
122102 val c = Channel .buffered[Int ](2 )
123103 c.send(1 )
124104 c.error(new RuntimeException (" test" ))
125105 c.tryReceiveOrClosed() should matchPattern { case ChannelClosed .Error (_) => }
126- }
127106
128- it should " return Some(value) from a done channel that still has buffered values" in {
107+ it should " return Some(value) from a done channel that still has buffered values" in :
129108 val c = Channel .buffered[Int ](2 )
130109 c.send(42 )
131110 c.done()
132111 c.tryReceiveOrClosed() shouldBe Some (42 )
133- }
134112end ChannelTryTest
0 commit comments