Skip to content

Commit

Permalink
Format Scala files in codesig test cases (#3323)
Browse files Browse the repository at this point in the history
Newer versions of Mill better find these nested modules
(#3270), so that our CI check
for formatted Scala files will fail once we bump to Mill `0.11.10` or
newer.

Pull request: #3323
  • Loading branch information
lefou authored Jul 31, 2024
1 parent 3093cc4 commit 1f3fb55
Show file tree
Hide file tree
Showing 20 changed files with 60 additions and 62 deletions.
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hello

object Hello{
object Hello {
def main(): Int = used()
def used(): Int = 2
def unused(): Int = 1
Expand All @@ -24,7 +24,7 @@ object Hello{
"hello.Hello$#used()int"
]
}
*/
*/

/* expected-transitive-call-graph
{
Expand All @@ -45,4 +45,4 @@ object Hello{
"hello.Hello$#used()int"
]
}
*/
*/
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package hello

object Hello{
object Hello {
def main(): Int = {

val foo = () => used()
Expand All @@ -23,7 +23,7 @@ object Hello{
"hello.Hello$#used()int"
]
}
*/
*/

/* expected-transitive-call-graph
{
Expand All @@ -40,4 +40,4 @@ object Hello{
"hello.Hello$#used()int"
]
}
*/
*/
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package hello

object Hello{
object Hello {
def main(): Int = {

val foo = new Function0[Int]{def apply() = used() }
val foo = new Function0[Int] { def apply() = used() }
foo()
}
def used(): Int = 2
Expand Down Expand Up @@ -69,7 +69,7 @@ object Hello{
"hello.Hello$#used()int"
]
}
*/
*/

/* expected-transitive-call-graph
{
Expand Down Expand Up @@ -311,4 +311,4 @@ object Hello{
"hello.Hello$$anon$1#toString()java.lang.String"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,12 @@

package hello

trait MyTrait{
trait MyTrait {
Hello.used()
def used() = 1
}
object MyObject extends MyTrait{

}
object Hello{
object MyObject extends MyTrait {}
object Hello {
def main(): Int = MyObject.used()
def used(): Int = 2
def unused(): Int = 1
Expand Down Expand Up @@ -50,7 +48,7 @@ object Hello{
"hello.MyTrait#used()int"
]
}
*/
*/

/* expected-transitive-call-graph
{
Expand Down Expand Up @@ -95,4 +93,4 @@ object Hello{
"hello.MyTrait#used()int"
]
}
*/
*/
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
package hello

trait TestIter[+A]{
trait TestIter[+A] {
def hasNext: Boolean
def next(): A
def foreach[U](f: A => U) = { while (hasNext) f(next()) }
}

class SubTestIter() extends TestIter[Nothing]{
class SubTestIter() extends TestIter[Nothing] {
def hasNext: Boolean = false
def next(): Nothing = throw new NoSuchElementException("next on empty iterator")
}

object Hello{
object Hello {
def minimizedIterator(): Array[Int] = {
val iterator = new SubTestIter()
val holder = Array(1)
Expand Down Expand Up @@ -46,4 +46,4 @@ object Hello{
"hello.TestIter#foreach(scala.Function1)void"
]
}
*/
*/
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
package hello

object Hello{
object Hello {
class TestElements() extends TestIterator

trait TestIterator {
def run(f: TestCallback[Int, Int]): Int = f(123)
}
abstract class TestCallback[T, void]{
abstract class TestCallback[T, void] {
def apply(x: T): void
}
class TestCallbackImpl extends TestCallback[Int, Int]{
class TestCallbackImpl extends TestCallback[Int, Int] {
// Because `TestCallbackImpl` is a SAM implementation,
// we treat `apply` as being called from `<init>`
def apply(x: Int): Int = x + 1
Expand Down Expand Up @@ -48,4 +48,4 @@ object Hello{
"hello.Hello$#staticSpecialInterfaceMethods()int"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package hello

import scala.collection.AbstractIterator

object Hello{
object Hello {

class Elements[T](arr: Array[T]) extends AbstractIterator[T] {
val end = arr.length
Expand Down Expand Up @@ -77,4 +77,4 @@ object Hello{
"hello.Hello$#manualIterator2(int)int"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package hello

import scala.collection.AbstractIterator

object Hello{
object Hello {
class SingletonBigTestIterator[T](a: T) extends BigTestIterator[T] {
var ready = true
def hasNext: Boolean = ready
Expand All @@ -20,7 +20,8 @@ object Hello{
def filter(p: A => Boolean): BigTestIterator[A] = new FilterBigTestIterator[A](this, p)
}

class FilterBigTestIterator[A](parent: BigTestIterator[A], pred: A => Boolean) extends BigTestIterator [A]{
class FilterBigTestIterator[A](parent: BigTestIterator[A], pred: A => Boolean)
extends BigTestIterator[A] {
private[this] var hd: A = _
private[this] var hdDefined: Boolean = false

Expand Down Expand Up @@ -87,4 +88,4 @@ object Hello{
"hello.Hello$#manualIterator3(int)int"
]
}
*/
*/
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
package hello

trait MyModule{
trait MyModule {
def x = "123"
def y = "456"
}

object Foo extends MyModule{
object Foo extends MyModule {
override def x = super.x + "abc"
}

object Bar extends MyModule{
object Bar extends MyModule {
override def y = super.y + "abc" + Foo.x
}


/* expected-direct-call-graph
{
"hello.Bar$#x()java.lang.String": [
Expand Down Expand Up @@ -53,4 +52,4 @@ object Bar extends MyModule{
"hello.MyModule#y()java.lang.String"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package hello

// Taken from https://github.com/lihaoyi/Metascala/blob/76dfbfa18484b9ee39bd09453328ea1081fcab6b/src/test/java/metascala/features/classes/Inheritance.java


class Cow {
def moo: String = {
return "moooo"
Expand All @@ -22,10 +21,10 @@ class Matrix(aa: Float, ab: Float, ba: Float, bb: Float) {
}

class DoubleMatrix(aa: Float, ab: Float, ba: Float, bb: Float)
extends Matrix(aa*2, ab*2, ba*2, bb*2)
extends Matrix(aa * 2, ab * 2, ba * 2, bb * 2)

class DoubleDetMatrix(aa: Float, ab: Float, ba: Float, bb: Float)
extends Matrix(aa*2, ab*2, ba*2, bb*2){
extends Matrix(aa * 2, ab * 2, ba * 2, bb * 2) {

override def determinant: Float = {
return super.determinant * 2
Expand Down Expand Up @@ -81,4 +80,4 @@ class LinkedList {
"hello.LinkedList$Inner#value()int"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package hello

import scala.collection.AbstractIterator

object Hello{
object Hello {

object TestManifestFactory {
val Nothing = new PhantomManifest()
Expand Down Expand Up @@ -30,4 +30,4 @@ object Hello{
"hello.Hello$#testManifestFactory()java.lang.String"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package hello

import scala.collection.AbstractIterator

object Hello{
object Hello {

sealed abstract class TestList[+A] {
def isEmpty: Boolean
Expand Down Expand Up @@ -76,4 +76,4 @@ object Hello{
"hello.Hello$#simpleLinkedListForeach()int[]"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@ package hello

import scala.collection.AbstractIterator

object Hello{
class TestArraySeq[T](inner: Array[T]){
object Hello {
class TestArraySeq[T](inner: Array[T]) {
def foreach[void](f: T => void) = {
var i = 0
while (i < inner.length){
while (i < inner.length) {
f(inner(i))
i += 1
}
Expand All @@ -33,4 +33,4 @@ object Hello{
"hello.Hello$#simpleArraySeqForeach()int[]"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -90,4 +90,4 @@ object Main {
"hello.Main$#mergeSortSequential(scala.collection.immutable.IndexedSeq,scala.math.Ordering)scala.collection.immutable.IndexedSeq"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ package hello
// Taken from https://github.com/handsonscala/handsonscala/blob/ebc0367144513fc181281a024f8071a6153be424/examples/16.8%20-%20LoggingRearrangedPipeline2/LoggingPipeline.sc
import scalatags.Text.all._
import scala.concurrent._, duration.Duration.Inf
class DiskActor(logPath: os.Path, rotateSize: Int = 50)
(implicit cc: castor.Context) extends castor.SimpleActor[String]{
class DiskActor(logPath: os.Path, rotateSize: Int = 50)(implicit cc: castor.Context)
extends castor.SimpleActor[String] {
val oldPath = logPath / os.up / (logPath.last + "-old")
def run(s: String) = {
val newLogSize = logSize + s.length + 1
Expand All @@ -17,28 +17,27 @@ class DiskActor(logPath: os.Path, rotateSize: Int = 50)
private var logSize = 0
}

class Base64Actor(dest: castor.Actor[String])
(implicit cc: castor.Context) extends castor.SimpleActor[String]{
class Base64Actor(dest: castor.Actor[String])(implicit cc: castor.Context)
extends castor.SimpleActor[String] {
def run(msg: String) = {
dest.send(java.util.Base64.getEncoder.encodeToString(msg.getBytes))
}
}

class UploadActor(url: String)
(implicit cc: castor.Context) extends castor.SimpleActor[String]{
class UploadActor(url: String)(implicit cc: castor.Context) extends castor.SimpleActor[String] {
def run(msg: String) = {
val res = requests.post(url, data = msg)
println(s"response ${res.statusCode} " + ujson.read(res)("data"))
}
}
class SanitizeActor(dest: castor.Actor[String])
(implicit cc: castor.Context) extends castor.SimpleActor[String]{
class SanitizeActor(dest: castor.Actor[String])(implicit cc: castor.Context)
extends castor.SimpleActor[String] {
def run(msg: String) = {
dest.send(msg.replaceAll("([0-9]{4})[0-9]{8}([0-9]{4})", "<redacted>"))
}
}

object Hello{
object Hello {
def main() = {
implicit val cc = new castor.Context.Test()

Expand Down Expand Up @@ -100,4 +99,4 @@ object Hello{
"hello.UploadActor#run(java.lang.String)void"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ sealed trait Phrase
class Word(s: String) extends Phrase
class Pair(lhs: Phrase, rhs: Phrase) extends Phrase

object Parser{
object Parser {
def prefix[_: P] = P("hello" | "goodbye").!.map(new Word(_))

def suffix[_: P] = P("world" | "seattle").!.map(new Word(_))
Expand Down Expand Up @@ -58,4 +58,4 @@ object Parser{
"hello.Parser$#ws(fastparse.ParsingRun)fastparse.ParsingRun"
]
}
*/
*/
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ package hello
* Very verbose Scaladoc comment on top of class
*/
object Hello {

/**
* less verbose Scaladoc comment for single method
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package hello

object Hello {
def main: Int = {println(1); println(2); println(3); println(4); used}
def main: Int = { println(1); println(2); println(3); println(4); used }
def used = 2
def unused = 1
}
Loading

0 comments on commit 1f3fb55

Please sign in to comment.