Skip to content

Commit b6468bf

Browse files
committed
Rename test class mill.api.Opt to TestOpt
1 parent c54f0db commit b6468bf

File tree

3 files changed

+87
-87
lines changed

3 files changed

+87
-87
lines changed

core/api/test/src/mill/api/ApplicativeTests.scala

Lines changed: 57 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -23,125 +23,125 @@ object ApplicativeTests extends TestSuite {
2323

2424
test("selfContained") {
2525

26-
test("simple") - assert(Opt("lol " + 1) == Opt.some("lol 1"))
27-
test("singleSome") - assert(Opt("lol " + Opt.some("hello")()) == Opt.some("lol hello"))
26+
test("simple") - assert(TestOpt("lol " + 1) == TestOpt.some("lol 1"))
27+
test("singleSome") - assert(TestOpt("lol " + TestOpt.some("hello")()) == TestOpt.some("lol hello"))
2828
test("twoSomes") - assert(
29-
Opt(Opt.some("lol ")() + Opt.some("hello")()) == Opt.some("lol hello")
29+
TestOpt(TestOpt.some("lol ")() + TestOpt.some("hello")()) == TestOpt.some("lol hello")
3030
)
31-
test("singleNone") - assert(Opt("lol " + Opt.none()) == Opt.none)
32-
test("twoNones") - assert(Opt("lol " + Opt.none() + Opt.none()) == Opt.none)
31+
test("singleNone") - assert(TestOpt("lol " + TestOpt.none()) == TestOpt.none)
32+
test("twoNones") - assert(TestOpt("lol " + TestOpt.none() + TestOpt.none()) == TestOpt.none)
3333
test("moreThan22") {
3434
assert(
35-
Opt(
35+
TestOpt(
3636
"lol " +
37-
Opt.none() + Opt.none() + Opt.none() + Opt.none() + Opt.none() +
38-
Opt.none() + Opt.none() + Opt.none() + Opt.none() + Opt.some(" world")() +
39-
Opt.none() + Opt.none() + Opt.none() + Opt.none() + Opt.none() +
40-
Opt.none() + Opt.none() + Opt.none() + Opt.none() + Opt.none() +
41-
Opt.none() + Opt.none() + Opt.none() + Opt.none() + Opt.some(" moo")()
42-
) == Opt.none
37+
TestOpt.none() + TestOpt.none() + TestOpt.none() + TestOpt.none() + TestOpt.none() +
38+
TestOpt.none() + TestOpt.none() + TestOpt.none() + TestOpt.none() + TestOpt.some(" world")() +
39+
TestOpt.none() + TestOpt.none() + TestOpt.none() + TestOpt.none() + TestOpt.none() +
40+
TestOpt.none() + TestOpt.none() + TestOpt.none() + TestOpt.none() + TestOpt.none() +
41+
TestOpt.none() + TestOpt.none() + TestOpt.none() + TestOpt.none() + TestOpt.some(" moo")()
42+
) == TestOpt.none
4343
)
4444
assert(
45-
Opt(
45+
TestOpt(
4646
"lol " +
47-
Opt.some("a")() + Opt.some("b")() + Opt.some("c")() + Opt.some("d")() +
48-
Opt.some("e")() + Opt.some("a")() + Opt.some("b")() + Opt.some("c")() +
49-
Opt.some("d")() + Opt.some("e")() + Opt.some("a")() + Opt.some("b")() +
50-
Opt.some("c")() + Opt.some("d")() + Opt.some("e")() + Opt.some("a")() +
51-
Opt.some("b")() + Opt.some("c")() + Opt.some("d")() + Opt.some("e")() +
52-
Opt.some("a")() + Opt.some("b")() + Opt.some("c")() + Opt.some("d")() +
53-
Opt.some("e")() + Opt.some("a")() + Opt.some("b")() + Opt.some("c")() +
54-
Opt.some("d")() + Opt.some("e")() + Opt.some("a")() + Opt.some("b")() +
55-
Opt.some("c")() + Opt.some("d")() + Opt.some("e")() + Opt.some("a")() +
56-
Opt.some("b")() + Opt.some("c")() + Opt.some("d")() + Opt.some("e")() +
57-
Opt.some("a")() + Opt.some("b")() + Opt.some("c")() + Opt.some("d")() +
58-
Opt.some("e")() + Opt.some("a")() + Opt.some("b")() + Opt.some("c")() +
59-
Opt.some("d")() + Opt.some("e")()
60-
) == Opt.some("lol abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde")
47+
TestOpt.some("a")() + TestOpt.some("b")() + TestOpt.some("c")() + TestOpt.some("d")() +
48+
TestOpt.some("e")() + TestOpt.some("a")() + TestOpt.some("b")() + TestOpt.some("c")() +
49+
TestOpt.some("d")() + TestOpt.some("e")() + TestOpt.some("a")() + TestOpt.some("b")() +
50+
TestOpt.some("c")() + TestOpt.some("d")() + TestOpt.some("e")() + TestOpt.some("a")() +
51+
TestOpt.some("b")() + TestOpt.some("c")() + TestOpt.some("d")() + TestOpt.some("e")() +
52+
TestOpt.some("a")() + TestOpt.some("b")() + TestOpt.some("c")() + TestOpt.some("d")() +
53+
TestOpt.some("e")() + TestOpt.some("a")() + TestOpt.some("b")() + TestOpt.some("c")() +
54+
TestOpt.some("d")() + TestOpt.some("e")() + TestOpt.some("a")() + TestOpt.some("b")() +
55+
TestOpt.some("c")() + TestOpt.some("d")() + TestOpt.some("e")() + TestOpt.some("a")() +
56+
TestOpt.some("b")() + TestOpt.some("c")() + TestOpt.some("d")() + TestOpt.some("e")() +
57+
TestOpt.some("a")() + TestOpt.some("b")() + TestOpt.some("c")() + TestOpt.some("d")() +
58+
TestOpt.some("e")() + TestOpt.some("a")() + TestOpt.some("b")() + TestOpt.some("c")() +
59+
TestOpt.some("d")() + TestOpt.some("e")()
60+
) == TestOpt.some("lol abcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcdeabcde")
6161
)
6262
}
6363
}
6464
test("context") {
65-
assert(Opt(Opt.ctx() + Opt.some("World")()) == Opt.some("hellooooWorld"))
65+
assert(TestOpt(TestOpt.ctx() + TestOpt.some("World")()) == TestOpt.some("hellooooWorld"))
6666
}
6767
test("capturing") {
6868
val lol = "lol "
6969
def hell(o: String) = "hell" + o
70-
test("simple") - assert(Opt(lol + 1) == Opt.some("lol 1"))
71-
test("singleSome") - assert(Opt(lol + Opt.some(hell("o"))()) == Opt.some("lol hello"))
70+
test("simple") - assert(TestOpt(lol + 1) == TestOpt.some("lol 1"))
71+
test("singleSome") - assert(TestOpt(lol + TestOpt.some(hell("o"))()) == TestOpt.some("lol hello"))
7272
test("twoSomes") - assert(
73-
Opt(Opt.some(lol)() + Opt.some(hell("o"))()) == Opt.some("lol hello")
73+
TestOpt(TestOpt.some(lol)() + TestOpt.some(hell("o"))()) == TestOpt.some("lol hello")
7474
)
75-
test("singleNone") - assert(Opt(lol + Opt.none()) == Opt.none)
76-
test("twoNones") - assert(Opt(lol + Opt.none() + Opt.none()) == Opt.none)
75+
test("singleNone") - assert(TestOpt(lol + TestOpt.none()) == TestOpt.none)
76+
test("twoNones") - assert(TestOpt(lol + TestOpt.none() + TestOpt.none()) == TestOpt.none)
7777
}
7878
test("allowedLocalDef") {
79-
// Although x is defined inside the Opt{...} block, it is also defined
79+
// Although x is defined inside the TestOpt{...} block, it is also defined
8080
// within the LHS of the Applyable#apply call, so it is safe to life it
8181
// out into the `zipMap` arguments list.
82-
val res = Opt { "lol " + new Opt(Some("hello").flatMap(x => Some(x))).apply() }
83-
assert(res == Opt.some("lol hello"))
82+
val res = TestOpt { "lol " + new TestOpt(Some("hello").flatMap(x => Some(x))).apply() }
83+
assert(res == TestOpt.some("lol hello"))
8484
}
8585
test("upstreamAlwaysEvaluated") {
8686
// Whether or not control-flow reaches the Applyable#apply call inside an
87-
// Opt{...} block, we always evaluate the LHS of the Applyable#apply
87+
// TestOpt{...} block, we always evaluate the LHS of the Applyable#apply
8888
// because it gets lifted out of any control flow statements
8989
val counter = new Counter()
90-
def up = Opt { "lol " + counter() }
91-
val down = Opt { if ("lol".length > 10) up() else "fail" }
90+
def up = TestOpt { "lol " + counter() }
91+
val down = TestOpt { if ("lol".length > 10) up() else "fail" }
9292
assert(
93-
down == Opt.some("fail"),
93+
down == TestOpt.some("fail"),
9494
counter.value == 1
9595
)
9696
}
9797
test("upstreamEvaluatedOnlyOnce") {
9898
// Even if control-flow reaches the Applyable#apply call more than once,
99-
// it only gets evaluated once due to its lifting out of the Opt{...} block
99+
// it only gets evaluated once due to its lifting out of the TestOpt{...} block
100100
val counter = new Counter()
101-
def up = Opt { "lol " + counter() }
101+
def up = TestOpt { "lol " + counter() }
102102
def runTwice[T](t: => T) = (t, t)
103-
val down = Opt { runTwice(up()) }
103+
val down = TestOpt { runTwice(up()) }
104104
assert(
105-
down == Opt.some(("lol 1", "lol 1")),
105+
down == TestOpt.some(("lol 1", "lol 1")),
106106
counter.value == 1
107107
)
108108
}
109109
test("evaluationsInsideLambdasWork") {
110110
// This required some fiddling with owner chains inside the macro to get
111111
// working, so ensure it doesn't regress
112112
val counter = new Counter()
113-
def up = Opt { "hello" + counter() }
114-
val down1 = Opt { (() => up())() }
115-
val down2 = Opt { Seq(1, 2, 3).map(n => up() * n) }
113+
def up = TestOpt { "hello" + counter() }
114+
val down1 = TestOpt { (() => up())() }
115+
val down2 = TestOpt { Seq(1, 2, 3).map(n => up() * n) }
116116
assert(
117-
down1 == Opt.some("hello1"),
118-
down2 == Opt.some(Seq("hello2", "hello2hello2", "hello2hello2hello2"))
117+
down1 == TestOpt.some("hello1"),
118+
down2 == TestOpt.some(Seq("hello2", "hello2hello2", "hello2hello2hello2"))
119119
)
120120
}
121121
test("appliesEvaluatedOncePerLexicalCallsite") {
122122
// If you have multiple Applyable#apply() lexically in the source code of
123-
// your Opt{...} call, each one gets evaluated once, even if the LHS of each
123+
// your TestOpt{...} call, each one gets evaluated once, even if the LHS of each
124124
// apply() call is identical. It's up to the downstream zipMap()
125125
// implementation to decide if it wants to dedup them or do other things.
126126
val counter = new Counter()
127-
def up = Opt { s"hello${counter()}" }
128-
val down = Opt { Seq(1, 2, 3).map(n => n + up() + up()) }
129-
assert(down == Opt.some(Seq("1hello1hello2", "2hello1hello2", "3hello1hello2")))
127+
def up = TestOpt { s"hello${counter()}" }
128+
val down = TestOpt { Seq(1, 2, 3).map(n => n + up() + up()) }
129+
assert(down == TestOpt.some(Seq("1hello1hello2", "2hello1hello2", "3hello1hello2")))
130130
}
131131
test("appliesEvaluateBeforehand") {
132-
// Every Applyable#apply() within a Opt{...} block evaluates before any
132+
// Every Applyable#apply() within a TestOpt{...} block evaluates before any
133133
// other logic within that block, even if they would happen first in the
134134
// normal Scala evaluation order
135135
val counter = new Counter()
136-
def up = Opt { counter() }
137-
val down = Opt {
136+
def up = TestOpt { counter() }
137+
val down = TestOpt {
138138
val res = counter()
139139
val one = up()
140140
val two = up()
141141
val three = up()
142142
(res, one, two, three)
143143
}
144-
assert(down == Opt.some((4, 1, 2, 3)))
144+
assert(down == TestOpt.some((4, 1, 2, 3)))
145145
}
146146
}
147147
}

core/api/test/src/mill/api/Opt.scala

Lines changed: 0 additions & 30 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
package mill.api
2+
3+
import mill.api.internal.Applicative
4+
5+
import scala.quoted.*
6+
7+
case class TestOpt[+T](self: Option[T]) extends Applicative.Applyable[TestOpt, T]
8+
object TestOpt {
9+
def none: TestOpt[Nothing] = new TestOpt(None)
10+
def some[T](t: T): TestOpt[T] = new TestOpt(Some(t))
11+
val injectedCtx = "helloooo"
12+
13+
def ctx()(using c: String): String = c
14+
inline def apply[T](inline t: T): TestOpt[T] = ${ applyImpl[T]('t) }
15+
16+
def traverseCtx[I, R](xs: Seq[TestOpt[I]])(f: (Seq[I], String) => Applicative.Id[R])
17+
: TestOpt[R] = {
18+
new TestOpt(
19+
if (xs.exists(_.self.isEmpty)) None
20+
else Some(f(xs.map(_.self.get).toVector, TestOpt.injectedCtx))
21+
)
22+
}
23+
def applyImpl[T: Type](t: Expr[T])(using
24+
Quotes
25+
): Expr[TestOpt[T]] =
26+
Applicative.impl[TestOpt, TestOpt, Applicative.Id, T, String](
27+
(args, fn) => '{ traverseCtx($args)($fn) },
28+
t
29+
)
30+
}

0 commit comments

Comments
 (0)