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

Test constructors #394

Merged
merged 3 commits into from
Feb 25, 2025
Merged

Test constructors #394

merged 3 commits into from
Feb 25, 2025

Conversation

simerplaha
Copy link
Member

@simerplaha simerplaha commented Feb 25, 2025

Implements test-constructors for all Token types with additional test constructors, removing the need for the indexOf function call in most tests. This makes test cases a bit quicker to write and shorter in width.

The constructors were generated, and existing calls to indexOf were replaced wherever a simple regex-replace could do the job. The remaining can be replaced later.

Towards #104.

@simerplaha simerplaha requested a review from tdroxler February 25, 2025 03:31
def AlphUppercase(index: SourceIndex): SoftAST.TokenDocumented[Token.AlphUppercase.type] =
TokenDocumented(
index = index,
token = Token.AlphUppercase
Copy link
Member

@tdroxler tdroxler Feb 25, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Did you use AI to generate all this? otherwise congrats ^^

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nah. Just println

def code(token: Token) = {
  val objectName = token.productPrefix
  s"""
     |def $objectName(code: String): SoftAST.TokenDocumented[Token.$objectName.type] =
     |  $objectName(indexOf(code))
     |
     |def $objectName(index: SourceIndex): SoftAST.TokenDocumented[Token.$objectName.type] =
     |  TokenDocumented(
     |    index = index,
     |    token = Token.$objectName
     |  )
     |
     |""".stripMargin
}

val strings = tokens map code

println(strings.mkString)

Copy link
Member

@tdroxler tdroxler left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice cleaning

@simerplaha simerplaha merged commit f2f225c into master Feb 25, 2025
3 checks passed
@simerplaha simerplaha deleted the test_constructors branch February 25, 2025 08:36
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants