Skip to content

Commit e9d4255

Browse files
committed
Scala 3 support!
1 parent 5293740 commit e9d4255

File tree

15 files changed

+190
-197
lines changed

15 files changed

+190
-197
lines changed

.github/workflows/ci.yml

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,10 @@ jobs:
1212
strategy:
1313
matrix:
1414
include:
15-
- java: 8
15+
- java: 14
1616
scala: 2.13.6
17+
- java: 8
18+
scala: 3.0.1
1719

1820
steps:
1921
- name: Git checkout
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package teststate.dsl
2+
3+
trait HasErrorString {
4+
def errorString: String
5+
}
6+
7+
object HasErrorString {
8+
implicit def formatHasErrorString(e: HasErrorString): String =
9+
e.errorString
10+
}

core/shared/src/main/scala/teststate/dsl/package.scala

-12
This file was deleted.

core/shared/src/test/scala/teststate/ActionTest.scala

+5-5
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@ import utest._
99

1010
object ActionTest extends TestSuite {
1111

12-
val * = Dsl[Unit, Unit, Unit]
12+
val dsl = Dsl[Unit, Unit, Unit]
1313

14-
val a1 = *.action("A1")(_ => ())
15-
val a2 = *.action("A2")(_ => ())
16-
val a3 = *.action("A3")(_ => ())
17-
val c1 = *.chooseAction("C1")(_ => a1)
14+
val a1 = dsl.action("A1")(_ => ())
15+
val a2 = dsl.action("A2")(_ => ())
16+
val a3 = dsl.action("A3")(_ => ())
17+
val c1 = dsl.chooseAction("C1")(_ => a1)
1818
val g1 = (a1 >> a2).group("G1")
1919

2020
override def tests = Tests {

core/shared/src/test/scala/teststate/CompositionTest.scala

+4-4
Original file line numberDiff line numberDiff line change
@@ -4,23 +4,23 @@ import cats.instances.string._
44
import nyaya.prop._
55
import nyaya.test.PropTest._
66
import teststate.Exports._
7-
import teststate.RandomData.*
87
import teststate.TestUtil._
98
import teststate.typeclass.PolyComposable
109
import teststate.typeclass.PolyComposable.{Can, SeqOp}
1110
import utest._
1211

1312
object CompositionTest extends TestSuite {
13+
import teststate.RandomData.dsl
1414

1515
def associativity[A, B, C, AB, BC](implicit
1616
x1: PolyComposable[SeqOp, A, B, AB],
1717
x2: PolyComposable[SeqOp, B, C, BC],
18-
x3: PolyComposable[SeqOp, AB, C, *.Actions],
19-
x4: PolyComposable[SeqOp, A, BC, *.Actions]) = {
18+
x3: PolyComposable[SeqOp, AB, C, dsl.Actions],
19+
x4: PolyComposable[SeqOp, A, BC, dsl.Actions]) = {
2020

2121
implicit def anyCanSeq[X]: Can[SeqOp, X] = Can
2222

23-
def results(a: *.Actions): String =
23+
def results(a: dsl.Actions): String =
2424
"\n" + Plan.action(a).stateless.testU.runU().format(inspectionFormat)
2525

2626
Prop.equal[(A, B, C)]("associativity")(

core/shared/src/test/scala/teststate/CoproductExample.scala

+10-10
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@ object CoproductExample {
1010
}
1111

1212
object Txt {
13-
val * = Dsl[Txt, String, String]
13+
val dsl = Dsl[Txt, String, String]
1414

15-
val txt = *.focus("Txt value").obsAndState(identity, identity)
15+
val txt = dsl.focus("Txt value").obsAndState(identity, identity)
1616

1717
def add(a: String) =
18-
*.action("Add")(_.ref.txt += a).updateState(_ + a)
18+
dsl.action("Add")(_.ref.txt += a).updateState(_ + a)
1919
.addCheck(txt.assert.equal.beforeAndAfter)
2020

2121
val test = Plan.action(add("x").times(2)).test(Observer(_.txt))
@@ -26,12 +26,12 @@ object CoproductExample {
2626
}
2727

2828
object Num {
29-
val * = Dsl[Num, Int, Int]
29+
val dsl = Dsl[Num, Int, Int]
3030

31-
val num = *.focus("Number value").obsAndState(identity, identity)
31+
val num = dsl.focus("Number value").obsAndState(identity, identity)
3232

3333
def add(a: Int) =
34-
*.action("Add")(_.ref.num += a).updateState(_ + a)
34+
dsl.action("Add")(_.ref.num += a).updateState(_ + a)
3535
.addCheck(num.assert.equal.beforeAndAfter)
3636

3737
val test = Plan.action(add(2).times(2)).test(Observer(_.num))
@@ -69,9 +69,9 @@ object CoproductExample {
6969
case class State(t: Type, num: Int, txt: String)
7070
type Obs = Int Either String
7171

72-
val * = Dsl[Top, Obs, State]
72+
val dsl = Dsl[Top, Obs, State]
7373

74-
val curType = *.focus("Current type").obsAndState[Type]({
74+
val curType = dsl.focus("Current type").obsAndState[Type]({
7575
case Left(_) => Type.Num
7676
case Right(_) => Type.Txt
7777
}, _.t)
@@ -108,9 +108,9 @@ object CoproductExample {
108108
curType.assert.equal
109109

110110
val swapTypes =
111-
*.action("Swap types")(_.ref.swap()).updateStateBy(i => i.state.copy(t = i.state.t.swap))
111+
dsl.action("Swap types")(_.ref.swap()).updateStateBy(i => i.state.copy(t = i.state.t.swap))
112112

113-
val actions: *.Actions =
113+
val actions: dsl.Actions =
114114
testNum >> swapTypes >> testTxt
115115

116116
val test = Plan(actions, invariants).test(

core/shared/src/test/scala/teststate/DslTest.scala

+7-7
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import utest._
88

99
object DslTest extends TestSuite {
1010

11-
val * = Dsl[Unit, Unit, Unit]
11+
val dsl = Dsl[Unit, Unit, Unit]
1212

1313
// def extract1[A, B](s: Sack[A, B]): B =
1414
// s match {
@@ -37,36 +37,36 @@ object DslTest extends TestSuite {
3737
override def tests = Tests {
3838

3939
"changeTo" - {
40-
"pos" - testName(*.focus("Counter").value(_ => 7).assert.changeTo(_ + 1),
40+
"pos" - testName(dsl.focus("Counter").value(_ => 7).assert.changeTo(_ + 1),
4141
"Counter should be <?>.",
4242
"Counter should be 8.")
4343

44-
"neg" - testName(*.focus("Counter").value(_ => 7).assert.not.changeTo(_ + 1),
44+
"neg" - testName(dsl.focus("Counter").value(_ => 7).assert.not.changeTo(_ + 1),
4545
"Counter shouldn't be <?>.",
4646
"Counter shouldn't be 8.")
4747

4848
// TODO Didn't catch. Try using changeTo in multiple actions and verify final history. Might be Name strictness.
4949
}
5050

5151
"incrementBy" - {
52-
"pos" - testName(*.focus("Counter").value(_ => 7).assert.increaseBy(2),
52+
"pos" - testName(dsl.focus("Counter").value(_ => 7).assert.increaseBy(2),
5353
"Counter should increase by 2.",
5454
"Counter should increase by 2.")
5555
// "Counter should be 9.")
5656

57-
"neg" - testName(*.focus("Counter").value(_ => 7).assert.not.increaseBy(2),
57+
"neg" - testName(dsl.focus("Counter").value(_ => 7).assert.not.increaseBy(2),
5858
"Counter shouldn't increase by 2.",
5959
"Counter shouldn't increase by 2.")
6060
// "Counter shouldn't be 9.")
6161
}
6262

6363
"decrementBy" - {
64-
"pos" - testName(*.focus("Counter").value(_ => 7).assert.decreaseBy(2),
64+
"pos" - testName(dsl.focus("Counter").value(_ => 7).assert.decreaseBy(2),
6565
"Counter should decrease by 2.",
6666
"Counter should decrease by 2.")
6767
// "Counter should be 5.")
6868

69-
"neg" - testName(*.focus("Counter").value(_ => 7).assert.not.decreaseBy(2),
69+
"neg" - testName(dsl.focus("Counter").value(_ => 7).assert.not.decreaseBy(2),
7070
"Counter shouldn't decrease by 2.",
7171
"Counter shouldn't decrease by 2.")
7272
// "Counter shouldn't be 5.")

0 commit comments

Comments
 (0)