Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move test constructors out from SoftAST to TestSoftAST #339

Merged
merged 1 commit into from
Dec 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -103,17 +103,6 @@ object SoftAST {
abstract class ExpectedErrorAST(element: String) extends ErrorAST(s"$element expected")
abstract class TokenExpectedErrorAST(token: Token) extends ExpectedErrorAST(s"'${token.lexeme}'")

object Fn {

def apply(code: Code): Fn =
Fn(
index = code.index,
documentation = None,
code = code
)

}

case class Fn(
index: SourceIndex,
documentation: Option[Comments],
Expand All @@ -126,17 +115,6 @@ object SoftAST {
code: Code)
extends TokenDocumentedAST

object Comma {

def apply(code: Code): Comma =
Comma(
index = code.index,
documentation = None,
code = code
)

}

case class Comma(
index: SourceIndex,
documentation: Option[Comments],
Expand Down Expand Up @@ -186,17 +164,6 @@ object SoftAST {
code: Code)
extends TokenDocumentedAST

object At {

def apply(code: Code): At =
At(
index = code.index,
documentation = None,
code = code
)

}

case class At(
index: SourceIndex,
documentation: Option[Comments],
Expand Down Expand Up @@ -227,34 +194,12 @@ object SoftAST {

sealed trait TemplateToken extends TokenDocumentedAST

object Contract {

def apply(code: Code): Contract =
Contract(
index = code.index,
documentation = None,
code = code
)

}

case class Contract(
index: SourceIndex,
documentation: Option[Comments],
code: Code)
extends TemplateToken

object TxScript {

def apply(code: Code): TxScript =
TxScript(
index = code.index,
documentation = None,
code = code
)

}

case class TxScript(
index: SourceIndex,
documentation: Option[Comments],
Expand Down Expand Up @@ -283,17 +228,6 @@ object SoftAST {

sealed trait ColonAST extends SoftAST

object Colon {

def apply(code: Code): Colon =
Colon(
index = code.index,
documentation = None,
code = code
)

}

case class Colon(
index: SourceIndex,
documentation: Option[Comments],
Expand All @@ -308,17 +242,6 @@ object SoftAST {

sealed trait ForwardArrowAST extends SoftAST

object ForwardArrow {

def apply(code: Code): ForwardArrow =
ForwardArrow(
index = code.index,
documentation = None,
code = code
)

}

case class ForwardArrow(
index: SourceIndex,
documentation: Option[Comments],
Expand All @@ -333,17 +256,6 @@ object SoftAST {

sealed trait OpenParenAST extends SoftAST

object OpenParen {

def apply(code: Code): OpenParen =
OpenParen(
index = code.index,
documentation = None,
code = code
)

}

case class OpenParen(
index: SourceIndex,
documentation: Option[Comments],
Expand All @@ -358,17 +270,6 @@ object SoftAST {

sealed trait CloseParenAST extends SoftAST

object CloseParen {

def apply(code: Code): CloseParen =
CloseParen(
index = code.index,
documentation = None,
code = code
)

}

case class CloseParen(
index: SourceIndex,
documentation: Option[Comments],
Expand All @@ -383,17 +284,6 @@ object SoftAST {

sealed trait OpenCurlyAST extends SoftAST

object OpenCurly {

def apply(code: Code): OpenCurly =
OpenCurly(
index = code.index,
documentation = None,
code = code
)

}

case class OpenCurly(
index: SourceIndex,
documentation: Option[Comments],
Expand All @@ -408,17 +298,6 @@ object SoftAST {

sealed trait CloseCurlyAST extends SoftAST

object CloseCurly {

def apply(code: Code): CloseCurly =
CloseCurly(
index = code.index,
documentation = None,
code = code
)

}

case class CloseCurly(
index: SourceIndex,
documentation: Option[Comments],
Expand Down Expand Up @@ -570,17 +449,6 @@ object SoftAST {

sealed trait IdentifierAST extends TypeAST with ReferenceCallOrIdentifier

object Identifier {

def apply(code: Code): Identifier =
Identifier(
index = code.index,
documentation = None,
code = code
)

}

case class Identifier(
index: SourceIndex,
documentation: Option[Comments],
Expand Down Expand Up @@ -609,17 +477,6 @@ object SoftAST {
postTextSpace: Option[Space])
extends BodyPartAST

object Unresolved {

def apply(code: Code): Unresolved =
Unresolved(
index = code.index,
documentation = None,
code = code
)

}

case class Unresolved(
index: SourceIndex,
documentation: Option[Comments],
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ package org.alephium.ralph.lsp.access.compiler.parser.soft

import org.alephium.ralph.lsp.access.compiler.parser.soft.TestParser._
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.{SoftAST, Token}
import org.alephium.ralph.lsp.access.compiler.parser.soft.ast.TestSoftAST._
import org.alephium.ralph.lsp.access.util.TestCodeUtil._
import org.alephium.ralph.lsp.utils.Node
import org.scalatest.matchers.should.Matchers
Expand All @@ -34,12 +35,7 @@ class AnnotationSpec extends AnyWordSpec with Matchers {
annotation shouldBe
SoftAST.Annotation(
index = indexOf(">>@<<"),
at = SoftAST.At(
SoftAST.Code(
index = indexOf(">>@<<"),
text = Token.At.lexeme
)
),
at = At(indexOf(">>@<<")),
preIdentifierSpace = None,
identifier = SoftAST.IdentifierExpected(indexOf("@>><<")),
postIdentifierSpace = None,
Expand All @@ -53,14 +49,7 @@ class AnnotationSpec extends AnyWordSpec with Matchers {
parseAnnotation("@anno(")

// opening paren is parsed
annotation.tuple.value.openParen shouldBe
SoftAST.OpenParen(
SoftAST.Code(
index = indexOf("@anno>>(<<"),
text = Token.OpenParen.lexeme
)
)

annotation.tuple.value.openParen shouldBe OpenParen(indexOf("@anno>>(<<"))
// closing paren is reported as expected
annotation.tuple.value.closeParen shouldBe SoftAST.CloseParenExpected(indexOf("@anno(>><<"))
}
Expand All @@ -84,12 +73,7 @@ class AnnotationSpec extends AnyWordSpec with Matchers {
annotation shouldBe
SoftAST.Annotation(
index = indexOf(">>@<<fn function()"),
at = SoftAST.At(
SoftAST.Code(
index = indexOf(">>@<<fn function()"),
text = Token.At.lexeme
)
),
at = At(indexOf(">>@<<fn function()")),
preIdentifierSpace = None,
identifier = SoftAST.IdentifierExpected(indexOf("@>><<fn function()")),
postIdentifierSpace = None,
Expand All @@ -106,18 +90,11 @@ class AnnotationSpec extends AnyWordSpec with Matchers {
annotation shouldBe
SoftAST.Annotation(
index = indexOf(">>@anno<<"),
at = SoftAST.At(
SoftAST.Code(
index = indexOf(">>@<<anno"),
text = Token.At.lexeme
)
),
at = At(indexOf(">>@<<anno")),
preIdentifierSpace = None,
identifier = SoftAST.Identifier(
SoftAST.Code(
index = indexOf("@>>anno<<"),
text = "anno"
)
identifier = Identifier(
index = indexOf("@>>anno<<"),
text = "anno"
),
postIdentifierSpace = None,
tuple = None,
Expand All @@ -132,18 +109,11 @@ class AnnotationSpec extends AnyWordSpec with Matchers {
annotation shouldBe
SoftAST.Annotation(
index = indexOf(">>@anno(a, b, c + d)<<"),
at = SoftAST.At(
SoftAST.Code(
index = indexOf(">>@<<anno(a, b, c + d)"),
text = Token.At.lexeme
)
),
at = At(indexOf(">>@<<anno(a, b, c + d)")),
preIdentifierSpace = None,
identifier = SoftAST.Identifier(
SoftAST.Code(
index = indexOf("@>>anno<<(a, b, c + d)"),
text = "anno"
)
identifier = Identifier(
index = indexOf("@>>anno<<(a, b, c + d)"),
text = "anno"
),
postIdentifierSpace = None,
// No need to test the AST for the Tuple. Simply test that a tuple is defined
Expand Down Expand Up @@ -189,35 +159,33 @@ class AnnotationSpec extends AnyWordSpec with Matchers {
// These test-cases are for annotations.
// The behaviour of Comments is tests in CommentsSpec
Some(expectedComment),
code = SoftAST.Code(
code = Code(
index = indexOf {
"""// documentation
|>>@<<anno
|""".stripMargin
},
text = Token.At.lexeme
token = Token.At
)
),
preIdentifierSpace = None,
identifier = SoftAST.Identifier(
SoftAST.Code(
index = indexOf {
"""// documentation
|@>>anno<<
|""".stripMargin
},
text = "anno"
)
identifier = Identifier(
index = indexOf {
"""// documentation
|@>>anno<<
|""".stripMargin
},
text = "anno"
),
postIdentifierSpace = Some(
SoftAST.Space(
SoftAST.Code(
Code(
index = indexOf {
"""// documentation
|@anno>>
|<<""".stripMargin
},
text = Token.Newline.lexeme
token = Token.Newline
)
)
),
Expand Down
Loading
Loading