Skip to content

Commit 4710941

Browse files
committed
Unrelated tests
I piggyback these here to not go through the ceremony of another PR
1 parent 3d50596 commit 4710941

File tree

3 files changed

+59
-2
lines changed

3 files changed

+59
-2
lines changed

tests/pos/fewer-braces.scala

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,13 @@
11
import language.experimental.fewerBraces
22

3-
object Test:
3+
def Test =
4+
5+
val xo: Option[Int] = Some(1)
6+
7+
val y =
8+
xo.fold:
9+
22
10+
.apply: x =>
11+
x + 1
12+
println(y)
413

5-
assert((new Object: Any).isInstanceOf[Object])

tests/run/patmat.check

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
Bob is 22 years old and lives in Paris
2+
Hello Peter
3+
Bob is 22 years old and lives in Paris
4+
Hello PersonExtractor(Peter)

tests/run/patmat.scala

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
object Test1:
2+
class User(val name: String, val age: Int, val city: String)
3+
object User:
4+
def unapply(user: User) = UserExtractor(user.name, user.age, user.city)
5+
6+
case class UserExtractor(name: String, age: Int, city: String)
7+
8+
class Person(val name: String)
9+
object Person:
10+
def unapply(person: Person) = PersonExtractor(person.name)
11+
12+
case class PersonExtractor(name: String)
13+
14+
def test =
15+
val user = User("Bob", 22, "Paris")
16+
(user: Any) match
17+
case User(name, age, city) => println(s"$name is $age years old and lives in $city")
18+
val p = Person("Peter")
19+
(p: Any) match
20+
case Person(n) => println(s"Hello $n")
21+
22+
object Test2:
23+
class User(val name: String, val age: Int, val city: String)
24+
object User:
25+
def unapply(user: User): Option[UserExtractor] = Some(UserExtractor(user.name, user.age, user.city))
26+
27+
case class UserExtractor(name: String, age: Int, city: String)
28+
29+
class Person(val name: String)
30+
object Person:
31+
def unapply(person: Person): Some[PersonExtractor] = Some(PersonExtractor(person.name))
32+
33+
case class PersonExtractor(name: String)
34+
35+
def test =
36+
val user = User("Bob", 22, "Paris")
37+
(user: Any) match
38+
case User(name, age, city) => println(s"$name is $age years old and lives in $city")
39+
val p = Person("Peter")
40+
(p: Any) match
41+
case Person(n) => println(s"Hello $n")
42+
43+
@main def Test =
44+
Test1.test
45+
Test2.test

0 commit comments

Comments
 (0)