Skip to content

Commit

Permalink
Merge pull request scalameta#4052 from tgodzik/port-test-fixes
Browse files Browse the repository at this point in the history
chore: Port minor changes from the Scala 3 PR
  • Loading branch information
tgodzik authored Dec 3, 2024
2 parents 53342a8 + 8643c40 commit 4aa1e0f
Show file tree
Hide file tree
Showing 14 changed files with 37 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ trait Equality {
def isEqual[F[x <: Tree] <: TreeEquality[x]](
b: A
)(implicit conv: Tree => F[Tree], eqEv: Equal[F[Tree]]): Boolean =
(a eq b) || eqEv.isEqual(a, b)
(a eq b) || eqEv.isEqual(conv(a), conv(b))
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class ScalametaParser(input: Input)(implicit dialect: Dialect) {
def parseAmmonite(): MultiSource = parseRule(entryPointAmmonite())

def entryPointAmmonite(): MultiSource = {
require(input.isInstanceOf[Input.Ammonite])
assert(input.isInstanceOf[Input.Ammonite], s"Expected Input.Ammonite, not ${input.getClass}")
val builder = List.newBuilder[Source]

doWhile(builder += parseRuleAfterBOF(parseSourceImpl())) {
Expand Down Expand Up @@ -567,7 +567,7 @@ class ScalametaParser(input: Input)(implicit dialect: Dialect) {
}

private def unquote[T <: Tree: AstInfo](unquote: Unquote): T with Quasi = {
require(unquote.input.chars(unquote.start + 1) != '$')
assert(unquote.input.chars(unquote.start + 1) != '$', "Expected unquote to start with $")
val unquoteDialect = dialect.unquoteParentDialect
if (null eq unquoteDialect) syntaxError(s"$dialect doesn't support unquotes", at = unquote)
// NOTE: I considered having Input.Slice produce absolute positions from the get-go,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ class ReificationMacros(val c: Context) extends AstReflection with AdtLiftables

type MetaParser = (Input, Dialect) => MetaTree
val XtensionQuasiquoteTerm = "shadow scala.meta quasiquotes"
val XtensionParsersDialectApply = "shadow extension method conflict"

// NOTE: only Mode.Pattern really needs holes, and that's only because of Scala's limitations
// read a comment in liftUnquote for more information on that
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,6 @@ package object meta
with trees.Api
with trees.Aliases {

type XtensionParsersDialectApply // shadow conflicting implicit class
type XtensionTokenizersDialectApply // shadow conflicting implicit class
implicit class XtensionDialectApply(private val dialect: scala.meta.Dialect) extends AnyVal {
def apply[T](inputLike: T)(implicit
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -299,7 +299,7 @@ class DefnSuite extends ParseSuite {
val layout = """|new A { def b: C = ??? }
|""".stripMargin
val tree = Term.NewAnonymous(tpl(
List(Init(pname("A"), anon, Nil)),
List(Init(pname("A"), anon, List.empty[Term.ArgClause])),
List(Defn.Def(Nil, tname("b"), Nil, Some(pname("C")), tname("???")))
))
runTestAssert[Stat](code, layout)(tree)
Expand All @@ -315,7 +315,7 @@ class DefnSuite extends ParseSuite {
val layout = """|new A { def b: C = ??? }
|""".stripMargin
val tree = Term.NewAnonymous(tpl(
List(Init(pname("A"), anon, Nil)),
List(Init(pname("A"), anon, List.empty[Term.ArgClause])),
List(Defn.Def(Nil, tname("b"), Nil, Some(pname("C")), tname("???")))
))
runTestAssert[Stat](code, layout)(tree)
Expand Down Expand Up @@ -350,7 +350,7 @@ class DefnSuite extends ParseSuite {
val layout = """|new A { def b: C = ??? }
|""".stripMargin
val tree = Term.NewAnonymous(tpl(
List(Init(pname("A"), anon, Nil)),
List(Init(pname("A"), anon, List.empty[Term.ArgClause])),
List(Defn.Def(Nil, tname("b"), Nil, Some(pname("C")), tname("???")))
))
runTestAssert[Stat](code, layout)(tree)
Expand All @@ -367,7 +367,7 @@ class DefnSuite extends ParseSuite {
val layout = """|new A { def b: C = ??? }
|""".stripMargin
val tree = Term.NewAnonymous(tpl(
List(Init(pname("A"), anon, Nil)),
List(Init(pname("A"), anon, List.empty[Term.ArgClause])),
List(Defn.Def(Nil, tname("b"), Nil, Some(pname("C")), tname("???")))
))
runTestAssert[Stat](code, layout)(tree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ class LitSuite extends ParseSuite {

test("\"foo\"")(assertTree(term("\"foo\""))(str("foo")))

test("'foo'")(assertTree(term("'foo"))(Lit.Symbol('foo)))
test("'foo'")(assertTree(term("'foo"))(Lit.Symbol(Symbol("foo"))))

test("null")(assertTree(term("null"))(Lit.Null()))

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ class SbtSuite extends TreeSuiteBase {
test("\"...\".parse[Stat]")(intercept[ParseException](simpleBuildSyntax.parse[Stat].get))

test("source\"...\"") {
val tree = source"""
val tree = """
lazy val commonSettings = Seq(
organization := "com.example",
version := "0.1.0",
Expand All @@ -27,7 +27,7 @@ class SbtSuite extends TreeSuiteBase {
settings(
name := "hello"
)
"""
""".parse[Source].get
assertStruct(tree)(simpleBuildStructure)
assertSyntaxWithClue(tree)(expectedSyntax)(simpleBuildStructure)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ class GivenSyntax36Suite extends BaseDottySuite {
Nil,
Type.Name("A"),
Type.ParamClause(Nil),
Ctor.Primary(Nil, Name.Anonymous(), Nil),
Ctor.Primary(Nil, Name.Anonymous(), Seq.empty[Term.ParamClause]),
Template(
None,
Nil,
Expand Down Expand Up @@ -76,7 +76,7 @@ class GivenSyntax36Suite extends BaseDottySuite {
Nil,
Type.Name("A"),
Type.ParamClause(Nil),
Ctor.Primary(Nil, Name.Anonymous(), Nil),
Ctor.Primary(Nil, Name.Anonymous(), Seq.empty[Term.ParamClause]),
Template(
None,
Nil,
Expand Down Expand Up @@ -126,7 +126,7 @@ class GivenSyntax36Suite extends BaseDottySuite {
Nil,
Type.Name("Sorted"),
Type.ParamClause(Nil),
Ctor.Primary(Nil, Name.Anonymous(), Nil),
Ctor.Primary(Nil, Name.Anonymous(), Seq.empty[Term.ParamClause]),
Template(
None,
Nil,
Expand Down Expand Up @@ -248,7 +248,7 @@ class GivenSyntax36Suite extends BaseDottySuite {
List(Init(
Type.Apply(Type.Name("Ord"), Type.ArgClause(List(Type.Name("Int")))),
Name.Anonymous(),
Nil
Seq.empty[Term.ArgClause]
)),
body,
Nil
Expand All @@ -264,7 +264,7 @@ class GivenSyntax36Suite extends BaseDottySuite {
Type.ArgClause(List(Type.Apply(Type.Name("List"), Type.ArgClause(List(Type.Name("A"))))))
),
Name.Anonymous(),
Nil
Seq.empty[Term.ArgClause]
)),
Template.Body(
None,
Expand Down Expand Up @@ -470,7 +470,7 @@ class GivenSyntax36Suite extends BaseDottySuite {
List(Init(
Type.Apply(Type.Name("Ord"), Type.ArgClause(List(Type.Name("Int")))),
Name.Anonymous(),
Nil
Seq.empty[Term.ArgClause]
)),
body,
Nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ class MacroSuite extends BaseDottySuite {
test("macro-quote-expr: x match { case 'c => 1 }") {
val layoutMatchSimple = "x match {\n case 'c => 1\n}"
runTestAssert[Stat]("x match { case 'c => 1 }", assertLayout = Some(layoutMatchSimple))(
Term.Match(tname("x"), List(Case(Lit.Symbol('c), None, int(1))), Nil)
Term.Match(tname("x"), List(Case(Lit.Symbol(Symbol("c")), None, int(1))), Nil)
)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2822,7 +2822,7 @@ class SignificantIndentationSuite extends BaseDottySuite {
val layout = """|new A { def b: C = ??? }
|""".stripMargin
val tree = Term.NewAnonymous(tpl(
List(Init(pname("A"), anon, Nil)),
List(Init(pname("A"), anon, List.empty[Term.ArgClause])),
List(Defn.Def(Nil, tname("b"), Nil, Some(pname("C")), tname("???")))
))
runTestAssert[Stat](code, layout)(tree)
Expand All @@ -2838,7 +2838,7 @@ class SignificantIndentationSuite extends BaseDottySuite {
val layout = """|new A { def b: C = ??? }
|""".stripMargin
val tree = Term.NewAnonymous(tpl(
List(Init(pname("A"), anon, Nil)),
List(Init(pname("A"), anon, List.empty[Term.ArgClause])),
List(Defn.Def(Nil, tname("b"), Nil, Some(pname("C")), tname("???")))
))
runTestAssert[Stat](code, layout)(tree)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ class TokensSuite {
val d1: Seq[Token] = d ++ d
val d2: Seq[Token] = newToken +: d
val d3: Seq[Token] = d :+ newToken
val (d41: Token) +: (d42: Seq[Token]) :+ (d43: Token) = d
val d41: Token = d.head
val d42: Token = d(1)
val d43: Token = d(2)
val d5a: Seq[Int] = d.map(_ => 42)
val d5b: Seq[Token] = d5a.map(_ => newToken)
val d5c: Seq[Token] = d.map(_.toString).flatMap(_ => List(newToken))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,17 +3,20 @@ package trees

import scala.meta._
import scala.meta.dialects.Scala211
import scala.meta.tests.parsers.ParseSuite

import munit._

class ChildrenSuite extends FunSuite {
class ChildrenSuite extends ParseSuite {
test("Template.children") {
val tree = q"""
class Foo {
import bar.baz.one
import bar.baz.two
}
"""
val tree = stat(
"""|
|class Foo {
| import bar.baz.one
| import bar.baz.two
|}
|""".stripMargin
)
assertEquals(tree.children.length, 4)
assertEquals(tree.children(0).productPrefix, "Type.Name")
assertEquals(tree.children(1).productPrefix, "Type.ParamClause")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,9 @@ class InfrastructureSuite extends TreeSuiteBase {
}

test("copy parent") {
val Term.Select(x1: Term.Name, _) = "foo.bar".parse[Term].get
val tree = "foo.bar".parse[Term].get
assertTree(tree)(Term.Select(Term.Name("foo"), Term.Name("bar")))
val x1 = tree.asInstanceOf[Term.Select].name
val x2 = x1.copy()
assert(x1.parent.nonEmpty)
assert(x2.parent.isEmpty)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@ import munit._

class TreeSuite extends FunSuite {
test("Name.unapply") {
assert(Name.unapply(q"a").contains("a"))
assert(Name.unapply(t"a").contains("a"))
assert(Name.unapply(Term.Name("a")).contains("a"))
assert(Name.unapply(Type.Name("a")).contains("a"))
}

Seq(("+", Unary.Plus), ("-", Unary.Minus), ("~", Unary.Tilde), ("!", Unary.Not)).foreach {
Expand Down

0 comments on commit 4aa1e0f

Please sign in to comment.