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

add more tests #106

Merged
merged 1 commit into from
Mar 10, 2024
Merged
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
45 changes: 41 additions & 4 deletions localServer/src/test/scala/scalameta_ast/IntegrationTest.scala
Original file line number Diff line number Diff line change
Expand Up @@ -95,10 +95,22 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
input.press("\n")
}

private def formatOutput(page: Page): Locator = {
getById(page, AriaRole.CHECKBOX, "format")
}

private def wildcardImport(page: Page): Locator = {
getById(page, AriaRole.CHECKBOX, "wildcard_import")
}

private def removeNewFields(page: Page): Locator = {
getById(page, AriaRole.CHECKBOX, "remove_new_fields")
}

private def initialExtractor(page: Page): Locator = {
getById(page, AriaRole.CHECKBOX, "initial_extractor")
}

private def changeOutputType(page: Page, outputType: String): Unit = {
page
.getByRole(AriaRole.RADIO)
Expand All @@ -121,6 +133,17 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
getTextboxById(page, "rule_name")
}

private def selectedDialect(page: Page): String = {
page.getByLabel("dialect").all().asScala.map(_.inputValue()).toList match {
case List(value) =>
value
case Nil =>
sys.error("not found dialect")
case values =>
sys.error(s"found multi values ${values}")
}
}

"change input" in withBrowser { page =>
setInput(page, "class A")
val expect = Seq(
Expand Down Expand Up @@ -211,6 +234,7 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
changeOutputType(page, "raw")
assert(output(page).textContent() contains """Term.Select(Term.Name("enum"), Term.Name("A"))""")
page.selectOption("select#dialect", "Scala3")
assert(selectedDialect(page) == "Scala3")
assert(output(page).textContent() contains "Defn.Enum")
}

Expand Down Expand Up @@ -302,32 +326,36 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A

assert(outSingleLine() == """Term.If(Term.Name("a"), Lit.Int(2), Lit.Int(3), Nil)""")

getById(page, AriaRole.CHECKBOX, "remove_new_fields").check()
removeNewFields(page).check()
assert(outSingleLine() == """Term.If(Term.Name("a"), Lit.Int(2), Lit.Int(3))""")

getById(page, AriaRole.CHECKBOX, "initial_extractor").check()
initialExtractor(page).check()
assert(outSingleLine() == """Term.If.Initial(Term.Name("a"), Lit.Int(2), Lit.Int(3))""")
}

"localStorage" in withBrowser { page =>
def check(
scalafmt: String,
formatOut: Boolean,
wildcard: Boolean,
_initialExtractor: Boolean,
outputType: String,
dialect: String,
pkg: String,
rule: String,
input: String
) = {
assert(scalafmtConfig(page).inputValue() == scalafmt)
assert(formatOutput(page).isChecked == formatOut)
assert(wildcardImport(page).isChecked == wildcard)
assert(initialExtractor(page).isChecked == _initialExtractor)
assert(
page.getByRole(AriaRole.RADIO).all().asScala.filter(_.isChecked).map(_.getAttribute("id")) == Seq(outputType)
)
assert(selectedDialect(page) == dialect)
assert(packageName(page).inputValue() == pkg)
assert(ruleName(page).inputValue() == rule)
assert(inputElem(page).inputValue() == input)

// TODO check more inputs
}

changeOutputType(page, "syntactic")
Expand All @@ -340,16 +368,22 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A
"""continuationIndent.defnSite = 2""",
"""continuationIndent.extendSite = 2""",
).mkString("\n"),
formatOut = true,
wildcard = false,
_initialExtractor = false,
outputType = "syntactic",
dialect = "Auto",
pkg = "fix",
rule = "",
input = "def a = b",
)

setScalafmtConfig(page, Seq("runner.dialect = Scala213"))
formatOutput(page).uncheck()
wildcardImport(page).check()
initialExtractor(page).check()
changeOutputType(page, "semantic")
page.selectOption("select#dialect", "Scala211")
packageName(page).fill("ppppppppp")
ruleName(page).fill("FFFFFFFFFF")
setInput(page, "aaa")
Expand All @@ -358,8 +392,11 @@ abstract class IntegrationTest(browserType: Playwright => BrowserType) extends A

check(
scalafmt = "runner.dialect = Scala213",
formatOut = false,
wildcard = true,
_initialExtractor = true,
outputType = "semantic",
dialect = "Scala211",
pkg = "ppppppppp",
rule = "FFFFFFFFFF",
input = "aaa\n",
Expand Down