diff --git a/core/build.gradle.kts b/core/build.gradle.kts index 536df406..61cf7447 100644 --- a/core/build.gradle.kts +++ b/core/build.gradle.kts @@ -20,6 +20,7 @@ import org.jetbrains.kotlin.gradle.dsl.abi.ExperimentalAbiValidation plugins { kotlin("jvm") + id("java-test-fixtures") alias(libs.plugins.dokka) alias(libs.plugins.dokka.javadoc) alias(libs.plugins.shadowJar) @@ -41,9 +42,11 @@ dependencies { api(libs.kotlin.stdlib) api(libs.kotlin.compilerEmbeddable) implementation(libs.ec4j) + + testFixturesApi(libs.googleTruth) + testFixturesApi(libs.junit) + testFixturesImplementation(libs.kotlin.test.junit4) testImplementation(libs.kotlin.test.junit4) - testImplementation(libs.googleTruth) - testImplementation(libs.junit) } val generateSources by tasks.registering { @@ -53,7 +56,11 @@ val generateSources by tasks.registering { tasks { // Run tests with UTF-16 encoding - test { jvmArgs("-Dfile.encoding=UTF-16") } + test { + jvmArgs("-Dfile.encoding=UTF-16") + // Forward the test-migration dump directory (see KtfmtDump) to the forked test JVM. + System.getProperty("ktfmt.dump.dir")?.let { systemProperty("ktfmt.dump.dir", it) } + } // Handle multiple versions of Kotlin here withType { diff --git a/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt b/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt index c93a0eff..ceb5995b 100644 --- a/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt +++ b/core/src/main/java/com/facebook/ktfmt/cli/ParsedArgs.kt @@ -252,15 +252,16 @@ data class ParsedArgs( return ParseResult.Error("partial formatting is only supported for a single file") } - val parsedArgs = ParsedArgs( - fileNames, - formattingOptions.copy(removeUnusedImports = removeUnusedImports), - dryRun, - setExitIfChanged, - stdinName, - editorConfig, - quiet, - ) + val parsedArgs = + ParsedArgs( + fileNames, + formattingOptions.copy(removeUnusedImports = removeUnusedImports), + dryRun, + setExitIfChanged, + stdinName, + editorConfig, + quiet, + ) parsedArgs.lineRanges.addAll(lineRanges) parsedArgs.characterRanges.addAll(characterRanges) return ParseResult.Ok(parsedArgs) diff --git a/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt b/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt index 57612b47..d5fd0d63 100644 --- a/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt +++ b/core/src/test/java/com/facebook/ktfmt/format/FormatterTest.kt @@ -17,9 +17,9 @@ package com.facebook.ktfmt.format import com.facebook.ktfmt.format.Formatter.META_FORMAT -import com.facebook.ktfmt.testutil.assertFormatted -import com.facebook.ktfmt.testutil.assertThatFormatting -import com.facebook.ktfmt.testutil.defaultTestFormattingOptions +import com.facebook.ktfmt.assertFormatted +import com.facebook.ktfmt.assertThatFormatting +import com.facebook.ktfmt.defaultTestFormattingOptions import com.google.common.truth.Truth.assertThat import org.junit.Assert.fail import org.junit.BeforeClass @@ -31,4494 +31,6 @@ import org.junit.runners.JUnit4 @RunWith(JUnit4::class) class FormatterTest { - @Test - fun `support script (kts) files`() = assertFormatted( - """ - |package foo - | - |import java.io.File - | - |val one: String - | - |val two: String - | - |fun f() { - | println("asd") - |} - | - |println("Called with args:") - | - |args.forEach { println(File + "-") } - |""" - .trimMargin(), - ) - - @Test - fun `support script (kts) files with a shebang`() = assertFormatted( - """ - |#!/usr/bin/env kscript - |package foo - | - |println("Called") - |""" - .trimMargin(), - ) - - @Test - fun `call chains`() = assertFormatted( - """ - |//////////////////////////////////////////////////////// - |fun f() { - | // Static method calls are attached to the class name. - | ImmutableList.newBuilder() - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .build() - | - | // Multiple call expressions --> each on its own line. - | ImmutableList() - | .newBuilder() - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .build() - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `line breaks in function arguments`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |fun f() { - | computeBreaks( - | javaOutput.commentsHelper, - | maxWidth, - | Doc.State(+0, 0)) - | computeBreaks( - | output.commentsHelper, maxWidth, State(0)) - | doc.computeBreaks( - | javaOutput.commentsHelper, - | maxWidth, - | Doc.State(+0, 0)) - | doc.computeBreaks( - | output.commentsHelper, maxWidth, State(0)) - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `parameters and return type in function definitions`() = assertFormatted( - """ - |//////////////////////////////////////// - |fun format( - | code: String, - | maxWidth: Int = - | DEFAULT_MAX_WIDTH_VERY_LONG - |): String { - | val a = 0 - |} - | - |fun print( - | code: String, - | maxWidth: Int = - | DEFAULT_MAX_WIDTH_VERY_LONG - |) { - | val a = 0 - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `kitchen sink of tests`() { - // Don't add more tests here - val code = - """ - |fun - |f ( - |a : Int - | , b: Double , c:String) { var result = 0 - | val aVeryLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongVar = 43 - | foo.bar.zed.accept( - | - | ) - | - | foo( - | - | ) - | - | foo.bar.zed.accept( - | DoSomething.bar() - | ) - | - | bar( - | ImmutableList.newBuilder().add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).build()) - | - | - | ImmutableList.newBuilder().add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).build() - | } - |""" - .trimMargin() - - val expected = - """ - |fun f(a: Int, b: Double, c: String) { - | var result = 0 - | val aVeryLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongVar = - | 43 - | foo.bar.zed.accept() - | - | foo() - | - | foo.bar.zed.accept(DoSomething.bar()) - | - | bar( - | ImmutableList.newBuilder() - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .build()) - | - | ImmutableList.newBuilder() - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .add(1) - | .build() - |} - |""" - .trimMargin() - - assertThatFormatting(code).isEqualTo(expected) - // Don't add more tests here - } - - @Test - fun `spacing around variable declarations`() = assertFormatted( - """ - |fun f() { - | var x: Int = 4 - | val y = 0 - |} - |""" - .trimMargin(), - ) - - @Test fun `class without a body nor properties`() = assertFormatted("class Foo\n") - - @Test fun `interface without a body nor properties`() = assertFormatted("interface Foo\n") - - @Test fun `preserve empty primary constructor`() = assertFormatted("class Foo()\n") - - @Test - fun `simple fun interface`() = assertFormatted( - """ - |fun interface MyRunnable { - | fun runIt() - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle complex fun interface without body`() = - assertFormatted("public fun interface Function> : (Int, T?) -> T?\n") - - @Test - fun `class without a body, with explicit ctor params`() = - assertFormatted("class Foo(a: Int, var b: Double, val c: String)\n") - - @Test - fun `class with a body and explicit ctor params`() = assertFormatted( - """ - |class Foo(a: Int, var b: Double, val c: String) { - | val x = 2 - | - | fun method() {} - | - | class Bar - |} - |""" - .trimMargin(), - ) - - @Test - fun `properties and fields with modifiers`() = assertFormatted( - """ - |class Foo(public val p1: Int, private val p2: Int, open val p3: Int, final val p4: Int) { - | private var f1 = 0 - | - | public var f2 = 0 - | - | open var f3 = 0 - | - | final var f4 = 0 - |} - |""" - .trimMargin(), - ) - - @Test - fun `properties with multiple modifiers`() = assertFormatted( - """ - |class Foo(public open inner val p1: Int) { - | public open inner var f2 = 0 - |} - |""" - .trimMargin(), - ) - - @Test - fun `spaces around binary operations`() = assertFormatted( - """ - |fun foo() { - | a = 5 - | x + 1 - |} - |""" - .trimMargin(), - ) - - @Test - fun `breaking long binary operations`() = assertFormatted( - """ - |//////////////////// - |fun foo() { - | val finalWidth = - | value1 + - | value2 + - | (value3 + - | value4 + - | value5) + - | foo(v) + - | (1 + 2) + - | function( - | value7, - | value8) + - | value9 - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `prioritize according to associativity`() = assertFormatted( - """ - |////////////////////////////////////// - |fun foo() { - | return expression1 != expression2 || - | expression2 != expression1 - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `once a binary expression is broken, split on every line`() = assertFormatted( - """ - |////////////////////////////////////// - |fun foo() { - | val sentence = - | "The" + - | "quick" + - | ("brown" + "fox") + - | "jumps" + - | "over" + - | "the" + - | "lazy" + - | "dog" - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `long binary expressions with ranges in the middle`() = assertFormatted( - """ - |////////////////////////////////////// - |fun foo() { - | val sentence = - | "The" + - | "quick" + - | ("brown".."fox") + - | ("brown"..<"fox") + - | "jumps" + - | "over" + - | "the".."lazy" + "dog" - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `line comment before binary operator keeps operator with operand`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |fun foo() { - | val result = - | firstCond && - | secondCond - | // comment about thirdCond. - | && thirdCond - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `line comment before operator in multi-operand chain`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |fun foo() { - | val result = - | firstCond && - | secondCond - | // comment about thirdCond. - | && thirdCond && - | fourthCond - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `block comment before binary operator keeps operator with operand`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |fun foo() { - | val result = - | firstCond && - | secondCond - | /* comment. */ - | && thirdCond - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `line comment before or operator keeps operator with operand`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |fun foo() { - | val result = - | firstCond || - | secondCond - | // comment about thirdCond. - | || thirdCond - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `inline block comment before binary operator does not break chain`() = assertFormatted( - """ - |////////////////////////////////////////////////////// - |fun foo() { - | val result = - | firstCondition || - | secondCondition /*tag*/ || - | thirdCondition - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `assignment expressions with scoping functions are block-like`() = assertFormatted( - """ - |/////////////////////////// - |fun f() { - | name.sub = scope { x -> - | // - | } - | name.sub += scope { x -> - | // - | } - | name.sub -= scope { x -> - | // - | } - | name.sub *= scope { x -> - | // - | } - | name.sub /= scope { x -> - | // - | } - | name.sub %= scope { x -> - | // - | } - |} - | - |fun h() { - | long.name.sub = - | scope { x -> - | // - | } - | long.name.sub += - | scope { x -> - | // - | } - | long.name.sub -= - | scope { x -> - | // - | } - | long.name.sub *= - | scope { x -> - | // - | } - | long.name.sub /= - | scope { x -> - | // - | } - | long.name.sub %= - | scope { x -> - | // - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `don't keep adding newlines between these two comments when they're at end of file`() { - assertFormatted( - """ - |package foo - |// a - | - |/* Another comment */ - |""" - .trimMargin(), - ) - - assertFormatted( - """ - |// Comment as first element - |package foo - |// a - | - |/* Another comment */ - |""" - .trimMargin(), - ) - - assertFormatted( - """ - |// Comment as first element then blank line - | - |package foo - |// a - | - |/* Another comment */ - |""" - .trimMargin(), - ) - - assertFormatted( - """ - |// Comment as first element - |package foo - |// Adjacent line comments - |// Don't separate - |""" - .trimMargin(), - ) - } - - @Test - fun `properties with line comment above initializer`() = assertFormatted( - """ - |class Foo { - | var x: Int = - | // Comment - | 0 - | - | var y: Int = - | // Comment - | scope { - | 0 // - | } - | - | var z: Int = - | // Comment - | if (cond) { - | 0 - | } else { - | 1 - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `properties with line comment above delegate`() = assertFormatted( - """ - |class Foo { - | var x: Int by - | // Comment - | 0 - | - | var y: Int by - | // Comment - | scope { - | 0 // - | } - | - | var z: Int by - | // Comment - | if (cond) { - | 0 - | } else { - | 1 - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `properties with accessors`() = assertFormatted( - """ - |class Foo { - | var x: Int - | get() = field - | - | var y: Boolean - | get() = x.equals(123) - | set(value) { - | field = value - | } - | - | var z: Boolean - | get() { - | x.equals(123) - | } - | - | var zz = false - | private set - |} - |""" - .trimMargin(), - ) - - @Test - fun `properties with accessors and semicolons on same line`() { - val code = - """ - |class Foo { - | var x = false; private set - | - | internal val a by lazy { 5 }; internal get - | - | var foo: Int; get() = 6; set(x) {}; - |} - |""" - .trimMargin() - - val expected = - """ - |class Foo { - | var x = false - | private set - | - | internal val a by lazy { 5 } - | internal get - | - | var foo: Int - | get() = 6 - | set(x) {} - |} - |""" - .trimMargin() - - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `a property with a too long name being broken on multiple lines`() = assertFormatted( - """ - |//////////////////// - |class Foo { - | val thisIsALongName: - | String = - | "Hello there this is long" - | get() = field - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `multi-character unary and binary operators such as ==`() = assertFormatted( - """ - |fun f() { - | 3 == 4 - | true && false - | a++ - | a === b - |} - |""" - .trimMargin(), - ) - - @Test - fun `package names stay in one line`() { - val code = - """ - | package com .example. subexample - | - |fun f() = 1 - |""" - .trimMargin() - val expected = - """ - |package com.example.subexample - | - |fun f() = 1 - |""" - .trimMargin() - - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `handle package name and imports with escapes and spaces`() = assertFormatted( - """ - |package com.`fun times`.`with package names` - | - |import `nothing stops`.`us`.`from doing this` - | - |fun f() = `from doing this`() - |""" - .trimMargin(), - ) - - @Test - fun `safe dot operator expression`() = assertFormatted( - """ - |fun f() { - | node?.name - |} - |""" - .trimMargin(), - ) - - @Test - fun `safe dot operator expression with normal`() = assertFormatted( - """ - |fun f() { - | node?.name.hello - |} - |""" - .trimMargin(), - ) - - @Test - fun `safe dot operator expression chain in expression function`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |fun f(number: Int) = - | Something.doStuff(number)?.size - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `avoid breaking suspected package names`() = assertFormatted( - """ - |/////////////////////// - |fun f() { - | com.facebook.Foo - | .format() - | org.facebook.Foo - | .format() - | java.lang.stuff.Foo - | .format() - | javax.lang.stuff.Foo - | .format() - | kotlin.lang.Foo - | .format() - | foo.facebook.Foo - | .format() - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `an assortment of tests for emitQualifiedExpression`() = assertFormatted( - """ - |///////////////////////////////////// - |fun f() { - | // Regression test: - | // https://github.com/facebook/ktfmt/issues/56 - | kjsdfglkjdfgkjdfkgjhkerjghkdfj - | ?.methodName1() - | - | // a series of field accesses - | // followed by a single call - | // expression is kept together. - | abcdefghijkl.abcdefghijkl - | ?.methodName2() - | - | // Similar to above. - | abcdefghijkl.abcdefghijkl - | ?.methodName3 - | ?.abcdefghijkl() - | - | // Multiple call expressions cause - | // each part of the expression - | // to be placed on its own line. - | abcdefghijkl - | ?.abcdefghijkl - | ?.methodName4() - | ?.abcdefghijkl() - | - | // Don't break first call - | // expression if it fits. - | foIt(something.something.happens()) - | .thenReturn(result) - | - | // Break after `longerThanFour(` - | // because it's longer than 4 chars - | longerThanFour( - | something.something - | .happens()) - | .thenReturn(result) - | - | // Similarly to above, when part of - | // qualified expression. - | foo.longerThanFour( - | something.something - | .happens()) - | .thenReturn(result) - | - | // Keep 'super' attached to the - | // method name - | super.abcdefghijkl - | .methodName4() - | .abcdefghijkl() - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `an assortment of tests for emitQualifiedExpression with lambdas`() = assertFormatted( - """ - |////////////////////////////////////////////////////////////////////////////// - |fun f() { - | val items = - | items.toMutableList.apply { - | // - | foo - | } - | - | val items = - | items.toMutableList().apply { - | // - | foo - | } - | - | // All dereferences are on one line (because they fit), even though - | // the apply() at the end requires a line break. - | val items = - | items.toMutableList.sdfkjsdf.sdfjksdflk.sdlfkjsldfj.apply { - | // - | foo - | } - | - | // All method calls are on one line (because they fit), even though - | // the apply() at the end requires a line break. - | val items = - | items.toMutableList().sdfkjsdf().sdfjksdflk().sdlfkjsldfj().apply { - | // - | foo - | } - | - | // All method calls with lambdas could fit, but we avoid a block like syntax - | // and break to one call per line - | val items = - | items - | .map { it + 1 } - | .filter { it > 0 } - | .apply { - | // - | foo - | } - | - | // the lambda is indented properly with the break before it - | val items = - | items.fieldName.sdfkjsdf.sdfjksdflk.sdlfkjsldfj.sdfjksdflk.sdlfkjsldfj - | .sdlfkjsldfj - | .apply { - | // - | foo - | } - | items.fieldName.sdfkjsdf.sdfjksdflk.sdlfkjsldfj.sdfjksdflk.sdlfkjsldfj - | .apply { - | // - | foo - | } - | - | // When there are multiple method calls, and they don't fit on one - | // line, put each on a new line. - | val items = - | items - | .toMutableList() - | .sdfkjsdf() - | .sdfjksdflk() - | .sdlfkjsldfj() - | .sdfjksdflk() - | .sdlfkjsldfj() - | .apply { - | // - | foo - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `when two lambdas are in a chain, avoid block syntax`() = assertFormatted( - """ - |class Foo : Bar() { - | fun doIt() { - | fruit.onlyBananas().forEach { banana -> - | val seeds = banana.find { it.type == SEED } - | println(seeds) - | } - | - | fruit - | .filter { isBanana(it, Bananas.types) } - | .forEach { banana -> - | val seeds = banana.find { it.type == SEED } - | println(seeds) - | } - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `don't one-line lambdas following argument breaks`() = assertFormatted( - """ - |/////////////////////////////////////////////////////////////////////////////// - |class Foo : Bar() { - | fun doIt() { - | // don't break in lambda, no argument breaks found - | fruit.forEach { eat(it) } - | - | // break in the lambda, without comma - | fruit.forEach( - | someVeryLongParameterNameThatWillCauseABreak, - | evenWithoutATrailingCommaOnTheParameterListSoLetsSeeIt) { - | eat(it) - | } - | - | // break in the lambda, with comma - | fruit.forEach( - | fromTheVine = true, - | ) { - | eat(it) - | } - | - | // don't break in the inner lambda, as nesting doesn't respect outer levels - | fruit.forEach( - | fromTheVine = true, - | ) { - | fruit.forEach { eat(it) } - | } - | - | // don't break in the lambda, as breaks don't propagate - | fruit - | .onlyBananas( - | fromTheVine = true, - | ) - | .forEach { eat(it) } - | - | // don't break in the inner lambda, as breaks don't propagate to parameters - | fruit.onlyBananas( - | fromTheVine = true, - | processThem = { eat(it) }, - | ) { - | eat(it) - | } - | - | // don't break in the inner lambda, as breaks don't propagate to the body - | fruit.onlyBananas( - | fromTheVine = true, - | ) { - | val anon = { eat(it) } - | } - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `indent parameters after a break when there's a lambda afterwards`() = assertFormatted( - """ - |/////////////////////////// - |class C { - | fun method() { - | Foo.FooBar( - | param1, param2) - | .apply { - | // - | foo - | } - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `no forward propagation of breaks in call expressions (at trailing lambda)`() = assertFormatted( - """ - |////////////////////////// - |fun test() { - | foo_bar_baz__zip(b) { - | c - | } - | foo.bar(baz).zip(b) { - | c - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `forward propagation of breaks in call expressions (at value args)`() = assertFormatted( - """ - |////////////////////// - |fun test() { - | foo_bar_baz__zip( - | b) { - | c - | } - |} - | - |fun test() { - | foo.bar(baz).zip( - | b) { - | c - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `forward propagation of breaks in call expressions (at type args)`() = assertFormatted( - """ - |/////////////////// - |fun test() { - | foo_bar_baz__zip< - | A>( - | b) { - | c - | } - | foo.bar(baz).zip< - | A>( - | b) { - | c - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `expected indent in methods following single-line strings`() = assertFormatted( - """ - |///////////////////////// - |"Hello %s" - | .format(expression) - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `forced break between multi-line strings and their selectors`() = assertFormatted( - """ - |///////////////////////// - |val STRING = - | $TQ - | |foo - | |$TQ - | .wouldFit() - | - |val STRING = - | $TQ - | |foo - | |//////////////////////////////////$TQ - | .wouldntFit() - | - |val STRING = - | $TQ - | |foo - | |$TQ - | .firstLink() - | .secondLink() - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `import list`() { - val code = - """ - | import com .example.common.reality. FooBar - | import com .example.common.reality. FooBar2 as foosBars - | import com .example.common.reality. * - | import foo.bar // Test - | import abc.def /* - | test */ - | - |val x = FooBar.def { foosBars(bar) } - |""" - .trimMargin() - val expected = - """ - |import abc.def /* - | test */ - |import com.example.common.reality.* - |import com.example.common.reality.FooBar - |import com.example.common.reality.FooBar2 as foosBars - |import foo.bar // Test - | - |val x = FooBar.def { foosBars(bar) } - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `imports with trailing comments and expressions`() { - val code = - """ - |import com.example.zab // test - |import com.example.foo ; val x = Sample(foo, zab) - |""" - .trimMargin() - - val expected = - """ - |import com.example.foo - |import com.example.zab // test - | - |val x = Sample(foo, zab) - |""" - .trimMargin() - - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `imports with trailing block comment and expression`() { - val code = - """ - |import com.example.zab /* heya */ - |import com.example.foo ; val x = Sample(foo, zab) - |""" - .trimMargin() - - val expected = - """ - |import com.example.foo - |import com.example.zab /* heya */ - | - |val x = Sample(foo, zab) - |""" - .trimMargin() - - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `imports with trailing block comment and expression with false positive double slash`() { - val code = - """ - |import com.example.zab /* // */ - |import com.example.foo ; val x = Sample(foo, zab) - |""" - .trimMargin() - - val expected = - """ - |import com.example.foo - |import com.example.zab /* // */ - | - |val x = Sample(foo, zab) - |""" - .trimMargin() - - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `backticks are ignored in import sort order`() = assertFormatted( - """ - |import com.example.`if` - |import com.example.we - |import com.example.`when` - |import com.example.wow - | - |val x = `if` { we.`when`(wow) } - |""" - .trimMargin(), - ) - - @Test - fun `backticks are ignored in import sort order ('as' directory)`() = assertFormatted( - """ - |import com.example.a as `if` - |import com.example.a as we - |import com.example.a as `when` - |import com.example.a as wow - | - |val x = `if` { we.`when`(wow) } - |""" - .trimMargin(), - ) - - @Test - fun `imports are deduplicated`() { - val code = - """ - |import com.example.b.* - |import com.example.b - |import com.example.a as `if` - |import com.example.a as we - |import com.example.a as `when` - |import com.example.a as wow - |import com.example.a as `when` - | - |val x = `if` { we.`when`(wow) } ?: b - |""" - .trimMargin() - val expected = - """ - |import com.example.a as `if` - |import com.example.a as we - |import com.example.a as `when` - |import com.example.a as wow - |import com.example.b - |import com.example.b.* - | - |val x = `if` { we.`when`(wow) } ?: b - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `unused imports are removed`() { - val code = - """ - |import com.unused.Sample - |import com.used.FooBarBaz as Baz - |import com.used.bar // test - |import com.used.`class` - |import com.used.a.* - |import com.used.b as `if` - |import com.used.b as we - |import com.unused.a as `when` - |import com.unused.a as wow - | - |fun test(input: we) { - | Baz(`class`) - | `if` { bar } - | val x = unused() - |} - |""" - .trimMargin() - val expected = - """ - |import com.used.FooBarBaz as Baz - |import com.used.a.* - |import com.used.b as `if` - |import com.used.b as we - |import com.used.bar // test - |import com.used.`class` - | - |fun test(input: we) { - | Baz(`class`) - | `if` { bar } - | val x = unused() - |} - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `unused import removal handles backtick-escaped full-path imports`() { - val code = - """ - |import `com.example.Foo.bar` - |import `com.example.Foo.baz` as qux - |import `com.example.unused.Quux` - | - |fun test() = bar + qux - |""" - .trimMargin() - val expected = - """ - |import `com.example.Foo.bar` - |import `com.example.Foo.baz` as qux - | - |fun test() = bar + qux - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `used imports from this package are removed`() { - val code = - """ - |package com.example - | - |import com.example.Sample - |import com.example.Sample.CONSTANT - |import com.example.a.foo - | - |fun test() { - | foo(CONSTANT, Sample()) - |} - |""" - .trimMargin() - val expected = - """ - |package com.example - | - |import com.example.Sample.CONSTANT - |import com.example.a.foo - | - |fun test() { - | foo(CONSTANT, Sample()) - |} - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `potentially unused imports from this package are kept if they are overloaded`() { - val code = - """ - |package com.example - | - |import com.example.a - |import com.example.b - |import com.example.c - |import com.notexample.a - |import com.notexample.b - |import com.notexample.notC as c - | - |fun test() { - | a("hello") - | c("hello") - |} - |""" - .trimMargin() - val expected = - """ - |package com.example - | - |import com.example.a - |import com.example.c - |import com.notexample.a - |import com.notexample.notC as c - | - |fun test() { - | a("hello") - | c("hello") - |} - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `used imports from this package are kept if they are aliased`() { - val code = - """ - |package com.example - | - |import com.example.b as a - |import com.example.c - | - |fun test() { - | a("hello") - |} - |""" - .trimMargin() - val expected = - """ - |package com.example - | - |import com.example.b as a - | - |fun test() { - | a("hello") - |} - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `unused imports are computed using only the alias name if present`() { - val code = - """ - |package com.example - | - |import com.notexample.a as b - | - |fun test() { - | a("hello") - |} - |""" - .trimMargin() - val expected = - """ - |package com.example - | - |fun test() { - | a("hello") - |} - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `keep import elements only mentioned in kdoc`() { - val code = - """ - |package com.example.kdoc - | - |import com.example.Bar - |import com.example.Example - |import com.example.Foo - |import com.example.JavaDocLink - |import com.example.Param - |import com.example.R - |import com.example.ReturnedValue - |import com.example.Sample - |import com.example.unused - |import com.example.exception.AnException - |import com.example.kdoc.Doc - | - |/** - | * [Foo] is something only mentioned here, just like [R.layout.test] and [Doc]. - | * - | * Old {@link JavaDocLink} that gets removed. - | * - | * @throws AnException - | * @exception Sample.SampleException - | * @param unused [Param] - | * @property JavaDocLink [Param] - | * @return [Unit] as [ReturnedValue] - | * @sample Example - | * @see Bar for more info - | * @throws AnException - | */ - |class Dummy - |""" - .trimMargin() - val expected = - """ - |package com.example.kdoc - | - |import com.example.Bar - |import com.example.Example - |import com.example.Foo - |import com.example.Param - |import com.example.R - |import com.example.ReturnedValue - |import com.example.Sample - |import com.example.exception.AnException - | - |/** - | * [Foo] is something only mentioned here, just like [R.layout.test] and [Doc]. - | * - | * Old {@link JavaDocLink} that gets removed. - | * - | * @param unused [Param] - | * @property JavaDocLink [Param] - | * @return [Unit] as [ReturnedValue] - | * @throws AnException - | * @throws AnException - | * @exception Sample.SampleException - | * @sample Example - | * @see Bar for more info - | */ - |class Dummy - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `keep import elements only mentioned in kdoc, single line`() { - assertFormatted( - """ - |import com.shopping.Bag - | - |/** - | * Some summary. - | * - | * @param count you can fit this many in a [Bag] - | */ - |fun fetchBananas(count: Int) - |""" - .trimMargin(), - ) - } - - @Test - fun `keep import elements only mentioned in kdoc, multiline`() { - assertFormatted( - """ - |import com.shopping.Bag - | - |/** - | * Some summary. - | * - | * @param count this is how many of these wonderful fruit you can fit into the useful object that - | * you may refer to as a [Bag] - | */ - |fun fetchBananas(count: Int) - |""" - .trimMargin(), - ) - } - - @Test - fun `keep component imports`() = assertFormatted( - """ - |import com.example.component1 - |import com.example.component10 - |import com.example.component120 - |import com.example.component2 - |import com.example.component3 - |import com.example.component4 - |import com.example.component5 - |""" - .trimMargin(), - ) - - @Test - fun `keep operator imports`() = assertFormatted( - """ - |import com.example.and - |import com.example.compareTo - |import com.example.contains - |import com.example.dec - |import com.example.div - |import com.example.divAssign - |import com.example.equals - |import com.example.get - |import com.example.getValue - |import com.example.hasNext - |import com.example.inc - |import com.example.invoke - |import com.example.iterator - |import com.example.minus - |import com.example.minusAssign - |import com.example.mod - |import com.example.modAssign - |import com.example.next - |import com.example.not - |import com.example.or - |import com.example.plus - |import com.example.plusAssign - |import com.example.provideDelegate - |import com.example.rangeTo - |import com.example.rem - |import com.example.remAssign - |import com.example.set - |import com.example.setValue - |import com.example.times - |import com.example.timesAssign - |import com.example.unaryMinus - |import com.example.unaryPlus - |import org.gradle.kotlin.dsl.assign - |""" - .trimMargin(), - ) - - @Test - fun `keep unused imports when formatting options has feature turned off`() { - val code = - """ - |import com.unused.FooBarBaz as Baz - |import com.unused.Sample - |import com.unused.a as `when` - |import com.unused.a as wow - |import com.unused.a.* - |import com.unused.b as `if` - |import com.unused.b as we - |import com.unused.bar // test - |import com.unused.`class` - |""" - .trimMargin() - - assertThatFormatting(code) - .withOptions(defaultTestFormattingOptions.copy(removeUnusedImports = false)) - .isEqualTo(code) - } - - @Test - fun `comments between imports are moved above import list`() { - val code = - """ - |package com.facebook.ktfmt - | - |/* leading comment */ - |import com.example.abc - |/* internal comment 1 */ - |import com.example.bcd - |// internal comment 2 - |import com.example.Sample - |// trailing comment - | - |val x = Sample(abc, bcd) - |""" - .trimMargin() - val expected = - """ - |package com.facebook.ktfmt - | - |/* leading comment */ - |/* internal comment 1 */ - |// internal comment 2 - |import com.example.Sample - |import com.example.abc - |import com.example.bcd - | - |// trailing comment - | - |val x = Sample(abc, bcd) - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `no redundant newlines when there are no imports`() = assertFormatted( - """ - |package foo123 - | - |/* - |bar - |*/ - |""" - .trimMargin(), - ) - - @Test - fun `basic annotations`() = assertFormatted( - """ - |@Fancy - |class Foo { - | @Fancy - | fun baz(@Fancy foo: Int) { - | @Fancy val a = 1 + foo - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `function calls with multiple arguments`() = assertFormatted( - """ - |fun f() { - | foo(1, 2, 3) - | - | foo( - | 123456789012345678901234567890, - | 123456789012345678901234567890, - | 123456789012345678901234567890) - |} - |""" - .trimMargin(), - ) - - @Test - fun `function calls with multiple named arguments`() = assertFormatted( - """ - |fun f() { - | foo(1, b = 2, c = 3) - | - | foo( - | 123456789012345678901234567890, - | b = 23456789012345678901234567890, - | c = 3456789012345678901234567890) - |} - |""" - .trimMargin(), - ) - - @Test - fun `named arguments indent their value expression`() = assertFormatted( - """ - |fun f() = - | Bar( - | tokens = - | mutableListOf().apply { - | // Printing - | print() - | }, - | duration = duration) - |""" - .trimMargin(), - ) - - @Test - fun `Trailing comma forces variable value in list onto new line with manageTrailingCommas turned off`() = assertFormatted( - """ - val aVar = setOf( - Env.Dev, - Env.Prod, - ) - val aVar = setOf(Env.Dev, Env.Prod) - - """ - .trimIndent(), - deduceMaxWidth = false, - ) - - @Test - fun `nested functions, maps, and statements in named parameters - default`() = assertFormatted( - """ - |//////////////////////////////////////////////////////////////////// - |function( - | param = - | (rate downTo min step step).drop(1).map { - | nestedFun( - | rate = - | rate( - | value = - | firstArg().info.get(0).rate.value)) - | }) - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `nested functions, maps, and statements in named parameters kotlin lang formats differently than default`() = assertFormatted( - """ - |///////////////////////////////////////////////////////////////////// - |function( - | param = - | (rate downTo min step step).drop(1).map { - | nestedFun( - | rate = - | rate( - | value = - | firstArg().info.get(0).rate.value, - | ), - | ) - | }, - |) - |""" - .trimMargin(), - formattingOptions = Formatter.KOTLINLANG_FORMAT, - deduceMaxWidth = true, - ) - - @Test - fun `complex calls and calculation in named parameters without wrapping`() = assertFormatted( - """ - calculateMath( - r = apr.sc(10) / BigDecimal(100) / BigDecimal(12), - n = 12 * term, - numerator = ((BigDecimal.ONE + r).pow(n)) - BigDecimal.ONE, - denominator = r * (BigDecimal.ONE + r).pow(n), - ) - - """ - .trimIndent(), - deduceMaxWidth = false, - ) - - @Test - fun `Arguments are blocks`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |override fun visitProperty(property: KtProperty) { - | builder.sync(property) - | builder.block(ZERO) { - | declareOne( - | kind = DeclarationKind.FIELD, - | modifiers = property.modifierList, - | valOrVarKeyword = - | property.valOrVarKeyword.text, - | typeParameters = - | property.typeParameterList, - | receiver = property.receiverTypeReference, - | name = property.nameIdentifier?.text, - | type = property.typeReference, - | typeConstraintList = - | property.typeConstraintList, - | delegate = property.delegate, - | initializer = property.initializer) - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `anonymous function`() = assertFormatted( - """ - |fun f() { - | setListener( - | fun(number: Int) { - | println(number) - | }) - |} - |""" - .trimMargin(), - ) - - @Test - fun `anonymous function with receiver`() = assertFormatted( - """ - |fun f() { - | setListener( - | fun View.() { - | println(this) - | }) - |} - |""" - .trimMargin(), - ) - - @Test - fun `newlines between clauses of when() are preserved`() { - assertThatFormatting( - """ - |fun f(x: Int) { - | when (x) { - | - | - | 1 -> print(1) - | 2 -> print(2) - | - | - | 3 -> - | // Comment - | print(3) - | - | else -> { - | print("else") - | } - | - | } - |} - |""" - .trimMargin(), - ) - .isEqualTo( - """ - |fun f(x: Int) { - | when (x) { - | 1 -> print(1) - | 2 -> print(2) - | - | 3 -> - | // Comment - | print(3) - | - | else -> { - | print("else") - | } - | } - |} - |""" - .trimMargin(), - ) - } - - @Test - fun `when() with a subject expression`() = assertFormatted( - """ - |fun f(x: Int) { - | when (x) { - | 1 -> print(1) - | 2 -> print(2) - | 3 -> - | // Comment - | print(3) - | else -> { - | print("else") - | } - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `when() expression with complex predicates`() = assertFormatted( - """ - |fun f(x: Int) { - | when { - | x == 1 || x == 2 -> print(1) - | x == 3 && x != 4 -> print(2) - | else -> { - | print(3) - | } - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `when() expression with several conditions`() = assertFormatted( - """ - |fun f(x: Int) { - | when { - | 0, - | 1 -> print(1) - | else -> print(0) - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `when() expression with is and in`() = assertFormatted( - """ - |fun f(x: Int) { - | when (x) { - | is String -> print(1) - | !is String -> print(2) - | in 1..3 -> print() - | in a..b -> print() - | in a..3 -> print() - | in 1..b -> print() - | !in 1..b -> print() - | in 1.. print() - | else -> print(3) - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `when() expression with enum values`() = assertFormatted( - """ - |fun f(x: Color) { - | when (x) { - | is Color.Red -> print(1) - | is Color.Green -> print(2) - | else -> print(3) - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `when() expression with generic matcher and exhaustive`() = assertFormatted( - """ - |fun f(x: Result) { - | when (x) { - | is Success<*> -> print(1) - | is Failure -> print(2) - | }.exhaustive - |} - |""" - .trimMargin(), - ) - - @Test - fun `when() expression with multiline condition`() = assertFormatted( - """ - |////////////////////////// - |fun foo() { - | when (expressions1 + - | expression2 + - | expression3) { - | 1 -> print(1) - | 2 -> print(2) - | } - | - | when (foo( - | expressions1 && - | expression2 && - | expression3)) { - | 1 -> print(1) - | 2 -> print(2) - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `lambda assigned to variable does not break before brace`() = assertFormatted( - """ - |fun doIt() { - | val lambda = { - | doItOnce() - | doItTwice() - | } - |} - | - |fun foo() = { - | doItOnce() - | doItTwice() - |} - |""" - .trimMargin(), - ) - - @Test - fun `when() expression storing in local variable`() = assertFormatted( - """ - |fun f(x: Result) { - | when (val y = x.improved()) { - | is Success<*> -> print(y) - | is Failure -> print(2) - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `line breaks inside when expressions and conditions`() = assertFormatted( - """ - |fun f() { - | return Text.create(c) - | .onTouch { - | when (it.motionEvent.action) { - | ACTION_DOWN -> - | Toast.makeText(it.view.context, "Down!", Toast.LENGTH_SHORT, blablabla).show() - | ACTION_UP -> Toast.makeText(it.view.context, "Up!", Toast.LENGTH_SHORT).show() - | ACTION_DOWN -> - | Toast.makeText( - | it.view.context, "Down!", Toast.LENGTH_SHORT, blablabla, blablabl, blabla) - | .show() - | } - | } - | .build() - |} - |""" - .trimMargin(), - ) - - @Test - fun `when() expression with lambda body`() = assertFormatted( - """ - |fun f(x: ModifierType) { - | when (x) { - | is FirstModifierType -> { myObject -> - | doCustomModification(x, myObject) - | } - | is SecondModifierType -> { myObject -> - | doOtherModification(x, myObject) - | } - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `when() expression with no-param lambda body`() = assertFormatted( - """ - |fun f(x: Int) { - | when (x) { - | 0 -> { - | doSomething() - | } - | 1 -> print("hello") - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `when() expression with lambda body containing multiple statements`() = assertFormatted( - """ - |fun f(x: ModifierType) { - | when (x) { - | is FirstModifierType -> { myObject -> - | doFirstThing(myObject) - | doSecondThing(myObject) - | doThirdThing(myObject) - | } - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `function return types`() = assertFormatted( - """ - |fun f1(): Int = 0 - | - |fun f2(): Int {} - |""" - .trimMargin(), - ) - - @Test - fun `multi line function without a block body`() = assertFormatted( - """ - |///////////////////////// - |fun longFunctionNoBlock(): - | Int = - | 1234567 + 1234567 - | - |fun shortFun(): Int = - | 1234567 + 1234567 - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `return type doesn't fit in one line`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |interface X { - | fun f( - | arg1: Arg1Type, - | arg2: Arg2Type - | ): Map>? { - | // - | } - | - | fun functionWithGenericReturnType( - | arg1: Arg1Type, - | arg2: Arg2Type - | ): Map>? { - | // - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `list of superclasses`() = assertFormatted( - """ - |class Derived2 : Super1, Super2 {} - | - |class Derived1 : Super1, Super2 - | - |class Derived3(a: Int) : Super1(a) - | - |class Derived4 : Super1() - | - |class Derived5 : Super3() - |""" - .trimMargin(), - ) - - @Test - fun `list of superclasses over multiple lines`() = assertFormatted( - """ - |//////////////////// - |class Derived2 : - | Super1, - | Super2 {} - | - |class Derived1 : - | Super1, Super2 - | - |class Derived3( - | a: Int - |) : Super1(a) - | - |class Derived4 : - | Super1() - | - |class Derived5 : - | Super3() - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `annotations with parameters`() = assertFormatted( - """ - |@AnnWithArrayValue(1, 2, 3) class C - |""" - .trimMargin(), - ) - - @Test - fun `method modifiers`() = assertFormatted( - """ - |override internal fun f() {} - |""" - .trimMargin(), - ) - - @Test - fun `class modifiers`() = assertFormatted( - """ - |abstract class Foo - | - |inner class Foo - | - |final class Foo - | - |open class Foo - |""" - .trimMargin(), - ) - - @Test - fun `kdoc comments`() { - val code = - """ - |/** - | * foo - | */ class F { - | - | } - |""" - .trimMargin() - val expected = - """ - |/** foo */ - |class F {} - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `nested kdoc comments`() { - val code = - """ - |/** - | * foo /* bla */ - | */ class F { - | - | } - |""" - .trimMargin() - val expected = - """ - |/** foo /* bla */ */ - |class F {} - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `nested kdoc inside code block`() = assertFormatted( - """ - |/** - | * ``` - | * edit -> { /* open edit screen */ } - | * ``` - | */ - |fun foo() {} - |""" - .trimMargin(), - ) - - @Test - fun `formatting kdoc doesn't add p HTML tags`() = assertFormatted( - """ - |/** - | * Bla bla bla bla - | * - | * This is an inferred paragraph, and as you can see, we don't add a p tag to it, even though bla - | * bla. - | * - | *

On the other hand, we respect existing tags, and don't remove them. + */ diff --git a/core/testData/format/meta/kdoc/htmlTags.kt b/core/testData/format/meta/kdoc/htmlTags.kt new file mode 100644 index 00000000..99358b4a --- /dev/null +++ b/core/testData/format/meta/kdoc/htmlTags.kt @@ -0,0 +1,8 @@ +/** + * Bla bla bla bla + * + * This is an inferred paragraph, and as you can see, we don't add a p tag to it, even though bla + * bla. + * + *

On the other hand, we respect existing tags, and don't remove them. + */ diff --git a/core/testData/format/meta/kdoc/lists.expected.kt b/core/testData/format/meta/kdoc/lists.expected.kt new file mode 100644 index 00000000..8803a942 --- /dev/null +++ b/core/testData/format/meta/kdoc/lists.expected.kt @@ -0,0 +1,7 @@ +/** + * Here are some fruit I like: + * - Banana + * - Apple + * + * This is another paragraph + */ diff --git a/core/testData/format/meta/kdoc/lists.kt b/core/testData/format/meta/kdoc/lists.kt new file mode 100644 index 00000000..8803a942 --- /dev/null +++ b/core/testData/format/meta/kdoc/lists.kt @@ -0,0 +1,7 @@ +/** + * Here are some fruit I like: + * - Banana + * - Apple + * + * This is another paragraph + */ diff --git a/core/testData/format/meta/kdoc/lists2.expected.kt b/core/testData/format/meta/kdoc/lists2.expected.kt new file mode 100644 index 00000000..b5e66b43 --- /dev/null +++ b/core/testData/format/meta/kdoc/lists2.expected.kt @@ -0,0 +1,8 @@ +/** + * Here are some fruit I like: + * - Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana + * Banana Banana Banana Banana Banana + * - Apple Apple Apple Apple Apple Apple + * + * This is another paragraph + */ diff --git a/core/testData/format/meta/kdoc/lists2.kt b/core/testData/format/meta/kdoc/lists2.kt new file mode 100644 index 00000000..d67fe72d --- /dev/null +++ b/core/testData/format/meta/kdoc/lists2.kt @@ -0,0 +1,8 @@ +/** + * Here are some fruit I like: + * - Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana + * - Apple Apple Apple Apple + * Apple Apple + * + * This is another paragraph + */ diff --git a/core/testData/format/meta/kdoc/lists3.expected.kt b/core/testData/format/meta/kdoc/lists3.expected.kt new file mode 100644 index 00000000..495d6ab6 --- /dev/null +++ b/core/testData/format/meta/kdoc/lists3.expected.kt @@ -0,0 +1,7 @@ +/** + * Here are some fruit I like: + * * Banana + * * Apple + * + * This is another paragraph + */ diff --git a/core/testData/format/meta/kdoc/lists3.kt b/core/testData/format/meta/kdoc/lists3.kt new file mode 100644 index 00000000..495d6ab6 --- /dev/null +++ b/core/testData/format/meta/kdoc/lists3.kt @@ -0,0 +1,7 @@ +/** + * Here are some fruit I like: + * * Banana + * * Apple + * + * This is another paragraph + */ diff --git a/core/testData/format/meta/kdoc/lists4.expected.kt b/core/testData/format/meta/kdoc/lists4.expected.kt new file mode 100644 index 00000000..293bec48 --- /dev/null +++ b/core/testData/format/meta/kdoc/lists4.expected.kt @@ -0,0 +1,7 @@ +/** + * Here are some fruit I like: + * 1. Banana + * 2. Apple + * + * This is another paragraph + */ diff --git a/core/testData/format/meta/kdoc/lists4.kt b/core/testData/format/meta/kdoc/lists4.kt new file mode 100644 index 00000000..293bec48 --- /dev/null +++ b/core/testData/format/meta/kdoc/lists4.kt @@ -0,0 +1,7 @@ +/** + * Here are some fruit I like: + * 1. Banana + * 2. Apple + * + * This is another paragraph + */ diff --git a/core/testData/format/meta/kdoc/markdownErrors.expected.kt b/core/testData/format/meta/kdoc/markdownErrors.expected.kt new file mode 100644 index 00000000..29ebf40f --- /dev/null +++ b/core/testData/format/meta/kdoc/markdownErrors.expected.kt @@ -0,0 +1,2 @@ +/** \[ */ +fun markdownError() = Unit diff --git a/core/testData/format/meta/kdoc/markdownErrors.kt b/core/testData/format/meta/kdoc/markdownErrors.kt new file mode 100644 index 00000000..29ebf40f --- /dev/null +++ b/core/testData/format/meta/kdoc/markdownErrors.kt @@ -0,0 +1,2 @@ +/** \[ */ +fun markdownError() = Unit diff --git a/core/testData/format/meta/kdoc/nestedKDoc.expected.kt b/core/testData/format/meta/kdoc/nestedKDoc.expected.kt new file mode 100644 index 00000000..cdc5b5c9 --- /dev/null +++ b/core/testData/format/meta/kdoc/nestedKDoc.expected.kt @@ -0,0 +1,2 @@ +/** foo /* bla */ */ +class F {} diff --git a/core/testData/format/meta/kdoc/nestedKDoc.kt b/core/testData/format/meta/kdoc/nestedKDoc.kt new file mode 100644 index 00000000..5367d8f7 --- /dev/null +++ b/core/testData/format/meta/kdoc/nestedKDoc.kt @@ -0,0 +1,5 @@ +/** + * foo /* bla */ + */ class F { + + } diff --git a/core/testData/format/meta/kdoc/nestedKDocInCodeBlock.expected.kt b/core/testData/format/meta/kdoc/nestedKDocInCodeBlock.expected.kt new file mode 100644 index 00000000..b475f6f6 --- /dev/null +++ b/core/testData/format/meta/kdoc/nestedKDocInCodeBlock.expected.kt @@ -0,0 +1,6 @@ +/** + * ``` + * edit -> { /* open edit screen */ } + * ``` + */ +fun foo() {} diff --git a/core/testData/format/meta/kdoc/nestedKDocInCodeBlock.kt b/core/testData/format/meta/kdoc/nestedKDocInCodeBlock.kt new file mode 100644 index 00000000..b475f6f6 --- /dev/null +++ b/core/testData/format/meta/kdoc/nestedKDocInCodeBlock.kt @@ -0,0 +1,6 @@ +/** + * ``` + * edit -> { /* open edit screen */ } + * ``` + */ +fun foo() {} diff --git a/core/testData/format/meta/misc/arrayIndexing.expected.kt b/core/testData/format/meta/misc/arrayIndexing.expected.kt new file mode 100644 index 00000000..d98bbc99 --- /dev/null +++ b/core/testData/format/meta/misc/arrayIndexing.expected.kt @@ -0,0 +1,4 @@ +fun f(a: Magic) { + a[3] + b[3, 4] +} diff --git a/core/testData/format/meta/misc/arrayIndexing.kt b/core/testData/format/meta/misc/arrayIndexing.kt new file mode 100644 index 00000000..d98bbc99 --- /dev/null +++ b/core/testData/format/meta/misc/arrayIndexing.kt @@ -0,0 +1,4 @@ +fun f(a: Magic) { + a[3] + b[3, 4] +} diff --git a/core/testData/format/meta/misc/arrayIndexing2.expected.kt b/core/testData/format/meta/misc/arrayIndexing2.expected.kt new file mode 100644 index 00000000..173e44fb --- /dev/null +++ b/core/testData/format/meta/misc/arrayIndexing2.expected.kt @@ -0,0 +1,14 @@ +fun f(a: Magic) { + foo.bar() + .foobar[1, 2, 3] + foo.bar() + .foobar[ + 1, + 2, + 3, + 4, + 5] + foo.bar() + .foobar[1, 2, 3] + .barfoo[3, 2, 1] +} diff --git a/core/testData/format/meta/misc/arrayIndexing2.kt b/core/testData/format/meta/misc/arrayIndexing2.kt new file mode 100644 index 00000000..170d3bdb --- /dev/null +++ b/core/testData/format/meta/misc/arrayIndexing2.kt @@ -0,0 +1,17 @@ +// MAX_WIDTH 23 +// TRAILING_COMMA_STRATEGY NONE + +fun f(a: Magic) { + foo.bar() + .foobar[1, 2, 3] + foo.bar() + .foobar[ + 1, + 2, + 3, + 4, + 5] + foo.bar() + .foobar[1, 2, 3] + .barfoo[3, 2, 1] +} diff --git a/core/testData/format/meta/misc/arrayIndexing3.expected.kt b/core/testData/format/meta/misc/arrayIndexing3.expected.kt new file mode 100644 index 00000000..173e44fb --- /dev/null +++ b/core/testData/format/meta/misc/arrayIndexing3.expected.kt @@ -0,0 +1,14 @@ +fun f(a: Magic) { + foo.bar() + .foobar[1, 2, 3] + foo.bar() + .foobar[ + 1, + 2, + 3, + 4, + 5] + foo.bar() + .foobar[1, 2, 3] + .barfoo[3, 2, 1] +} diff --git a/core/testData/format/meta/misc/arrayIndexing3.kt b/core/testData/format/meta/misc/arrayIndexing3.kt new file mode 100644 index 00000000..170d3bdb --- /dev/null +++ b/core/testData/format/meta/misc/arrayIndexing3.kt @@ -0,0 +1,17 @@ +// MAX_WIDTH 23 +// TRAILING_COMMA_STRATEGY NONE + +fun f(a: Magic) { + foo.bar() + .foobar[1, 2, 3] + foo.bar() + .foobar[ + 1, + 2, + 3, + 4, + 5] + foo.bar() + .foobar[1, 2, 3] + .barfoo[3, 2, 1] +} diff --git a/core/testData/format/meta/misc/combination.expected.kt b/core/testData/format/meta/misc/combination.expected.kt new file mode 100644 index 00000000..0ccc2e8a --- /dev/null +++ b/core/testData/format/meta/misc/combination.expected.kt @@ -0,0 +1,37 @@ +fun f(a: Int, b: Double, c: String) { + var result = 0 + val aVeryLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongVar = + 43 + foo.bar.zed.accept() + + foo() + + foo.bar.zed.accept(DoSomething.bar()) + + bar( + ImmutableList.newBuilder() + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .build()) + + ImmutableList.newBuilder() + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .build() +} diff --git a/core/testData/format/meta/misc/combination.kt b/core/testData/format/meta/misc/combination.kt new file mode 100644 index 00000000..e820552e --- /dev/null +++ b/core/testData/format/meta/misc/combination.kt @@ -0,0 +1,25 @@ +// TRAILING_COMMA_STRATEGY NONE + +fun +f ( +a : Int + , b: Double , c:String) { var result = 0 + val aVeryLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongLongVar = 43 + foo.bar.zed.accept( + + ) + + foo( + + ) + + foo.bar.zed.accept( + DoSomething.bar() + ) + + bar( + ImmutableList.newBuilder().add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).build()) + + + ImmutableList.newBuilder().add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).add(1).build() + } \ No newline at end of file diff --git a/core/testData/format/meta/misc/destructuringDeclaration.expected.kt b/core/testData/format/meta/misc/destructuringDeclaration.expected.kt new file mode 100644 index 00000000..027b159d --- /dev/null +++ b/core/testData/format/meta/misc/destructuringDeclaration.expected.kt @@ -0,0 +1,9 @@ +fun f() { + val (a, b: Int) = listOf(1, 2) + val (asd, asd, asd, asd, asd, asd, asd) = + foo.bar(asdasd, asdasd) + + val (accountType, accountId) = + oneTwoThreeFourFiveSixSeven( + foo, bar, zed, boo) +} diff --git a/core/testData/format/meta/misc/destructuringDeclaration.kt b/core/testData/format/meta/misc/destructuringDeclaration.kt new file mode 100644 index 00000000..6d6352a6 --- /dev/null +++ b/core/testData/format/meta/misc/destructuringDeclaration.kt @@ -0,0 +1,12 @@ +// MAX_WIDTH 50 +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + val (a, b: Int) = listOf(1, 2) + val (asd, asd, asd, asd, asd, asd, asd) = + foo.bar(asdasd, asdasd) + + val (accountType, accountId) = + oneTwoThreeFourFiveSixSeven( + foo, bar, zed, boo) +} diff --git a/core/testData/format/meta/misc/destructuringDeclarationInLoop.expected.kt b/core/testData/format/meta/misc/destructuringDeclarationInLoop.expected.kt new file mode 100644 index 00000000..dddbc6c1 --- /dev/null +++ b/core/testData/format/meta/misc/destructuringDeclarationInLoop.expected.kt @@ -0,0 +1,3 @@ +fun f(a: List>) { + for ((x, y: Int) in a) {} +} diff --git a/core/testData/format/meta/misc/destructuringDeclarationInLoop.kt b/core/testData/format/meta/misc/destructuringDeclarationInLoop.kt new file mode 100644 index 00000000..dddbc6c1 --- /dev/null +++ b/core/testData/format/meta/misc/destructuringDeclarationInLoop.kt @@ -0,0 +1,3 @@ +fun f(a: List>) { + for ((x, y: Int) in a) {} +} diff --git a/core/testData/format/meta/misc/escapedIdentifier.expected.kt b/core/testData/format/meta/misc/escapedIdentifier.expected.kt new file mode 100644 index 00000000..91acabd6 --- /dev/null +++ b/core/testData/format/meta/misc/escapedIdentifier.expected.kt @@ -0,0 +1,11 @@ +import foo as `foo foo` +import org.mockito.Mockito.`when` as `yay yay` + +fun `spaces in functions`() { + val `when` = NEVER + val (`do not`, `ever write`) = SERIOUSLY + val `a a`: Int + `yay yay`(`foo foo`) +} + +class `more spaces` diff --git a/core/testData/format/meta/misc/escapedIdentifier.kt b/core/testData/format/meta/misc/escapedIdentifier.kt new file mode 100644 index 00000000..91acabd6 --- /dev/null +++ b/core/testData/format/meta/misc/escapedIdentifier.kt @@ -0,0 +1,11 @@ +import foo as `foo foo` +import org.mockito.Mockito.`when` as `yay yay` + +fun `spaces in functions`() { + val `when` = NEVER + val (`do not`, `ever write`) = SERIOUSLY + val `a a`: Int + `yay yay`(`foo foo`) +} + +class `more spaces` diff --git a/core/testData/format/meta/misc/explicitBackingField.expected.kt b/core/testData/format/meta/misc/explicitBackingField.expected.kt new file mode 100644 index 00000000..cf661fd0 --- /dev/null +++ b/core/testData/format/meta/misc/explicitBackingField.expected.kt @@ -0,0 +1,7 @@ +class Foo { + val city: StateFlow + field = MutableStateFlow("") + + var numbers: List + field: MutableList = mutableListOf() +} diff --git a/core/testData/format/meta/misc/explicitBackingField.kt b/core/testData/format/meta/misc/explicitBackingField.kt new file mode 100644 index 00000000..cf661fd0 --- /dev/null +++ b/core/testData/format/meta/misc/explicitBackingField.kt @@ -0,0 +1,7 @@ +class Foo { + val city: StateFlow + field = MutableStateFlow("") + + var numbers: List + field: MutableList = mutableListOf() +} diff --git a/core/testData/format/meta/misc/explicitBackingFieldWithoutType.expected.kt b/core/testData/format/meta/misc/explicitBackingFieldWithoutType.expected.kt new file mode 100644 index 00000000..340d9189 --- /dev/null +++ b/core/testData/format/meta/misc/explicitBackingFieldWithoutType.expected.kt @@ -0,0 +1,4 @@ +class Foo { + val count: Int + field = 0 +} diff --git a/core/testData/format/meta/misc/explicitBackingFieldWithoutType.kt b/core/testData/format/meta/misc/explicitBackingFieldWithoutType.kt new file mode 100644 index 00000000..340d9189 --- /dev/null +++ b/core/testData/format/meta/misc/explicitBackingFieldWithoutType.kt @@ -0,0 +1,4 @@ +class Foo { + val count: Int + field = 0 +} diff --git a/core/testData/format/meta/misc/explicitBackingWithPrivateSet.expected.kt b/core/testData/format/meta/misc/explicitBackingWithPrivateSet.expected.kt new file mode 100644 index 00000000..d61c1081 --- /dev/null +++ b/core/testData/format/meta/misc/explicitBackingWithPrivateSet.expected.kt @@ -0,0 +1,5 @@ +class Foo { + var count: Int + field = 0 + private set +} diff --git a/core/testData/format/meta/misc/explicitBackingWithPrivateSet.kt b/core/testData/format/meta/misc/explicitBackingWithPrivateSet.kt new file mode 100644 index 00000000..d61c1081 --- /dev/null +++ b/core/testData/format/meta/misc/explicitBackingWithPrivateSet.kt @@ -0,0 +1,5 @@ +class Foo { + var count: Int + field = 0 + private set +} diff --git a/core/testData/format/meta/misc/forLoop.expected.kt b/core/testData/format/meta/misc/forLoop.expected.kt new file mode 100644 index 00000000..748bbb6b --- /dev/null +++ b/core/testData/format/meta/misc/forLoop.expected.kt @@ -0,0 +1,5 @@ +fun f(a: List) { + for (i in a.indices) { + println(i) + } +} diff --git a/core/testData/format/meta/misc/forLoop.kt b/core/testData/format/meta/misc/forLoop.kt new file mode 100644 index 00000000..748bbb6b --- /dev/null +++ b/core/testData/format/meta/misc/forLoop.kt @@ -0,0 +1,5 @@ +fun f(a: List) { + for (i in a.indices) { + println(i) + } +} diff --git a/core/testData/format/meta/misc/forLoopWithLongCondition.expected.kt b/core/testData/format/meta/misc/forLoopWithLongCondition.expected.kt new file mode 100644 index 00000000..c2905aee --- /dev/null +++ b/core/testData/format/meta/misc/forLoopWithLongCondition.expected.kt @@ -0,0 +1,14 @@ +fun f(a: Node) { + for (child in node.next.data()) { + println(child) + } + for (child in + node.next.next.data()) { + println(child) + } + for (child in + node.next.next.next.next + .data()) { + println(child) + } +} diff --git a/core/testData/format/meta/misc/forLoopWithLongCondition.kt b/core/testData/format/meta/misc/forLoopWithLongCondition.kt new file mode 100644 index 00000000..92248ed2 --- /dev/null +++ b/core/testData/format/meta/misc/forLoopWithLongCondition.kt @@ -0,0 +1,16 @@ +// MAX_WIDTH 35 + +fun f(a: Node) { + for (child in node.next.data()) { + println(child) + } + for (child in + node.next.next.data()) { + println(child) + } + for (child in + node.next.next.next.next + .data()) { + println(child) + } +} diff --git a/core/testData/format/meta/misc/generics.expected.kt b/core/testData/format/meta/misc/generics.expected.kt new file mode 100644 index 00000000..68ebe4ce --- /dev/null +++ b/core/testData/format/meta/misc/generics.expected.kt @@ -0,0 +1,6 @@ +fun doIt(a: List): List? { + val b: List = convert(listOf(5, 4)) + return b +} + +class Foo diff --git a/core/testData/format/meta/misc/generics.kt b/core/testData/format/meta/misc/generics.kt new file mode 100644 index 00000000..68ebe4ce --- /dev/null +++ b/core/testData/format/meta/misc/generics.kt @@ -0,0 +1,6 @@ +fun doIt(a: List): List? { + val b: List = convert(listOf(5, 4)) + return b +} + +class Foo diff --git a/core/testData/format/meta/misc/kotlinInputBug.expected.kt b/core/testData/format/meta/misc/kotlinInputBug.expected.kt new file mode 100644 index 00000000..07b9d8b3 --- /dev/null +++ b/core/testData/format/meta/misc/kotlinInputBug.expected.kt @@ -0,0 +1 @@ +val x = 2 diff --git a/core/testData/format/meta/misc/kotlinInputBug.kt b/core/testData/format/meta/misc/kotlinInputBug.kt new file mode 100644 index 00000000..07b9d8b3 --- /dev/null +++ b/core/testData/format/meta/misc/kotlinInputBug.kt @@ -0,0 +1 @@ +val x = 2 diff --git a/core/testData/format/meta/misc/labeledThis.expected.kt b/core/testData/format/meta/misc/labeledThis.expected.kt new file mode 100644 index 00000000..b31b341b --- /dev/null +++ b/core/testData/format/meta/misc/labeledThis.expected.kt @@ -0,0 +1,5 @@ +class Foo { + fun f() { + g { println(this@Foo) } + } +} diff --git a/core/testData/format/meta/misc/labeledThis.kt b/core/testData/format/meta/misc/labeledThis.kt new file mode 100644 index 00000000..b31b341b --- /dev/null +++ b/core/testData/format/meta/misc/labeledThis.kt @@ -0,0 +1,5 @@ +class Foo { + fun f() { + g { println(this@Foo) } + } +} diff --git a/core/testData/format/meta/misc/multilineAssignment.expected.kt b/core/testData/format/meta/misc/multilineAssignment.expected.kt new file mode 100644 index 00000000..89c61306 --- /dev/null +++ b/core/testData/format/meta/misc/multilineAssignment.expected.kt @@ -0,0 +1,5 @@ +fun f() { + var myVariable = 5 + myVariable = + function1(4, 60, 8) + function2(57, 39, 20) +} diff --git a/core/testData/format/meta/misc/multilineAssignment.kt b/core/testData/format/meta/misc/multilineAssignment.kt new file mode 100644 index 00000000..23f70cb9 --- /dev/null +++ b/core/testData/format/meta/misc/multilineAssignment.kt @@ -0,0 +1,7 @@ +// MAX_WIDTH 50 + +fun f() { + var myVariable = 5 + myVariable = + function1(4, 60, 8) + function2(57, 39, 20) +} diff --git a/core/testData/format/meta/misc/nameBasedDestructuringDeclaration.expected.kt b/core/testData/format/meta/misc/nameBasedDestructuringDeclaration.expected.kt new file mode 100644 index 00000000..6a1248b0 --- /dev/null +++ b/core/testData/format/meta/misc/nameBasedDestructuringDeclaration.expected.kt @@ -0,0 +1,9 @@ +fun f(d: D) { + val [a, b] = d + val (a, x = b) = d + var [a, _] = d + [var a, var b] = d + [val a: Int, val _: String] = d + (var x = a, var y = b) = d + (val x: Int = a, var y: String = b) = d +} diff --git a/core/testData/format/meta/misc/nameBasedDestructuringDeclaration.kt b/core/testData/format/meta/misc/nameBasedDestructuringDeclaration.kt new file mode 100644 index 00000000..d06dd08a --- /dev/null +++ b/core/testData/format/meta/misc/nameBasedDestructuringDeclaration.kt @@ -0,0 +1,9 @@ +fun f(d: D) { + val [a, b ] = d + val (a, x = b ) = d + var [a, _ ] = d + [var a, var b ] = d + [val a: Int, val _: String ] = d + (var x = a, var y = b ) = d + (val x: Int = a, var y: String = b ) = d +} diff --git a/core/testData/format/meta/misc/simple.expected.kts b/core/testData/format/meta/misc/simple.expected.kts new file mode 100644 index 00000000..064eed6d --- /dev/null +++ b/core/testData/format/meta/misc/simple.expected.kts @@ -0,0 +1,15 @@ +package foo + +import java.io.File + +val one: String + +val two: String + +fun f() { + println("asd") +} + +println("Called with args:") + +args.forEach { println(File + "-") } diff --git a/core/testData/format/meta/misc/simple.kts b/core/testData/format/meta/misc/simple.kts new file mode 100644 index 00000000..064eed6d --- /dev/null +++ b/core/testData/format/meta/misc/simple.kts @@ -0,0 +1,15 @@ +package foo + +import java.io.File + +val one: String + +val two: String + +fun f() { + println("asd") +} + +println("Called with args:") + +args.forEach { println(File + "-") } diff --git a/core/testData/format/meta/misc/topLevelConstants.expected.kt b/core/testData/format/meta/misc/topLevelConstants.expected.kt new file mode 100644 index 00000000..6839ed21 --- /dev/null +++ b/core/testData/format/meta/misc/topLevelConstants.expected.kt @@ -0,0 +1,5 @@ +val a = 5 + +const val b = "a" + +val a = 5 diff --git a/core/testData/format/meta/misc/topLevelConstants.kt b/core/testData/format/meta/misc/topLevelConstants.kt new file mode 100644 index 00000000..9d4d204b --- /dev/null +++ b/core/testData/format/meta/misc/topLevelConstants.kt @@ -0,0 +1,7 @@ +// MAX_WIDTH 30 + +val a = 5 + +const val b = "a" + +val a = 5 diff --git a/core/testData/format/meta/misc/trailingComma.expected.kt b/core/testData/format/meta/misc/trailingComma.expected.kt new file mode 100644 index 00000000..908aa341 --- /dev/null +++ b/core/testData/format/meta/misc/trailingComma.expected.kt @@ -0,0 +1,5 @@ +val aVar = setOf( + Env.Dev, + Env.Prod, +) +val aVar = setOf(Env.Dev, Env.Prod) diff --git a/core/testData/format/meta/misc/trailingComma.kt b/core/testData/format/meta/misc/trailingComma.kt new file mode 100644 index 00000000..852ab956 --- /dev/null +++ b/core/testData/format/meta/misc/trailingComma.kt @@ -0,0 +1,7 @@ +// TRAILING_COMMA_STRATEGY NONE + +val aVar = setOf( + Env.Dev, + Env.Prod, +) +val aVar = setOf(Env.Dev, Env.Prod) diff --git a/core/testData/format/meta/misc/unaryPostfix.expected.kt b/core/testData/format/meta/misc/unaryPostfix.expected.kt new file mode 100644 index 00000000..24f5f9b8 --- /dev/null +++ b/core/testData/format/meta/misc/unaryPostfix.expected.kt @@ -0,0 +1,10 @@ +fun f() { + a!! + a++ + a-- + + a--!! + a++!! + + a!! !! +} diff --git a/core/testData/format/meta/misc/unaryPostfix.kt b/core/testData/format/meta/misc/unaryPostfix.kt new file mode 100644 index 00000000..24f5f9b8 --- /dev/null +++ b/core/testData/format/meta/misc/unaryPostfix.kt @@ -0,0 +1,10 @@ +fun f() { + a!! + a++ + a-- + + a--!! + a++!! + + a!! !! +} diff --git a/core/testData/format/meta/misc/unaryPrefix.expected.kt b/core/testData/format/meta/misc/unaryPrefix.expected.kt new file mode 100644 index 00000000..1f12dec8 --- /dev/null +++ b/core/testData/format/meta/misc/unaryPrefix.expected.kt @@ -0,0 +1,25 @@ +fun f() { + !a + -4 + val x = -foo() + +4 + ++a + --a + + + +a + +-a + +!a + -+a + - -a + -!a + !+a + !a + ! !a + + + ++a + +--a + -++a + - --a + !++a + !--a +} diff --git a/core/testData/format/meta/misc/unaryPrefix.kt b/core/testData/format/meta/misc/unaryPrefix.kt new file mode 100644 index 00000000..1f12dec8 --- /dev/null +++ b/core/testData/format/meta/misc/unaryPrefix.kt @@ -0,0 +1,25 @@ +fun f() { + !a + -4 + val x = -foo() + +4 + ++a + --a + + + +a + +-a + +!a + -+a + - -a + -!a + !+a + !a + ! !a + + + ++a + +--a + -++a + - --a + !++a + !--a +} diff --git a/core/testData/format/meta/property/lineCommentAboveDelegate.expected.kt b/core/testData/format/meta/property/lineCommentAboveDelegate.expected.kt new file mode 100644 index 00000000..1575ccac --- /dev/null +++ b/core/testData/format/meta/property/lineCommentAboveDelegate.expected.kt @@ -0,0 +1,19 @@ +class Foo { + var x: Int by + // Comment + 0 + + var y: Int by + // Comment + scope { + 0 // + } + + var z: Int by + // Comment + if (cond) { + 0 + } else { + 1 + } +} diff --git a/core/testData/format/meta/property/lineCommentAboveDelegate.kt b/core/testData/format/meta/property/lineCommentAboveDelegate.kt new file mode 100644 index 00000000..1575ccac --- /dev/null +++ b/core/testData/format/meta/property/lineCommentAboveDelegate.kt @@ -0,0 +1,19 @@ +class Foo { + var x: Int by + // Comment + 0 + + var y: Int by + // Comment + scope { + 0 // + } + + var z: Int by + // Comment + if (cond) { + 0 + } else { + 1 + } +} diff --git a/core/testData/format/meta/property/lineCommentInPropertyInitializer.expected.kt b/core/testData/format/meta/property/lineCommentInPropertyInitializer.expected.kt new file mode 100644 index 00000000..337eecb4 --- /dev/null +++ b/core/testData/format/meta/property/lineCommentInPropertyInitializer.expected.kt @@ -0,0 +1,19 @@ +class Foo { + var x: Int = + // Comment + 0 + + var y: Int = + // Comment + scope { + 0 // + } + + var z: Int = + // Comment + if (cond) { + 0 + } else { + 1 + } +} diff --git a/core/testData/format/meta/property/lineCommentInPropertyInitializer.kt b/core/testData/format/meta/property/lineCommentInPropertyInitializer.kt new file mode 100644 index 00000000..337eecb4 --- /dev/null +++ b/core/testData/format/meta/property/lineCommentInPropertyInitializer.kt @@ -0,0 +1,19 @@ +class Foo { + var x: Int = + // Comment + 0 + + var y: Int = + // Comment + scope { + 0 // + } + + var z: Int = + // Comment + if (cond) { + 0 + } else { + 1 + } +} diff --git a/core/testData/format/meta/property/propertiesWithAccessors.expected.kt b/core/testData/format/meta/property/propertiesWithAccessors.expected.kt new file mode 100644 index 00000000..ee392306 --- /dev/null +++ b/core/testData/format/meta/property/propertiesWithAccessors.expected.kt @@ -0,0 +1,18 @@ +class Foo { + var x: Int + get() = field + + var y: Boolean + get() = x.equals(123) + set(value) { + field = value + } + + var z: Boolean + get() { + x.equals(123) + } + + var zz = false + private set +} diff --git a/core/testData/format/meta/property/propertiesWithAccessors.kt b/core/testData/format/meta/property/propertiesWithAccessors.kt new file mode 100644 index 00000000..ee392306 --- /dev/null +++ b/core/testData/format/meta/property/propertiesWithAccessors.kt @@ -0,0 +1,18 @@ +class Foo { + var x: Int + get() = field + + var y: Boolean + get() = x.equals(123) + set(value) { + field = value + } + + var z: Boolean + get() { + x.equals(123) + } + + var zz = false + private set +} diff --git a/core/testData/format/meta/property/propertiesWithAccessors2.expected.kt b/core/testData/format/meta/property/propertiesWithAccessors2.expected.kt new file mode 100644 index 00000000..a86bd90b --- /dev/null +++ b/core/testData/format/meta/property/propertiesWithAccessors2.expected.kt @@ -0,0 +1,11 @@ +class Foo { + var x = false + private set + + internal val a by lazy { 5 } + internal get + + var foo: Int + get() = 6 + set(x) {} +} diff --git a/core/testData/format/meta/property/propertiesWithAccessors2.kt b/core/testData/format/meta/property/propertiesWithAccessors2.kt new file mode 100644 index 00000000..50c983fc --- /dev/null +++ b/core/testData/format/meta/property/propertiesWithAccessors2.kt @@ -0,0 +1,7 @@ +class Foo { + var x = false; private set + + internal val a by lazy { 5 }; internal get + + var foo: Int; get() = 6; set(x) {}; +} diff --git a/core/testData/format/meta/property/propertiesWithModifiers.expected.kt b/core/testData/format/meta/property/propertiesWithModifiers.expected.kt new file mode 100644 index 00000000..55ebecbc --- /dev/null +++ b/core/testData/format/meta/property/propertiesWithModifiers.expected.kt @@ -0,0 +1,9 @@ +class Foo(public val p1: Int, private val p2: Int, open val p3: Int, final val p4: Int) { + private var f1 = 0 + + public var f2 = 0 + + open var f3 = 0 + + final var f4 = 0 +} diff --git a/core/testData/format/meta/property/propertiesWithModifiers.kt b/core/testData/format/meta/property/propertiesWithModifiers.kt new file mode 100644 index 00000000..55ebecbc --- /dev/null +++ b/core/testData/format/meta/property/propertiesWithModifiers.kt @@ -0,0 +1,9 @@ +class Foo(public val p1: Int, private val p2: Int, open val p3: Int, final val p4: Int) { + private var f1 = 0 + + public var f2 = 0 + + open var f3 = 0 + + final var f4 = 0 +} diff --git a/core/testData/format/meta/property/propertiesWithModifiers2.expected.kt b/core/testData/format/meta/property/propertiesWithModifiers2.expected.kt new file mode 100644 index 00000000..6f5fa5f8 --- /dev/null +++ b/core/testData/format/meta/property/propertiesWithModifiers2.expected.kt @@ -0,0 +1,3 @@ +class Foo(public open inner val p1: Int) { + public open inner var f2 = 0 +} diff --git a/core/testData/format/meta/property/propertiesWithModifiers2.kt b/core/testData/format/meta/property/propertiesWithModifiers2.kt new file mode 100644 index 00000000..6f5fa5f8 --- /dev/null +++ b/core/testData/format/meta/property/propertiesWithModifiers2.kt @@ -0,0 +1,3 @@ +class Foo(public open inner val p1: Int) { + public open inner var f2 = 0 +} diff --git a/core/testData/format/meta/property/propertyWithALongName.expected.kt b/core/testData/format/meta/property/propertyWithALongName.expected.kt new file mode 100644 index 00000000..a21dafb4 --- /dev/null +++ b/core/testData/format/meta/property/propertyWithALongName.expected.kt @@ -0,0 +1,6 @@ +class Foo { + val thisIsALongName: + String = + "Hello there this is long" + get() = field +} diff --git a/core/testData/format/meta/property/propertyWithALongName.kt b/core/testData/format/meta/property/propertyWithALongName.kt new file mode 100644 index 00000000..36f50a43 --- /dev/null +++ b/core/testData/format/meta/property/propertyWithALongName.kt @@ -0,0 +1,8 @@ +// MAX_WIDTH 20 + +class Foo { + val thisIsALongName: + String = + "Hello there this is long" + get() = field +} diff --git a/core/testData/format/meta/property/vars.expected.kt b/core/testData/format/meta/property/vars.expected.kt new file mode 100644 index 00000000..61f22431 --- /dev/null +++ b/core/testData/format/meta/property/vars.expected.kt @@ -0,0 +1,4 @@ +fun f() { + var x: Int = 4 + val y = 0 +} diff --git a/core/testData/format/meta/property/vars.kt b/core/testData/format/meta/property/vars.kt new file mode 100644 index 00000000..61f22431 --- /dev/null +++ b/core/testData/format/meta/property/vars.kt @@ -0,0 +1,4 @@ +fun f() { + var x: Int = 4 + val y = 0 +} diff --git a/core/testData/format/meta/string/commentAfterMultilineString.expected.kt b/core/testData/format/meta/string/commentAfterMultilineString.expected.kt new file mode 100644 index 00000000..9d39bede --- /dev/null +++ b/core/testData/format/meta/string/commentAfterMultilineString.expected.kt @@ -0,0 +1,6 @@ +val bar = + """ + |content + """ + // This comment should be preserved + .trimMargin() diff --git a/core/testData/format/meta/string/commentAfterMultilineString.kt b/core/testData/format/meta/string/commentAfterMultilineString.kt new file mode 100644 index 00000000..9d39bede --- /dev/null +++ b/core/testData/format/meta/string/commentAfterMultilineString.kt @@ -0,0 +1,6 @@ +val bar = + """ + |content + """ + // This comment should be preserved + .trimMargin() diff --git a/core/testData/format/meta/string/commentAfterMultilineString2.expected.kt b/core/testData/format/meta/string/commentAfterMultilineString2.expected.kt new file mode 100644 index 00000000..4e35fb0e --- /dev/null +++ b/core/testData/format/meta/string/commentAfterMultilineString2.expected.kt @@ -0,0 +1,6 @@ +val bar = + """ + content + """ + // This comment should be preserved + .trimIndent() diff --git a/core/testData/format/meta/string/commentAfterMultilineString2.kt b/core/testData/format/meta/string/commentAfterMultilineString2.kt new file mode 100644 index 00000000..4e35fb0e --- /dev/null +++ b/core/testData/format/meta/string/commentAfterMultilineString2.kt @@ -0,0 +1,6 @@ +val bar = + """ + content + """ + // This comment should be preserved + .trimIndent() diff --git a/core/testData/format/meta/string/commentAfterMultilineString3.expected.kt b/core/testData/format/meta/string/commentAfterMultilineString3.expected.kt new file mode 100644 index 00000000..dc3cd69e --- /dev/null +++ b/core/testData/format/meta/string/commentAfterMultilineString3.expected.kt @@ -0,0 +1,7 @@ +val bar = + """ + |content + """ + // First comment + // Second comment + .trimMargin() diff --git a/core/testData/format/meta/string/commentAfterMultilineString3.kt b/core/testData/format/meta/string/commentAfterMultilineString3.kt new file mode 100644 index 00000000..dc3cd69e --- /dev/null +++ b/core/testData/format/meta/string/commentAfterMultilineString3.kt @@ -0,0 +1,7 @@ +val bar = + """ + |content + """ + // First comment + // Second comment + .trimMargin() diff --git a/core/testData/format/meta/string/commentAfterMultilineString4.expected.kt b/core/testData/format/meta/string/commentAfterMultilineString4.expected.kt new file mode 100644 index 00000000..33568f17 --- /dev/null +++ b/core/testData/format/meta/string/commentAfterMultilineString4.expected.kt @@ -0,0 +1,9 @@ +val bar = + """ + | a + """ + + """ + | b + """ + // This comment will not be deleted + .trimMargin() diff --git a/core/testData/format/meta/string/commentAfterMultilineString4.kt b/core/testData/format/meta/string/commentAfterMultilineString4.kt new file mode 100644 index 00000000..16a6c6a0 --- /dev/null +++ b/core/testData/format/meta/string/commentAfterMultilineString4.kt @@ -0,0 +1,9 @@ +val bar = + """ + | a + """ + + """ + | b + """ + // This comment will not be deleted +.trimMargin() \ No newline at end of file diff --git a/core/testData/format/meta/string/multiDollarString.expected.kt b/core/testData/format/meta/string/multiDollarString.expected.kt new file mode 100644 index 00000000..1e421060 --- /dev/null +++ b/core/testData/format/meta/string/multiDollarString.expected.kt @@ -0,0 +1,8 @@ +val margin = + $$""" + |{ + | "$test": "string" + |} + | + """ + .trimMargin() diff --git a/core/testData/format/meta/string/multiDollarString.kt b/core/testData/format/meta/string/multiDollarString.kt new file mode 100644 index 00000000..3b8e6a92 --- /dev/null +++ b/core/testData/format/meta/string/multiDollarString.kt @@ -0,0 +1,10 @@ +// TRAILING_COMMA_STRATEGY NONE +// ALLOW_TRAILING_WHITESPACE + +val margin = + $$""" + |{ + "$test": "string" + |} + + """.trimMargin() diff --git a/core/testData/format/meta/string/multiLineStringWithSelector.expected.kt b/core/testData/format/meta/string/multiLineStringWithSelector.expected.kt new file mode 100644 index 00000000..3ea95e04 --- /dev/null +++ b/core/testData/format/meta/string/multiLineStringWithSelector.expected.kt @@ -0,0 +1,18 @@ +val STRING = + """ + |foo + |""" + .wouldFit() + +val STRING = + """ + |foo + |//////////////////////////////////""" + .wouldntFit() + +val STRING = + """ + |foo + |""" + .firstLink() + .secondLink() diff --git a/core/testData/format/meta/string/multiLineStringWithSelector.kt b/core/testData/format/meta/string/multiLineStringWithSelector.kt new file mode 100644 index 00000000..4e19ee78 --- /dev/null +++ b/core/testData/format/meta/string/multiLineStringWithSelector.kt @@ -0,0 +1,20 @@ +// MAX_WIDTH 25 + +val STRING = + """ + |foo + |""" + .wouldFit() + +val STRING = + """ + |foo + |//////////////////////////////////""" + .wouldntFit() + +val STRING = + """ + |foo + |""" + .firstLink() + .secondLink() diff --git a/core/testData/format/meta/string/multilineStringLiterals.expected.kt b/core/testData/format/meta/string/multilineStringLiterals.expected.kt new file mode 100644 index 00000000..2558b0d3 --- /dev/null +++ b/core/testData/format/meta/string/multilineStringLiterals.expected.kt @@ -0,0 +1,10 @@ +fun doIt(world: String) { + println( + """Hello + world!""") + println( + """Hello + world!""", + """Goodbye + world!""") +} diff --git a/core/testData/format/meta/string/multilineStringLiterals.kt b/core/testData/format/meta/string/multilineStringLiterals.kt new file mode 100644 index 00000000..453c75e3 --- /dev/null +++ b/core/testData/format/meta/string/multilineStringLiterals.kt @@ -0,0 +1,12 @@ +// TRAILING_COMMA_STRATEGY NONE + +fun doIt(world: String) { + println( + """Hello + world!""") + println( + """Hello + world!""", + """Goodbye + world!""") +} diff --git a/core/testData/format/meta/string/multilineStringsWithTemplateExpressions.expected.kt b/core/testData/format/meta/string/multilineStringsWithTemplateExpressions.expected.kt new file mode 100644 index 00000000..fa7d650c --- /dev/null +++ b/core/testData/format/meta/string/multilineStringsWithTemplateExpressions.expected.kt @@ -0,0 +1,13 @@ +val margin1 = + """my math = ${ "}" + (1 + 2).toString() } + | checks + | out + |""" + .trimMargin() + +val margin2 = + $$"""my math = $${ "}" + (1 + 2).toString() } + | checks + | out + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/multilineStringsWithTemplateExpressions.kt b/core/testData/format/meta/string/multilineStringsWithTemplateExpressions.kt new file mode 100644 index 00000000..fa7d650c --- /dev/null +++ b/core/testData/format/meta/string/multilineStringsWithTemplateExpressions.kt @@ -0,0 +1,13 @@ +val margin1 = + """my math = ${ "}" + (1 + 2).toString() } + | checks + | out + |""" + .trimMargin() + +val margin2 = + $$"""my math = $${ "}" + (1 + 2).toString() } + | checks + | out + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/multilineStringsWithTemplateExpressions2.expected.kt b/core/testData/format/meta/string/multilineStringsWithTemplateExpressions2.expected.kt new file mode 100644 index 00000000..adc71565 --- /dev/null +++ b/core/testData/format/meta/string/multilineStringsWithTemplateExpressions2.expected.kt @@ -0,0 +1,17 @@ +val margin1 = + """ + not_a_var$ + $1 + $\{ + $} + """ + .trimIndent() + +val margin2 = + $$""" + |not_a_var$$ + |$$1 + |$$\{ + |$$} + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/multilineStringsWithTemplateExpressions2.kt b/core/testData/format/meta/string/multilineStringsWithTemplateExpressions2.kt new file mode 100644 index 00000000..6916f232 --- /dev/null +++ b/core/testData/format/meta/string/multilineStringsWithTemplateExpressions2.kt @@ -0,0 +1,17 @@ +val margin1 = + """ +not_a_var$ +$1 +$\{ +$} +""" + .trimIndent() + +val margin2 = + $$""" +not_a_var$$ +$$1 +$$\{ +$$} + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/nestedMultilineString.expected.kt b/core/testData/format/meta/string/nestedMultilineString.expected.kt new file mode 100644 index 00000000..959ecf20 --- /dev/null +++ b/core/testData/format/meta/string/nestedMultilineString.expected.kt @@ -0,0 +1,17 @@ +val margin = + """ + |my math = ${ + if (condition) { + "}" + (1 + 2) + .toString() + } else { + """ + my own multiline trimmed string + is here + """ + .trimIndent() + } + } + | string + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/nestedMultilineString.kt b/core/testData/format/meta/string/nestedMultilineString.kt new file mode 100644 index 00000000..959ecf20 --- /dev/null +++ b/core/testData/format/meta/string/nestedMultilineString.kt @@ -0,0 +1,17 @@ +val margin = + """ + |my math = ${ + if (condition) { + "}" + (1 + 2) + .toString() + } else { + """ + my own multiline trimmed string + is here + """ + .trimIndent() + } + } + | string + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/nestedMultilineString2.expected.kt b/core/testData/format/meta/string/nestedMultilineString2.expected.kt new file mode 100644 index 00000000..29739c02 --- /dev/null +++ b/core/testData/format/meta/string/nestedMultilineString2.expected.kt @@ -0,0 +1,16 @@ +val margin = + $$""" + |my math = $${ + if (condition) { + "}" + (1 + 2) + .toString() + }else{ + """ + my own multiline trimmed string + is here + """.trimIndent() + } + } + | string + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/nestedMultilineString2.kt b/core/testData/format/meta/string/nestedMultilineString2.kt new file mode 100644 index 00000000..29739c02 --- /dev/null +++ b/core/testData/format/meta/string/nestedMultilineString2.kt @@ -0,0 +1,16 @@ +val margin = + $$""" + |my math = $${ + if (condition) { + "}" + (1 + 2) + .toString() + }else{ + """ + my own multiline trimmed string + is here + """.trimIndent() + } + } + | string + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/singleLineStrings.expected.kt b/core/testData/format/meta/string/singleLineStrings.expected.kt new file mode 100644 index 00000000..1fcfbeac --- /dev/null +++ b/core/testData/format/meta/string/singleLineStrings.expected.kt @@ -0,0 +1,2 @@ +"Hello %s" + .format(expression) diff --git a/core/testData/format/meta/string/singleLineStrings.kt b/core/testData/format/meta/string/singleLineStrings.kt new file mode 100644 index 00000000..8cbb02ab --- /dev/null +++ b/core/testData/format/meta/string/singleLineStrings.kt @@ -0,0 +1,4 @@ +// MAX_WIDTH 25 + +"Hello %s" + .format(expression) diff --git a/core/testData/format/meta/string/stringLiterals.expected.kt b/core/testData/format/meta/string/stringLiterals.expected.kt new file mode 100644 index 00000000..5e51dd58 --- /dev/null +++ b/core/testData/format/meta/string/stringLiterals.expected.kt @@ -0,0 +1,5 @@ +fun doIt(world: String) { + println("Hello world!") + println("Hello! $world") + println("Hello! ${"wor" + "ld"}") +} diff --git a/core/testData/format/meta/string/stringLiterals.kt b/core/testData/format/meta/string/stringLiterals.kt new file mode 100644 index 00000000..5e51dd58 --- /dev/null +++ b/core/testData/format/meta/string/stringLiterals.kt @@ -0,0 +1,5 @@ +fun doIt(world: String) { + println("Hello world!") + println("Hello! $world") + println("Hello! ${"wor" + "ld"}") +} diff --git a/core/testData/format/meta/string/trimIndentHandling.expected.kt b/core/testData/format/meta/string/trimIndentHandling.expected.kt new file mode 100644 index 00000000..37f8f40d --- /dev/null +++ b/core/testData/format/meta/string/trimIndentHandling.expected.kt @@ -0,0 +1,10 @@ +val indent = + """ + example + of + a + + multiline + string + """ + .trimIndent() diff --git a/core/testData/format/meta/string/trimIndentHandling.kt b/core/testData/format/meta/string/trimIndentHandling.kt new file mode 100644 index 00000000..96f0b75d --- /dev/null +++ b/core/testData/format/meta/string/trimIndentHandling.kt @@ -0,0 +1,10 @@ +val indent = + """ + example + of + a + + multiline + string + """ + .trimIndent() diff --git a/core/testData/format/meta/string/trimIndentHandling2.expected.kt b/core/testData/format/meta/string/trimIndentHandling2.expected.kt new file mode 100644 index 00000000..9816b71e --- /dev/null +++ b/core/testData/format/meta/string/trimIndentHandling2.expected.kt @@ -0,0 +1,5 @@ +val margin = + """ + is this the end of the line? + """ + .trimIndent() diff --git a/core/testData/format/meta/string/trimIndentHandling2.kt b/core/testData/format/meta/string/trimIndentHandling2.kt new file mode 100644 index 00000000..510f8587 --- /dev/null +++ b/core/testData/format/meta/string/trimIndentHandling2.kt @@ -0,0 +1,4 @@ +val margin = + """ + is this the end of the line?""" + .trimIndent() diff --git a/core/testData/format/meta/string/trimMarginAndTrimIndent.expected.kt b/core/testData/format/meta/string/trimMarginAndTrimIndent.expected.kt new file mode 100644 index 00000000..eefe9830 --- /dev/null +++ b/core/testData/format/meta/string/trimMarginAndTrimIndent.expected.kt @@ -0,0 +1,22 @@ +foo( + """ + |example + | of + | a + | + |multiline + | string + |""" + .trimMargin(), +) + .bar( + """ + example + of + a + + multiline + string + """ + .trimIndent(), + ) diff --git a/core/testData/format/meta/string/trimMarginAndTrimIndent.kt b/core/testData/format/meta/string/trimMarginAndTrimIndent.kt new file mode 100644 index 00000000..5215817b --- /dev/null +++ b/core/testData/format/meta/string/trimMarginAndTrimIndent.kt @@ -0,0 +1,21 @@ +foo( + """example + | of + | a + + |multiline + | string + |""" + .trimMargin() +) + .bar( + """ + example + of + a + + multiline + string + """ + .trimIndent() + ) \ No newline at end of file diff --git a/core/testData/format/meta/string/trimMarginHandling.expected.kt b/core/testData/format/meta/string/trimMarginHandling.expected.kt new file mode 100644 index 00000000..893f874e --- /dev/null +++ b/core/testData/format/meta/string/trimMarginHandling.expected.kt @@ -0,0 +1,9 @@ +val margin = + """ + |example + | of + | a + |multiline + | string + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/trimMarginHandling.kt b/core/testData/format/meta/string/trimMarginHandling.kt new file mode 100644 index 00000000..0beb8155 --- /dev/null +++ b/core/testData/format/meta/string/trimMarginHandling.kt @@ -0,0 +1,8 @@ +val margin = + """example + | of + | a + |multiline + | string + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/trimMarginHandling2.expected.kt b/core/testData/format/meta/string/trimMarginHandling2.expected.kt new file mode 100644 index 00000000..6a42d39e --- /dev/null +++ b/core/testData/format/meta/string/trimMarginHandling2.expected.kt @@ -0,0 +1,5 @@ +val margin = + """ + |is this the end of the line? + """ + .trimMargin() diff --git a/core/testData/format/meta/string/trimMarginHandling2.kt b/core/testData/format/meta/string/trimMarginHandling2.kt new file mode 100644 index 00000000..fd62b8ad --- /dev/null +++ b/core/testData/format/meta/string/trimMarginHandling2.kt @@ -0,0 +1,4 @@ +val margin = + """ + |is this the end of the line?""" + .trimMargin() diff --git a/core/testData/format/meta/string/trimMarginHandling3.expected.kt b/core/testData/format/meta/string/trimMarginHandling3.expected.kt new file mode 100644 index 00000000..7c29a323 --- /dev/null +++ b/core/testData/format/meta/string/trimMarginHandling3.expected.kt @@ -0,0 +1,6 @@ +val margin = + """ + |test + | string + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/trimMarginHandling3.kt b/core/testData/format/meta/string/trimMarginHandling3.kt new file mode 100644 index 00000000..4481f309 --- /dev/null +++ b/core/testData/format/meta/string/trimMarginHandling3.kt @@ -0,0 +1,7 @@ +val margin = + """ + |test + string + | + """ + .trimMargin() diff --git a/core/testData/format/meta/string/trimMarginHandling4.expected.kt b/core/testData/format/meta/string/trimMarginHandling4.expected.kt new file mode 100644 index 00000000..7c29a323 --- /dev/null +++ b/core/testData/format/meta/string/trimMarginHandling4.expected.kt @@ -0,0 +1,6 @@ +val margin = + """ + |test + | string + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/trimMarginHandling4.kt b/core/testData/format/meta/string/trimMarginHandling4.kt new file mode 100644 index 00000000..d11635dd --- /dev/null +++ b/core/testData/format/meta/string/trimMarginHandling4.kt @@ -0,0 +1,5 @@ +val margin = + """ |test + | string + |""" + .trimMargin() diff --git a/core/testData/format/meta/string/trimMarginHandling5.expected.kt b/core/testData/format/meta/string/trimMarginHandling5.expected.kt new file mode 100644 index 00000000..8578176e --- /dev/null +++ b/core/testData/format/meta/string/trimMarginHandling5.expected.kt @@ -0,0 +1,7 @@ +val margin = + """ + | echo hello | wc -c + | cat hay_stack.txt | grep needle + | {myList.joinToString("|")} + """ + .trimMargin() diff --git a/core/testData/format/meta/string/trimMarginHandling5.kt b/core/testData/format/meta/string/trimMarginHandling5.kt new file mode 100644 index 00000000..bd963050 --- /dev/null +++ b/core/testData/format/meta/string/trimMarginHandling5.kt @@ -0,0 +1,7 @@ +val margin = + """ + echo hello | wc -c + cat hay_stack.txt | grep needle + {myList.joinToString("|")} + """ + .trimMargin() diff --git a/core/testData/format/meta/string/whitespaces.expected.kt b/core/testData/format/meta/string/whitespaces.expected.kt new file mode 100644 index 00000000..7ca1c3b6 --- /dev/null +++ b/core/testData/format/meta/string/whitespaces.expected.kt @@ -0,0 +1,14 @@ +fun doIt(world: String) { + println( + """This line has trailing whitespace + world!""") + println( + """This line has trailing whitespace $s + world!""") + println( + """This line has trailing whitespace ${s} + world!""") + println( + """This line has trailing whitespace $ + world!""") +} diff --git a/core/testData/format/meta/string/whitespaces.kt b/core/testData/format/meta/string/whitespaces.kt new file mode 100644 index 00000000..9f1d1171 --- /dev/null +++ b/core/testData/format/meta/string/whitespaces.kt @@ -0,0 +1,17 @@ +// TRAILING_COMMA_STRATEGY NONE +// ALLOW_TRAILING_WHITESPACE + +fun doIt(world: String) { + println( + """This line has trailing whitespace + world!""") + println( + """This line has trailing whitespace $s + world!""") + println( + """This line has trailing whitespace ${s} + world!""") + println( + """This line has trailing whitespace $ + world!""") +} diff --git a/core/testData/format/meta/string/whitespaces2.expected.kt b/core/testData/format/meta/string/whitespaces2.expected.kt new file mode 100644 index 00000000..bf90d079 --- /dev/null +++ b/core/testData/format/meta/string/whitespaces2.expected.kt @@ -0,0 +1,7 @@ +val x = + """ + + + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do +""" diff --git a/core/testData/format/meta/string/whitespaces2.kt b/core/testData/format/meta/string/whitespaces2.kt new file mode 100644 index 00000000..bf90d079 --- /dev/null +++ b/core/testData/format/meta/string/whitespaces2.kt @@ -0,0 +1,7 @@ +val x = + """ + + + +Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do +""" diff --git a/core/testData/format/meta/type/bounds.expected.kt b/core/testData/format/meta/type/bounds.expected.kt new file mode 100644 index 00000000..d53cedbe --- /dev/null +++ b/core/testData/format/meta/type/bounds.expected.kt @@ -0,0 +1 @@ +class Foo, out S : Any?> diff --git a/core/testData/format/meta/type/bounds.kt b/core/testData/format/meta/type/bounds.kt new file mode 100644 index 00000000..d53cedbe --- /dev/null +++ b/core/testData/format/meta/type/bounds.kt @@ -0,0 +1 @@ +class Foo, out S : Any?> diff --git a/core/testData/format/meta/type/bounds2.expected.kt b/core/testData/format/meta/type/bounds2.expected.kt new file mode 100644 index 00000000..ae5377b8 --- /dev/null +++ b/core/testData/format/meta/type/bounds2.expected.kt @@ -0,0 +1 @@ +class Foo(n: Int) where T : Bar, T : FooBar {} diff --git a/core/testData/format/meta/type/bounds2.kt b/core/testData/format/meta/type/bounds2.kt new file mode 100644 index 00000000..ae5377b8 --- /dev/null +++ b/core/testData/format/meta/type/bounds2.kt @@ -0,0 +1 @@ +class Foo(n: Int) where T : Bar, T : FooBar {} diff --git a/core/testData/format/meta/type/compondBoundOnClassDelegate.expected.kt b/core/testData/format/meta/type/compondBoundOnClassDelegate.expected.kt new file mode 100644 index 00000000..8e858b0d --- /dev/null +++ b/core/testData/format/meta/type/compondBoundOnClassDelegate.expected.kt @@ -0,0 +1,2 @@ +class Foo() : Bar by bar + where T : Qux diff --git a/core/testData/format/meta/type/compondBoundOnClassDelegate.kt b/core/testData/format/meta/type/compondBoundOnClassDelegate.kt new file mode 100644 index 00000000..8e858b0d --- /dev/null +++ b/core/testData/format/meta/type/compondBoundOnClassDelegate.kt @@ -0,0 +1,2 @@ +class Foo() : Bar by bar + where T : Qux diff --git a/core/testData/format/meta/type/compondBoundOnProperty.expected.kt b/core/testData/format/meta/type/compondBoundOnProperty.expected.kt new file mode 100644 index 00000000..d7319fbd --- /dev/null +++ b/core/testData/format/meta/type/compondBoundOnProperty.expected.kt @@ -0,0 +1,4 @@ +val List.twiceSum: Int where T : Int + get() { + return 2 * sum() + } diff --git a/core/testData/format/meta/type/compondBoundOnProperty.kt b/core/testData/format/meta/type/compondBoundOnProperty.kt new file mode 100644 index 00000000..d7319fbd --- /dev/null +++ b/core/testData/format/meta/type/compondBoundOnProperty.kt @@ -0,0 +1,4 @@ +val List.twiceSum: Int where T : Int + get() { + return 2 * sum() + } diff --git a/core/testData/format/meta/type/compondBounds.expected.kt b/core/testData/format/meta/type/compondBounds.expected.kt new file mode 100644 index 00000000..047bc058 --- /dev/null +++ b/core/testData/format/meta/type/compondBounds.expected.kt @@ -0,0 +1 @@ +fun foo(n: Int) where T : Bar, T : FooBar {} diff --git a/core/testData/format/meta/type/compondBounds.kt b/core/testData/format/meta/type/compondBounds.kt new file mode 100644 index 00000000..047bc058 --- /dev/null +++ b/core/testData/format/meta/type/compondBounds.kt @@ -0,0 +1 @@ +fun foo(n: Int) where T : Bar, T : FooBar {} diff --git a/core/testData/format/meta/type/explicitTypeOnGetter.expected.kt b/core/testData/format/meta/type/explicitTypeOnGetter.expected.kt new file mode 100644 index 00000000..695b6afa --- /dev/null +++ b/core/testData/format/meta/type/explicitTypeOnGetter.expected.kt @@ -0,0 +1,4 @@ +class Foo { + val silly: Int + get(): Int = 1 +} diff --git a/core/testData/format/meta/type/explicitTypeOnGetter.kt b/core/testData/format/meta/type/explicitTypeOnGetter.kt new file mode 100644 index 00000000..695b6afa --- /dev/null +++ b/core/testData/format/meta/type/explicitTypeOnGetter.kt @@ -0,0 +1,4 @@ +class Foo { + val silly: Int + get(): Int = 1 +} diff --git a/core/testData/format/meta/type/generics.expected.kt b/core/testData/format/meta/type/generics.expected.kt new file mode 100644 index 00000000..2b4ba102 --- /dev/null +++ b/core/testData/format/meta/type/generics.expected.kt @@ -0,0 +1,3 @@ +class Foo(n: Int) where T : Bar, T : FooBar + +fun foo(n: Int) where T : Bar, T : FooBar {} diff --git a/core/testData/format/meta/type/generics.kt b/core/testData/format/meta/type/generics.kt new file mode 100644 index 00000000..2b4ba102 --- /dev/null +++ b/core/testData/format/meta/type/generics.kt @@ -0,0 +1,3 @@ +class Foo(n: Int) where T : Bar, T : FooBar + +fun foo(n: Int) where T : Bar, T : FooBar {} diff --git a/core/testData/format/meta/type/generics2.expected.kt b/core/testData/format/meta/type/generics2.expected.kt new file mode 100644 index 00000000..54caf634 --- /dev/null +++ b/core/testData/format/meta/type/generics2.expected.kt @@ -0,0 +1,5 @@ +class Foo(n: Int) + where T : Bar, T : FooBar + +fun foo(n: Int) + where T : Bar, T : FooBar {} diff --git a/core/testData/format/meta/type/generics2.kt b/core/testData/format/meta/type/generics2.kt new file mode 100644 index 00000000..f4894ae5 --- /dev/null +++ b/core/testData/format/meta/type/generics2.kt @@ -0,0 +1,6 @@ +// MAX_WIDTH 32 +class Foo(n: Int) + where T : Bar, T : FooBar + +fun foo(n: Int) + where T : Bar, T : FooBar {} diff --git a/core/testData/format/meta/type/generics3.expected.kt b/core/testData/format/meta/type/generics3.expected.kt new file mode 100644 index 00000000..b294fb05 --- /dev/null +++ b/core/testData/format/meta/type/generics3.expected.kt @@ -0,0 +1,9 @@ +class Foo(n: Int) + where + T : Bar, + T : FooBar + +fun foo(n: Int) + where + T : Bar, + T : FooBar {} diff --git a/core/testData/format/meta/type/generics3.kt b/core/testData/format/meta/type/generics3.kt new file mode 100644 index 00000000..4f7257e8 --- /dev/null +++ b/core/testData/format/meta/type/generics3.kt @@ -0,0 +1,11 @@ +// MAX_WIDTH 29 + +class Foo(n: Int) + where + T : Bar, + T : FooBar + +fun foo(n: Int) + where + T : Bar, + T : FooBar {} diff --git a/core/testData/format/meta/type/intersections.expected.kt b/core/testData/format/meta/type/intersections.expected.kt new file mode 100644 index 00000000..d74b0f34 --- /dev/null +++ b/core/testData/format/meta/type/intersections.expected.kt @@ -0,0 +1,4 @@ +fun f() { + val l: Decl + val p = Ctor +} diff --git a/core/testData/format/meta/type/intersections.kt b/core/testData/format/meta/type/intersections.kt new file mode 100644 index 00000000..d74b0f34 --- /dev/null +++ b/core/testData/format/meta/type/intersections.kt @@ -0,0 +1,4 @@ +fun f() { + val l: Decl + val p = Ctor +} diff --git a/core/testData/format/meta/type/nullableFunctionType.expected.kt b/core/testData/format/meta/type/nullableFunctionType.expected.kt new file mode 100644 index 00000000..3dfd1898 --- /dev/null +++ b/core/testData/format/meta/type/nullableFunctionType.expected.kt @@ -0,0 +1 @@ +var listener: ((Boolean) -> Unit)? = null diff --git a/core/testData/format/meta/type/nullableFunctionType.kt b/core/testData/format/meta/type/nullableFunctionType.kt new file mode 100644 index 00000000..3dfd1898 --- /dev/null +++ b/core/testData/format/meta/type/nullableFunctionType.kt @@ -0,0 +1 @@ +var listener: ((Boolean) -> Unit)? = null diff --git a/core/testData/format/meta/type/nullableTypes.expected.kt b/core/testData/format/meta/type/nullableTypes.expected.kt new file mode 100644 index 00000000..cc3eaaac --- /dev/null +++ b/core/testData/format/meta/type/nullableTypes.expected.kt @@ -0,0 +1,15 @@ +var x: Int? = null +var x: (Int)? = null +var x: (Int?) = null +var x: ((Int))? = null +var x: ((Int?)) = null +var x: ((Int)?) = null + +var x: @Anno Int? = null +var x: @Anno() (Int)? = null +var x: @Anno (Int?) = null +var x: (@Anno Int)? = null +var x: (@Anno Int?) = null +var x: (@Anno() (Int))? = null +var x: (@Anno (Int?)) = null +var x: (@Anno() (Int)?) = null diff --git a/core/testData/format/meta/type/nullableTypes.kt b/core/testData/format/meta/type/nullableTypes.kt new file mode 100644 index 00000000..cc3eaaac --- /dev/null +++ b/core/testData/format/meta/type/nullableTypes.kt @@ -0,0 +1,15 @@ +var x: Int? = null +var x: (Int)? = null +var x: (Int?) = null +var x: ((Int))? = null +var x: ((Int?)) = null +var x: ((Int)?) = null + +var x: @Anno Int? = null +var x: @Anno() (Int)? = null +var x: @Anno (Int?) = null +var x: (@Anno Int)? = null +var x: (@Anno Int?) = null +var x: (@Anno() (Int))? = null +var x: (@Anno (Int?)) = null +var x: (@Anno() (Int)?) = null diff --git a/core/testData/format/meta/type/parenthesisInFunctionType.expected.kt b/core/testData/format/meta/type/parenthesisInFunctionType.expected.kt new file mode 100644 index 00000000..20825664 --- /dev/null +++ b/core/testData/format/meta/type/parenthesisInFunctionType.expected.kt @@ -0,0 +1,3 @@ +val a: (Int) = 7 + +var listener: ((Boolean) -> Unit) = foo diff --git a/core/testData/format/meta/type/parenthesisInFunctionType.kt b/core/testData/format/meta/type/parenthesisInFunctionType.kt new file mode 100644 index 00000000..20825664 --- /dev/null +++ b/core/testData/format/meta/type/parenthesisInFunctionType.kt @@ -0,0 +1,3 @@ +val a: (Int) = 7 + +var listener: ((Boolean) -> Unit) = foo diff --git a/core/testData/format/meta/type/qualifiedType.expected.kt b/core/testData/format/meta/type/qualifiedType.expected.kt new file mode 100644 index 00000000..c73bf1f7 --- /dev/null +++ b/core/testData/format/meta/type/qualifiedType.expected.kt @@ -0,0 +1,5 @@ +fun f() { + var plusFour: Indent.Const + var x: Map.Entry + var x: List.Iterator +} diff --git a/core/testData/format/meta/type/qualifiedType.kt b/core/testData/format/meta/type/qualifiedType.kt new file mode 100644 index 00000000..c73bf1f7 --- /dev/null +++ b/core/testData/format/meta/type/qualifiedType.kt @@ -0,0 +1,5 @@ +fun f() { + var plusFour: Indent.Const + var x: Map.Entry + var x: List.Iterator +} diff --git a/core/testData/format/meta/type/variance.expected.kt b/core/testData/format/meta/type/variance.expected.kt new file mode 100644 index 00000000..a8079df8 --- /dev/null +++ b/core/testData/format/meta/type/variance.expected.kt @@ -0,0 +1 @@ +val p: Pair diff --git a/core/testData/format/meta/type/variance.kt b/core/testData/format/meta/type/variance.kt new file mode 100644 index 00000000..a8079df8 --- /dev/null +++ b/core/testData/format/meta/type/variance.kt @@ -0,0 +1 @@ +val p: Pair diff --git a/core/testData/format/meta/type/variance2.expected.kt b/core/testData/format/meta/type/variance2.expected.kt new file mode 100644 index 00000000..cbcbb088 --- /dev/null +++ b/core/testData/format/meta/type/variance2.expected.kt @@ -0,0 +1 @@ +class Foo diff --git a/core/testData/format/meta/type/variance2.kt b/core/testData/format/meta/type/variance2.kt new file mode 100644 index 00000000..cbcbb088 --- /dev/null +++ b/core/testData/format/meta/type/variance2.kt @@ -0,0 +1 @@ +class Foo diff --git a/core/testData/format/meta/type/wildcards.expected.kt b/core/testData/format/meta/type/wildcards.expected.kt new file mode 100644 index 00000000..98e07864 --- /dev/null +++ b/core/testData/format/meta/type/wildcards.expected.kt @@ -0,0 +1,4 @@ +fun f() { + val l: List<*> + val p: Pair<*, *> +} diff --git a/core/testData/format/meta/type/wildcards.kt b/core/testData/format/meta/type/wildcards.kt new file mode 100644 index 00000000..98e07864 --- /dev/null +++ b/core/testData/format/meta/type/wildcards.kt @@ -0,0 +1,4 @@ +fun f() { + val l: List<*> + val p: Pair<*, *> +} diff --git a/core/testData/format/meta/when/complexConditions.expected.kt b/core/testData/format/meta/when/complexConditions.expected.kt new file mode 100644 index 00000000..c37ea307 --- /dev/null +++ b/core/testData/format/meta/when/complexConditions.expected.kt @@ -0,0 +1,9 @@ +fun f(x: Int) { + when { + x == 1 || x == 2 -> print(1) + x == 3 && x != 4 -> print(2) + else -> { + print(3) + } + } +} diff --git a/core/testData/format/meta/when/complexConditions.kt b/core/testData/format/meta/when/complexConditions.kt new file mode 100644 index 00000000..c37ea307 --- /dev/null +++ b/core/testData/format/meta/when/complexConditions.kt @@ -0,0 +1,9 @@ +fun f(x: Int) { + when { + x == 1 || x == 2 -> print(1) + x == 3 && x != 4 -> print(2) + else -> { + print(3) + } + } +} diff --git a/core/testData/format/meta/when/enum.expected.kt b/core/testData/format/meta/when/enum.expected.kt new file mode 100644 index 00000000..9b1ffa72 --- /dev/null +++ b/core/testData/format/meta/when/enum.expected.kt @@ -0,0 +1,7 @@ +fun f(x: Color) { + when (x) { + is Color.Red -> print(1) + is Color.Green -> print(2) + else -> print(3) + } +} diff --git a/core/testData/format/meta/when/enum.kt b/core/testData/format/meta/when/enum.kt new file mode 100644 index 00000000..9b1ffa72 --- /dev/null +++ b/core/testData/format/meta/when/enum.kt @@ -0,0 +1,7 @@ +fun f(x: Color) { + when (x) { + is Color.Red -> print(1) + is Color.Green -> print(2) + else -> print(3) + } +} diff --git a/core/testData/format/meta/when/generics.expected.kt b/core/testData/format/meta/when/generics.expected.kt new file mode 100644 index 00000000..569c0f71 --- /dev/null +++ b/core/testData/format/meta/when/generics.expected.kt @@ -0,0 +1,6 @@ +fun f(x: Result) { + when (x) { + is Success<*> -> print(1) + is Failure -> print(2) + }.exhaustive +} diff --git a/core/testData/format/meta/when/generics.kt b/core/testData/format/meta/when/generics.kt new file mode 100644 index 00000000..569c0f71 --- /dev/null +++ b/core/testData/format/meta/when/generics.kt @@ -0,0 +1,6 @@ +fun f(x: Result) { + when (x) { + is Success<*> -> print(1) + is Failure -> print(2) + }.exhaustive +} diff --git a/core/testData/format/meta/when/isAndIn.expected.kt b/core/testData/format/meta/when/isAndIn.expected.kt new file mode 100644 index 00000000..974bd745 --- /dev/null +++ b/core/testData/format/meta/when/isAndIn.expected.kt @@ -0,0 +1,13 @@ +fun f(x: Int) { + when (x) { + is String -> print(1) + !is String -> print(2) + in 1..3 -> print() + in a..b -> print() + in a..3 -> print() + in 1..b -> print() + !in 1..b -> print() + in 1.. print() + else -> print(3) + } +} diff --git a/core/testData/format/meta/when/isAndIn.kt b/core/testData/format/meta/when/isAndIn.kt new file mode 100644 index 00000000..974bd745 --- /dev/null +++ b/core/testData/format/meta/when/isAndIn.kt @@ -0,0 +1,13 @@ +fun f(x: Int) { + when (x) { + is String -> print(1) + !is String -> print(2) + in 1..3 -> print() + in a..b -> print() + in a..3 -> print() + in 1..b -> print() + !in 1..b -> print() + in 1.. print() + else -> print(3) + } +} diff --git a/core/testData/format/meta/when/lineBreaks.expected.kt b/core/testData/format/meta/when/lineBreaks.expected.kt new file mode 100644 index 00000000..c877fe21 --- /dev/null +++ b/core/testData/format/meta/when/lineBreaks.expected.kt @@ -0,0 +1,15 @@ +fun f() { + return Text.create(c) + .onTouch { + when (it.motionEvent.action) { + ACTION_DOWN -> + Toast.makeText(it.view.context, "Down!", Toast.LENGTH_SHORT, blablabla).show() + ACTION_UP -> Toast.makeText(it.view.context, "Up!", Toast.LENGTH_SHORT).show() + ACTION_DOWN -> + Toast.makeText( + it.view.context, "Down!", Toast.LENGTH_SHORT, blablabla, blablabl, blabla) + .show() + } + } + .build() +} diff --git a/core/testData/format/meta/when/lineBreaks.kt b/core/testData/format/meta/when/lineBreaks.kt new file mode 100644 index 00000000..6ee7f4ea --- /dev/null +++ b/core/testData/format/meta/when/lineBreaks.kt @@ -0,0 +1,17 @@ +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + return Text.create(c) + .onTouch { + when (it.motionEvent.action) { + ACTION_DOWN -> + Toast.makeText(it.view.context, "Down!", Toast.LENGTH_SHORT, blablabla).show() + ACTION_UP -> Toast.makeText(it.view.context, "Up!", Toast.LENGTH_SHORT).show() + ACTION_DOWN -> + Toast.makeText( + it.view.context, "Down!", Toast.LENGTH_SHORT, blablabla, blablabl, blabla) + .show() + } + } + .build() +} diff --git a/core/testData/format/meta/when/multilineCondition.expected.kt b/core/testData/format/meta/when/multilineCondition.expected.kt new file mode 100644 index 00000000..f4ea31de --- /dev/null +++ b/core/testData/format/meta/when/multilineCondition.expected.kt @@ -0,0 +1,16 @@ +fun foo() { + when (expressions1 + + expression2 + + expression3) { + 1 -> print(1) + 2 -> print(2) + } + + when (foo( + expressions1 && + expression2 && + expression3)) { + 1 -> print(1) + 2 -> print(2) + } +} diff --git a/core/testData/format/meta/when/multilineCondition.kt b/core/testData/format/meta/when/multilineCondition.kt new file mode 100644 index 00000000..0c400e85 --- /dev/null +++ b/core/testData/format/meta/when/multilineCondition.kt @@ -0,0 +1,19 @@ +// MAX_WIDTH 26 +// TRAILING_COMMA_STRATEGY NONE + +fun foo() { + when (expressions1 + + expression2 + + expression3) { + 1 -> print(1) + 2 -> print(2) + } + + when (foo( + expressions1 && + expression2 && + expression3)) { + 1 -> print(1) + 2 -> print(2) + } +} diff --git a/core/testData/format/meta/when/multipleConditions.expected.kt b/core/testData/format/meta/when/multipleConditions.expected.kt new file mode 100644 index 00000000..11f2abb2 --- /dev/null +++ b/core/testData/format/meta/when/multipleConditions.expected.kt @@ -0,0 +1,7 @@ +fun f(x: Int) { + when { + 0, + 1 -> print(1) + else -> print(0) + } +} diff --git a/core/testData/format/meta/when/multipleConditions.kt b/core/testData/format/meta/when/multipleConditions.kt new file mode 100644 index 00000000..11f2abb2 --- /dev/null +++ b/core/testData/format/meta/when/multipleConditions.kt @@ -0,0 +1,7 @@ +fun f(x: Int) { + when { + 0, + 1 -> print(1) + else -> print(0) + } +} diff --git a/core/testData/format/meta/when/newLinesBetweenClauses.expected.kt b/core/testData/format/meta/when/newLinesBetweenClauses.expected.kt new file mode 100644 index 00000000..bc6d0021 --- /dev/null +++ b/core/testData/format/meta/when/newLinesBetweenClauses.expected.kt @@ -0,0 +1,14 @@ +fun f(x: Int) { + when (x) { + 1 -> print(1) + 2 -> print(2) + + 3 -> + // Comment + print(3) + + else -> { + print("else") + } + } +} diff --git a/core/testData/format/meta/when/newLinesBetweenClauses.kt b/core/testData/format/meta/when/newLinesBetweenClauses.kt new file mode 100644 index 00000000..6b4bc550 --- /dev/null +++ b/core/testData/format/meta/when/newLinesBetweenClauses.kt @@ -0,0 +1,18 @@ +fun f(x: Int) { + when (x) { + + + 1 -> print(1) + 2 -> print(2) + + + 3 -> + // Comment + print(3) + + else -> { + print("else") + } + + } +} diff --git a/core/testData/format/meta/when/valInSubject.expected.kt b/core/testData/format/meta/when/valInSubject.expected.kt new file mode 100644 index 00000000..b00d5e00 --- /dev/null +++ b/core/testData/format/meta/when/valInSubject.expected.kt @@ -0,0 +1,6 @@ +fun f(x: Result) { + when (val y = x.improved()) { + is Success<*> -> print(y) + is Failure -> print(2) + } +} diff --git a/core/testData/format/meta/when/valInSubject.kt b/core/testData/format/meta/when/valInSubject.kt new file mode 100644 index 00000000..b00d5e00 --- /dev/null +++ b/core/testData/format/meta/when/valInSubject.kt @@ -0,0 +1,6 @@ +fun f(x: Result) { + when (val y = x.improved()) { + is Success<*> -> print(y) + is Failure -> print(2) + } +} diff --git a/core/testData/format/meta/when/whenWithLambdaBody.expected.kt b/core/testData/format/meta/when/whenWithLambdaBody.expected.kt new file mode 100644 index 00000000..37e7cde7 --- /dev/null +++ b/core/testData/format/meta/when/whenWithLambdaBody.expected.kt @@ -0,0 +1,10 @@ +fun f(x: ModifierType) { + when (x) { + is FirstModifierType -> { myObject -> + doCustomModification(x, myObject) + } + is SecondModifierType -> { myObject -> + doOtherModification(x, myObject) + } + } +} diff --git a/core/testData/format/meta/when/whenWithLambdaBody.kt b/core/testData/format/meta/when/whenWithLambdaBody.kt new file mode 100644 index 00000000..37e7cde7 --- /dev/null +++ b/core/testData/format/meta/when/whenWithLambdaBody.kt @@ -0,0 +1,10 @@ +fun f(x: ModifierType) { + when (x) { + is FirstModifierType -> { myObject -> + doCustomModification(x, myObject) + } + is SecondModifierType -> { myObject -> + doOtherModification(x, myObject) + } + } +} diff --git a/core/testData/format/meta/when/whenWithLambdaBody2.expected.kt b/core/testData/format/meta/when/whenWithLambdaBody2.expected.kt new file mode 100644 index 00000000..a47593e5 --- /dev/null +++ b/core/testData/format/meta/when/whenWithLambdaBody2.expected.kt @@ -0,0 +1,9 @@ +fun f(x: ModifierType) { + when (x) { + is FirstModifierType -> { myObject -> + doFirstThing(myObject) + doSecondThing(myObject) + doThirdThing(myObject) + } + } +} diff --git a/core/testData/format/meta/when/whenWithLambdaBody2.kt b/core/testData/format/meta/when/whenWithLambdaBody2.kt new file mode 100644 index 00000000..a47593e5 --- /dev/null +++ b/core/testData/format/meta/when/whenWithLambdaBody2.kt @@ -0,0 +1,9 @@ +fun f(x: ModifierType) { + when (x) { + is FirstModifierType -> { myObject -> + doFirstThing(myObject) + doSecondThing(myObject) + doThirdThing(myObject) + } + } +} diff --git a/core/testData/format/meta/when/whenWithSubject.expected.kt b/core/testData/format/meta/when/whenWithSubject.expected.kt new file mode 100644 index 00000000..b48b5b03 --- /dev/null +++ b/core/testData/format/meta/when/whenWithSubject.expected.kt @@ -0,0 +1,12 @@ +fun f(x: Int) { + when (x) { + 1 -> print(1) + 2 -> print(2) + 3 -> + // Comment + print(3) + else -> { + print("else") + } + } +} diff --git a/core/testData/format/meta/when/whenWithSubject.kt b/core/testData/format/meta/when/whenWithSubject.kt new file mode 100644 index 00000000..b48b5b03 --- /dev/null +++ b/core/testData/format/meta/when/whenWithSubject.kt @@ -0,0 +1,12 @@ +fun f(x: Int) { + when (x) { + 1 -> print(1) + 2 -> print(2) + 3 -> + // Comment + print(3) + else -> { + print("else") + } + } +}

On the other hand, we respect existing tags, and don't remove them. - | */ - |""" - .trimMargin(), - ) - - @Test - fun `formatting kdoc preserves lists`() = assertFormatted( - """ - |/** - | * Here are some fruit I like: - | * - Banana - | * - Apple - | * - | * This is another paragraph - | */ - |""" - .trimMargin(), - ) - - @Test - fun `formatting kdoc lists with line wraps breaks and merges correctly`() { - val code = - """ - |/** - | * Here are some fruit I like: - | * - Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana - | * - Apple Apple Apple Apple - | * Apple Apple - | * - | * This is another paragraph - | */ - |""" - .trimMargin() - val expected = - """ - |/** - | * Here are some fruit I like: - | * - Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana Banana - | * Banana Banana Banana Banana Banana - | * - Apple Apple Apple Apple Apple Apple - | * - | * This is another paragraph - | */ - |""" - .trimMargin() - assertThatFormatting(code).isEqualTo(expected) - } - - @Test - fun `formatting kdoc preserves lists of asterisks`() = assertFormatted( - """ - |/** - | * Here are some fruit I like: - | * * Banana - | * * Apple - | * - | * This is another paragraph - | */ - |""" - .trimMargin(), - ) - - @Test - fun `formatting kdoc preserves numbered`() = assertFormatted( - """ - |/** - | * Here are some fruit I like: - | * 1. Banana - | * 2. Apple - | * - | * This is another paragraph - | */ - |""" - .trimMargin(), - ) - - @Test - fun `formatting kdoc with markdown errors`() = assertFormatted( - """ - |/** \[ */ - |fun markdownError() = Unit - |""" - .trimMargin(), - ) - - @Test - fun `return statement with value`() = assertFormatted( - """ - |fun random(): Int { - | return 4 - |} - |""" - .trimMargin(), - ) - - @Test - fun `return statement without value`() = assertFormatted( - """ - |fun print(b: Boolean) { - | print(b) - | return - |} - |""" - .trimMargin(), - ) - - @Test - fun `return expression without value`() = assertFormatted( - """ - |fun print(b: Boolean?) { - | print(b ?: return) - |} - |""" - .trimMargin(), - ) - - @Test - fun `if statement without else`() = assertFormatted( - """ - |fun maybePrint(b: Boolean) { - | if (b) { - | println(b) - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `if statement with else`() = assertFormatted( - """ - |fun maybePrint(b: Boolean) { - | if (b) { - | println(2) - | } else { - | println(1) - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `if expression with else`() = assertFormatted( - """ - |fun maybePrint(b: Boolean) { - | println(if (b) 1 else 2) - | println( - | if (b) { - | val a = 1 + 1 - | 2 * a - | } else 2) - | return if (b) 1 else 2 - |} - |""" - .trimMargin(), - ) - - @Test - fun `if expression with break before else`() = assertFormatted( - """ - |////////////////////////////// - |fun compute(b: Boolean) { - | val c = - | if (a + b < 20) a + b - | else a - | return if (a + b < 20) a + b - | else c - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `if expression with break before expressions`() = assertFormatted( - """ - |////////////////////////// - |fun compute(b: Boolean) { - | val c = - | if (a + b < 20) - | a + b - | else if (a < 20) a - | else - | a + b + b + 1000 - | return if (a + b < 20) - | a + b - | else c - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `blocky expressions in if-else`() = assertFormatted( - """ - |fun numbers() { - | if (true) - | do { - | eat("is") - | matches += type() - | } while (eat(",")) - | else - | while (1 < 2) { - | println("Everything is okay") - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `if expression with multiline condition`() = assertFormatted( - """ - |//////////////////////////// - |fun foo() { - | if (expressions1 && - | expression2 && - | expression3) { - | bar() - | } - | - | if (foo( - | expressions1 && - | expression2 && - | expression3)) { - | bar() - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `if expression with comment`() = assertFormatted( - """ - |//////////////////////////// - |fun foo() { - | if (expressions1) - | // comment - | bar() - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `assignment expression on multiple lines`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |fun f() { - | var myVariable = 5 - | myVariable = - | function1(4, 60, 8) + function2(57, 39, 20) - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `A program that tickled a bug in KotlinInput`() = assertFormatted( - """ - |val x = 2 - |""" - .trimMargin(), - ) - - @Test - fun `a few variations of constructors`() = assertFormatted( - """ - |////////////////////////////////////////////////////// - |class Foo constructor(number: Int) {} - | - |class Foo2 private constructor(number: Int) {} - | - |class Foo3 @Inject constructor(number: Int) {} - | - |class Foo4 @Inject private constructor(number: Int) {} - | - |class Foo5 - |@Inject - |private constructor( - | number: Int, - | number2: Int, - | number3: Int, - | number4: Int, - | number5: Int, - | number6: Int - |) {} - | - |class Foo6 - |@Inject - |private constructor(hasSpaceForAnnos: Innnt) { - | // @Inject - |} - | - |class FooTooLongForCtorAndSupertypes - |@Inject - |private constructor(x: Int) : NoooooooSpaceForAnnos {} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `a primary constructor without a class body `() = assertFormatted( - """ - |///////////////////////// - |data class Foo( - | val number: Int = 0 - |) - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `a secondary constructor without a body`() = assertFormatted( - """ - |/////////////////////////// - |data class Foo { - | constructor( - | val number: Int = 0 - | ) - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `a secondary constructor with a body breaks before closing parenthesis`() = assertFormatted( - """ - |/////////////////////////// - |data class Foo { - | constructor( - | val number: Int = 0 - | ) {} - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `a constructor with many arguments over breaking to next line`() = assertFormatted( - """ - |data class Foo( - | val number: Int, - | val name: String, - | val age: Int, - | val title: String, - | val offspring2: List - |) {} - |""" - .trimMargin(), - ) - - @Test - fun `a constructor with keyword and many arguments over breaking to next line`() = assertFormatted( - """ - |data class Foo - |constructor( - | val name: String, - | val age: Int, - | val title: String, - | val offspring: List, - | val foo: String - |) {} - |""" - .trimMargin(), - ) - - @Test - fun `a constructor with many arguments over multiple lines`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |data class Foo - |constructor( - | val number: Int, - | val name: String, - | val age: Int, - | val title: String, - | val offspring: List - |) {} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `handle secondary constructors`() = assertFormatted( - """ - |class Foo private constructor(number: Int) { - | private constructor(n: Float) : this(1) - | - | private constructor(n: Double) : this(1) { - | println("built") - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `a secondary constructor with many arguments over multiple lines`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |data class Foo { - | constructor( - | val number: Int, - | val name: String, - | val age: Int, - | val title: String, - | val offspring: List - | ) - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `a secondary constructor with many arguments passed to delegate`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |data class Foo { - | constructor( - | val number: Int, - | val name: String, - | val age: Int, - | val title: String, - | val offspring: List - | ) : this( - | number, - | name, - | age, - | title, - | offspring, - | offspring) - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `a secondary constructor with no arguments passed to delegate`() = assertFormatted( - """ - |////////////////////////////////////////////////// - |data class Foo { - | constructor() : - | this( - | Foo.createSpeciallyDesignedParameter(), - | Foo.createSpeciallyDesignedParameter(), - | ) - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `secondary constructor with param list that fits in one line, with delegate`() = assertFormatted( - """ - |class C { - | constructor( - | context: Context?, - | attrs: AttributeSet?, - | defStyleAttr: Int, - | defStyleRes: Int - | ) : super(context, attrs, defStyleAttr, defStyleRes) { - | init(attrs) - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle calling super constructor in secondary constructor`() = assertFormatted( - """ - |class Foo : Bar { - | internal constructor(number: Int) : super(number) {} - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle super statement with with type argument`() = assertFormatted( - """ - |class Foo : Bar(), FooBar { - | override fun doIt() { - | super.doIt() - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle super statement with with label argument`() = assertFormatted( - """ - |class Foo : Bar(), FooBar { - | override fun doIt() { - | foo.doThat { - | super@Foo.doIt() - | - | // this one is actually generics on the call expression, not super - | super@Foo.doIt() - | } - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `primary constructor without parameters with a KDoc`() = assertFormatted( - """ - |class Class - |/** A comment */ - |constructor() {} - |""" - .trimMargin(), - ) - - @Test - fun `handle objects`() = assertFormatted( - """ - |object Foo(n: Int) {} - |""" - .trimMargin(), - ) - - @Test - fun `handle object expression`() = assertFormatted( - """ - |fun f(): Any { - | return object : Adapter() {} - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle object expression in parenthesis`() = assertFormatted( - """ - |fun f(): Any { - | return (object : Adapter() {}) - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle array indexing operator`() = assertFormatted( - """ - |fun f(a: Magic) { - | a[3] - | b[3, 4] - |} - |""" - .trimMargin(), - ) - - @Test - fun `keep array indexing grouped with expression is possible`() = assertFormatted( - """ - |/////////////////////// - |fun f(a: Magic) { - | foo.bar() - | .foobar[1, 2, 3] - | foo.bar() - | .foobar[ - | 1, - | 2, - | 3, - | 4, - | 5] - | foo.bar() - | .foobar[1, 2, 3] - | .barfoo[3, 2, 1] - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `mixed chains`() = assertFormatted( - """ - |/////////////////////// - |fun f(a: Magic) { - | foo.bar() - | .foobar[1, 2, 3] - | foo.bar() - | .foobar[ - | 1, - | 2, - | 3, - | 4, - | 5] - | foo.bar() - | .foobar[1, 2, 3] - | .barfoo[3, 2, 1] - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `handle destructuring declaration`() = assertFormatted( - """ - |/////////////////////////////////////////////// - |fun f() { - | val (a, b: Int) = listOf(1, 2) - | val (asd, asd, asd, asd, asd, asd, asd) = - | foo.bar(asdasd, asdasd) - | - | val (accountType, accountId) = - | oneTwoThreeFourFiveSixSeven( - | foo, bar, zed, boo) - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `handle name based destructuring declaration`() { - if (KotlinVersion.CURRENT < KotlinVersion(2, 3)) return - - assertThatFormatting( - """ - |fun f(d: D) { - | val [a, b ] = d - | val (a, x = b ) = d - | var [a, _ ] = d - | [var a, var b ] = d - | [val a: Int, val _: String ] = d - | (var x = a, var y = b ) = d - | (val x: Int = a, var y: String = b ) = d - |} - |""" - .trimMargin(), - ) - .isEqualTo( - """ - |fun f(d: D) { - | val [a, b] = d - | val (a, x = b) = d - | var [a, _] = d - | [var a, var b] = d - | [val a: Int, val _: String] = d - | (var x = a, var y = b) = d - | (val x: Int = a, var y: String = b) = d - |} - |""" - .trimMargin(), - ) - } - - @Test - fun `chains with derferences and array indexing`() = assertFormatted( - """ - |/////////////////////// - |fun f() { - | foo.bam() - | .uber!![0, 1, 2] - | .boom()[1, 3, 5] - | .lah - | .doo { it } - | .feep[1] - | as Boo - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `block like syntax after dereferences and indexing with short lines`() = assertFormatted( - """ - |/////////////////////// - |fun f() { - | foo.bam() - | .uber!![0, 1, 2] - | .forEach { - | println(it) - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `block like syntax after dereferences and indexing with long lines`() = assertFormatted( - """ - |////////////////////////////////// - |fun f() { - | foo.uber!![0, 1, 2].forEach { - | println(it) - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `try to keep type names together`() = assertFormatted( - """ - |/////////////////////// - |fun f() { - | com.facebook.foo.Foo( - | 1, 2) - | com.facebook.foo - | .Foo(1, 2) - | .andAlsoThis() - | com.facebook.Foo.foo( - | 1, 2) - | com.facebook - | .foobarFoo - | .foo(1, 2) - | foo.invoke( - | foo, bar, bar) - | foo.invoke(foo, bar) - | .invoke() - | FooFoo.foooooooo() - | .foooooooo() - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `avoid breaking brackets and keep them with array name`() = assertFormatted( - """ - |///////////////////////////////////////////////////////////////////////// - |fun f() { - | val a = - | invokeIt(context.packageName) - | .getInternalMutablePackageInfo(context.packageName) - | .someItems[0] - | .getInternalMutablePackageInfo(context.packageName) - | .someItems[0] - | .doIt() - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `keep function call with type name even if array expression is next`() = assertFormatted( - """ - |class f { - | private val somePropertyWithBackingOne - | get() = - | _somePropertyWithBackingOne - | ?: Classname.getStuff(requireContext())[ - | somePropertiesProvider, somePropertyCallbacks] - | .also { _somePropertyWithBackingOne = it } - |} - |""" - .trimMargin(), - ) - - @Test - fun `array access in middle of chain and end of it behaves similarly`() = assertFormatted( - """ - |////////////////////////////////////// - |fun f() { - | if (aaaaa == null || - | aaaaa.bbbbb[0] == null || - | aaaaa.bbbbb[0].cc == null || - | aaaaa.bbbbb[0].dddd == null) { - | println() - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `handle qmark for nullable types`() = assertFormatted( - """ - |var x: Int? = null - |var x: (Int)? = null - |var x: (Int?) = null - |var x: ((Int))? = null - |var x: ((Int?)) = null - |var x: ((Int)?) = null - | - |var x: @Anno Int? = null - |var x: @Anno() (Int)? = null - |var x: @Anno (Int?) = null - |var x: (@Anno Int)? = null - |var x: (@Anno Int?) = null - |var x: (@Anno() (Int))? = null - |var x: (@Anno (Int?)) = null - |var x: (@Anno() (Int)?) = null - |""" - .trimMargin(), - ) - - @Test - fun `nullable function type`() = assertFormatted( - """ - |var listener: ((Boolean) -> Unit)? = null - |""" - .trimMargin(), - ) - - @Test - fun `redundant parenthesis in function types`() = assertFormatted( - """ - |val a: (Int) = 7 - | - |var listener: ((Boolean) -> Unit) = foo - |""" - .trimMargin(), - ) - - @Test - fun `handle string literals`() = assertFormatted( - """ - |fun doIt(world: String) { - | println("Hello world!") - | println("Hello! ${'$'}world") - | println("Hello! ${'$'}{"wor" + "ld"}") - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle multiline string literals`() = assertFormatted( - """ - |fun doIt(world: String) { - | println( - | ${TQ}Hello - | world!${TQ}) - | println( - | ${TQ}Hello - | world!${TQ}, - | ${TQ}Goodbye - | world!${TQ}) - |} - |""" - .trimMargin(), - ) - - @Test - fun `Trailing whitespaces are preserved in multiline strings`() { - val code = listOf( - "fun doIt(world: String) {", - " println(", - " ${TQ}This line has trailing whitespace ", - " world!${TQ})", - " println(", - " ${TQ}This line has trailing whitespace \$s ", - " world!${TQ})", - " println(", - " ${TQ}This line has trailing whitespace \${s} ", - " world!${TQ})", - " println(", - " ${TQ}This line has trailing whitespace \$ ", - " world!${TQ})", - "}", - "", - ) - .joinToString("\n") - assertThatFormatting(code).allowTrailingWhitespace().isEqualTo(code) - } - - @Test - fun `Consecutive line breaks in multiline strings are preserved`() = assertFormatted( - """ - |val x = - | $TQ - | - | - | - |Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do - |$TQ - |""" - .trimMargin(), - ) - - @Test - fun `multiline trimMargin special handling`() { - val before = - """ - |val margin = - | ${TQ}example - | | of - | | a - | |multiline - | | string - | |$TQ - | .trimMargin() - |""" - .trimMargin() - val after = - """ - |val margin = - | $TQ - | |example - | | of - | | a - | |multiline - | | string - | |$TQ - | .trimMargin() - |""" - .trimMargin() - - assertThatFormatting(before).isEqualTo(after) - } - - @Test - fun `multiline trimIndent special handling`() { - val before = - """ - |val indent = - | $TQ - | example - | of - | a - | - | multiline - | string - | $TQ - | .trimIndent() - |""" - .trimMargin() - val after = - """ - |val indent = - | $TQ - | example - | of - | a - | - | multiline - | string - | $TQ - | .trimIndent() - |""" - .trimMargin() - - assertThatFormatting(before).isEqualTo(after) - } - - @Test - fun `multiline trimIndent and trimMargin inside of function call`() { - assertThatFormatting( - """ - |foo( - | ${TQ}example - | | of - | | a - | - | |multiline - | | string - | |$TQ - | .trimMargin() - |) - | .bar( - | ${TQ} - | example - | of - | a - | - | multiline - | string - | $TQ - | .trimIndent() - | ) - |""" - .trimMargin(), - ) - .withOptions(META_FORMAT) - .isEqualTo( - """ - |foo( - | $TQ - | |example - | | of - | | a - | | - | |multiline - | | string - | |$TQ - | .trimMargin(), - |) - | .bar( - | $TQ - | example - | of - | a - | - | multiline - | string - | $TQ - | .trimIndent(), - | ) - |""" - .trimMargin(), - ) - } - - @Test - fun `trimIndent and trimMargin formatting does not add new lines`() { - assertThatFormatting( - """ - |val margin = - | $TQ${" "} - | |is this the end of the line?$TQ - | .trimMargin() - |""" - .trimMargin(), - ) - .isEqualTo( - """ - |val margin = - | $TQ - | |is this the end of the line? - | $TQ - | .trimMargin() - |""" - .trimMargin(), - ) - - assertThatFormatting( - """ - |val margin = - | $TQ${" "} - | is this the end of the line?$TQ - | .trimIndent() - |""" - .trimMargin(), - ) - .isEqualTo( - """ - |val margin = - | $TQ - | is this the end of the line? - | $TQ - | .trimIndent() - |""" - .trimMargin(), - ) - } - - @Test - fun `properly handles trimMargin blank lines at the end of multiline string`() = assertThatFormatting( - """ - |val margin = - | $TQ - | |test - | string - | | - | $TQ - | .trimMargin() - |""" - .trimMargin(), - ) - .isEqualTo( - """ - |val margin = - | $TQ - | |test - | | string - | |$TQ - | .trimMargin() - |""" - .trimMargin(), - ) - - @Test - fun `properly handles trimMargin that has margin in the first line`() = assertThatFormatting( - """ - |val margin = - | $TQ |test - | | string - | |$TQ - | .trimMargin() - |""" - .trimMargin(), - ) - .isEqualTo( - """ - |val margin = - | $TQ - | |test - | | string - | |$TQ - | .trimMargin() - |""" - .trimMargin(), - ) - - @Test - fun `handles multiline trim with template expressions inside of it`() { - assertFormatted( - """ - |val margin = - | $TQ - | |my math = ${'$'}{ - | if (condition) { - | "}" + (1 + 2) - | .toString() - | } else { - | $TQ - | my own multiline trimmed string - | is here - | $TQ - | .trimIndent() - | } - | } - | | string - | |$TQ - | .trimMargin() - |""" - .trimMargin(), - ) - - assertFormatted( - """ - |val margin = - | ${"$$"}$TQ - | |my math = ${"$$"}{ - | if (condition) { - | "}" + (1 + 2) - | .toString() - | }else{ - | $TQ - | my own multiline trimmed string - | is here - | $TQ.trimIndent() - | } - | } - | | string - | |$TQ - | .trimMargin() - |""" - .trimMargin(), - ) - } - - @Test - fun `handles multiline trimMargin with pipe not being the margin character`() { - assertThatFormatting( - """ - |val margin = - | $TQ - | echo hello | wc -c - | cat hay_stack.txt | grep needle - | {myList.joinToString("|")} - | $TQ - | .trimMargin() - |""" - .trimMargin(), - ) - .isEqualTo( - """ - |val margin = - | $TQ - | | echo hello | wc -c - | | cat hay_stack.txt | grep needle - | | {myList.joinToString("|")} - | $TQ - | .trimMargin() - |""" - .trimMargin(), - ) - } - - @Test - fun `comments between multiline string and trimMargin are preserved`() = assertFormatted( - """ - |val bar = - | $TQ - | |content - | $TQ - | // This comment should be preserved - | .trimMargin() - |""" - .trimMargin(), - ) - - @Test - fun `comments between multiline string and trimIndent are preserved`() = assertFormatted( - """ - |val bar = - | $TQ - | content - | $TQ - | // This comment should be preserved - | .trimIndent() - |""" - .trimMargin(), - ) - - @Test - fun `multiple comments between multiline string and trimMargin are preserved`() = assertFormatted( - """ - |val bar = - | $TQ - | |content - | $TQ - | // First comment - | // Second comment - | .trimMargin() - |""" - .trimMargin(), - ) - - @Test - fun `comment between multiline string and trimMargin is not deleted in string concatenation`() { - val before = - """ - |val bar = - | $TQ - | | a - | $TQ + - | $TQ - | | b - | $TQ - | // This comment will not be deleted - |.trimMargin() - |""" - .trimMargin() - val after = - """ - |val bar = - | $TQ - | | a - | $TQ + - | $TQ - | | b - | $TQ - | // This comment will not be deleted - | .trimMargin() - |""" - .trimMargin() - - assertThatFormatting(before).isEqualTo(after) - } - - @Test - fun `handles multiline trim formatting with template expressions`() { - assertFormatted( - """ - |val margin1 = - | ${TQ}my math = ${'$'}{ "}" + (1 + 2).toString() } - | | checks - | | out - | |$TQ - | .trimMargin() - | - |val margin2 = - | ${"$$"}${TQ}my math = ${"$$"}{ "}" + (1 + 2).toString() } - | | checks - | | out - | |$TQ - | .trimMargin() - |""" - .trimMargin(), - ) - - assertThatFormatting( - """ - |val margin1 = - | $TQ - |not_a_var$ - |$1 - |$\{ - |$} - |$TQ - | .trimIndent() - | - |val margin2 = - | ${"$$"}$TQ - |not_a_var$$ - |$$1 - |$$\{ - |$$} - | |$TQ - | .trimMargin() - |""" - .trimMargin(), - ) - .isEqualTo( - """ - |val margin1 = - | $TQ - | not_a_var$ - | $1 - | $\{ - | $} - | $TQ - | .trimIndent() - | - |val margin2 = - | ${"$$"}$TQ - | |not_a_var$$ - | |$$1 - | |$$\{ - | |$$} - | |$TQ - | .trimMargin() - |""" - .trimMargin(), - ) - } - - @Test - fun `handles multi-dollar string`() = assertThatFormatting( - """ - |val margin = - | ${"$$"}$TQ - | |{ - | "${'$'}test": "string" - | |} - | - | $TQ.trimMargin() - |""" - .trimMargin(), - ) - .isEqualTo( - """ - |val margin = - | ${"$$"}$TQ - | |{ - | | "${'$'}test": "string" - | |} - | |$TQ - | .trimMargin() - |""" - .trimMargin(), - ) - - @Test - fun `Trailing spaces in a comment are not preserved`() { - val before = - listOf("// trailing spaces in a comment are not preserved ", "").joinToString("\n") - val after = listOf("// trailing spaces in a comment are not preserved", "").joinToString("\n") - assertThatFormatting(before).allowTrailingWhitespace().isEqualTo(after) - } - - @Test - fun `Code with tombstones is not supported`() { - val code = - """ - |fun good() { - | // ${'\u0003'} - |} - |""" - .trimMargin() - try { - Formatter.format(code) - fail() - } catch (e: ParseError) { - assertThat(e.errorDescription).contains("\\u0003") - assertThat(e.lineColumn.line).isEqualTo(1) - assertThat(e.lineColumn.column).isEqualTo(5) - } - } - - @Test - fun `handle some basic generics scenarios`() = assertFormatted( - """ - |fun doIt(a: List): List? { - | val b: List = convert(listOf(5, 4)) - | return b - |} - | - |class Foo - |""" - .trimMargin(), - ) - - @Test - fun `handle for loops`() = assertFormatted( - """ - |fun f(a: List) { - | for (i in a.indices) { - | println(i) - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle for loops with long dot chains`() = assertFormatted( - """ - |/////////////////////////////////// - |fun f(a: Node) { - | for (child in node.next.data()) { - | println(child) - | } - | for (child in - | node.next.next.data()) { - | println(child) - | } - | for (child in - | node.next.next.next.next - | .data()) { - | println(child) - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `when two lambdas following a call, indent the lambda properly`() = assertFormatted( - """ - |//////////////////////////// - |fun f() { - | doIt() - | .apply { - | number = - | computeNumber1() - | } - | .apply { - | number = 2 * number - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `when two lambdas following a field, indent the lambda properly`() = assertFormatted( - """ - |//////////////////////////// - |fun f() { - | field - | .apply { - | number = - | computeNumber1() - | } - | .apply { - | number = 2 * number - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `break after 'four' (even though it's 4 chars long) because there's a lambda afterwards`() = assertFormatted( - """ - |fun f() { - | four - | .let { - | // - | foo() - | } - | .methodCall() - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle where formatting, fits into single line`() = assertFormatted( - """ - |class Foo(n: Int) where T : Bar, T : FooBar - | - |fun foo(n: Int) where T : Bar, T : FooBar {} - |""" - .trimMargin(), - ) - - @Test - fun `handle where formatting, full expression breaks into single line`() = assertFormatted( - """ - |//////////////////////////////// - |class Foo(n: Int) - | where T : Bar, T : FooBar - | - |fun foo(n: Int) - | where T : Bar, T : FooBar {} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `handle where formatting, everything breaks into multiple lines`() = assertFormatted( - """ - |//////////////////////////// - |class Foo(n: Int) - | where - | T : Bar, - | T : FooBar - | - |fun foo(n: Int) - | where - | T : Bar, - | T : FooBar {} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `keep last expression in qualified indented`() = assertFormatted( - """ - |//////////////////////////// - |fun f() { - | Stuff() - | .doIt( - | Foo.doIt() - | .doThat()) - | .doIt( - | Foo.doIt() - | .doThat()) - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `properly place lambda arguments into blocks`() = assertFormatted( - """ - |/////////////////////// - |fun f() { - | foo { - | red.orange.yellow() - | } - | - | foo.bar { - | red.orange.yellow() - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `properly handle one statement lambda with comment`() = assertFormatted( - """ - |//////////////////////// - |fun f() { - | foo { - | // this is a comment - | red.orange.yellow() - | } - | foo { - | /* this is also a comment */ - | red.orange.yellow() - | } - | foo.bar { - | // this is a comment - | red.orange.yellow() - | } - | foo.bar() { - | // this is a comment - | red.orange.yellow() - | } - | foo.bar { - | /* this is also a comment */ - | red.orange.yellow() - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `properly handle one statement lambda with comment after body statements`() = assertFormatted( - """ - |//////////////////////// - |fun f() { - | foo { - | red.orange.yellow() - | // this is a comment - | } - | foo { - | red.orange.yellow() - | /* this is also a comment */ - | } - | foo.bar { - | red.orange.yellow() - | // this is a comment - | } - | foo.bar() { - | red.orange.yellow() - | // this is a comment - | } - | foo.bar { - | red.orange.yellow() - | /* this is also a comment */ - | } - | red.orange.yellow() - | // this is a comment - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `try to keep expression in the same line until the first lambda`() = assertFormatted( - """ - |///////////////////////// - |fun f() { - | foo.bar.bar?.let { - | a() - | } - | foo.bar.bar?.let { - | action() - | action2() - | } - | foo.bar.bar.bar.bar - | ?.let { a() } - | foo.bar.bar.bar.bar - | ?.let { - | action() - | action2() - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `different indentation in chained calls`() = assertFormatted( - """ - |/////////////////////////// - |fun f() { - | fooDdoIt( - | foo1, foo2, foo3) - | foo.doIt( - | foo1, foo2, foo3) - | foo.doIt( - | foo1, foo2, foo3) - | .doThat() - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `always add a conditional break for a lambda which is not last`() = assertFormatted( - """ - |//////////////////// - |fun f() { - | foofoo - | .doIt { - | doStuff() - | } - | .doIt { - | doStuff() - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `keep parenthesis and braces together when there's only one lambda argument`() = assertFormatted( - """ - |fun f() { - | doIt({}) - | doIt({ it + it }) - | doIt({ - | val a = it - | a + a - | }) - | doIt(functor = { it + it }) - | doIt( - | functor = { - | val a = it - | a + a - | }) - |} - |""" - .trimMargin(), - ) - - @Test - fun `Qualified type`() = assertFormatted( - """ - |fun f() { - | var plusFour: Indent.Const - | var x: Map.Entry - | var x: List.Iterator - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle destructuring declaration in for loop`() = assertFormatted( - """ - |fun f(a: List>) { - | for ((x, y: Int) in a) {} - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle function references`() = assertFormatted( - """ - |//////////////////////////////// - |fun f(a: List) { - | a.forEach(::println) - | a.map(Int::toString) - | a.map(String?::isNullOrEmpty) - | a.map( - | SuperLongClassName?:: - | functionName) - | val f = - | SuperLongClassName:: - | functionName - | val g = - | invoke(a, b)::functionName - | val h = - | invoke(a, b, c):: - | functionName - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `handle escaped identifier`() = assertFormatted( - """ - |import foo as `foo foo` - |import org.mockito.Mockito.`when` as `yay yay` - | - |fun `spaces in functions`() { - | val `when` = NEVER - | val (`do not`, `ever write`) = SERIOUSLY - | val `a a`: Int - | `yay yay`(`foo foo`) - |} - | - |class `more spaces` - |""" - .trimMargin(), - ) - - @Test - fun `handle annotations with arguments`() = assertFormatted( - """ - |@Px fun f(): Int = 5 - | - |@Dimenstion(unit = DP) fun g(): Int = 5 - | - |@RunWith(MagicRunner::class) - |@Px - |class Test { - | // - |} - |""" - .trimMargin(), - ) - - @Test - fun `no newlines after annotations if entire expr fits in one line`() = assertFormatted( - """ - |/////////////////////////////////////////////// - |@Px @Px fun f(): Int = 5 - | - |@Px - |@Px - |@Px - |@Px - |@Px - |@Px - |@Px - |@Px - |fun f(): Int = 5 - | - |@Px - |@Px - |fun f(): Int { - | return 5 - |} - | - |@Dimenstion(unit = DP) @Px fun g(): Int = 5 - | - |@Dimenstion(unit = DP) - |@Px - |fun g(): Int { - | return 5 - |} - | - |@RunWith @Px class Test - | - |@RunWith(MagicRunner::class) @Px class Test - | - |@RunWith @Px class Test {} - | - |@RunWith(MagicRunner::class) @Px class Test {} - | - |@RunWith(MagicRunner::class) - |@Px - |@Px - |class Test {} - | - |@RunWith(MagicRunner::class) - |@Px - |class Test { - | // - |} - | - |fun f() { - | if (@Stuff(Magic::class) isGood()) { - | println("") - | } - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `no newlines after annotations on properties if entire expression fits in one line`() = assertFormatted( - """ - |//////////////////////////////////////////// - |@Suppress("UnsafeCast") - |val ClassA.methodA - | get() = foo as Bar - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `when annotations cause line breaks, and constant has no type dont break before value`() = assertFormatted( - """ - |////////////////////////////////////////////////////////// - |object Foo { - | @LongLongLongLongAnnotation - | @LongLongLongLongLongAnnotation - | private val ROW_HEIGHT = 72 - |} - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `annotations in literal function types`() = assertFormatted( - """ - |val callback: (@Anno List<@JvmSuppressWildcards String>) -> Unit = foo - |""" - .trimMargin(), - ) - - @Test - fun `annotations on type parameters`() = assertFormatted( - """ - |class Foo<@Anno out @Anno T, @Anno in @Anno U> { - | inline fun <@Anno reified @Anno X, @Anno reified @Anno Y> bar() {} - |} - |""" - .trimMargin(), - ) - - @Test - fun `annotations on type constraints`() = assertFormatted( - """ - |class Foo where U : @Anno Kip, U : @Anno Qux { - | fun bar() where U : @Anno Kip, U : @Anno Qux {} - |} - |""" - .trimMargin(), - ) - - @Test - fun `annotations on type arguments`() = assertFormatted( - """ - |fun foo(x: Foo) {} - |""" - .trimMargin(), - ) - - @Test - fun `annotations on destructuring declaration elements`() = assertFormatted( - """ - |val x = { (@Anno x, @Anno y) -> x } - |""" - .trimMargin(), - ) - - @Test - fun `annotations on exceptions`() = assertFormatted( - """ - |fun doIt() { - | try { - | doItAgain() - | } catch (@Nullable e: Exception) { - | // - | } catch (@Suppress("GeneralException") e: Exception) {} - |} - |""" - .trimMargin(), - ) - - @Test - fun `annotations on return statements`() = assertFormatted( - """ - |fun foo(): Map { - | @Suppress("AsCollectionCall") - | return map.asMap() - |} - |""" - .trimMargin(), - ) - - @Test - fun `Unary prefix expressions`() = assertFormatted( - """ - |fun f() { - | !a - | -4 - | val x = -foo() - | +4 - | ++a - | --a - | - | + +a - | +-a - | +!a - | -+a - | - -a - | -!a - | !+a - | !a - | ! !a - | - | + ++a - | +--a - | -++a - | - --a - | !++a - | !--a - |} - |""" - .trimMargin(), - ) - - @Test - fun `Unary postfix expressions`() = assertFormatted( - """ - |fun f() { - | a!! - | a++ - | a-- - | - | a--!! - | a++!! - | - | a!! !! - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle wildcard generics`() = assertFormatted( - """ - |fun f() { - | val l: List<*> - | val p: Pair<*, *> - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle intersection generics`() = assertFormatted( - """ - |fun f() { - | val l: Decl - | val p = Ctor - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle covariant and contravariant type arguments`() = assertFormatted( - """ - |val p: Pair - |""" - .trimMargin(), - ) - - @Test - fun `handle covariant and contravariant type parameters`() = assertFormatted( - """ - |class Foo - |""" - .trimMargin(), - ) - - @Test - fun `handle bounds for type parameters`() = assertFormatted( - """ - |class Foo, out S : Any?> - |""" - .trimMargin(), - ) - - @Test - fun `handle compound generic bounds on classes`() = assertFormatted( - """ - |class Foo(n: Int) where T : Bar, T : FooBar {} - |""" - .trimMargin(), - ) - - @Test - fun `handle compound generic bounds on functions`() = assertFormatted( - """ - |fun foo(n: Int) where T : Bar, T : FooBar {} - |""" - .trimMargin(), - ) - - @Test - fun `handle compound generic bounds on properties`() = assertFormatted( - """ - |val List.twiceSum: Int where T : Int - | get() { - | return 2 * sum() - | } - |""" - .trimMargin(), - ) - - @Test - fun `handle compound generic bounds on class with delegate`() = assertFormatted( - """ - |class Foo() : Bar by bar - | where T : Qux - |""" - .trimMargin(), - ) - - @Test - fun `explicit type on property getter`() = assertFormatted( - """ - |class Foo { - | val silly: Int - | get(): Int = 1 - |} - |""" - .trimMargin(), - ) - - @Test - fun `explicit backing field`() = assertFormatted( - """ - |class Foo { - | val city: StateFlow - | field = MutableStateFlow("") - | - | var numbers: List - | field: MutableList = mutableListOf() - |} - |""" - .trimMargin(), - ) - - @Test - fun `explicit backing field without type`() = assertFormatted( - """ - |class Foo { - | val count: Int - | field = 0 - |} - |""" - .trimMargin(), - ) - - @Test - fun `explicit backing field with private set accessor`() = assertFormatted( - """ - |class Foo { - | var count: Int - | field = 0 - | private set - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle method calls with lambda arg only`() = assertFormatted( - """ - |fun f() { - | val a = g { 1 + 1 } - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle method calls value args and a lambda arg`() = assertFormatted( - """ - |fun f() { - | val a = g(1, 2) { 1 + 1 } - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle top level constants`() = assertFormatted( - """ - |///////////////////////////// - |val a = 5 - | - |const val b = "a" - | - |val a = 5 - |""" - .trimMargin(), - deduceMaxWidth = true, - ) - - @Test - fun `handle lambda arg with named arguments`() = assertFormatted( - """ - |fun f() { - | val b = { x: Int, y: Int -> x + y } - |} - |""" - .trimMargin(), - ) - - @Test - fun `avoid newline before lambda argument if it is named`() = assertFormatted( - """ - |private fun f(items: List) { - | doSomethingCool( - | items, - | lambdaArgument = { - | step1() - | step2() - | }) { - | it.doIt() - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle labeled this pointer`() = assertFormatted( - """ - |class Foo { - | fun f() { - | g { println(this@Foo) } - | } - |} - |""" - .trimMargin(), - ) - - @Test - fun `handle extension and operator functions`() = assertFormatted( - """ - |operator fun Point.component1() = x - |""" - .trimMargin(), - ) - @Test fun `handle extension methods with very long names`() = assertFormatted( """ diff --git a/core/src/test/java/com/facebook/ktfmt/format/FormatterTest2.kt b/core/src/test/java/com/facebook/ktfmt/format/FormatterTest2.kt new file mode 100644 index 00000000..47655d44 --- /dev/null +++ b/core/src/test/java/com/facebook/ktfmt/format/FormatterTest2.kt @@ -0,0 +1,35 @@ +package com.facebook.ktfmt.format + +import com.facebook.ktfmt.TEST_DATA_ROOT +import com.facebook.ktfmt.runFormatterTest +import org.junit.runner.RunWith +import org.junit.runners.Parameterized +import java.nio.file.Files +import kotlin.io.path.extension +import kotlin.io.path.isRegularFile +import kotlin.io.path.name +import kotlin.streams.asSequence +import kotlin.test.Test + +@RunWith(Parameterized::class) +class FormatterTest2(private val relativePath: String) { + + @Test + fun format() = runFormatterTest(relativePath) + + companion object { + val TEST_DATA_PATH = TEST_DATA_ROOT.resolve("format/meta") + + @JvmStatic + @Parameterized.Parameters(name = "{0}") + fun data(): List> = + Files.walk(TEST_DATA_PATH).asSequence() + .filter { it.isRegularFile() } + .filter { it.extension == "kt" || it.extension == "kts" } + .filterNot { it.name.contains(".expected.") } // skip golden files + .map { TEST_DATA_ROOT.relativize(it).toString() } + .sorted() + .map { arrayOf(it) } + .toList() + } +} diff --git a/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt b/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt index 45377751..88b34c1a 100644 --- a/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt +++ b/core/src/test/java/com/facebook/ktfmt/format/GoogleStyleFormatterKtTest.kt @@ -16,9 +16,9 @@ package com.facebook.ktfmt.format -import com.facebook.ktfmt.testutil.assertFormatted -import com.facebook.ktfmt.testutil.assertThatFormatting -import com.facebook.ktfmt.testutil.defaultTestFormattingOptions +import com.facebook.ktfmt.assertFormatted +import com.facebook.ktfmt.assertThatFormatting +import com.facebook.ktfmt.defaultTestFormattingOptions import org.junit.BeforeClass import org.junit.Test import org.junit.runner.RunWith diff --git a/core/src/test/java/com/facebook/ktfmt/kdoc/KDocFormatterTest.kt b/core/src/test/java/com/facebook/ktfmt/kdoc/KDocFormatterTest.kt index 1a7a4175..7457f8da 100644 --- a/core/src/test/java/com/facebook/ktfmt/kdoc/KDocFormatterTest.kt +++ b/core/src/test/java/com/facebook/ktfmt/kdoc/KDocFormatterTest.kt @@ -32,6 +32,7 @@ package com.facebook.ktfmt.kdoc +import com.facebook.ktfmt.DokkaVerifier import com.google.common.truth.Truth.assertThat import com.google.common.truth.Truth.assertWithMessage import kotlin.io.path.createTempDirectory diff --git a/core/src/testFixtures/java/com/facebook/ktfmt/Directvie.kt b/core/src/testFixtures/java/com/facebook/ktfmt/Directvie.kt new file mode 100644 index 00000000..fda9a597 --- /dev/null +++ b/core/src/testFixtures/java/com/facebook/ktfmt/Directvie.kt @@ -0,0 +1,26 @@ +package com.facebook.ktfmt + +import kotlin.text.appendLine + +interface Directive { + val name: String + val callback: (String) -> Unit + + fun matches(line: String): Boolean = line.startsWith("// $name") + + fun apply(line: String) { + callback(line.removePrefix("// $name").trim()) + } +} + +interface DirectiveContainer { + val result: T + val directives: List + + fun processDirectives(code: String): String = buildString { + code.lines().forEach { line -> + val directive = directives.firstOrNull { it.matches(line) } + if (directive != null) directive.apply(line) else appendLine(line) + } + } +} \ No newline at end of file diff --git a/core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt b/core/src/testFixtures/java/com/facebook/ktfmt/DokkaVerifier.kt similarity index 99% rename from core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt rename to core/src/testFixtures/java/com/facebook/ktfmt/DokkaVerifier.kt index 4b102c79..70848c70 100644 --- a/core/src/test/java/com/facebook/ktfmt/kdoc/DokkaVerifier.kt +++ b/core/src/testFixtures/java/com/facebook/ktfmt/DokkaVerifier.kt @@ -16,7 +16,7 @@ @file:Suppress("PropertyName", "PrivatePropertyName") -package com.facebook.ktfmt.kdoc +package com.facebook.ktfmt import com.google.common.truth.Truth.assertThat import java.io.BufferedReader diff --git a/core/src/testFixtures/java/com/facebook/ktfmt/FormatterTestDirectives.kt b/core/src/testFixtures/java/com/facebook/ktfmt/FormatterTestDirectives.kt new file mode 100644 index 00000000..68340a32 --- /dev/null +++ b/core/src/testFixtures/java/com/facebook/ktfmt/FormatterTestDirectives.kt @@ -0,0 +1,20 @@ +package com.facebook.ktfmt + +data class FormatterTestOptions( + val allowTrailingWhitespace: Boolean = false +) + +class FormatterTestDirectives : DirectiveContainer { + override val result get() = FormatterTestOptions(allowTrailingWhitespace = allowTrailingWhitespace) + + var allowTrailingWhitespace: Boolean = false + + override val directives = listOf( + FormatterTestOptionsDirective("ALLOW_TRAILING_WHITESPACE") { allowTrailingWhitespace = true }, + ) + + data class FormatterTestOptionsDirective( + override val name: String, + override val callback: (String) -> Unit, + ) : Directive +} diff --git a/core/src/testFixtures/java/com/facebook/ktfmt/FormatterTestFixture.kt b/core/src/testFixtures/java/com/facebook/ktfmt/FormatterTestFixture.kt new file mode 100644 index 00000000..e3654e3b --- /dev/null +++ b/core/src/testFixtures/java/com/facebook/ktfmt/FormatterTestFixture.kt @@ -0,0 +1,131 @@ +package com.facebook.ktfmt + +import com.facebook.ktfmt.debughelpers.PrintAstVisitor +import com.facebook.ktfmt.format.Formatter +import com.facebook.ktfmt.format.FormattingOptions +import com.facebook.ktfmt.format.Parser +import com.google.common.truth.FailureMetadata +import com.google.common.truth.Subject +import com.google.common.truth.Truth +import java.nio.file.Path +import java.nio.file.Paths +import kotlin.io.path.exists +import kotlin.io.path.extension +import kotlin.io.path.nameWithoutExtension +import kotlin.io.path.readText +import kotlin.io.path.writeText +import org.intellij.lang.annotations.Language +import org.junit.Assert + +fun runFormatterTest(path: String, body: FormatterTestFixture.() -> Unit = {}) { + val fixture = FormatterTestFixture(path) + fixture.body() + fixture.runTest() +} + +class FormatterTestFixture( + val sourcePath: String, +) { + val formattingOptionsDirectives = FormattingOptionsDirectives() + val formatterTestOptions = FormatterTestDirectives() + + fun runTest() { + val sourceFile = TEST_DATA_PATH.resolve(sourcePath) + val expectedFile = sourceFile.expectedFile + + var sourceCode = sourceFile.readText() + sourceCode = formatterTestOptions.processDirectives(sourceCode).trim() + sourceCode = formattingOptionsDirectives.processDirectives(sourceCode).trim() + + if (!expectedFile.exists()) { + val formattedCode = formatCode(sourceCode, formattingOptionsDirectives.result) + expectedFile.writeText(formattedCode) + error("Expected file $expectedFile does not exist, created code:\n$formattedCode") + } + + val expectedCode = expectedFile.readText() + assertThatFormatting(sourceCode).isEqualTo(expectedCode) + } + + fun formatCode(code: String, options: FormattingOptions): String = Formatter.format(options, code) + + fun assertThatFormatting(@Language("kts") code: String): FormattedCodeSubject { + fun codes(): Subject.Factory { + return Subject.Factory { metadata, subject -> + FormattedCodeSubject( + metadata, + code = checkNotNull(subject), + testOptions = formatterTestOptions.result, + formattingOptions = formattingOptionsDirectives.result, + ) + } + } + return Truth.assertAbout(codes()).that(code) + } + + class FormattedCodeSubject( + metadata: FailureMetadata, + private val code: String, + private val testOptions: FormatterTestOptions, + private val formattingOptions: FormattingOptions, + ) : Subject(metadata, code) { + + fun isEqualTo(@Language("kts") expectedFormatting: String) { + if (!testOptions.allowTrailingWhitespace && expectedFormatting.lines().any { it.endsWith(" ") }) { + throw RuntimeException( + "Expected code contains trailing whitespace, which the formatter usually doesn't output:\n" + + expectedFormatting + .lines() + .map { if (it.endsWith(" ")) "[$it]" else it } + .joinToString("\n"), + ) + } + val actualFormatting: String + try { + actualFormatting = Formatter.format(formattingOptions, code) + if (actualFormatting != expectedFormatting) { + reportError(code) + println("# Output: ") + println("#".repeat(20)) + println(actualFormatting) + println("# Expected: ") + println("#".repeat(20)) + println(expectedFormatting) + println("#".repeat(20)) + println( + "Need more information about the break operations? " + + "Run test with assertion with \"FormattingOptions(debuggingPrintOpsAfterFormatting = true)\"", + ) + } + } catch (e: Error) { + reportError(code) + throw e + } + Assert.assertEquals(expectedFormatting, actualFormatting) + } + + private fun reportError(code: String) { + val file = Parser.parse(code) + println("# Parse tree of input: ") + println("#".repeat(20)) + file.accept(PrintAstVisitor()) + println() + println("# Input: ") + println("#".repeat(20)) + println(code) + println() + } + } + + companion object { + val TEST_DATA_PATH = Paths.get("testData") + + val Path.expectedFile: Path + get() { + val fileName = this.fileName + val name = fileName.nameWithoutExtension + val extension = fileName.extension + return resolveSibling("$name.expected.$extension") + } + } +} diff --git a/core/src/testFixtures/java/com/facebook/ktfmt/FormattingOptionsDirectives.kt b/core/src/testFixtures/java/com/facebook/ktfmt/FormattingOptionsDirectives.kt new file mode 100644 index 00000000..78633d3c --- /dev/null +++ b/core/src/testFixtures/java/com/facebook/ktfmt/FormattingOptionsDirectives.kt @@ -0,0 +1,40 @@ +package com.facebook.ktfmt + +import com.facebook.ktfmt.format.Formatter +import com.facebook.ktfmt.format.FormattingOptions +import com.facebook.ktfmt.format.TrailingCommaManagementStrategy + +class FormattingOptionsDirectives( + default: FormattingOptions = Formatter.META_FORMAT, +) : DirectiveContainer { + private val builder = default.toBuilder() + + override val result: FormattingOptions + get() = builder.build() + + override val directives = + listOf( + FormattingOptionDirective("MAX_WIDTH") { builder.maxWidth(it.toInt()) }, + FormattingOptionDirective("BLOCK_INDENT") { builder.blockIndent(it.toInt()) }, + FormattingOptionDirective("CONTINUATION_INDENT") { + builder.continuationIndent(it.toInt()) + }, + FormattingOptionDirective("TRAILING_COMMA_STRATEGY") { + builder.trailingCommaManagementStrategy(TrailingCommaManagementStrategy.valueOf(it)) + }, + FormattingOptionDirective("REMOVE_UNUSED_IMPORTS") { + builder.removeUnusedImports(it.toBooleanStrict()) + }, + FormattingOptionDirective("PRESERVE_LAMBDA_BREAKS") { + builder.preserveLambdaBreaks(it.toBooleanStrict()) + }, + FormattingOptionDirective("PRINT_OPTS_AFTER_FORMATTING") { + builder.debuggingPrintOpsAfterFormatting(it.toBooleanStrict()) + }, + ) + + data class FormattingOptionDirective( + override val name: String, + override val callback: (String) -> Unit, + ) : Directive +} diff --git a/core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt b/core/src/testFixtures/java/com/facebook/ktfmt/KtfmtTruth.kt similarity index 99% rename from core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt rename to core/src/testFixtures/java/com/facebook/ktfmt/KtfmtTruth.kt index f9d0655a..14142f15 100644 --- a/core/src/test/java/com/facebook/ktfmt/testutil/KtfmtTruth.kt +++ b/core/src/testFixtures/java/com/facebook/ktfmt/KtfmtTruth.kt @@ -14,7 +14,7 @@ * limitations under the License. */ -package com.facebook.ktfmt.testutil +package com.facebook.ktfmt import com.facebook.ktfmt.debughelpers.PrintAstVisitor import com.facebook.ktfmt.format.Formatter diff --git a/core/src/testFixtures/java/com/facebook/ktfmt/testData.kt b/core/src/testFixtures/java/com/facebook/ktfmt/testData.kt new file mode 100644 index 00000000..a4718dc9 --- /dev/null +++ b/core/src/testFixtures/java/com/facebook/ktfmt/testData.kt @@ -0,0 +1,5 @@ +package com.facebook.ktfmt + +import java.nio.file.Paths + +val TEST_DATA_ROOT = Paths.get("testData") \ No newline at end of file diff --git a/core/testData/format/meta/annotation/annotationInFunctionTypes.expected.kt b/core/testData/format/meta/annotation/annotationInFunctionTypes.expected.kt new file mode 100644 index 00000000..f7cebf7f --- /dev/null +++ b/core/testData/format/meta/annotation/annotationInFunctionTypes.expected.kt @@ -0,0 +1 @@ +val callback: (@Anno List<@JvmSuppressWildcards String>) -> Unit = foo diff --git a/core/testData/format/meta/annotation/annotationInFunctionTypes.kt b/core/testData/format/meta/annotation/annotationInFunctionTypes.kt new file mode 100644 index 00000000..f7cebf7f --- /dev/null +++ b/core/testData/format/meta/annotation/annotationInFunctionTypes.kt @@ -0,0 +1 @@ +val callback: (@Anno List<@JvmSuppressWildcards String>) -> Unit = foo diff --git a/core/testData/format/meta/annotation/annotationOnProperty.expected.kt b/core/testData/format/meta/annotation/annotationOnProperty.expected.kt new file mode 100644 index 00000000..15f73309 --- /dev/null +++ b/core/testData/format/meta/annotation/annotationOnProperty.expected.kt @@ -0,0 +1,3 @@ +@Suppress("UnsafeCast") +val ClassA.methodA + get() = foo as Bar diff --git a/core/testData/format/meta/annotation/annotationOnProperty.kt b/core/testData/format/meta/annotation/annotationOnProperty.kt new file mode 100644 index 00000000..378af220 --- /dev/null +++ b/core/testData/format/meta/annotation/annotationOnProperty.kt @@ -0,0 +1,5 @@ +// MAX_WIDTH 44 + +@Suppress("UnsafeCast") +val ClassA.methodA + get() = foo as Bar diff --git a/core/testData/format/meta/annotation/annotationWithParams.expected.kt b/core/testData/format/meta/annotation/annotationWithParams.expected.kt new file mode 100644 index 00000000..8a6e20bc --- /dev/null +++ b/core/testData/format/meta/annotation/annotationWithParams.expected.kt @@ -0,0 +1 @@ +@AnnWithArrayValue(1, 2, 3) class C diff --git a/core/testData/format/meta/annotation/annotationWithParams.kt b/core/testData/format/meta/annotation/annotationWithParams.kt new file mode 100644 index 00000000..8a6e20bc --- /dev/null +++ b/core/testData/format/meta/annotation/annotationWithParams.kt @@ -0,0 +1 @@ +@AnnWithArrayValue(1, 2, 3) class C diff --git a/core/testData/format/meta/annotation/annotationsInDesctucturingDeclaration.expected.kt b/core/testData/format/meta/annotation/annotationsInDesctucturingDeclaration.expected.kt new file mode 100644 index 00000000..173efb02 --- /dev/null +++ b/core/testData/format/meta/annotation/annotationsInDesctucturingDeclaration.expected.kt @@ -0,0 +1 @@ +val x = { (@Anno x, @Anno y) -> x } diff --git a/core/testData/format/meta/annotation/annotationsInDesctucturingDeclaration.kt b/core/testData/format/meta/annotation/annotationsInDesctucturingDeclaration.kt new file mode 100644 index 00000000..173efb02 --- /dev/null +++ b/core/testData/format/meta/annotation/annotationsInDesctucturingDeclaration.kt @@ -0,0 +1 @@ +val x = { (@Anno x, @Anno y) -> x } diff --git a/core/testData/format/meta/annotation/annotationsOnTypeConstraints.expected.kt b/core/testData/format/meta/annotation/annotationsOnTypeConstraints.expected.kt new file mode 100644 index 00000000..cc37c12c --- /dev/null +++ b/core/testData/format/meta/annotation/annotationsOnTypeConstraints.expected.kt @@ -0,0 +1,3 @@ +class Foo where U : @Anno Kip, U : @Anno Qux { + fun bar() where U : @Anno Kip, U : @Anno Qux {} +} diff --git a/core/testData/format/meta/annotation/annotationsOnTypeConstraints.kt b/core/testData/format/meta/annotation/annotationsOnTypeConstraints.kt new file mode 100644 index 00000000..cc37c12c --- /dev/null +++ b/core/testData/format/meta/annotation/annotationsOnTypeConstraints.kt @@ -0,0 +1,3 @@ +class Foo where U : @Anno Kip, U : @Anno Qux { + fun bar() where U : @Anno Kip, U : @Anno Qux {} +} diff --git a/core/testData/format/meta/annotation/annotationsOnTypeParameters.expected.kt b/core/testData/format/meta/annotation/annotationsOnTypeParameters.expected.kt new file mode 100644 index 00000000..108509e9 --- /dev/null +++ b/core/testData/format/meta/annotation/annotationsOnTypeParameters.expected.kt @@ -0,0 +1,3 @@ +class Foo<@Anno out @Anno T, @Anno in @Anno U> { + inline fun <@Anno reified @Anno X, @Anno reified @Anno Y> bar() {} +} diff --git a/core/testData/format/meta/annotation/annotationsOnTypeParameters.kt b/core/testData/format/meta/annotation/annotationsOnTypeParameters.kt new file mode 100644 index 00000000..108509e9 --- /dev/null +++ b/core/testData/format/meta/annotation/annotationsOnTypeParameters.kt @@ -0,0 +1,3 @@ +class Foo<@Anno out @Anno T, @Anno in @Anno U> { + inline fun <@Anno reified @Anno X, @Anno reified @Anno Y> bar() {} +} diff --git a/core/testData/format/meta/annotation/annotationsOnTypeParameters2.expected.kt b/core/testData/format/meta/annotation/annotationsOnTypeParameters2.expected.kt new file mode 100644 index 00000000..eb80cb6e --- /dev/null +++ b/core/testData/format/meta/annotation/annotationsOnTypeParameters2.expected.kt @@ -0,0 +1 @@ +fun foo(x: Foo) {} diff --git a/core/testData/format/meta/annotation/annotationsOnTypeParameters2.kt b/core/testData/format/meta/annotation/annotationsOnTypeParameters2.kt new file mode 100644 index 00000000..eb80cb6e --- /dev/null +++ b/core/testData/format/meta/annotation/annotationsOnTypeParameters2.kt @@ -0,0 +1 @@ +fun foo(x: Foo) {} diff --git a/core/testData/format/meta/annotation/annotationsWithParams2.expected.kt b/core/testData/format/meta/annotation/annotationsWithParams2.expected.kt new file mode 100644 index 00000000..badd77c0 --- /dev/null +++ b/core/testData/format/meta/annotation/annotationsWithParams2.expected.kt @@ -0,0 +1,9 @@ +@Px fun f(): Int = 5 + +@Dimenstion(unit = DP) fun g(): Int = 5 + +@RunWith(MagicRunner::class) +@Px +class Test { + // +} diff --git a/core/testData/format/meta/annotation/annotationsWithParams2.kt b/core/testData/format/meta/annotation/annotationsWithParams2.kt new file mode 100644 index 00000000..badd77c0 --- /dev/null +++ b/core/testData/format/meta/annotation/annotationsWithParams2.kt @@ -0,0 +1,9 @@ +@Px fun f(): Int = 5 + +@Dimenstion(unit = DP) fun g(): Int = 5 + +@RunWith(MagicRunner::class) +@Px +class Test { + // +} diff --git a/core/testData/format/meta/annotation/basic.expected.kt b/core/testData/format/meta/annotation/basic.expected.kt new file mode 100644 index 00000000..5e94be4e --- /dev/null +++ b/core/testData/format/meta/annotation/basic.expected.kt @@ -0,0 +1,7 @@ +@Fancy +class Foo { + @Fancy + fun baz(@Fancy foo: Int) { + @Fancy val a = 1 + foo + } +} diff --git a/core/testData/format/meta/annotation/basic.kt b/core/testData/format/meta/annotation/basic.kt new file mode 100644 index 00000000..5e94be4e --- /dev/null +++ b/core/testData/format/meta/annotation/basic.kt @@ -0,0 +1,7 @@ +@Fancy +class Foo { + @Fancy + fun baz(@Fancy foo: Int) { + @Fancy val a = 1 + foo + } +} diff --git a/core/testData/format/meta/annotation/exception.expected.kt b/core/testData/format/meta/annotation/exception.expected.kt new file mode 100644 index 00000000..56414a81 --- /dev/null +++ b/core/testData/format/meta/annotation/exception.expected.kt @@ -0,0 +1,7 @@ +fun doIt() { + try { + doItAgain() + } catch (@Nullable e: Exception) { + // + } catch (@Suppress("GeneralException") e: Exception) {} +} diff --git a/core/testData/format/meta/annotation/exception.kt b/core/testData/format/meta/annotation/exception.kt new file mode 100644 index 00000000..56414a81 --- /dev/null +++ b/core/testData/format/meta/annotation/exception.kt @@ -0,0 +1,7 @@ +fun doIt() { + try { + doItAgain() + } catch (@Nullable e: Exception) { + // + } catch (@Suppress("GeneralException") e: Exception) {} +} diff --git a/core/testData/format/meta/annotation/longUnbreakableAnnotations.expected.kt b/core/testData/format/meta/annotation/longUnbreakableAnnotations.expected.kt new file mode 100644 index 00000000..2e6896d0 --- /dev/null +++ b/core/testData/format/meta/annotation/longUnbreakableAnnotations.expected.kt @@ -0,0 +1,5 @@ +object Foo { + @LongLongLongLongAnnotation + @LongLongLongLongLongAnnotation + private val ROW_HEIGHT = 72 +} diff --git a/core/testData/format/meta/annotation/longUnbreakableAnnotations.kt b/core/testData/format/meta/annotation/longUnbreakableAnnotations.kt new file mode 100644 index 00000000..d3344355 --- /dev/null +++ b/core/testData/format/meta/annotation/longUnbreakableAnnotations.kt @@ -0,0 +1,7 @@ +// MAX_WIDTH 60 + +object Foo { + @LongLongLongLongAnnotation + @LongLongLongLongLongAnnotation + private val ROW_HEIGHT = 72 +} diff --git a/core/testData/format/meta/annotation/noNewLineAfterAnnotations.expected.kt b/core/testData/format/meta/annotation/noNewLineAfterAnnotations.expected.kt new file mode 100644 index 00000000..71328a1e --- /dev/null +++ b/core/testData/format/meta/annotation/noNewLineAfterAnnotations.expected.kt @@ -0,0 +1,50 @@ +@Px @Px fun f(): Int = 5 + +@Px +@Px +@Px +@Px +@Px +@Px +@Px +@Px +fun f(): Int = 5 + +@Px +@Px +fun f(): Int { + return 5 +} + +@Dimenstion(unit = DP) @Px fun g(): Int = 5 + +@Dimenstion(unit = DP) +@Px +fun g(): Int { + return 5 +} + +@RunWith @Px class Test + +@RunWith(MagicRunner::class) @Px class Test + +@RunWith @Px class Test {} + +@RunWith(MagicRunner::class) @Px class Test {} + +@RunWith(MagicRunner::class) +@Px +@Px +class Test {} + +@RunWith(MagicRunner::class) +@Px +class Test { + // +} + +fun f() { + if (@Stuff(Magic::class) isGood()) { + println("") + } +} diff --git a/core/testData/format/meta/annotation/noNewLineAfterAnnotations.kt b/core/testData/format/meta/annotation/noNewLineAfterAnnotations.kt new file mode 100644 index 00000000..8bffb14f --- /dev/null +++ b/core/testData/format/meta/annotation/noNewLineAfterAnnotations.kt @@ -0,0 +1,52 @@ +// MAX_WIDTH 47 + +@Px @Px fun f(): Int = 5 + +@Px +@Px +@Px +@Px +@Px +@Px +@Px +@Px +fun f(): Int = 5 + +@Px +@Px +fun f(): Int { + return 5 +} + +@Dimenstion(unit = DP) @Px fun g(): Int = 5 + +@Dimenstion(unit = DP) +@Px +fun g(): Int { + return 5 +} + +@RunWith @Px class Test + +@RunWith(MagicRunner::class) @Px class Test + +@RunWith @Px class Test {} + +@RunWith(MagicRunner::class) @Px class Test {} + +@RunWith(MagicRunner::class) +@Px +@Px +class Test {} + +@RunWith(MagicRunner::class) +@Px +class Test { + // +} + +fun f() { + if (@Stuff(Magic::class) isGood()) { + println("") + } +} diff --git a/core/testData/format/meta/annotation/return.expected.kt b/core/testData/format/meta/annotation/return.expected.kt new file mode 100644 index 00000000..87fc90fc --- /dev/null +++ b/core/testData/format/meta/annotation/return.expected.kt @@ -0,0 +1,4 @@ +fun foo(): Map { + @Suppress("AsCollectionCall") + return map.asMap() +} diff --git a/core/testData/format/meta/annotation/return.kt b/core/testData/format/meta/annotation/return.kt new file mode 100644 index 00000000..87fc90fc --- /dev/null +++ b/core/testData/format/meta/annotation/return.kt @@ -0,0 +1,4 @@ +fun foo(): Map { + @Suppress("AsCollectionCall") + return map.asMap() +} diff --git a/core/testData/format/meta/binary/associativity.expected.kt b/core/testData/format/meta/binary/associativity.expected.kt new file mode 100644 index 00000000..0eabd42e --- /dev/null +++ b/core/testData/format/meta/binary/associativity.expected.kt @@ -0,0 +1,4 @@ +fun foo() { + return expression1 != expression2 || + expression2 != expression1 +} diff --git a/core/testData/format/meta/binary/associativity.kt b/core/testData/format/meta/binary/associativity.kt new file mode 100644 index 00000000..c60beb04 --- /dev/null +++ b/core/testData/format/meta/binary/associativity.kt @@ -0,0 +1,6 @@ +// MAX_WIDTH 39 + +fun foo() { + return expression1 != expression2 || + expression2 != expression1 +} diff --git a/core/testData/format/meta/binary/binaryExpressionSplit.expected.kt b/core/testData/format/meta/binary/binaryExpressionSplit.expected.kt new file mode 100644 index 00000000..58e4e3be --- /dev/null +++ b/core/testData/format/meta/binary/binaryExpressionSplit.expected.kt @@ -0,0 +1,11 @@ +fun foo() { + val sentence = + "The" + + "quick" + + ("brown" + "fox") + + "jumps" + + "over" + + "the" + + "lazy" + + "dog" +} diff --git a/core/testData/format/meta/binary/binaryExpressionSplit.kt b/core/testData/format/meta/binary/binaryExpressionSplit.kt new file mode 100644 index 00000000..fc3c2b59 --- /dev/null +++ b/core/testData/format/meta/binary/binaryExpressionSplit.kt @@ -0,0 +1,13 @@ +// MAX_WIDTH 40 + +fun foo() { + val sentence = + "The" + + "quick" + + ("brown" + "fox") + + "jumps" + + "over" + + "the" + + "lazy" + + "dog" +} diff --git a/core/testData/format/meta/binary/binaryExpressionWithRanges.expected.kt b/core/testData/format/meta/binary/binaryExpressionWithRanges.expected.kt new file mode 100644 index 00000000..2dc5add2 --- /dev/null +++ b/core/testData/format/meta/binary/binaryExpressionWithRanges.expected.kt @@ -0,0 +1,10 @@ +fun foo() { + val sentence = + "The" + + "quick" + + ("brown".."fox") + + ("brown"..<"fox") + + "jumps" + + "over" + + "the".."lazy" + "dog" +} diff --git a/core/testData/format/meta/binary/binaryExpressionWithRanges.kt b/core/testData/format/meta/binary/binaryExpressionWithRanges.kt new file mode 100644 index 00000000..7fa8fd42 --- /dev/null +++ b/core/testData/format/meta/binary/binaryExpressionWithRanges.kt @@ -0,0 +1,12 @@ +// MAX_WIDTH 40 + +fun foo() { + val sentence = + "The" + + "quick" + + ("brown".."fox") + + ("brown"..<"fox") + + "jumps" + + "over" + + "the".."lazy" + "dog" +} diff --git a/core/testData/format/meta/binary/binaryOperations.expected.kt b/core/testData/format/meta/binary/binaryOperations.expected.kt new file mode 100644 index 00000000..bca032ad --- /dev/null +++ b/core/testData/format/meta/binary/binaryOperations.expected.kt @@ -0,0 +1,4 @@ +fun foo() { + a = 5 + x + 1 +} diff --git a/core/testData/format/meta/binary/binaryOperations.kt b/core/testData/format/meta/binary/binaryOperations.kt new file mode 100644 index 00000000..bca032ad --- /dev/null +++ b/core/testData/format/meta/binary/binaryOperations.kt @@ -0,0 +1,4 @@ +fun foo() { + a = 5 + x + 1 +} diff --git a/core/testData/format/meta/binary/commentBeforeBinaryOperator.expected.kt b/core/testData/format/meta/binary/commentBeforeBinaryOperator.expected.kt new file mode 100644 index 00000000..657d1d5a --- /dev/null +++ b/core/testData/format/meta/binary/commentBeforeBinaryOperator.expected.kt @@ -0,0 +1,7 @@ +fun foo() { + val result = + firstCond && + secondCond + // comment about thirdCond. + && thirdCond +} diff --git a/core/testData/format/meta/binary/commentBeforeBinaryOperator.kt b/core/testData/format/meta/binary/commentBeforeBinaryOperator.kt new file mode 100644 index 00000000..0dcf936f --- /dev/null +++ b/core/testData/format/meta/binary/commentBeforeBinaryOperator.kt @@ -0,0 +1,9 @@ +// MAX_WIDTH 50 + +fun foo() { + val result = + firstCond && + secondCond + // comment about thirdCond. + && thirdCond +} diff --git a/core/testData/format/meta/binary/inlineCommentBeforeOperator.expected.kt b/core/testData/format/meta/binary/inlineCommentBeforeOperator.expected.kt new file mode 100644 index 00000000..3c527268 --- /dev/null +++ b/core/testData/format/meta/binary/inlineCommentBeforeOperator.expected.kt @@ -0,0 +1,6 @@ +fun foo() { + val result = + firstCondition || + secondCondition /*tag*/ || + thirdCondition +} diff --git a/core/testData/format/meta/binary/inlineCommentBeforeOperator.kt b/core/testData/format/meta/binary/inlineCommentBeforeOperator.kt new file mode 100644 index 00000000..5851f24b --- /dev/null +++ b/core/testData/format/meta/binary/inlineCommentBeforeOperator.kt @@ -0,0 +1,8 @@ +// MAX_WIDTH 55 + +fun foo() { + val result = + firstCondition || + secondCondition /*tag*/ || + thirdCondition +} diff --git a/core/testData/format/meta/binary/lineCommentBeforeOperator.expected.kt b/core/testData/format/meta/binary/lineCommentBeforeOperator.expected.kt new file mode 100644 index 00000000..4f6ecf54 --- /dev/null +++ b/core/testData/format/meta/binary/lineCommentBeforeOperator.expected.kt @@ -0,0 +1,7 @@ +fun foo() { + val result = + firstCond || + secondCond + // comment about thirdCond. + || thirdCond +} diff --git a/core/testData/format/meta/binary/lineCommentBeforeOperator.kt b/core/testData/format/meta/binary/lineCommentBeforeOperator.kt new file mode 100644 index 00000000..57ac34b5 --- /dev/null +++ b/core/testData/format/meta/binary/lineCommentBeforeOperator.kt @@ -0,0 +1,9 @@ +// MAX_WIDTH 50 + +fun foo() { + val result = + firstCond || + secondCond + // comment about thirdCond. + || thirdCond +} diff --git a/core/testData/format/meta/binary/longBinaryOperations.expected.kt b/core/testData/format/meta/binary/longBinaryOperations.expected.kt new file mode 100644 index 00000000..d4a5d3f1 --- /dev/null +++ b/core/testData/format/meta/binary/longBinaryOperations.expected.kt @@ -0,0 +1,14 @@ +fun foo() { + val finalWidth = + value1 + + value2 + + (value3 + + value4 + + value5) + + foo(v) + + (1 + 2) + + function( + value7, + value8) + + value9 +} diff --git a/core/testData/format/meta/binary/longBinaryOperations.kt b/core/testData/format/meta/binary/longBinaryOperations.kt new file mode 100644 index 00000000..a22e467f --- /dev/null +++ b/core/testData/format/meta/binary/longBinaryOperations.kt @@ -0,0 +1,17 @@ +// MAX_WIDTH 20 +// TRAILING_COMMA_STRATEGY NONE + +fun foo() { + val finalWidth = + value1 + + value2 + + (value3 + + value4 + + value5) + + foo(v) + + (1 + 2) + + function( + value7, + value8) + + value9 +} diff --git a/core/testData/format/meta/binary/multiCharacterBinaryOperators.expected.kt b/core/testData/format/meta/binary/multiCharacterBinaryOperators.expected.kt new file mode 100644 index 00000000..4b47bf1b --- /dev/null +++ b/core/testData/format/meta/binary/multiCharacterBinaryOperators.expected.kt @@ -0,0 +1,6 @@ +fun f() { + 3 == 4 + true && false + a++ + a === b +} diff --git a/core/testData/format/meta/binary/multiCharacterBinaryOperators.kt b/core/testData/format/meta/binary/multiCharacterBinaryOperators.kt new file mode 100644 index 00000000..4b47bf1b --- /dev/null +++ b/core/testData/format/meta/binary/multiCharacterBinaryOperators.kt @@ -0,0 +1,6 @@ +fun f() { + 3 == 4 + true && false + a++ + a === b +} diff --git a/core/testData/format/meta/binary/multiOperandChain.expected.kt b/core/testData/format/meta/binary/multiOperandChain.expected.kt new file mode 100644 index 00000000..dc0d64a4 --- /dev/null +++ b/core/testData/format/meta/binary/multiOperandChain.expected.kt @@ -0,0 +1,8 @@ +fun foo() { + val result = + firstCond && + secondCond + // comment about thirdCond. + && thirdCond && + fourthCond +} diff --git a/core/testData/format/meta/binary/multiOperandChain.kt b/core/testData/format/meta/binary/multiOperandChain.kt new file mode 100644 index 00000000..e997a428 --- /dev/null +++ b/core/testData/format/meta/binary/multiOperandChain.kt @@ -0,0 +1,10 @@ +// MAX_WIDTH 50 + +fun foo() { + val result = + firstCond && + secondCond + // comment about thirdCond. + && thirdCond && + fourthCond +} diff --git a/core/testData/format/meta/call/anonymousFun.expected.kt b/core/testData/format/meta/call/anonymousFun.expected.kt new file mode 100644 index 00000000..54449702 --- /dev/null +++ b/core/testData/format/meta/call/anonymousFun.expected.kt @@ -0,0 +1,6 @@ +fun f() { + setListener( + fun(number: Int) { + println(number) + }) +} diff --git a/core/testData/format/meta/call/anonymousFun.kt b/core/testData/format/meta/call/anonymousFun.kt new file mode 100644 index 00000000..108a84d8 --- /dev/null +++ b/core/testData/format/meta/call/anonymousFun.kt @@ -0,0 +1,8 @@ +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + setListener( + fun(number: Int) { + println(number) + }) +} diff --git a/core/testData/format/meta/call/anonymousFunWithReceiver.expected.kt b/core/testData/format/meta/call/anonymousFunWithReceiver.expected.kt new file mode 100644 index 00000000..4a24128e --- /dev/null +++ b/core/testData/format/meta/call/anonymousFunWithReceiver.expected.kt @@ -0,0 +1,6 @@ +fun f() { + setListener( + fun View.() { + println(this) + }) +} diff --git a/core/testData/format/meta/call/anonymousFunWithReceiver.kt b/core/testData/format/meta/call/anonymousFunWithReceiver.kt new file mode 100644 index 00000000..daea03fd --- /dev/null +++ b/core/testData/format/meta/call/anonymousFunWithReceiver.kt @@ -0,0 +1,8 @@ +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + setListener( + fun View.() { + println(this) + }) +} diff --git a/core/testData/format/meta/call/arrayAccessInTheCallChain.expected.kt b/core/testData/format/meta/call/arrayAccessInTheCallChain.expected.kt new file mode 100644 index 00000000..3055f364 --- /dev/null +++ b/core/testData/format/meta/call/arrayAccessInTheCallChain.expected.kt @@ -0,0 +1,8 @@ +fun f() { + if (aaaaa == null || + aaaaa.bbbbb[0] == null || + aaaaa.bbbbb[0].cc == null || + aaaaa.bbbbb[0].dddd == null) { + println() + } +} diff --git a/core/testData/format/meta/call/arrayAccessInTheCallChain.kt b/core/testData/format/meta/call/arrayAccessInTheCallChain.kt new file mode 100644 index 00000000..b2f0378b --- /dev/null +++ b/core/testData/format/meta/call/arrayAccessInTheCallChain.kt @@ -0,0 +1,11 @@ +// MAX_WIDTH 40 +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + if (aaaaa == null || + aaaaa.bbbbb[0] == null || + aaaaa.bbbbb[0].cc == null || + aaaaa.bbbbb[0].dddd == null) { + println() + } +} diff --git a/core/testData/format/meta/call/blockArgs.expected.kt b/core/testData/format/meta/call/blockArgs.expected.kt new file mode 100644 index 00000000..5cd1a61a --- /dev/null +++ b/core/testData/format/meta/call/blockArgs.expected.kt @@ -0,0 +1,19 @@ +override fun visitProperty(property: KtProperty) { + builder.sync(property) + builder.block(ZERO) { + declareOne( + kind = DeclarationKind.FIELD, + modifiers = property.modifierList, + valOrVarKeyword = + property.valOrVarKeyword.text, + typeParameters = + property.typeParameterList, + receiver = property.receiverTypeReference, + name = property.nameIdentifier?.text, + type = property.typeReference, + typeConstraintList = + property.typeConstraintList, + delegate = property.delegate, + initializer = property.initializer) + } +} diff --git a/core/testData/format/meta/call/blockArgs.kt b/core/testData/format/meta/call/blockArgs.kt new file mode 100644 index 00000000..5f94f3ae --- /dev/null +++ b/core/testData/format/meta/call/blockArgs.kt @@ -0,0 +1,22 @@ +// MAX_WIDTH 50 +// TRAILING_COMMA_STRATEGY NONE + +override fun visitProperty(property: KtProperty) { + builder.sync(property) + builder.block(ZERO) { + declareOne( + kind = DeclarationKind.FIELD, + modifiers = property.modifierList, + valOrVarKeyword = + property.valOrVarKeyword.text, + typeParameters = + property.typeParameterList, + receiver = property.receiverTypeReference, + name = property.nameIdentifier?.text, + type = property.typeReference, + typeConstraintList = + property.typeConstraintList, + delegate = property.delegate, + initializer = property.initializer) + } +} diff --git a/core/testData/format/meta/call/bracketsAreNotBreaking.expected.kt b/core/testData/format/meta/call/bracketsAreNotBreaking.expected.kt new file mode 100644 index 00000000..73c36499 --- /dev/null +++ b/core/testData/format/meta/call/bracketsAreNotBreaking.expected.kt @@ -0,0 +1,9 @@ +fun f() { + val a = + invokeIt(context.packageName) + .getInternalMutablePackageInfo(context.packageName) + .someItems[0] + .getInternalMutablePackageInfo(context.packageName) + .someItems[0] + .doIt() +} diff --git a/core/testData/format/meta/call/bracketsAreNotBreaking.kt b/core/testData/format/meta/call/bracketsAreNotBreaking.kt new file mode 100644 index 00000000..4217ee29 --- /dev/null +++ b/core/testData/format/meta/call/bracketsAreNotBreaking.kt @@ -0,0 +1,11 @@ +// MAX_WIDTH 74 + +fun f() { + val a = + invokeIt(context.packageName) + .getInternalMutablePackageInfo(context.packageName) + .someItems[0] + .getInternalMutablePackageInfo(context.packageName) + .someItems[0] + .doIt() +} diff --git a/core/testData/format/meta/call/breakBeforeLambda.expected.kt b/core/testData/format/meta/call/breakBeforeLambda.expected.kt new file mode 100644 index 00000000..3f269495 --- /dev/null +++ b/core/testData/format/meta/call/breakBeforeLambda.expected.kt @@ -0,0 +1,8 @@ +fun f() { + four + .let { + // + foo() + } + .methodCall() +} diff --git a/core/testData/format/meta/call/breakBeforeLambda.kt b/core/testData/format/meta/call/breakBeforeLambda.kt new file mode 100644 index 00000000..3f269495 --- /dev/null +++ b/core/testData/format/meta/call/breakBeforeLambda.kt @@ -0,0 +1,8 @@ +fun f() { + four + .let { + // + foo() + } + .methodCall() +} diff --git a/core/testData/format/meta/call/callArgsStickToFunctionName.expected.kt b/core/testData/format/meta/call/callArgsStickToFunctionName.expected.kt new file mode 100644 index 00000000..7a074611 --- /dev/null +++ b/core/testData/format/meta/call/callArgsStickToFunctionName.expected.kt @@ -0,0 +1,8 @@ +class f { + private val somePropertyWithBackingOne + get() = + _somePropertyWithBackingOne + ?: Classname.getStuff(requireContext())[ + somePropertiesProvider, somePropertyCallbacks] + .also { _somePropertyWithBackingOne = it } +} diff --git a/core/testData/format/meta/call/callArgsStickToFunctionName.kt b/core/testData/format/meta/call/callArgsStickToFunctionName.kt new file mode 100644 index 00000000..4208a2ed --- /dev/null +++ b/core/testData/format/meta/call/callArgsStickToFunctionName.kt @@ -0,0 +1,10 @@ +// TRAILING_COMMA_STRATEGY NONE + +class f { + private val somePropertyWithBackingOne + get() = + _somePropertyWithBackingOne + ?: Classname.getStuff(requireContext())[ + somePropertiesProvider, somePropertyCallbacks] + .also { _somePropertyWithBackingOne = it } +} diff --git a/core/testData/format/meta/call/callChain.expected.kt b/core/testData/format/meta/call/callChain.expected.kt new file mode 100644 index 00000000..5ace5603 --- /dev/null +++ b/core/testData/format/meta/call/callChain.expected.kt @@ -0,0 +1,30 @@ +fun f() { + // Static method calls are attached to the class name. + ImmutableList.newBuilder() + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .build() + + // Multiple call expressions --> each on its own line. + ImmutableList() + .newBuilder() + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .build() +} diff --git a/core/testData/format/meta/call/callChain.kt b/core/testData/format/meta/call/callChain.kt new file mode 100644 index 00000000..5ace5603 --- /dev/null +++ b/core/testData/format/meta/call/callChain.kt @@ -0,0 +1,30 @@ +fun f() { + // Static method calls are attached to the class name. + ImmutableList.newBuilder() + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .build() + + // Multiple call expressions --> each on its own line. + ImmutableList() + .newBuilder() + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .add(1) + .build() +} diff --git a/core/testData/format/meta/call/callChainOnTheSameLineBeforeLambda.expected.kt b/core/testData/format/meta/call/callChainOnTheSameLineBeforeLambda.expected.kt new file mode 100644 index 00000000..b07bb701 --- /dev/null +++ b/core/testData/format/meta/call/callChainOnTheSameLineBeforeLambda.expected.kt @@ -0,0 +1,16 @@ +fun f() { + foo.bar.bar?.let { + a() + } + foo.bar.bar?.let { + action() + action2() + } + foo.bar.bar.bar.bar + ?.let { a() } + foo.bar.bar.bar.bar + ?.let { + action() + action2() + } +} diff --git a/core/testData/format/meta/call/callChainOnTheSameLineBeforeLambda.kt b/core/testData/format/meta/call/callChainOnTheSameLineBeforeLambda.kt new file mode 100644 index 00000000..87d60696 --- /dev/null +++ b/core/testData/format/meta/call/callChainOnTheSameLineBeforeLambda.kt @@ -0,0 +1,18 @@ +// MAX_WIDTH 25 + +fun f() { + foo.bar.bar?.let { + a() + } + foo.bar.bar?.let { + action() + action2() + } + foo.bar.bar.bar.bar + ?.let { a() } + foo.bar.bar.bar.bar + ?.let { + action() + action2() + } +} diff --git a/core/testData/format/meta/call/callWithOnlyLambdaArg.expected.kt b/core/testData/format/meta/call/callWithOnlyLambdaArg.expected.kt new file mode 100644 index 00000000..dc096c9f --- /dev/null +++ b/core/testData/format/meta/call/callWithOnlyLambdaArg.expected.kt @@ -0,0 +1,3 @@ +fun f() { + val a = g { 1 + 1 } +} diff --git a/core/testData/format/meta/call/callWithOnlyLambdaArg.kt b/core/testData/format/meta/call/callWithOnlyLambdaArg.kt new file mode 100644 index 00000000..dc096c9f --- /dev/null +++ b/core/testData/format/meta/call/callWithOnlyLambdaArg.kt @@ -0,0 +1,3 @@ +fun f() { + val a = g { 1 + 1 } +} diff --git a/core/testData/format/meta/call/callWithTrailingLambda.expected.kt b/core/testData/format/meta/call/callWithTrailingLambda.expected.kt new file mode 100644 index 00000000..1211ecb7 --- /dev/null +++ b/core/testData/format/meta/call/callWithTrailingLambda.expected.kt @@ -0,0 +1,3 @@ +fun f() { + val a = g(1, 2) { 1 + 1 } +} diff --git a/core/testData/format/meta/call/callWithTrailingLambda.kt b/core/testData/format/meta/call/callWithTrailingLambda.kt new file mode 100644 index 00000000..1211ecb7 --- /dev/null +++ b/core/testData/format/meta/call/callWithTrailingLambda.kt @@ -0,0 +1,3 @@ +fun f() { + val a = g(1, 2) { 1 + 1 } +} diff --git a/core/testData/format/meta/call/chainWithBlockAfterDereferencing.expected.kt b/core/testData/format/meta/call/chainWithBlockAfterDereferencing.expected.kt new file mode 100644 index 00000000..59eebd92 --- /dev/null +++ b/core/testData/format/meta/call/chainWithBlockAfterDereferencing.expected.kt @@ -0,0 +1,7 @@ +fun f() { + foo.bam() + .uber!![0, 1, 2] + .forEach { + println(it) + } +} diff --git a/core/testData/format/meta/call/chainWithBlockAfterDereferencing.kt b/core/testData/format/meta/call/chainWithBlockAfterDereferencing.kt new file mode 100644 index 00000000..bcf74d01 --- /dev/null +++ b/core/testData/format/meta/call/chainWithBlockAfterDereferencing.kt @@ -0,0 +1,9 @@ +// MAX_WIDTH 25 + +fun f() { + foo.bam() + .uber!![0, 1, 2] + .forEach { + println(it) + } +} diff --git a/core/testData/format/meta/call/chainWithBlockAfterDereferencing2.expected.kt b/core/testData/format/meta/call/chainWithBlockAfterDereferencing2.expected.kt new file mode 100644 index 00000000..e71a1c99 --- /dev/null +++ b/core/testData/format/meta/call/chainWithBlockAfterDereferencing2.expected.kt @@ -0,0 +1,5 @@ +fun f() { + foo.uber!![0, 1, 2].forEach { + println(it) + } +} diff --git a/core/testData/format/meta/call/chainWithBlockAfterDereferencing2.kt b/core/testData/format/meta/call/chainWithBlockAfterDereferencing2.kt new file mode 100644 index 00000000..cea22602 --- /dev/null +++ b/core/testData/format/meta/call/chainWithBlockAfterDereferencing2.kt @@ -0,0 +1,7 @@ +// MAX_WIDTH 35 + +fun f() { + foo.uber!![0, 1, 2].forEach { + println(it) + } +} diff --git a/core/testData/format/meta/call/chainWithDereferences.expected.kt b/core/testData/format/meta/call/chainWithDereferences.expected.kt new file mode 100644 index 00000000..248b7819 --- /dev/null +++ b/core/testData/format/meta/call/chainWithDereferences.expected.kt @@ -0,0 +1,9 @@ +fun f() { + foo.bam() + .uber!![0, 1, 2] + .boom()[1, 3, 5] + .lah + .doo { it } + .feep[1] + as Boo +} diff --git a/core/testData/format/meta/call/chainWithDereferences.kt b/core/testData/format/meta/call/chainWithDereferences.kt new file mode 100644 index 00000000..1da39bfa --- /dev/null +++ b/core/testData/format/meta/call/chainWithDereferences.kt @@ -0,0 +1,11 @@ +// MAX_WIDTH 25 + +fun f() { + foo.bam() + .uber!![0, 1, 2] + .boom()[1, 3, 5] + .lah + .doo { it } + .feep[1] + as Boo +} diff --git a/core/testData/format/meta/call/complexArgs.expected.kt b/core/testData/format/meta/call/complexArgs.expected.kt new file mode 100644 index 00000000..cc8ca6fa --- /dev/null +++ b/core/testData/format/meta/call/complexArgs.expected.kt @@ -0,0 +1,6 @@ +calculateMath( + r = apr.sc(10) / BigDecimal(100) / BigDecimal(12), + n = 12 * term, + numerator = ((BigDecimal.ONE + r).pow(n)) - BigDecimal.ONE, + denominator = r * (BigDecimal.ONE + r).pow(n), +) diff --git a/core/testData/format/meta/call/complexArgs.kt b/core/testData/format/meta/call/complexArgs.kt new file mode 100644 index 00000000..cc8ca6fa --- /dev/null +++ b/core/testData/format/meta/call/complexArgs.kt @@ -0,0 +1,6 @@ +calculateMath( + r = apr.sc(10) / BigDecimal(100) / BigDecimal(12), + n = 12 * term, + numerator = ((BigDecimal.ONE + r).pow(n)) - BigDecimal.ONE, + denominator = r * (BigDecimal.ONE + r).pow(n), +) diff --git a/core/testData/format/meta/call/dirrefentIndentations.expected.kt b/core/testData/format/meta/call/dirrefentIndentations.expected.kt new file mode 100644 index 00000000..0fbb760b --- /dev/null +++ b/core/testData/format/meta/call/dirrefentIndentations.expected.kt @@ -0,0 +1,9 @@ +fun f() { + fooDdoIt( + foo1, foo2, foo3) + foo.doIt( + foo1, foo2, foo3) + foo.doIt( + foo1, foo2, foo3) + .doThat() +} diff --git a/core/testData/format/meta/call/dirrefentIndentations.kt b/core/testData/format/meta/call/dirrefentIndentations.kt new file mode 100644 index 00000000..5e9e0839 --- /dev/null +++ b/core/testData/format/meta/call/dirrefentIndentations.kt @@ -0,0 +1,12 @@ +// MAX_WIDTH 27 +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + fooDdoIt( + foo1, foo2, foo3) + foo.doIt( + foo1, foo2, foo3) + foo.doIt( + foo1, foo2, foo3) + .doThat() +} diff --git a/core/testData/format/meta/call/forwardPropagationInCallExpr.expected.kt b/core/testData/format/meta/call/forwardPropagationInCallExpr.expected.kt new file mode 100644 index 00000000..bcf45777 --- /dev/null +++ b/core/testData/format/meta/call/forwardPropagationInCallExpr.expected.kt @@ -0,0 +1,13 @@ +fun test() { + foo_bar_baz__zip( + b) { + c + } +} + +fun test() { + foo.bar(baz).zip( + b) { + c + } +} diff --git a/core/testData/format/meta/call/forwardPropagationInCallExpr.kt b/core/testData/format/meta/call/forwardPropagationInCallExpr.kt new file mode 100644 index 00000000..c031bf6e --- /dev/null +++ b/core/testData/format/meta/call/forwardPropagationInCallExpr.kt @@ -0,0 +1,16 @@ +// MAX_WIDTH 23 +// TRAILING_COMMA_STRATEGY NONE + +fun test() { + foo_bar_baz__zip( + b) { + c + } +} + +fun test() { + foo.bar(baz).zip( + b) { + c + } +} diff --git a/core/testData/format/meta/call/forwardPropagationInCallExpr2.expected.kt b/core/testData/format/meta/call/forwardPropagationInCallExpr2.expected.kt new file mode 100644 index 00000000..ddcdcb99 --- /dev/null +++ b/core/testData/format/meta/call/forwardPropagationInCallExpr2.expected.kt @@ -0,0 +1,12 @@ +fun test() { + foo_bar_baz__zip< + A>( + b) { + c + } + foo.bar(baz).zip< + A>( + b) { + c + } +} diff --git a/core/testData/format/meta/call/forwardPropagationInCallExpr2.kt b/core/testData/format/meta/call/forwardPropagationInCallExpr2.kt new file mode 100644 index 00000000..bf8cc519 --- /dev/null +++ b/core/testData/format/meta/call/forwardPropagationInCallExpr2.kt @@ -0,0 +1,15 @@ +// MAX_WIDTH 20 +// TRAILING_COMMA_STRATEGY NONE + +fun test() { + foo_bar_baz__zip< + A>( + b) { + c + } + foo.bar(baz).zip< + A>( + b) { + c + } +} diff --git a/core/testData/format/meta/call/functionReference.expected.kt b/core/testData/format/meta/call/functionReference.expected.kt new file mode 100644 index 00000000..0b683052 --- /dev/null +++ b/core/testData/format/meta/call/functionReference.expected.kt @@ -0,0 +1,16 @@ +fun f(a: List) { + a.forEach(::println) + a.map(Int::toString) + a.map(String?::isNullOrEmpty) + a.map( + SuperLongClassName?:: + functionName) + val f = + SuperLongClassName:: + functionName + val g = + invoke(a, b)::functionName + val h = + invoke(a, b, c):: + functionName +} diff --git a/core/testData/format/meta/call/functionReference.kt b/core/testData/format/meta/call/functionReference.kt new file mode 100644 index 00000000..ddbf236e --- /dev/null +++ b/core/testData/format/meta/call/functionReference.kt @@ -0,0 +1,19 @@ +// MAX_WIDTH 32 +// TRAILING_COMMA_STRATEGY NONE + +fun f(a: List) { + a.forEach(::println) + a.map(Int::toString) + a.map(String?::isNullOrEmpty) + a.map( + SuperLongClassName?:: + functionName) + val f = + SuperLongClassName:: + functionName + val g = + invoke(a, b)::functionName + val h = + invoke(a, b, c):: + functionName +} diff --git a/core/testData/format/meta/call/lambdaArg.expected.kt b/core/testData/format/meta/call/lambdaArg.expected.kt new file mode 100644 index 00000000..07c3a053 --- /dev/null +++ b/core/testData/format/meta/call/lambdaArg.expected.kt @@ -0,0 +1,14 @@ +fun f() { + doIt({}) + doIt({ it + it }) + doIt({ + val a = it + a + a + }) + doIt(functor = { it + it }) + doIt( + functor = { + val a = it + a + a + }) +} diff --git a/core/testData/format/meta/call/lambdaArg.kt b/core/testData/format/meta/call/lambdaArg.kt new file mode 100644 index 00000000..aa93ab0b --- /dev/null +++ b/core/testData/format/meta/call/lambdaArg.kt @@ -0,0 +1,16 @@ +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + doIt({}) + doIt({ it + it }) + doIt({ + val a = it + a + a + }) + doIt(functor = { it + it }) + doIt( + functor = { + val a = it + a + a + }) +} diff --git a/core/testData/format/meta/call/lambdaBlocks.expected.kt b/core/testData/format/meta/call/lambdaBlocks.expected.kt new file mode 100644 index 00000000..ba821813 --- /dev/null +++ b/core/testData/format/meta/call/lambdaBlocks.expected.kt @@ -0,0 +1,9 @@ +fun f() { + foo { + red.orange.yellow() + } + + foo.bar { + red.orange.yellow() + } +} diff --git a/core/testData/format/meta/call/lambdaBlocks.kt b/core/testData/format/meta/call/lambdaBlocks.kt new file mode 100644 index 00000000..e57beabc --- /dev/null +++ b/core/testData/format/meta/call/lambdaBlocks.kt @@ -0,0 +1,11 @@ +// MAX_WIDTH 23 + +fun f() { + foo { + red.orange.yellow() + } + + foo.bar { + red.orange.yellow() + } +} diff --git a/core/testData/format/meta/call/lambdaBlocksWithComment.expected.kt b/core/testData/format/meta/call/lambdaBlocksWithComment.expected.kt new file mode 100644 index 00000000..78026cca --- /dev/null +++ b/core/testData/format/meta/call/lambdaBlocksWithComment.expected.kt @@ -0,0 +1,22 @@ +fun f() { + foo { + // this is a comment + red.orange.yellow() + } + foo { + /* this is also a comment */ + red.orange.yellow() + } + foo.bar { + // this is a comment + red.orange.yellow() + } + foo.bar() { + // this is a comment + red.orange.yellow() + } + foo.bar { + /* this is also a comment */ + red.orange.yellow() + } +} diff --git a/core/testData/format/meta/call/lambdaBlocksWithComment.kt b/core/testData/format/meta/call/lambdaBlocksWithComment.kt new file mode 100644 index 00000000..28ea5ebe --- /dev/null +++ b/core/testData/format/meta/call/lambdaBlocksWithComment.kt @@ -0,0 +1,24 @@ +// MAX_WIDTH 24 + +fun f() { + foo { + // this is a comment + red.orange.yellow() + } + foo { + /* this is also a comment */ + red.orange.yellow() + } + foo.bar { + // this is a comment + red.orange.yellow() + } + foo.bar() { + // this is a comment + red.orange.yellow() + } + foo.bar { + /* this is also a comment */ + red.orange.yellow() + } +} diff --git a/core/testData/format/meta/call/lambdaBlocksWithComment2.expected.kt b/core/testData/format/meta/call/lambdaBlocksWithComment2.expected.kt new file mode 100644 index 00000000..304a50d0 --- /dev/null +++ b/core/testData/format/meta/call/lambdaBlocksWithComment2.expected.kt @@ -0,0 +1,24 @@ +fun f() { + foo { + red.orange.yellow() + // this is a comment + } + foo { + red.orange.yellow() + /* this is also a comment */ + } + foo.bar { + red.orange.yellow() + // this is a comment + } + foo.bar() { + red.orange.yellow() + // this is a comment + } + foo.bar { + red.orange.yellow() + /* this is also a comment */ + } + red.orange.yellow() + // this is a comment +} diff --git a/core/testData/format/meta/call/lambdaBlocksWithComment2.kt b/core/testData/format/meta/call/lambdaBlocksWithComment2.kt new file mode 100644 index 00000000..8cc23b89 --- /dev/null +++ b/core/testData/format/meta/call/lambdaBlocksWithComment2.kt @@ -0,0 +1,26 @@ +// MAX_WIDTH 24 + +fun f() { + foo { + red.orange.yellow() + // this is a comment + } + foo { + red.orange.yellow() + /* this is also a comment */ + } + foo.bar { + red.orange.yellow() + // this is a comment + } + foo.bar() { + red.orange.yellow() + // this is a comment + } + foo.bar { + red.orange.yellow() + /* this is also a comment */ + } + red.orange.yellow() + // this is a comment +} diff --git a/core/testData/format/meta/call/lambdaChain.expected.kt b/core/testData/format/meta/call/lambdaChain.expected.kt new file mode 100644 index 00000000..ecab750d --- /dev/null +++ b/core/testData/format/meta/call/lambdaChain.expected.kt @@ -0,0 +1,15 @@ +class Foo : Bar() { + fun doIt() { + fruit.onlyBananas().forEach { banana -> + val seeds = banana.find { it.type == SEED } + println(seeds) + } + + fruit + .filter { isBanana(it, Bananas.types) } + .forEach { banana -> + val seeds = banana.find { it.type == SEED } + println(seeds) + } + } +} diff --git a/core/testData/format/meta/call/lambdaChain.kt b/core/testData/format/meta/call/lambdaChain.kt new file mode 100644 index 00000000..ecab750d --- /dev/null +++ b/core/testData/format/meta/call/lambdaChain.kt @@ -0,0 +1,15 @@ +class Foo : Bar() { + fun doIt() { + fruit.onlyBananas().forEach { banana -> + val seeds = banana.find { it.type == SEED } + println(seeds) + } + + fruit + .filter { isBanana(it, Bananas.types) } + .forEach { banana -> + val seeds = banana.find { it.type == SEED } + println(seeds) + } + } +} diff --git a/core/testData/format/meta/call/lambdaConditionaBreak.expected.kt b/core/testData/format/meta/call/lambdaConditionaBreak.expected.kt new file mode 100644 index 00000000..19a5d5a4 --- /dev/null +++ b/core/testData/format/meta/call/lambdaConditionaBreak.expected.kt @@ -0,0 +1,9 @@ +fun f() { + foofoo + .doIt { + doStuff() + } + .doIt { + doStuff() + } +} diff --git a/core/testData/format/meta/call/lambdaConditionaBreak.kt b/core/testData/format/meta/call/lambdaConditionaBreak.kt new file mode 100644 index 00000000..1bd1a91c --- /dev/null +++ b/core/testData/format/meta/call/lambdaConditionaBreak.kt @@ -0,0 +1,11 @@ +// MAX_WIDTH 20 + +fun f() { + foofoo + .doIt { + doStuff() + } + .doIt { + doStuff() + } +} diff --git a/core/testData/format/meta/call/multipleArgs.expected.kt b/core/testData/format/meta/call/multipleArgs.expected.kt new file mode 100644 index 00000000..9f168021 --- /dev/null +++ b/core/testData/format/meta/call/multipleArgs.expected.kt @@ -0,0 +1,8 @@ +fun f() { + foo(1, 2, 3) + + foo( + 123456789012345678901234567890, + 123456789012345678901234567890, + 123456789012345678901234567890) +} diff --git a/core/testData/format/meta/call/multipleArgs.kt b/core/testData/format/meta/call/multipleArgs.kt new file mode 100644 index 00000000..9dd4a61e --- /dev/null +++ b/core/testData/format/meta/call/multipleArgs.kt @@ -0,0 +1,10 @@ +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + foo(1, 2, 3) + + foo( + 123456789012345678901234567890, + 123456789012345678901234567890, + 123456789012345678901234567890) +} diff --git a/core/testData/format/meta/call/multipleNamedArgs.expected.kt b/core/testData/format/meta/call/multipleNamedArgs.expected.kt new file mode 100644 index 00000000..e55f8ac4 --- /dev/null +++ b/core/testData/format/meta/call/multipleNamedArgs.expected.kt @@ -0,0 +1,8 @@ +fun f() { + foo(1, b = 2, c = 3) + + foo( + 123456789012345678901234567890, + b = 23456789012345678901234567890, + c = 3456789012345678901234567890) +} diff --git a/core/testData/format/meta/call/multipleNamedArgs.kt b/core/testData/format/meta/call/multipleNamedArgs.kt new file mode 100644 index 00000000..d7e1980e --- /dev/null +++ b/core/testData/format/meta/call/multipleNamedArgs.kt @@ -0,0 +1,10 @@ +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + foo(1, b = 2, c = 3) + + foo( + 123456789012345678901234567890, + b = 23456789012345678901234567890, + c = 3456789012345678901234567890) +} diff --git a/core/testData/format/meta/call/namedArgsWithValueExpr.expected.kt b/core/testData/format/meta/call/namedArgsWithValueExpr.expected.kt new file mode 100644 index 00000000..bcb178dc --- /dev/null +++ b/core/testData/format/meta/call/namedArgsWithValueExpr.expected.kt @@ -0,0 +1,8 @@ +fun f() = + Bar( + tokens = + mutableListOf().apply { + // Printing + print() + }, + duration = duration) diff --git a/core/testData/format/meta/call/namedArgsWithValueExpr.kt b/core/testData/format/meta/call/namedArgsWithValueExpr.kt new file mode 100644 index 00000000..67b03339 --- /dev/null +++ b/core/testData/format/meta/call/namedArgsWithValueExpr.kt @@ -0,0 +1,10 @@ +// TRAILING_COMMA_STRATEGY NONE + +fun f() = + Bar( + tokens = + mutableListOf().apply { + // Printing + print() + }, + duration = duration) diff --git a/core/testData/format/meta/call/nestedCallChains.expected.kt b/core/testData/format/meta/call/nestedCallChains.expected.kt new file mode 100644 index 00000000..b6a9ad4b --- /dev/null +++ b/core/testData/format/meta/call/nestedCallChains.expected.kt @@ -0,0 +1,9 @@ +fun f() { + Stuff() + .doIt( + Foo.doIt() + .doThat()) + .doIt( + Foo.doIt() + .doThat()) +} diff --git a/core/testData/format/meta/call/nestedCallChains.kt b/core/testData/format/meta/call/nestedCallChains.kt new file mode 100644 index 00000000..7ed542b8 --- /dev/null +++ b/core/testData/format/meta/call/nestedCallChains.kt @@ -0,0 +1,12 @@ +// MAX_WIDTH 28 +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + Stuff() + .doIt( + Foo.doIt() + .doThat()) + .doIt( + Foo.doIt() + .doThat()) +} diff --git a/core/testData/format/meta/call/nestedCalls.expected.kt b/core/testData/format/meta/call/nestedCalls.expected.kt new file mode 100644 index 00000000..028bb122 --- /dev/null +++ b/core/testData/format/meta/call/nestedCalls.expected.kt @@ -0,0 +1,9 @@ +function( + param = + (rate downTo min step step).drop(1).map { + nestedFun( + rate = + rate( + value = + firstArg().info.get(0).rate.value)) + }) diff --git a/core/testData/format/meta/call/nestedCalls.kt b/core/testData/format/meta/call/nestedCalls.kt new file mode 100644 index 00000000..6cec9aef --- /dev/null +++ b/core/testData/format/meta/call/nestedCalls.kt @@ -0,0 +1,12 @@ +// MAX_WIDTH 70 +// TRAILING_COMMA_STRATEGY NONE + +function( + param = + (rate downTo min step step).drop(1).map { + nestedFun( + rate = + rate( + value = + firstArg().info.get(0).rate.value)) + }) diff --git a/core/testData/format/meta/call/nestedCallsKotlinlangStyle.expected.kt b/core/testData/format/meta/call/nestedCallsKotlinlangStyle.expected.kt new file mode 100644 index 00000000..2473c681 --- /dev/null +++ b/core/testData/format/meta/call/nestedCallsKotlinlangStyle.expected.kt @@ -0,0 +1,12 @@ +function( + param = + (rate downTo min step step).drop(1).map { + nestedFun( + rate = + rate( + value = + firstArg().info.get(0).rate.value, + ), + ) + }, +) diff --git a/core/testData/format/meta/call/nestedCallsKotlinlangStyle.kt b/core/testData/format/meta/call/nestedCallsKotlinlangStyle.kt new file mode 100644 index 00000000..b836af34 --- /dev/null +++ b/core/testData/format/meta/call/nestedCallsKotlinlangStyle.kt @@ -0,0 +1,17 @@ +// MAX_WIDTH 70 +// BLOCK_INDENT 4 +// CONTINUATION_INDENT 4 +// TRAILING_COMMA_STRATEGY NONE + +function( + param = + (rate downTo min step step).drop(1).map { + nestedFun( + rate = + rate( + value = + firstArg().info.get(0).rate.value, + ), + ) + }, +) diff --git a/core/testData/format/meta/call/newLineBeforeNamedLambdaArg.expected.kt b/core/testData/format/meta/call/newLineBeforeNamedLambdaArg.expected.kt new file mode 100644 index 00000000..30154a7a --- /dev/null +++ b/core/testData/format/meta/call/newLineBeforeNamedLambdaArg.expected.kt @@ -0,0 +1,10 @@ +private fun f(items: List) { + doSomethingCool( + items, + lambdaArgument = { + step1() + step2() + }) { + it.doIt() + } +} diff --git a/core/testData/format/meta/call/newLineBeforeNamedLambdaArg.kt b/core/testData/format/meta/call/newLineBeforeNamedLambdaArg.kt new file mode 100644 index 00000000..a2bc4fcc --- /dev/null +++ b/core/testData/format/meta/call/newLineBeforeNamedLambdaArg.kt @@ -0,0 +1,12 @@ +// TRAILING_COMMA_STRATEGY NONE + +private fun f(items: List) { + doSomethingCool( + items, + lambdaArgument = { + step1() + step2() + }) { + it.doIt() + } +} diff --git a/core/testData/format/meta/call/noForwardPropagationInCallExpr.expected.kt b/core/testData/format/meta/call/noForwardPropagationInCallExpr.expected.kt new file mode 100644 index 00000000..34f0f447 --- /dev/null +++ b/core/testData/format/meta/call/noForwardPropagationInCallExpr.expected.kt @@ -0,0 +1,8 @@ +fun test() { + foo_bar_baz__zip(b) { + c + } + foo.bar(baz).zip(b) { + c + } +} diff --git a/core/testData/format/meta/call/noForwardPropagationInCallExpr.kt b/core/testData/format/meta/call/noForwardPropagationInCallExpr.kt new file mode 100644 index 00000000..9d9194b4 --- /dev/null +++ b/core/testData/format/meta/call/noForwardPropagationInCallExpr.kt @@ -0,0 +1,10 @@ +// MAX_WIDTH 30 + +fun test() { + foo_bar_baz__zip(b) { + c + } + foo.bar(baz).zip(b) { + c + } +} diff --git a/core/testData/format/meta/call/qualifiedExpressions.expected.kt b/core/testData/format/meta/call/qualifiedExpressions.expected.kt new file mode 100644 index 00000000..38757fd0 --- /dev/null +++ b/core/testData/format/meta/call/qualifiedExpressions.expected.kt @@ -0,0 +1,50 @@ +fun f() { + // Regression test: + // https://github.com/facebook/ktfmt/issues/56 + kjsdfglkjdfgkjdfkgjhkerjghkdfj + ?.methodName1() + + // a series of field accesses + // followed by a single call + // expression is kept together. + abcdefghijkl.abcdefghijkl + ?.methodName2() + + // Similar to above. + abcdefghijkl.abcdefghijkl + ?.methodName3 + ?.abcdefghijkl() + + // Multiple call expressions cause + // each part of the expression + // to be placed on its own line. + abcdefghijkl + ?.abcdefghijkl + ?.methodName4() + ?.abcdefghijkl() + + // Don't break first call + // expression if it fits. + foIt(something.something.happens()) + .thenReturn(result) + + // Break after `longerThanFour(` + // because it's longer than 4 chars + longerThanFour( + something.something + .happens()) + .thenReturn(result) + + // Similarly to above, when part of + // qualified expression. + foo.longerThanFour( + something.something + .happens()) + .thenReturn(result) + + // Keep 'super' attached to the + // method name + super.abcdefghijkl + .methodName4() + .abcdefghijkl() +} diff --git a/core/testData/format/meta/call/qualifiedExpressions.kt b/core/testData/format/meta/call/qualifiedExpressions.kt new file mode 100644 index 00000000..a53d4fe7 --- /dev/null +++ b/core/testData/format/meta/call/qualifiedExpressions.kt @@ -0,0 +1,53 @@ +// MAX_WIDTH 37 +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + // Regression test: + // https://github.com/facebook/ktfmt/issues/56 + kjsdfglkjdfgkjdfkgjhkerjghkdfj + ?.methodName1() + + // a series of field accesses + // followed by a single call + // expression is kept together. + abcdefghijkl.abcdefghijkl + ?.methodName2() + + // Similar to above. + abcdefghijkl.abcdefghijkl + ?.methodName3 + ?.abcdefghijkl() + + // Multiple call expressions cause + // each part of the expression + // to be placed on its own line. + abcdefghijkl + ?.abcdefghijkl + ?.methodName4() + ?.abcdefghijkl() + + // Don't break first call + // expression if it fits. + foIt(something.something.happens()) + .thenReturn(result) + + // Break after `longerThanFour(` + // because it's longer than 4 chars + longerThanFour( + something.something + .happens()) + .thenReturn(result) + + // Similarly to above, when part of + // qualified expression. + foo.longerThanFour( + something.something + .happens()) + .thenReturn(result) + + // Keep 'super' attached to the + // method name + super.abcdefghijkl + .methodName4() + .abcdefghijkl() +} diff --git a/core/testData/format/meta/call/qualifiedExpressionsWithLambdas.expected.kt b/core/testData/format/meta/call/qualifiedExpressionsWithLambdas.expected.kt new file mode 100644 index 00000000..a9492fba --- /dev/null +++ b/core/testData/format/meta/call/qualifiedExpressionsWithLambdas.expected.kt @@ -0,0 +1,69 @@ +fun f() { + val items = + items.toMutableList.apply { + // + foo + } + + val items = + items.toMutableList().apply { + // + foo + } + + // All dereferences are on one line (because they fit), even though + // the apply() at the end requires a line break. + val items = + items.toMutableList.sdfkjsdf.sdfjksdflk.sdlfkjsldfj.apply { + // + foo + } + + // All method calls are on one line (because they fit), even though + // the apply() at the end requires a line break. + val items = + items.toMutableList().sdfkjsdf().sdfjksdflk().sdlfkjsldfj().apply { + // + foo + } + + // All method calls with lambdas could fit, but we avoid a block like syntax + // and break to one call per line + val items = + items + .map { it + 1 } + .filter { it > 0 } + .apply { + // + foo + } + + // the lambda is indented properly with the break before it + val items = + items.fieldName.sdfkjsdf.sdfjksdflk.sdlfkjsldfj.sdfjksdflk.sdlfkjsldfj + .sdlfkjsldfj + .apply { + // + foo + } + items.fieldName.sdfkjsdf.sdfjksdflk.sdlfkjsldfj.sdfjksdflk.sdlfkjsldfj + .apply { + // + foo + } + + // When there are multiple method calls, and they don't fit on one + // line, put each on a new line. + val items = + items + .toMutableList() + .sdfkjsdf() + .sdfjksdflk() + .sdlfkjsldfj() + .sdfjksdflk() + .sdlfkjsldfj() + .apply { + // + foo + } +} diff --git a/core/testData/format/meta/call/qualifiedExpressionsWithLambdas.kt b/core/testData/format/meta/call/qualifiedExpressionsWithLambdas.kt new file mode 100644 index 00000000..c074f6e7 --- /dev/null +++ b/core/testData/format/meta/call/qualifiedExpressionsWithLambdas.kt @@ -0,0 +1,72 @@ +// MAX_WIDTH 79 +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + val items = + items.toMutableList.apply { + // + foo + } + + val items = + items.toMutableList().apply { + // + foo + } + + // All dereferences are on one line (because they fit), even though + // the apply() at the end requires a line break. + val items = + items.toMutableList.sdfkjsdf.sdfjksdflk.sdlfkjsldfj.apply { + // + foo + } + + // All method calls are on one line (because they fit), even though + // the apply() at the end requires a line break. + val items = + items.toMutableList().sdfkjsdf().sdfjksdflk().sdlfkjsldfj().apply { + // + foo + } + + // All method calls with lambdas could fit, but we avoid a block like syntax + // and break to one call per line + val items = + items + .map { it + 1 } + .filter { it > 0 } + .apply { + // + foo + } + + // the lambda is indented properly with the break before it + val items = + items.fieldName.sdfkjsdf.sdfjksdflk.sdlfkjsldfj.sdfjksdflk.sdlfkjsldfj + .sdlfkjsldfj + .apply { + // + foo + } + items.fieldName.sdfkjsdf.sdfjksdflk.sdlfkjsldfj.sdfjksdflk.sdlfkjsldfj + .apply { + // + foo + } + + // When there are multiple method calls, and they don't fit on one + // line, put each on a new line. + val items = + items + .toMutableList() + .sdfkjsdf() + .sdfjksdflk() + .sdlfkjsldfj() + .sdfjksdflk() + .sdlfkjsldfj() + .apply { + // + foo + } +} diff --git a/core/testData/format/meta/call/safeDot.expected.kt b/core/testData/format/meta/call/safeDot.expected.kt new file mode 100644 index 00000000..b3902f92 --- /dev/null +++ b/core/testData/format/meta/call/safeDot.expected.kt @@ -0,0 +1,3 @@ +fun f() { + node?.name +} diff --git a/core/testData/format/meta/call/safeDot.kt b/core/testData/format/meta/call/safeDot.kt new file mode 100644 index 00000000..b3902f92 --- /dev/null +++ b/core/testData/format/meta/call/safeDot.kt @@ -0,0 +1,3 @@ +fun f() { + node?.name +} diff --git a/core/testData/format/meta/call/safeDotInCallChain.expected.kt b/core/testData/format/meta/call/safeDotInCallChain.expected.kt new file mode 100644 index 00000000..c038b92a --- /dev/null +++ b/core/testData/format/meta/call/safeDotInCallChain.expected.kt @@ -0,0 +1,2 @@ +fun f(number: Int) = + Something.doStuff(number)?.size diff --git a/core/testData/format/meta/call/safeDotInCallChain.kt b/core/testData/format/meta/call/safeDotInCallChain.kt new file mode 100644 index 00000000..b2d5a040 --- /dev/null +++ b/core/testData/format/meta/call/safeDotInCallChain.kt @@ -0,0 +1,4 @@ +// MAX_WIDTH 50 + +fun f(number: Int) = + Something.doStuff(number)?.size diff --git a/core/testData/format/meta/call/safeDotWithRegularDot.expected.kt b/core/testData/format/meta/call/safeDotWithRegularDot.expected.kt new file mode 100644 index 00000000..c42f798c --- /dev/null +++ b/core/testData/format/meta/call/safeDotWithRegularDot.expected.kt @@ -0,0 +1,3 @@ +fun f() { + node?.name.hello +} diff --git a/core/testData/format/meta/call/safeDotWithRegularDot.kt b/core/testData/format/meta/call/safeDotWithRegularDot.kt new file mode 100644 index 00000000..c42f798c --- /dev/null +++ b/core/testData/format/meta/call/safeDotWithRegularDot.kt @@ -0,0 +1,3 @@ +fun f() { + node?.name.hello +} diff --git a/core/testData/format/meta/call/twoLambdas.expected.kt b/core/testData/format/meta/call/twoLambdas.expected.kt new file mode 100644 index 00000000..57c12f36 --- /dev/null +++ b/core/testData/format/meta/call/twoLambdas.expected.kt @@ -0,0 +1,10 @@ +fun f() { + doIt() + .apply { + number = + computeNumber1() + } + .apply { + number = 2 * number + } +} diff --git a/core/testData/format/meta/call/twoLambdas.kt b/core/testData/format/meta/call/twoLambdas.kt new file mode 100644 index 00000000..2d8b6c60 --- /dev/null +++ b/core/testData/format/meta/call/twoLambdas.kt @@ -0,0 +1,12 @@ +// MAX_WIDTH 28 + +fun f() { + doIt() + .apply { + number = + computeNumber1() + } + .apply { + number = 2 * number + } +} diff --git a/core/testData/format/meta/call/twoLambdas2.expected.kt b/core/testData/format/meta/call/twoLambdas2.expected.kt new file mode 100644 index 00000000..80c8c15e --- /dev/null +++ b/core/testData/format/meta/call/twoLambdas2.expected.kt @@ -0,0 +1,10 @@ +fun f() { + field + .apply { + number = + computeNumber1() + } + .apply { + number = 2 * number + } +} diff --git a/core/testData/format/meta/call/twoLambdas2.kt b/core/testData/format/meta/call/twoLambdas2.kt new file mode 100644 index 00000000..7833debf --- /dev/null +++ b/core/testData/format/meta/call/twoLambdas2.kt @@ -0,0 +1,12 @@ +// MAX_WIDTH 28 + +fun f() { + field + .apply { + number = + computeNumber1() + } + .apply { + number = 2 * number + } +} diff --git a/core/testData/format/meta/call/typeNamesKeepTogether.expected.kt b/core/testData/format/meta/call/typeNamesKeepTogether.expected.kt new file mode 100644 index 00000000..6909cb3e --- /dev/null +++ b/core/testData/format/meta/call/typeNamesKeepTogether.expected.kt @@ -0,0 +1,18 @@ +fun f() { + com.facebook.foo.Foo( + 1, 2) + com.facebook.foo + .Foo(1, 2) + .andAlsoThis() + com.facebook.Foo.foo( + 1, 2) + com.facebook + .foobarFoo + .foo(1, 2) + foo.invoke( + foo, bar, bar) + foo.invoke(foo, bar) + .invoke() + FooFoo.foooooooo() + .foooooooo() +} diff --git a/core/testData/format/meta/call/typeNamesKeepTogether.kt b/core/testData/format/meta/call/typeNamesKeepTogether.kt new file mode 100644 index 00000000..afd004c0 --- /dev/null +++ b/core/testData/format/meta/call/typeNamesKeepTogether.kt @@ -0,0 +1,21 @@ +// MAX_WIDTH 23 +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + com.facebook.foo.Foo( + 1, 2) + com.facebook.foo + .Foo(1, 2) + .andAlsoThis() + com.facebook.Foo.foo( + 1, 2) + com.facebook + .foobarFoo + .foo(1, 2) + foo.invoke( + foo, bar, bar) + foo.invoke(foo, bar) + .invoke() + FooFoo.foooooooo() + .foooooooo() +} diff --git a/core/testData/format/meta/class/constructors.expected.kt b/core/testData/format/meta/class/constructors.expected.kt new file mode 100644 index 00000000..00868566 --- /dev/null +++ b/core/testData/format/meta/class/constructors.expected.kt @@ -0,0 +1,28 @@ +class Foo constructor(number: Int) {} + +class Foo2 private constructor(number: Int) {} + +class Foo3 @Inject constructor(number: Int) {} + +class Foo4 @Inject private constructor(number: Int) {} + +class Foo5 +@Inject +private constructor( + number: Int, + number2: Int, + number3: Int, + number4: Int, + number5: Int, + number6: Int +) {} + +class Foo6 +@Inject +private constructor(hasSpaceForAnnos: Innnt) { + // @Inject +} + +class FooTooLongForCtorAndSupertypes +@Inject +private constructor(x: Int) : NoooooooSpaceForAnnos {} diff --git a/core/testData/format/meta/class/constructors.kt b/core/testData/format/meta/class/constructors.kt new file mode 100644 index 00000000..62d26372 --- /dev/null +++ b/core/testData/format/meta/class/constructors.kt @@ -0,0 +1,31 @@ +// MAX_WIDTH 55 +// TRAILING_COMMA_STRATEGY NONE + +class Foo constructor(number: Int) {} + +class Foo2 private constructor(number: Int) {} + +class Foo3 @Inject constructor(number: Int) {} + +class Foo4 @Inject private constructor(number: Int) {} + +class Foo5 +@Inject +private constructor( + number: Int, + number2: Int, + number3: Int, + number4: Int, + number5: Int, + number6: Int +) {} + +class Foo6 +@Inject +private constructor(hasSpaceForAnnos: Innnt) { + // @Inject +} + +class FooTooLongForCtorAndSupertypes +@Inject +private constructor(x: Int) : NoooooooSpaceForAnnos {} diff --git a/core/testData/format/meta/class/emptyClass.expected.kt b/core/testData/format/meta/class/emptyClass.expected.kt new file mode 100644 index 00000000..c389887e --- /dev/null +++ b/core/testData/format/meta/class/emptyClass.expected.kt @@ -0,0 +1 @@ +class Foo diff --git a/core/testData/format/meta/class/emptyClass.kt b/core/testData/format/meta/class/emptyClass.kt new file mode 100644 index 00000000..c389887e --- /dev/null +++ b/core/testData/format/meta/class/emptyClass.kt @@ -0,0 +1 @@ +class Foo diff --git a/core/testData/format/meta/class/emptyInterface.expected.kt b/core/testData/format/meta/class/emptyInterface.expected.kt new file mode 100644 index 00000000..3f943170 --- /dev/null +++ b/core/testData/format/meta/class/emptyInterface.expected.kt @@ -0,0 +1 @@ +interface Foo diff --git a/core/testData/format/meta/class/emptyInterface.kt b/core/testData/format/meta/class/emptyInterface.kt new file mode 100644 index 00000000..3f943170 --- /dev/null +++ b/core/testData/format/meta/class/emptyInterface.kt @@ -0,0 +1 @@ +interface Foo diff --git a/core/testData/format/meta/class/emptyPrimaryConstructor.expected.kt b/core/testData/format/meta/class/emptyPrimaryConstructor.expected.kt new file mode 100644 index 00000000..d1a9ecca --- /dev/null +++ b/core/testData/format/meta/class/emptyPrimaryConstructor.expected.kt @@ -0,0 +1 @@ +class Foo() diff --git a/core/testData/format/meta/class/emptyPrimaryConstructor.kt b/core/testData/format/meta/class/emptyPrimaryConstructor.kt new file mode 100644 index 00000000..d1a9ecca --- /dev/null +++ b/core/testData/format/meta/class/emptyPrimaryConstructor.kt @@ -0,0 +1 @@ +class Foo() diff --git a/core/testData/format/meta/class/explicitConstructorParams.expected.kt b/core/testData/format/meta/class/explicitConstructorParams.expected.kt new file mode 100644 index 00000000..ba4dccc1 --- /dev/null +++ b/core/testData/format/meta/class/explicitConstructorParams.expected.kt @@ -0,0 +1 @@ +class Foo(a: Int, var b: Double, val c: String) diff --git a/core/testData/format/meta/class/explicitConstructorParams.kt b/core/testData/format/meta/class/explicitConstructorParams.kt new file mode 100644 index 00000000..ba4dccc1 --- /dev/null +++ b/core/testData/format/meta/class/explicitConstructorParams.kt @@ -0,0 +1 @@ +class Foo(a: Int, var b: Double, val c: String) diff --git a/core/testData/format/meta/class/explicitConstructorParamsAndBody.expected.kt b/core/testData/format/meta/class/explicitConstructorParamsAndBody.expected.kt new file mode 100644 index 00000000..089a13f5 --- /dev/null +++ b/core/testData/format/meta/class/explicitConstructorParamsAndBody.expected.kt @@ -0,0 +1,7 @@ +class Foo(a: Int, var b: Double, val c: String) { + val x = 2 + + fun method() {} + + class Bar +} diff --git a/core/testData/format/meta/class/explicitConstructorParamsAndBody.kt b/core/testData/format/meta/class/explicitConstructorParamsAndBody.kt new file mode 100644 index 00000000..089a13f5 --- /dev/null +++ b/core/testData/format/meta/class/explicitConstructorParamsAndBody.kt @@ -0,0 +1,7 @@ +class Foo(a: Int, var b: Double, val c: String) { + val x = 2 + + fun method() {} + + class Bar +} diff --git a/core/testData/format/meta/class/functionalInterface.expected.kt b/core/testData/format/meta/class/functionalInterface.expected.kt new file mode 100644 index 00000000..381351d2 --- /dev/null +++ b/core/testData/format/meta/class/functionalInterface.expected.kt @@ -0,0 +1,3 @@ +fun interface MyRunnable { + fun runIt() +} diff --git a/core/testData/format/meta/class/functionalInterface.kt b/core/testData/format/meta/class/functionalInterface.kt new file mode 100644 index 00000000..381351d2 --- /dev/null +++ b/core/testData/format/meta/class/functionalInterface.kt @@ -0,0 +1,3 @@ +fun interface MyRunnable { + fun runIt() +} diff --git a/core/testData/format/meta/class/functionalInterfaceWithTypeParams.expected.kt b/core/testData/format/meta/class/functionalInterfaceWithTypeParams.expected.kt new file mode 100644 index 00000000..c22e409a --- /dev/null +++ b/core/testData/format/meta/class/functionalInterfaceWithTypeParams.expected.kt @@ -0,0 +1 @@ +public fun interface Function> : (Int, T?) -> T? diff --git a/core/testData/format/meta/class/functionalInterfaceWithTypeParams.kt b/core/testData/format/meta/class/functionalInterfaceWithTypeParams.kt new file mode 100644 index 00000000..c22e409a --- /dev/null +++ b/core/testData/format/meta/class/functionalInterfaceWithTypeParams.kt @@ -0,0 +1 @@ +public fun interface Function> : (Int, T?) -> T? diff --git a/core/testData/format/meta/class/modifiers.expected.kt b/core/testData/format/meta/class/modifiers.expected.kt new file mode 100644 index 00000000..090fefa3 --- /dev/null +++ b/core/testData/format/meta/class/modifiers.expected.kt @@ -0,0 +1,7 @@ +abstract class Foo + +inner class Foo + +final class Foo + +open class Foo diff --git a/core/testData/format/meta/class/modifiers.kt b/core/testData/format/meta/class/modifiers.kt new file mode 100644 index 00000000..090fefa3 --- /dev/null +++ b/core/testData/format/meta/class/modifiers.kt @@ -0,0 +1,7 @@ +abstract class Foo + +inner class Foo + +final class Foo + +open class Foo diff --git a/core/testData/format/meta/class/multipleConstructors.expected.kt b/core/testData/format/meta/class/multipleConstructors.expected.kt new file mode 100644 index 00000000..9454635c --- /dev/null +++ b/core/testData/format/meta/class/multipleConstructors.expected.kt @@ -0,0 +1,7 @@ +class Foo private constructor(number: Int) { + private constructor(n: Float) : this(1) + + private constructor(n: Double) : this(1) { + println("built") + } +} diff --git a/core/testData/format/meta/class/multipleConstructors.kt b/core/testData/format/meta/class/multipleConstructors.kt new file mode 100644 index 00000000..9454635c --- /dev/null +++ b/core/testData/format/meta/class/multipleConstructors.kt @@ -0,0 +1,7 @@ +class Foo private constructor(number: Int) { + private constructor(n: Float) : this(1) + + private constructor(n: Double) : this(1) { + println("built") + } +} diff --git a/core/testData/format/meta/class/object.expected.kt b/core/testData/format/meta/class/object.expected.kt new file mode 100644 index 00000000..7053c227 --- /dev/null +++ b/core/testData/format/meta/class/object.expected.kt @@ -0,0 +1 @@ +object Foo(n: Int) {} diff --git a/core/testData/format/meta/class/object.kt b/core/testData/format/meta/class/object.kt new file mode 100644 index 00000000..7053c227 --- /dev/null +++ b/core/testData/format/meta/class/object.kt @@ -0,0 +1 @@ +object Foo(n: Int) {} diff --git a/core/testData/format/meta/class/objectExpr.expected.kt b/core/testData/format/meta/class/objectExpr.expected.kt new file mode 100644 index 00000000..63bb3682 --- /dev/null +++ b/core/testData/format/meta/class/objectExpr.expected.kt @@ -0,0 +1,3 @@ +fun f(): Any { + return object : Adapter() {} +} diff --git a/core/testData/format/meta/class/objectExpr.kt b/core/testData/format/meta/class/objectExpr.kt new file mode 100644 index 00000000..63bb3682 --- /dev/null +++ b/core/testData/format/meta/class/objectExpr.kt @@ -0,0 +1,3 @@ +fun f(): Any { + return object : Adapter() {} +} diff --git a/core/testData/format/meta/class/objectExpr2.expected.kt b/core/testData/format/meta/class/objectExpr2.expected.kt new file mode 100644 index 00000000..b67e67f1 --- /dev/null +++ b/core/testData/format/meta/class/objectExpr2.expected.kt @@ -0,0 +1,3 @@ +fun f(): Any { + return (object : Adapter() {}) +} diff --git a/core/testData/format/meta/class/objectExpr2.kt b/core/testData/format/meta/class/objectExpr2.kt new file mode 100644 index 00000000..b67e67f1 --- /dev/null +++ b/core/testData/format/meta/class/objectExpr2.kt @@ -0,0 +1,3 @@ +fun f(): Any { + return (object : Adapter() {}) +} diff --git a/core/testData/format/meta/class/primaryConstructor.expected.kt b/core/testData/format/meta/class/primaryConstructor.expected.kt new file mode 100644 index 00000000..b559a1c4 --- /dev/null +++ b/core/testData/format/meta/class/primaryConstructor.expected.kt @@ -0,0 +1,3 @@ +data class Foo( + val number: Int = 0 +) diff --git a/core/testData/format/meta/class/primaryConstructor.kt b/core/testData/format/meta/class/primaryConstructor.kt new file mode 100644 index 00000000..a0e5a568 --- /dev/null +++ b/core/testData/format/meta/class/primaryConstructor.kt @@ -0,0 +1,6 @@ +// MAX_WIDTH 25 +// TRAILING_COMMA_STRATEGY NONE + +data class Foo( + val number: Int = 0 +) diff --git a/core/testData/format/meta/class/primaryConstructor2.expected.kt b/core/testData/format/meta/class/primaryConstructor2.expected.kt new file mode 100644 index 00000000..a1abd4fd --- /dev/null +++ b/core/testData/format/meta/class/primaryConstructor2.expected.kt @@ -0,0 +1,7 @@ +data class Foo( + val number: Int, + val name: String, + val age: Int, + val title: String, + val offspring2: List +) {} diff --git a/core/testData/format/meta/class/primaryConstructor2.kt b/core/testData/format/meta/class/primaryConstructor2.kt new file mode 100644 index 00000000..4b9747fa --- /dev/null +++ b/core/testData/format/meta/class/primaryConstructor2.kt @@ -0,0 +1,9 @@ +// TRAILING_COMMA_STRATEGY NONE + +data class Foo( + val number: Int, + val name: String, + val age: Int, + val title: String, + val offspring2: List +) {} diff --git a/core/testData/format/meta/class/primaryConstructor3.expected.kt b/core/testData/format/meta/class/primaryConstructor3.expected.kt new file mode 100644 index 00000000..52753940 --- /dev/null +++ b/core/testData/format/meta/class/primaryConstructor3.expected.kt @@ -0,0 +1,8 @@ +data class Foo +constructor( + val number: Int, + val name: String, + val age: Int, + val title: String, + val offspring: List +) {} diff --git a/core/testData/format/meta/class/primaryConstructor3.kt b/core/testData/format/meta/class/primaryConstructor3.kt new file mode 100644 index 00000000..9dfd4694 --- /dev/null +++ b/core/testData/format/meta/class/primaryConstructor3.kt @@ -0,0 +1,11 @@ +// MAX_WIDTH 50 +// TRAILING_COMMA_STRATEGY NONE + +data class Foo +constructor( + val number: Int, + val name: String, + val age: Int, + val title: String, + val offspring: List +) {} diff --git a/core/testData/format/meta/class/primaryConstructorKDoc.expected.kt b/core/testData/format/meta/class/primaryConstructorKDoc.expected.kt new file mode 100644 index 00000000..d909a505 --- /dev/null +++ b/core/testData/format/meta/class/primaryConstructorKDoc.expected.kt @@ -0,0 +1,3 @@ +class Class +/** A comment */ +constructor() {} diff --git a/core/testData/format/meta/class/primaryConstructorKDoc.kt b/core/testData/format/meta/class/primaryConstructorKDoc.kt new file mode 100644 index 00000000..d909a505 --- /dev/null +++ b/core/testData/format/meta/class/primaryConstructorKDoc.kt @@ -0,0 +1,3 @@ +class Class +/** A comment */ +constructor() {} diff --git a/core/testData/format/meta/class/secondaryConstructor.expected.kt b/core/testData/format/meta/class/secondaryConstructor.expected.kt new file mode 100644 index 00000000..00a86514 --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructor.expected.kt @@ -0,0 +1,5 @@ +data class Foo { + constructor( + val number: Int = 0 + ) {} +} diff --git a/core/testData/format/meta/class/secondaryConstructor.kt b/core/testData/format/meta/class/secondaryConstructor.kt new file mode 100644 index 00000000..74ae3edf --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructor.kt @@ -0,0 +1,8 @@ +// MAX_WIDTH 28 +// TRAILING_COMMA_STRATEGY NONE + +data class Foo { + constructor( + val number: Int = 0 + ) {} +} diff --git a/core/testData/format/meta/class/secondaryConstructor2.expected.kt b/core/testData/format/meta/class/secondaryConstructor2.expected.kt new file mode 100644 index 00000000..11a18ee6 --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructor2.expected.kt @@ -0,0 +1,8 @@ +data class Foo +constructor( + val name: String, + val age: Int, + val title: String, + val offspring: List, + val foo: String +) {} diff --git a/core/testData/format/meta/class/secondaryConstructor2.kt b/core/testData/format/meta/class/secondaryConstructor2.kt new file mode 100644 index 00000000..dea90465 --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructor2.kt @@ -0,0 +1,10 @@ +// TRAILING_COMMA_STRATEGY NONE + +data class Foo +constructor( + val name: String, + val age: Int, + val title: String, + val offspring: List, + val foo: String +) {} diff --git a/core/testData/format/meta/class/secondaryConstructor3.expected.kt b/core/testData/format/meta/class/secondaryConstructor3.expected.kt new file mode 100644 index 00000000..ce3f4667 --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructor3.expected.kt @@ -0,0 +1,9 @@ +data class Foo { + constructor( + val number: Int, + val name: String, + val age: Int, + val title: String, + val offspring: List + ) +} diff --git a/core/testData/format/meta/class/secondaryConstructor3.kt b/core/testData/format/meta/class/secondaryConstructor3.kt new file mode 100644 index 00000000..b97d9679 --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructor3.kt @@ -0,0 +1,12 @@ +// MAX_WIDTH 50 +// TRAILING_COMMA_STRATEGY NONE + +data class Foo { + constructor( + val number: Int, + val name: String, + val age: Int, + val title: String, + val offspring: List + ) +} diff --git a/core/testData/format/meta/class/secondaryConstructorDelegate.expected.kt b/core/testData/format/meta/class/secondaryConstructorDelegate.expected.kt new file mode 100644 index 00000000..fb51b4ba --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructorDelegate.expected.kt @@ -0,0 +1,15 @@ +data class Foo { + constructor( + val number: Int, + val name: String, + val age: Int, + val title: String, + val offspring: List + ) : this( + number, + name, + age, + title, + offspring, + offspring) +} diff --git a/core/testData/format/meta/class/secondaryConstructorDelegate.kt b/core/testData/format/meta/class/secondaryConstructorDelegate.kt new file mode 100644 index 00000000..529115ca --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructorDelegate.kt @@ -0,0 +1,18 @@ +// MAX_WIDTH 50 +// TRAILING_COMMA_STRATEGY NONE + +data class Foo { + constructor( + val number: Int, + val name: String, + val age: Int, + val title: String, + val offspring: List + ) : this( + number, + name, + age, + title, + offspring, + offspring) +} diff --git a/core/testData/format/meta/class/secondaryConstructorDelegate2.expected.kt b/core/testData/format/meta/class/secondaryConstructorDelegate2.expected.kt new file mode 100644 index 00000000..9c6f71d2 --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructorDelegate2.expected.kt @@ -0,0 +1,7 @@ +data class Foo { + constructor() : + this( + Foo.createSpeciallyDesignedParameter(), + Foo.createSpeciallyDesignedParameter(), + ) +} diff --git a/core/testData/format/meta/class/secondaryConstructorDelegate2.kt b/core/testData/format/meta/class/secondaryConstructorDelegate2.kt new file mode 100644 index 00000000..95f2855e --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructorDelegate2.kt @@ -0,0 +1,10 @@ +// MAX_WIDTH 50 +// TRAILING_COMMA_STRATEGY NONE + +data class Foo { + constructor() : + this( + Foo.createSpeciallyDesignedParameter(), + Foo.createSpeciallyDesignedParameter(), + ) +} diff --git a/core/testData/format/meta/class/secondaryConstructorDelegate3.expected.kt b/core/testData/format/meta/class/secondaryConstructorDelegate3.expected.kt new file mode 100644 index 00000000..cc98e188 --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructorDelegate3.expected.kt @@ -0,0 +1,10 @@ +class C { + constructor( + context: Context?, + attrs: AttributeSet?, + defStyleAttr: Int, + defStyleRes: Int + ) : super(context, attrs, defStyleAttr, defStyleRes) { + init(attrs) + } +} diff --git a/core/testData/format/meta/class/secondaryConstructorDelegate3.kt b/core/testData/format/meta/class/secondaryConstructorDelegate3.kt new file mode 100644 index 00000000..1093160e --- /dev/null +++ b/core/testData/format/meta/class/secondaryConstructorDelegate3.kt @@ -0,0 +1,12 @@ +// TRAILING_COMMA_STRATEGY NONE + +class C { + constructor( + context: Context?, + attrs: AttributeSet?, + defStyleAttr: Int, + defStyleRes: Int + ) : super(context, attrs, defStyleAttr, defStyleRes) { + init(attrs) + } +} diff --git a/core/testData/format/meta/class/superConstructorCallInSecondary.expected.kt b/core/testData/format/meta/class/superConstructorCallInSecondary.expected.kt new file mode 100644 index 00000000..524590d7 --- /dev/null +++ b/core/testData/format/meta/class/superConstructorCallInSecondary.expected.kt @@ -0,0 +1,3 @@ +class Foo : Bar { + internal constructor(number: Int) : super(number) {} +} diff --git a/core/testData/format/meta/class/superConstructorCallInSecondary.kt b/core/testData/format/meta/class/superConstructorCallInSecondary.kt new file mode 100644 index 00000000..524590d7 --- /dev/null +++ b/core/testData/format/meta/class/superConstructorCallInSecondary.kt @@ -0,0 +1,3 @@ +class Foo : Bar { + internal constructor(number: Int) : super(number) {} +} diff --git a/core/testData/format/meta/class/superStatement.expected.kt b/core/testData/format/meta/class/superStatement.expected.kt new file mode 100644 index 00000000..1fd17285 --- /dev/null +++ b/core/testData/format/meta/class/superStatement.expected.kt @@ -0,0 +1,5 @@ +class Foo : Bar(), FooBar { + override fun doIt() { + super.doIt() + } +} diff --git a/core/testData/format/meta/class/superStatement.kt b/core/testData/format/meta/class/superStatement.kt new file mode 100644 index 00000000..1fd17285 --- /dev/null +++ b/core/testData/format/meta/class/superStatement.kt @@ -0,0 +1,5 @@ +class Foo : Bar(), FooBar { + override fun doIt() { + super.doIt() + } +} diff --git a/core/testData/format/meta/class/superStatement2.expected.kt b/core/testData/format/meta/class/superStatement2.expected.kt new file mode 100644 index 00000000..b3420971 --- /dev/null +++ b/core/testData/format/meta/class/superStatement2.expected.kt @@ -0,0 +1,10 @@ +class Foo : Bar(), FooBar { + override fun doIt() { + foo.doThat { + super@Foo.doIt() + + // this one is actually generics on the call expression, not super + super@Foo.doIt() + } + } +} diff --git a/core/testData/format/meta/class/superStatement2.kt b/core/testData/format/meta/class/superStatement2.kt new file mode 100644 index 00000000..b3420971 --- /dev/null +++ b/core/testData/format/meta/class/superStatement2.kt @@ -0,0 +1,10 @@ +class Foo : Bar(), FooBar { + override fun doIt() { + foo.doThat { + super@Foo.doIt() + + // this one is actually generics on the call expression, not super + super@Foo.doIt() + } + } +} diff --git a/core/testData/format/meta/class/superclasses.expected.kt b/core/testData/format/meta/class/superclasses.expected.kt new file mode 100644 index 00000000..e97649bd --- /dev/null +++ b/core/testData/format/meta/class/superclasses.expected.kt @@ -0,0 +1,9 @@ +class Derived2 : Super1, Super2 {} + +class Derived1 : Super1, Super2 + +class Derived3(a: Int) : Super1(a) + +class Derived4 : Super1() + +class Derived5 : Super3() diff --git a/core/testData/format/meta/class/superclasses.kt b/core/testData/format/meta/class/superclasses.kt new file mode 100644 index 00000000..e97649bd --- /dev/null +++ b/core/testData/format/meta/class/superclasses.kt @@ -0,0 +1,9 @@ +class Derived2 : Super1, Super2 {} + +class Derived1 : Super1, Super2 + +class Derived3(a: Int) : Super1(a) + +class Derived4 : Super1() + +class Derived5 : Super3() diff --git a/core/testData/format/meta/class/superclasses2.expected.kt b/core/testData/format/meta/class/superclasses2.expected.kt new file mode 100644 index 00000000..4f022f85 --- /dev/null +++ b/core/testData/format/meta/class/superclasses2.expected.kt @@ -0,0 +1,16 @@ +class Derived2 : + Super1, + Super2 {} + +class Derived1 : + Super1, Super2 + +class Derived3( + a: Int +) : Super1(a) + +class Derived4 : + Super1() + +class Derived5 : + Super3() diff --git a/core/testData/format/meta/class/superclasses2.kt b/core/testData/format/meta/class/superclasses2.kt new file mode 100644 index 00000000..1a0a95c0 --- /dev/null +++ b/core/testData/format/meta/class/superclasses2.kt @@ -0,0 +1,19 @@ +// MAX_WIDTH 20 +// TRAILING_COMMA_STRATEGY NONE + +class Derived2 : + Super1, + Super2 {} + +class Derived1 : + Super1, Super2 + +class Derived3( + a: Int +) : Super1(a) + +class Derived4 : + Super1() + +class Derived5 : + Super3() diff --git a/core/testData/format/meta/comment/blockComment.expected.kt b/core/testData/format/meta/comment/blockComment.expected.kt new file mode 100644 index 00000000..1d8ee63d --- /dev/null +++ b/core/testData/format/meta/comment/blockComment.expected.kt @@ -0,0 +1,7 @@ +fun foo() { + val result = + firstCond && + secondCond + /* comment. */ + && thirdCond +} diff --git a/core/testData/format/meta/comment/blockComment.kt b/core/testData/format/meta/comment/blockComment.kt new file mode 100644 index 00000000..e082c597 --- /dev/null +++ b/core/testData/format/meta/comment/blockComment.kt @@ -0,0 +1,9 @@ +// MAX_WIDTH 50 + +fun foo() { + val result = + firstCond && + secondCond + /* comment. */ + && thirdCond +} diff --git a/core/testData/format/meta/comment/newLineBetweenComments1.expected.kt b/core/testData/format/meta/comment/newLineBetweenComments1.expected.kt new file mode 100644 index 00000000..fbfaae71 --- /dev/null +++ b/core/testData/format/meta/comment/newLineBetweenComments1.expected.kt @@ -0,0 +1,4 @@ +package foo +// a + +/* Another comment */ diff --git a/core/testData/format/meta/comment/newLineBetweenComments1.kt b/core/testData/format/meta/comment/newLineBetweenComments1.kt new file mode 100644 index 00000000..fbfaae71 --- /dev/null +++ b/core/testData/format/meta/comment/newLineBetweenComments1.kt @@ -0,0 +1,4 @@ +package foo +// a + +/* Another comment */ diff --git a/core/testData/format/meta/comment/newLineBetweenComments2.expected.kt b/core/testData/format/meta/comment/newLineBetweenComments2.expected.kt new file mode 100644 index 00000000..ce510116 --- /dev/null +++ b/core/testData/format/meta/comment/newLineBetweenComments2.expected.kt @@ -0,0 +1,5 @@ +// Comment as first element +package foo +// a + +/* Another comment */ diff --git a/core/testData/format/meta/comment/newLineBetweenComments2.kt b/core/testData/format/meta/comment/newLineBetweenComments2.kt new file mode 100644 index 00000000..ce510116 --- /dev/null +++ b/core/testData/format/meta/comment/newLineBetweenComments2.kt @@ -0,0 +1,5 @@ +// Comment as first element +package foo +// a + +/* Another comment */ diff --git a/core/testData/format/meta/comment/newLineBetweenComments3.expected.kt b/core/testData/format/meta/comment/newLineBetweenComments3.expected.kt new file mode 100644 index 00000000..722ed6cb --- /dev/null +++ b/core/testData/format/meta/comment/newLineBetweenComments3.expected.kt @@ -0,0 +1,6 @@ +// Comment as first element then blank line + +package foo +// a + +/* Another comment */ diff --git a/core/testData/format/meta/comment/newLineBetweenComments3.kt b/core/testData/format/meta/comment/newLineBetweenComments3.kt new file mode 100644 index 00000000..722ed6cb --- /dev/null +++ b/core/testData/format/meta/comment/newLineBetweenComments3.kt @@ -0,0 +1,6 @@ +// Comment as first element then blank line + +package foo +// a + +/* Another comment */ diff --git a/core/testData/format/meta/comment/newLineBetweenComments4.expected.kt b/core/testData/format/meta/comment/newLineBetweenComments4.expected.kt new file mode 100644 index 00000000..80e45506 --- /dev/null +++ b/core/testData/format/meta/comment/newLineBetweenComments4.expected.kt @@ -0,0 +1,4 @@ +// Comment as first element +package foo +// Adjacent line comments +// Don't separate diff --git a/core/testData/format/meta/comment/newLineBetweenComments4.kt b/core/testData/format/meta/comment/newLineBetweenComments4.kt new file mode 100644 index 00000000..80e45506 --- /dev/null +++ b/core/testData/format/meta/comment/newLineBetweenComments4.kt @@ -0,0 +1,4 @@ +// Comment as first element +package foo +// Adjacent line comments +// Don't separate diff --git a/core/testData/format/meta/comment/shebang.expected.kts b/core/testData/format/meta/comment/shebang.expected.kts new file mode 100644 index 00000000..e05d4c9f --- /dev/null +++ b/core/testData/format/meta/comment/shebang.expected.kts @@ -0,0 +1,4 @@ +#!/usr/bin/env kscript +package foo + +println("Called") diff --git a/core/testData/format/meta/comment/shebang.kts b/core/testData/format/meta/comment/shebang.kts new file mode 100644 index 00000000..e05d4c9f --- /dev/null +++ b/core/testData/format/meta/comment/shebang.kts @@ -0,0 +1,4 @@ +#!/usr/bin/env kscript +package foo + +println("Called") diff --git a/core/testData/format/meta/comment/trailingSpace.expected.kt b/core/testData/format/meta/comment/trailingSpace.expected.kt new file mode 100644 index 00000000..66a89821 --- /dev/null +++ b/core/testData/format/meta/comment/trailingSpace.expected.kt @@ -0,0 +1 @@ +// trailing spaces in a comment are not preserved diff --git a/core/testData/format/meta/comment/trailingSpace.kt b/core/testData/format/meta/comment/trailingSpace.kt new file mode 100644 index 00000000..66a89821 --- /dev/null +++ b/core/testData/format/meta/comment/trailingSpace.kt @@ -0,0 +1 @@ +// trailing spaces in a comment are not preserved diff --git a/core/testData/format/meta/function/assignmentWithScopeFunction.expected.kt b/core/testData/format/meta/function/assignmentWithScopeFunction.expected.kt new file mode 100644 index 00000000..3310e61c --- /dev/null +++ b/core/testData/format/meta/function/assignmentWithScopeFunction.expected.kt @@ -0,0 +1,47 @@ +fun f() { + name.sub = scope { x -> + // + } + name.sub += scope { x -> + // + } + name.sub -= scope { x -> + // + } + name.sub *= scope { x -> + // + } + name.sub /= scope { x -> + // + } + name.sub %= scope { x -> + // + } +} + +fun h() { + long.name.sub = + scope { x -> + // + } + long.name.sub += + scope { x -> + // + } + long.name.sub -= + scope { x -> + // + } + long.name.sub *= + scope { x -> + // + } + long.name.sub /= + scope { x -> + // + } + long.name.sub %= + scope { x -> + // + } +} diff --git a/core/testData/format/meta/function/assignmentWithScopeFunction.kt b/core/testData/format/meta/function/assignmentWithScopeFunction.kt new file mode 100644 index 00000000..1bd2b590 --- /dev/null +++ b/core/testData/format/meta/function/assignmentWithScopeFunction.kt @@ -0,0 +1,49 @@ +// MAX_WIDTH 27 + +fun f() { + name.sub = scope { x -> + // + } + name.sub += scope { x -> + // + } + name.sub -= scope { x -> + // + } + name.sub *= scope { x -> + // + } + name.sub /= scope { x -> + // + } + name.sub %= scope { x -> + // + } +} + +fun h() { + long.name.sub = + scope { x -> + // + } + long.name.sub += + scope { x -> + // + } + long.name.sub -= + scope { x -> + // + } + long.name.sub *= + scope { x -> + // + } + long.name.sub /= + scope { x -> + // + } + long.name.sub %= + scope { x -> + // + } +} diff --git a/core/testData/format/meta/function/functionParams.expected.kt b/core/testData/format/meta/function/functionParams.expected.kt new file mode 100644 index 00000000..ef11f032 --- /dev/null +++ b/core/testData/format/meta/function/functionParams.expected.kt @@ -0,0 +1,15 @@ +fun format( + code: String, + maxWidth: Int = + DEFAULT_MAX_WIDTH_VERY_LONG +): String { + val a = 0 +} + +fun print( + code: String, + maxWidth: Int = + DEFAULT_MAX_WIDTH_VERY_LONG +) { + val a = 0 +} diff --git a/core/testData/format/meta/function/functionParams.kt b/core/testData/format/meta/function/functionParams.kt new file mode 100644 index 00000000..ec4966ac --- /dev/null +++ b/core/testData/format/meta/function/functionParams.kt @@ -0,0 +1,18 @@ +// MAX_WIDTH 40 +// TRAILING_COMMA_STRATEGY NONE + +fun format( + code: String, + maxWidth: Int = + DEFAULT_MAX_WIDTH_VERY_LONG +): String { + val a = 0 +} + +fun print( + code: String, + maxWidth: Int = + DEFAULT_MAX_WIDTH_VERY_LONG +) { + val a = 0 +} \ No newline at end of file diff --git a/core/testData/format/meta/function/lambdaAfterArgumentBreak.expected.kt b/core/testData/format/meta/function/lambdaAfterArgumentBreak.expected.kt new file mode 100644 index 00000000..56861dd5 --- /dev/null +++ b/core/testData/format/meta/function/lambdaAfterArgumentBreak.expected.kt @@ -0,0 +1,49 @@ +class Foo : Bar() { + fun doIt() { + // don't break in lambda, no argument breaks found + fruit.forEach { eat(it) } + + // break in the lambda, without comma + fruit.forEach( + someVeryLongParameterNameThatWillCauseABreak, + evenWithoutATrailingCommaOnTheParameterListSoLetsSeeIt) { + eat(it) + } + + // break in the lambda, with comma + fruit.forEach( + fromTheVine = true, + ) { + eat(it) + } + + // don't break in the inner lambda, as nesting doesn't respect outer levels + fruit.forEach( + fromTheVine = true, + ) { + fruit.forEach { eat(it) } + } + + // don't break in the lambda, as breaks don't propagate + fruit + .onlyBananas( + fromTheVine = true, + ) + .forEach { eat(it) } + + // don't break in the inner lambda, as breaks don't propagate to parameters + fruit.onlyBananas( + fromTheVine = true, + processThem = { eat(it) }, + ) { + eat(it) + } + + // don't break in the inner lambda, as breaks don't propagate to the body + fruit.onlyBananas( + fromTheVine = true, + ) { + val anon = { eat(it) } + } + } +} diff --git a/core/testData/format/meta/function/lambdaAfterArgumentBreak.kt b/core/testData/format/meta/function/lambdaAfterArgumentBreak.kt new file mode 100644 index 00000000..85be2b86 --- /dev/null +++ b/core/testData/format/meta/function/lambdaAfterArgumentBreak.kt @@ -0,0 +1,52 @@ +// MAX_WIDTH 80 +// TRAILING_COMMA_STRATEGY NONE + +class Foo : Bar() { + fun doIt() { + // don't break in lambda, no argument breaks found + fruit.forEach { eat(it) } + + // break in the lambda, without comma + fruit.forEach( + someVeryLongParameterNameThatWillCauseABreak, + evenWithoutATrailingCommaOnTheParameterListSoLetsSeeIt) { + eat(it) + } + + // break in the lambda, with comma + fruit.forEach( + fromTheVine = true, + ) { + eat(it) + } + + // don't break in the inner lambda, as nesting doesn't respect outer levels + fruit.forEach( + fromTheVine = true, + ) { + fruit.forEach { eat(it) } + } + + // don't break in the lambda, as breaks don't propagate + fruit + .onlyBananas( + fromTheVine = true, + ) + .forEach { eat(it) } + + // don't break in the inner lambda, as breaks don't propagate to parameters + fruit.onlyBananas( + fromTheVine = true, + processThem = { eat(it) }, + ) { + eat(it) + } + + // don't break in the inner lambda, as breaks don't propagate to the body + fruit.onlyBananas( + fromTheVine = true, + ) { + val anon = { eat(it) } + } + } +} diff --git a/core/testData/format/meta/function/lambdaAssignment.expected.kt b/core/testData/format/meta/function/lambdaAssignment.expected.kt new file mode 100644 index 00000000..b7c5b1f5 --- /dev/null +++ b/core/testData/format/meta/function/lambdaAssignment.expected.kt @@ -0,0 +1,11 @@ +fun doIt() { + val lambda = { + doItOnce() + doItTwice() + } +} + +fun foo() = { + doItOnce() + doItTwice() +} diff --git a/core/testData/format/meta/function/lambdaAssignment.kt b/core/testData/format/meta/function/lambdaAssignment.kt new file mode 100644 index 00000000..b7c5b1f5 --- /dev/null +++ b/core/testData/format/meta/function/lambdaAssignment.kt @@ -0,0 +1,11 @@ +fun doIt() { + val lambda = { + doItOnce() + doItTwice() + } +} + +fun foo() = { + doItOnce() + doItTwice() +} diff --git a/core/testData/format/meta/function/lambdaWithNamedArgs.expected.kt b/core/testData/format/meta/function/lambdaWithNamedArgs.expected.kt new file mode 100644 index 00000000..1abadaa5 --- /dev/null +++ b/core/testData/format/meta/function/lambdaWithNamedArgs.expected.kt @@ -0,0 +1,3 @@ +fun f() { + val b = { x: Int, y: Int -> x + y } +} diff --git a/core/testData/format/meta/function/lambdaWithNamedArgs.kt b/core/testData/format/meta/function/lambdaWithNamedArgs.kt new file mode 100644 index 00000000..1abadaa5 --- /dev/null +++ b/core/testData/format/meta/function/lambdaWithNamedArgs.kt @@ -0,0 +1,3 @@ +fun f() { + val b = { x: Int, y: Int -> x + y } +} diff --git a/core/testData/format/meta/function/lineBreaksInFunctionArguments.expected.kt b/core/testData/format/meta/function/lineBreaksInFunctionArguments.expected.kt new file mode 100644 index 00000000..6680b857 --- /dev/null +++ b/core/testData/format/meta/function/lineBreaksInFunctionArguments.expected.kt @@ -0,0 +1,14 @@ +fun f() { + computeBreaks( + javaOutput.commentsHelper, + maxWidth, + Doc.State(+0, 0)) + computeBreaks( + output.commentsHelper, maxWidth, State(0)) + doc.computeBreaks( + javaOutput.commentsHelper, + maxWidth, + Doc.State(+0, 0)) + doc.computeBreaks( + output.commentsHelper, maxWidth, State(0)) +} diff --git a/core/testData/format/meta/function/lineBreaksInFunctionArguments.kt b/core/testData/format/meta/function/lineBreaksInFunctionArguments.kt new file mode 100644 index 00000000..72d69094 --- /dev/null +++ b/core/testData/format/meta/function/lineBreaksInFunctionArguments.kt @@ -0,0 +1,17 @@ +// MAX_WIDTH 50 +// TRAILING_COMMA_STRATEGY NONE + +fun f() { + computeBreaks( + javaOutput.commentsHelper, + maxWidth, + Doc.State(+0, 0)) + computeBreaks( + output.commentsHelper, maxWidth, State(0)) + doc.computeBreaks( + javaOutput.commentsHelper, + maxWidth, + Doc.State(+0, 0)) + doc.computeBreaks( + output.commentsHelper, maxWidth, State(0)) +} diff --git a/core/testData/format/meta/function/modifiers.expected.kt b/core/testData/format/meta/function/modifiers.expected.kt new file mode 100644 index 00000000..627401c5 --- /dev/null +++ b/core/testData/format/meta/function/modifiers.expected.kt @@ -0,0 +1 @@ +override internal fun f() {} diff --git a/core/testData/format/meta/function/modifiers.kt b/core/testData/format/meta/function/modifiers.kt new file mode 100644 index 00000000..627401c5 --- /dev/null +++ b/core/testData/format/meta/function/modifiers.kt @@ -0,0 +1 @@ +override internal fun f() {} diff --git a/core/testData/format/meta/function/multiLineFunExpr.expected.kt b/core/testData/format/meta/function/multiLineFunExpr.expected.kt new file mode 100644 index 00000000..0e3f4a22 --- /dev/null +++ b/core/testData/format/meta/function/multiLineFunExpr.expected.kt @@ -0,0 +1,6 @@ +fun longFunctionNoBlock(): + Int = + 1234567 + 1234567 + +fun shortFun(): Int = + 1234567 + 1234567 diff --git a/core/testData/format/meta/function/multiLineFunExpr.kt b/core/testData/format/meta/function/multiLineFunExpr.kt new file mode 100644 index 00000000..4f708d67 --- /dev/null +++ b/core/testData/format/meta/function/multiLineFunExpr.kt @@ -0,0 +1,8 @@ +// MAX_WIDTH 26 + +fun longFunctionNoBlock(): + Int = + 1234567 + 1234567 + +fun shortFun(): Int = + 1234567 + 1234567 diff --git a/core/testData/format/meta/function/operatorExtensionFun.expected.kt b/core/testData/format/meta/function/operatorExtensionFun.expected.kt new file mode 100644 index 00000000..14d7f7ec --- /dev/null +++ b/core/testData/format/meta/function/operatorExtensionFun.expected.kt @@ -0,0 +1 @@ +operator fun Point.component1() = x diff --git a/core/testData/format/meta/function/operatorExtensionFun.kt b/core/testData/format/meta/function/operatorExtensionFun.kt new file mode 100644 index 00000000..14d7f7ec --- /dev/null +++ b/core/testData/format/meta/function/operatorExtensionFun.kt @@ -0,0 +1 @@ +operator fun Point.component1() = x diff --git a/core/testData/format/meta/function/parametersBreakWithLambda.expected.kt b/core/testData/format/meta/function/parametersBreakWithLambda.expected.kt new file mode 100644 index 00000000..6a8b0e8a --- /dev/null +++ b/core/testData/format/meta/function/parametersBreakWithLambda.expected.kt @@ -0,0 +1,10 @@ +class C { + fun method() { + Foo.FooBar( + param1, param2) + .apply { + // + foo + } + } +} diff --git a/core/testData/format/meta/function/parametersBreakWithLambda.kt b/core/testData/format/meta/function/parametersBreakWithLambda.kt new file mode 100644 index 00000000..c7d68cd1 --- /dev/null +++ b/core/testData/format/meta/function/parametersBreakWithLambda.kt @@ -0,0 +1,13 @@ +// MAX_WIDTH 27 +// TRAILING_COMMA_STRATEGY NONE + +class C { + fun method() { + Foo.FooBar( + param1, param2) + .apply { + // + foo + } + } +} diff --git a/core/testData/format/meta/function/returnExpression.expected.kt b/core/testData/format/meta/function/returnExpression.expected.kt new file mode 100644 index 00000000..0d268a3a --- /dev/null +++ b/core/testData/format/meta/function/returnExpression.expected.kt @@ -0,0 +1,3 @@ +fun print(b: Boolean?) { + print(b ?: return) +} diff --git a/core/testData/format/meta/function/returnExpression.kt b/core/testData/format/meta/function/returnExpression.kt new file mode 100644 index 00000000..0d268a3a --- /dev/null +++ b/core/testData/format/meta/function/returnExpression.kt @@ -0,0 +1,3 @@ +fun print(b: Boolean?) { + print(b ?: return) +} diff --git a/core/testData/format/meta/function/returnStatement.expected.kt b/core/testData/format/meta/function/returnStatement.expected.kt new file mode 100644 index 00000000..08698224 --- /dev/null +++ b/core/testData/format/meta/function/returnStatement.expected.kt @@ -0,0 +1,3 @@ +fun random(): Int { + return 4 +} diff --git a/core/testData/format/meta/function/returnStatement.kt b/core/testData/format/meta/function/returnStatement.kt new file mode 100644 index 00000000..08698224 --- /dev/null +++ b/core/testData/format/meta/function/returnStatement.kt @@ -0,0 +1,3 @@ +fun random(): Int { + return 4 +} diff --git a/core/testData/format/meta/function/returnStatement2.expected.kt b/core/testData/format/meta/function/returnStatement2.expected.kt new file mode 100644 index 00000000..fb186409 --- /dev/null +++ b/core/testData/format/meta/function/returnStatement2.expected.kt @@ -0,0 +1,4 @@ +fun print(b: Boolean) { + print(b) + return +} diff --git a/core/testData/format/meta/function/returnStatement2.kt b/core/testData/format/meta/function/returnStatement2.kt new file mode 100644 index 00000000..fb186409 --- /dev/null +++ b/core/testData/format/meta/function/returnStatement2.kt @@ -0,0 +1,4 @@ +fun print(b: Boolean) { + print(b) + return +} diff --git a/core/testData/format/meta/function/returnTypes.expected.kt b/core/testData/format/meta/function/returnTypes.expected.kt new file mode 100644 index 00000000..c83fcb44 --- /dev/null +++ b/core/testData/format/meta/function/returnTypes.expected.kt @@ -0,0 +1,3 @@ +fun f1(): Int = 0 + +fun f2(): Int {} diff --git a/core/testData/format/meta/function/returnTypes.kt b/core/testData/format/meta/function/returnTypes.kt new file mode 100644 index 00000000..c83fcb44 --- /dev/null +++ b/core/testData/format/meta/function/returnTypes.kt @@ -0,0 +1,3 @@ +fun f1(): Int = 0 + +fun f2(): Int {} diff --git a/core/testData/format/meta/function/returnTypes2.expected.kt b/core/testData/format/meta/function/returnTypes2.expected.kt new file mode 100644 index 00000000..3b48ff84 --- /dev/null +++ b/core/testData/format/meta/function/returnTypes2.expected.kt @@ -0,0 +1,15 @@ +interface X { + fun f( + arg1: Arg1Type, + arg2: Arg2Type + ): Map>? { + // + } + + fun functionWithGenericReturnType( + arg1: Arg1Type, + arg2: Arg2Type + ): Map>? { + // + } +} diff --git a/core/testData/format/meta/function/returnTypes2.kt b/core/testData/format/meta/function/returnTypes2.kt new file mode 100644 index 00000000..5142db05 --- /dev/null +++ b/core/testData/format/meta/function/returnTypes2.kt @@ -0,0 +1,18 @@ +// MAX_WIDTH 50 +// TRAILING_COMMA_STRATEGY NONE + +interface X { + fun f( + arg1: Arg1Type, + arg2: Arg2Type + ): Map>? { + // + } + + fun functionWithGenericReturnType( + arg1: Arg1Type, + arg2: Arg2Type + ): Map>? { + // + } +} diff --git a/core/testData/format/meta/if/blocks.expected.kt b/core/testData/format/meta/if/blocks.expected.kt new file mode 100644 index 00000000..0b5177ce --- /dev/null +++ b/core/testData/format/meta/if/blocks.expected.kt @@ -0,0 +1,11 @@ +fun numbers() { + if (true) + do { + eat("is") + matches += type() + } while (eat(",")) + else + while (1 < 2) { + println("Everything is okay") + } +} diff --git a/core/testData/format/meta/if/blocks.kt b/core/testData/format/meta/if/blocks.kt new file mode 100644 index 00000000..0b5177ce --- /dev/null +++ b/core/testData/format/meta/if/blocks.kt @@ -0,0 +1,11 @@ +fun numbers() { + if (true) + do { + eat("is") + matches += type() + } while (eat(",")) + else + while (1 < 2) { + println("Everything is okay") + } +} diff --git a/core/testData/format/meta/if/comment.expected.kt b/core/testData/format/meta/if/comment.expected.kt new file mode 100644 index 00000000..dd8f8535 --- /dev/null +++ b/core/testData/format/meta/if/comment.expected.kt @@ -0,0 +1,5 @@ +fun foo() { + if (expressions1) + // comment + bar() +} diff --git a/core/testData/format/meta/if/comment.kt b/core/testData/format/meta/if/comment.kt new file mode 100644 index 00000000..6b7f69bf --- /dev/null +++ b/core/testData/format/meta/if/comment.kt @@ -0,0 +1,7 @@ +// MAX_WIDTH 30 + +fun foo() { + if (expressions1) + // comment + bar() +} diff --git a/core/testData/format/meta/if/expr.expected.kt b/core/testData/format/meta/if/expr.expected.kt new file mode 100644 index 00000000..3646e631 --- /dev/null +++ b/core/testData/format/meta/if/expr.expected.kt @@ -0,0 +1,9 @@ +fun maybePrint(b: Boolean) { + println(if (b) 1 else 2) + println( + if (b) { + val a = 1 + 1 + 2 * a + } else 2) + return if (b) 1 else 2 +} diff --git a/core/testData/format/meta/if/expr.kt b/core/testData/format/meta/if/expr.kt new file mode 100644 index 00000000..381fef73 --- /dev/null +++ b/core/testData/format/meta/if/expr.kt @@ -0,0 +1,11 @@ +// TRAILING_COMMA_STRATEGY NONE + +fun maybePrint(b: Boolean) { + println(if (b) 1 else 2) + println( + if (b) { + val a = 1 + 1 + 2 * a + } else 2) + return if (b) 1 else 2 +} diff --git a/core/testData/format/meta/if/exprWithBreak.expected.kt b/core/testData/format/meta/if/exprWithBreak.expected.kt new file mode 100644 index 00000000..cf4a32e2 --- /dev/null +++ b/core/testData/format/meta/if/exprWithBreak.expected.kt @@ -0,0 +1,7 @@ +fun compute(b: Boolean) { + val c = + if (a + b < 20) a + b + else a + return if (a + b < 20) a + b + else c +} diff --git a/core/testData/format/meta/if/exprWithBreak.kt b/core/testData/format/meta/if/exprWithBreak.kt new file mode 100644 index 00000000..6085839f --- /dev/null +++ b/core/testData/format/meta/if/exprWithBreak.kt @@ -0,0 +1,9 @@ +// MAX_WIDTH 30 + +fun compute(b: Boolean) { + val c = + if (a + b < 20) a + b + else a + return if (a + b < 20) a + b + else c +} diff --git a/core/testData/format/meta/if/exprWithBreak2.expected.kt b/core/testData/format/meta/if/exprWithBreak2.expected.kt new file mode 100644 index 00000000..6e1cc0e4 --- /dev/null +++ b/core/testData/format/meta/if/exprWithBreak2.expected.kt @@ -0,0 +1,11 @@ +fun compute(b: Boolean) { + val c = + if (a + b < 20) + a + b + else if (a < 20) a + else + a + b + b + 1000 + return if (a + b < 20) + a + b + else c +} diff --git a/core/testData/format/meta/if/exprWithBreak2.kt b/core/testData/format/meta/if/exprWithBreak2.kt new file mode 100644 index 00000000..3cf67686 --- /dev/null +++ b/core/testData/format/meta/if/exprWithBreak2.kt @@ -0,0 +1,13 @@ +// MAX_WIDTH 26 + +fun compute(b: Boolean) { + val c = + if (a + b < 20) + a + b + else if (a < 20) a + else + a + b + b + 1000 + return if (a + b < 20) + a + b + else c +} diff --git a/core/testData/format/meta/if/multilineCond.expected.kt b/core/testData/format/meta/if/multilineCond.expected.kt new file mode 100644 index 00000000..7e8af825 --- /dev/null +++ b/core/testData/format/meta/if/multilineCond.expected.kt @@ -0,0 +1,14 @@ +fun foo() { + if (expressions1 && + expression2 && + expression3) { + bar() + } + + if (foo( + expressions1 && + expression2 && + expression3)) { + bar() + } +} diff --git a/core/testData/format/meta/if/multilineCond.kt b/core/testData/format/meta/if/multilineCond.kt new file mode 100644 index 00000000..4258c4d3 --- /dev/null +++ b/core/testData/format/meta/if/multilineCond.kt @@ -0,0 +1,17 @@ +// MAX_WIDTH 30 +// TRAILING_COMMA_STRATEGY NONE + +fun foo() { + if (expressions1 && + expression2 && + expression3) { + bar() + } + + if (foo( + expressions1 && + expression2 && + expression3)) { + bar() + } +} diff --git a/core/testData/format/meta/if/noElse.expected.kt b/core/testData/format/meta/if/noElse.expected.kt new file mode 100644 index 00000000..d91211ca --- /dev/null +++ b/core/testData/format/meta/if/noElse.expected.kt @@ -0,0 +1,5 @@ +fun maybePrint(b: Boolean) { + if (b) { + println(b) + } +} diff --git a/core/testData/format/meta/if/noElse.kt b/core/testData/format/meta/if/noElse.kt new file mode 100644 index 00000000..d91211ca --- /dev/null +++ b/core/testData/format/meta/if/noElse.kt @@ -0,0 +1,5 @@ +fun maybePrint(b: Boolean) { + if (b) { + println(b) + } +} diff --git a/core/testData/format/meta/if/withElse.expected.kt b/core/testData/format/meta/if/withElse.expected.kt new file mode 100644 index 00000000..c2bddcbb --- /dev/null +++ b/core/testData/format/meta/if/withElse.expected.kt @@ -0,0 +1,7 @@ +fun maybePrint(b: Boolean) { + if (b) { + println(2) + } else { + println(1) + } +} diff --git a/core/testData/format/meta/if/withElse.kt b/core/testData/format/meta/if/withElse.kt new file mode 100644 index 00000000..c2bddcbb --- /dev/null +++ b/core/testData/format/meta/if/withElse.kt @@ -0,0 +1,7 @@ +fun maybePrint(b: Boolean) { + if (b) { + println(2) + } else { + println(1) + } +} diff --git a/core/testData/format/meta/import/aliasedUnusedImports.expected.kt b/core/testData/format/meta/import/aliasedUnusedImports.expected.kt new file mode 100644 index 00000000..41dd627a --- /dev/null +++ b/core/testData/format/meta/import/aliasedUnusedImports.expected.kt @@ -0,0 +1,5 @@ +package com.example + +fun test() { + a("hello") +} diff --git a/core/testData/format/meta/import/aliasedUnusedImports.kt b/core/testData/format/meta/import/aliasedUnusedImports.kt new file mode 100644 index 00000000..21ccf2ec --- /dev/null +++ b/core/testData/format/meta/import/aliasedUnusedImports.kt @@ -0,0 +1,7 @@ +package com.example + +import com.notexample.a as b + +fun test() { + a("hello") +} diff --git a/core/testData/format/meta/import/aliasedUsedImports.expected.kt b/core/testData/format/meta/import/aliasedUsedImports.expected.kt new file mode 100644 index 00000000..c52b4720 --- /dev/null +++ b/core/testData/format/meta/import/aliasedUsedImports.expected.kt @@ -0,0 +1,7 @@ +package com.example + +import com.example.b as a + +fun test() { + a("hello") +} diff --git a/core/testData/format/meta/import/aliasedUsedImports.kt b/core/testData/format/meta/import/aliasedUsedImports.kt new file mode 100644 index 00000000..8c2d7f51 --- /dev/null +++ b/core/testData/format/meta/import/aliasedUsedImports.kt @@ -0,0 +1,8 @@ +package com.example + +import com.example.b as a +import com.example.c + +fun test() { + a("hello") +} diff --git a/core/testData/format/meta/import/commentsBetweenImports.expected.kt b/core/testData/format/meta/import/commentsBetweenImports.expected.kt new file mode 100644 index 00000000..7f521bfd --- /dev/null +++ b/core/testData/format/meta/import/commentsBetweenImports.expected.kt @@ -0,0 +1,12 @@ +package com.facebook.ktfmt + +/* leading comment */ +/* internal comment 1 */ +// internal comment 2 +import com.example.Sample +import com.example.abc +import com.example.bcd + +// trailing comment + +val x = Sample(abc, bcd) diff --git a/core/testData/format/meta/import/commentsBetweenImports.kt b/core/testData/format/meta/import/commentsBetweenImports.kt new file mode 100644 index 00000000..8c63756d --- /dev/null +++ b/core/testData/format/meta/import/commentsBetweenImports.kt @@ -0,0 +1,11 @@ +package com.facebook.ktfmt + +/* leading comment */ +import com.example.abc +/* internal comment 1 */ +import com.example.bcd +// internal comment 2 +import com.example.Sample +// trailing comment + +val x = Sample(abc, bcd) diff --git a/core/testData/format/meta/import/componentImports.expected.kt b/core/testData/format/meta/import/componentImports.expected.kt new file mode 100644 index 00000000..4ccaccfd --- /dev/null +++ b/core/testData/format/meta/import/componentImports.expected.kt @@ -0,0 +1,7 @@ +import com.example.component1 +import com.example.component10 +import com.example.component120 +import com.example.component2 +import com.example.component3 +import com.example.component4 +import com.example.component5 diff --git a/core/testData/format/meta/import/componentImports.kt b/core/testData/format/meta/import/componentImports.kt new file mode 100644 index 00000000..4ccaccfd --- /dev/null +++ b/core/testData/format/meta/import/componentImports.kt @@ -0,0 +1,7 @@ +import com.example.component1 +import com.example.component10 +import com.example.component120 +import com.example.component2 +import com.example.component3 +import com.example.component4 +import com.example.component5 diff --git a/core/testData/format/meta/import/importList.expected.kt b/core/testData/format/meta/import/importList.expected.kt new file mode 100644 index 00000000..9a52b376 --- /dev/null +++ b/core/testData/format/meta/import/importList.expected.kt @@ -0,0 +1,8 @@ +import abc.def /* + test */ +import com.example.common.reality.* +import com.example.common.reality.FooBar +import com.example.common.reality.FooBar2 as foosBars +import foo.bar // Test + +val x = FooBar.def { foosBars(bar) } diff --git a/core/testData/format/meta/import/importList.kt b/core/testData/format/meta/import/importList.kt new file mode 100644 index 00000000..67465cfa --- /dev/null +++ b/core/testData/format/meta/import/importList.kt @@ -0,0 +1,8 @@ + import com .example.common.reality. FooBar + import com .example.common.reality. FooBar2 as foosBars + import com .example.common.reality. * + import foo.bar // Test + import abc.def /* + test */ + +val x = FooBar.def { foosBars(bar) } \ No newline at end of file diff --git a/core/testData/format/meta/import/importsDeduplication.expected.kt b/core/testData/format/meta/import/importsDeduplication.expected.kt new file mode 100644 index 00000000..c5646ea1 --- /dev/null +++ b/core/testData/format/meta/import/importsDeduplication.expected.kt @@ -0,0 +1,8 @@ +import com.example.a as `if` +import com.example.a as we +import com.example.a as `when` +import com.example.a as wow +import com.example.b +import com.example.b.* + +val x = `if` { we.`when`(wow) } ?: b diff --git a/core/testData/format/meta/import/importsDeduplication.kt b/core/testData/format/meta/import/importsDeduplication.kt new file mode 100644 index 00000000..9ce2d21d --- /dev/null +++ b/core/testData/format/meta/import/importsDeduplication.kt @@ -0,0 +1,9 @@ +import com.example.b.* +import com.example.b +import com.example.a as `if` +import com.example.a as we +import com.example.a as `when` +import com.example.a as wow +import com.example.a as `when` + +val x = `if` { we.`when`(wow) } ?: b diff --git a/core/testData/format/meta/import/importsInKDoc.expected.kt b/core/testData/format/meta/import/importsInKDoc.expected.kt new file mode 100644 index 00000000..9848911c --- /dev/null +++ b/core/testData/format/meta/import/importsInKDoc.expected.kt @@ -0,0 +1,26 @@ +package com.example.kdoc + +import com.example.Bar +import com.example.Example +import com.example.Foo +import com.example.Param +import com.example.R +import com.example.ReturnedValue +import com.example.Sample +import com.example.exception.AnException + +/** + * [Foo] is something only mentioned here, just like [R.layout.test] and [Doc]. + * + * Old {@link JavaDocLink} that gets removed. + * + * @param unused [Param] + * @property JavaDocLink [Param] + * @return [Unit] as [ReturnedValue] + * @throws AnException + * @throws AnException + * @exception Sample.SampleException + * @sample Example + * @see Bar for more info + */ +class Dummy diff --git a/core/testData/format/meta/import/importsInKDoc.kt b/core/testData/format/meta/import/importsInKDoc.kt new file mode 100644 index 00000000..432d3bf0 --- /dev/null +++ b/core/testData/format/meta/import/importsInKDoc.kt @@ -0,0 +1,29 @@ +package com.example.kdoc + +import com.example.Bar +import com.example.Example +import com.example.Foo +import com.example.JavaDocLink +import com.example.Param +import com.example.R +import com.example.ReturnedValue +import com.example.Sample +import com.example.unused +import com.example.exception.AnException +import com.example.kdoc.Doc + +/** + * [Foo] is something only mentioned here, just like [R.layout.test] and [Doc]. + * + * Old {@link JavaDocLink} that gets removed. + * + * @throws AnException + * @exception Sample.SampleException + * @param unused [Param] + * @property JavaDocLink [Param] + * @return [Unit] as [ReturnedValue] + * @sample Example + * @see Bar for more info + * @throws AnException + */ +class Dummy diff --git a/core/testData/format/meta/import/importsInKDoc2.expected.kt b/core/testData/format/meta/import/importsInKDoc2.expected.kt new file mode 100644 index 00000000..868e2a9e --- /dev/null +++ b/core/testData/format/meta/import/importsInKDoc2.expected.kt @@ -0,0 +1,8 @@ +import com.shopping.Bag + +/** + * Some summary. + * + * @param count you can fit this many in a [Bag] + */ +fun fetchBananas(count: Int) diff --git a/core/testData/format/meta/import/importsInKDoc2.kt b/core/testData/format/meta/import/importsInKDoc2.kt new file mode 100644 index 00000000..868e2a9e --- /dev/null +++ b/core/testData/format/meta/import/importsInKDoc2.kt @@ -0,0 +1,8 @@ +import com.shopping.Bag + +/** + * Some summary. + * + * @param count you can fit this many in a [Bag] + */ +fun fetchBananas(count: Int) diff --git a/core/testData/format/meta/import/importsInKDoc3.expected.kt b/core/testData/format/meta/import/importsInKDoc3.expected.kt new file mode 100644 index 00000000..55bfd049 --- /dev/null +++ b/core/testData/format/meta/import/importsInKDoc3.expected.kt @@ -0,0 +1,9 @@ +import com.shopping.Bag + +/** + * Some summary. + * + * @param count this is how many of these wonderful fruit you can fit into the useful object that + * you may refer to as a [Bag] + */ +fun fetchBananas(count: Int) diff --git a/core/testData/format/meta/import/importsInKDoc3.kt b/core/testData/format/meta/import/importsInKDoc3.kt new file mode 100644 index 00000000..55bfd049 --- /dev/null +++ b/core/testData/format/meta/import/importsInKDoc3.kt @@ -0,0 +1,9 @@ +import com.shopping.Bag + +/** + * Some summary. + * + * @param count this is how many of these wonderful fruit you can fit into the useful object that + * you may refer to as a [Bag] + */ +fun fetchBananas(count: Int) diff --git a/core/testData/format/meta/import/importsWithBackticks.expected.kt b/core/testData/format/meta/import/importsWithBackticks.expected.kt new file mode 100644 index 00000000..0e812888 --- /dev/null +++ b/core/testData/format/meta/import/importsWithBackticks.expected.kt @@ -0,0 +1,6 @@ +import com.example.`if` +import com.example.we +import com.example.`when` +import com.example.wow + +val x = `if` { we.`when`(wow) } diff --git a/core/testData/format/meta/import/importsWithBackticks.kt b/core/testData/format/meta/import/importsWithBackticks.kt new file mode 100644 index 00000000..0e812888 --- /dev/null +++ b/core/testData/format/meta/import/importsWithBackticks.kt @@ -0,0 +1,6 @@ +import com.example.`if` +import com.example.we +import com.example.`when` +import com.example.wow + +val x = `if` { we.`when`(wow) } diff --git a/core/testData/format/meta/import/importsWithBackticks2.expected.kt b/core/testData/format/meta/import/importsWithBackticks2.expected.kt new file mode 100644 index 00000000..a5b4d153 --- /dev/null +++ b/core/testData/format/meta/import/importsWithBackticks2.expected.kt @@ -0,0 +1,6 @@ +import com.example.a as `if` +import com.example.a as we +import com.example.a as `when` +import com.example.a as wow + +val x = `if` { we.`when`(wow) } diff --git a/core/testData/format/meta/import/importsWithBackticks2.kt b/core/testData/format/meta/import/importsWithBackticks2.kt new file mode 100644 index 00000000..a5b4d153 --- /dev/null +++ b/core/testData/format/meta/import/importsWithBackticks2.kt @@ -0,0 +1,6 @@ +import com.example.a as `if` +import com.example.a as we +import com.example.a as `when` +import com.example.a as wow + +val x = `if` { we.`when`(wow) } diff --git a/core/testData/format/meta/import/importsWithTrailingExprs.expected.kt b/core/testData/format/meta/import/importsWithTrailingExprs.expected.kt new file mode 100644 index 00000000..61ade67e --- /dev/null +++ b/core/testData/format/meta/import/importsWithTrailingExprs.expected.kt @@ -0,0 +1,4 @@ +import com.example.foo +import com.example.zab // test + +val x = Sample(foo, zab) diff --git a/core/testData/format/meta/import/importsWithTrailingExprs.kt b/core/testData/format/meta/import/importsWithTrailingExprs.kt new file mode 100644 index 00000000..f834fc3d --- /dev/null +++ b/core/testData/format/meta/import/importsWithTrailingExprs.kt @@ -0,0 +1,2 @@ +import com.example.zab // test +import com.example.foo ; val x = Sample(foo, zab) diff --git a/core/testData/format/meta/import/importsWithTrailingExprs2.expected.kt b/core/testData/format/meta/import/importsWithTrailingExprs2.expected.kt new file mode 100644 index 00000000..05c97370 --- /dev/null +++ b/core/testData/format/meta/import/importsWithTrailingExprs2.expected.kt @@ -0,0 +1,4 @@ +import com.example.foo +import com.example.zab /* heya */ + +val x = Sample(foo, zab) diff --git a/core/testData/format/meta/import/importsWithTrailingExprs2.kt b/core/testData/format/meta/import/importsWithTrailingExprs2.kt new file mode 100644 index 00000000..11ca4b03 --- /dev/null +++ b/core/testData/format/meta/import/importsWithTrailingExprs2.kt @@ -0,0 +1,2 @@ +import com.example.zab /* heya */ +import com.example.foo ; val x = Sample(foo, zab) diff --git a/core/testData/format/meta/import/importsWithTrailingExprs3.expected.kt b/core/testData/format/meta/import/importsWithTrailingExprs3.expected.kt new file mode 100644 index 00000000..7166caa6 --- /dev/null +++ b/core/testData/format/meta/import/importsWithTrailingExprs3.expected.kt @@ -0,0 +1,4 @@ +import com.example.foo +import com.example.zab /* // */ + +val x = Sample(foo, zab) diff --git a/core/testData/format/meta/import/importsWithTrailingExprs3.kt b/core/testData/format/meta/import/importsWithTrailingExprs3.kt new file mode 100644 index 00000000..ced53ee0 --- /dev/null +++ b/core/testData/format/meta/import/importsWithTrailingExprs3.kt @@ -0,0 +1,2 @@ +import com.example.zab /* // */ +import com.example.foo ; val x = Sample(foo, zab) \ No newline at end of file diff --git a/core/testData/format/meta/import/keepUnusedImports.expected.kt b/core/testData/format/meta/import/keepUnusedImports.expected.kt new file mode 100644 index 00000000..db5e2895 --- /dev/null +++ b/core/testData/format/meta/import/keepUnusedImports.expected.kt @@ -0,0 +1,9 @@ +import com.unused.FooBarBaz as Baz +import com.unused.Sample +import com.unused.a as `when` +import com.unused.a as wow +import com.unused.a.* +import com.unused.b as `if` +import com.unused.b as we +import com.unused.bar // test +import com.unused.`class` diff --git a/core/testData/format/meta/import/keepUnusedImports.kt b/core/testData/format/meta/import/keepUnusedImports.kt new file mode 100644 index 00000000..1fb127bb --- /dev/null +++ b/core/testData/format/meta/import/keepUnusedImports.kt @@ -0,0 +1,11 @@ +// REMOVE_UNUSED_IMPORTS false + +import com.unused.FooBarBaz as Baz +import com.unused.Sample +import com.unused.a as `when` +import com.unused.a as wow +import com.unused.a.* +import com.unused.b as `if` +import com.unused.b as we +import com.unused.bar // test +import com.unused.`class` diff --git a/core/testData/format/meta/import/noImports.expected.kt b/core/testData/format/meta/import/noImports.expected.kt new file mode 100644 index 00000000..439fa2cc --- /dev/null +++ b/core/testData/format/meta/import/noImports.expected.kt @@ -0,0 +1,5 @@ +package foo123 + +/* +bar +*/ diff --git a/core/testData/format/meta/import/noImports.kt b/core/testData/format/meta/import/noImports.kt new file mode 100644 index 00000000..439fa2cc --- /dev/null +++ b/core/testData/format/meta/import/noImports.kt @@ -0,0 +1,5 @@ +package foo123 + +/* +bar +*/ diff --git a/core/testData/format/meta/import/operatorImports.expected.kt b/core/testData/format/meta/import/operatorImports.expected.kt new file mode 100644 index 00000000..86814ff5 --- /dev/null +++ b/core/testData/format/meta/import/operatorImports.expected.kt @@ -0,0 +1,33 @@ +import com.example.and +import com.example.compareTo +import com.example.contains +import com.example.dec +import com.example.div +import com.example.divAssign +import com.example.equals +import com.example.get +import com.example.getValue +import com.example.hasNext +import com.example.inc +import com.example.invoke +import com.example.iterator +import com.example.minus +import com.example.minusAssign +import com.example.mod +import com.example.modAssign +import com.example.next +import com.example.not +import com.example.or +import com.example.plus +import com.example.plusAssign +import com.example.provideDelegate +import com.example.rangeTo +import com.example.rem +import com.example.remAssign +import com.example.set +import com.example.setValue +import com.example.times +import com.example.timesAssign +import com.example.unaryMinus +import com.example.unaryPlus +import org.gradle.kotlin.dsl.assign diff --git a/core/testData/format/meta/import/operatorImports.kt b/core/testData/format/meta/import/operatorImports.kt new file mode 100644 index 00000000..86814ff5 --- /dev/null +++ b/core/testData/format/meta/import/operatorImports.kt @@ -0,0 +1,33 @@ +import com.example.and +import com.example.compareTo +import com.example.contains +import com.example.dec +import com.example.div +import com.example.divAssign +import com.example.equals +import com.example.get +import com.example.getValue +import com.example.hasNext +import com.example.inc +import com.example.invoke +import com.example.iterator +import com.example.minus +import com.example.minusAssign +import com.example.mod +import com.example.modAssign +import com.example.next +import com.example.not +import com.example.or +import com.example.plus +import com.example.plusAssign +import com.example.provideDelegate +import com.example.rangeTo +import com.example.rem +import com.example.remAssign +import com.example.set +import com.example.setValue +import com.example.times +import com.example.timesAssign +import com.example.unaryMinus +import com.example.unaryPlus +import org.gradle.kotlin.dsl.assign diff --git a/core/testData/format/meta/import/packageName.expected.kt b/core/testData/format/meta/import/packageName.expected.kt new file mode 100644 index 00000000..09c64e25 --- /dev/null +++ b/core/testData/format/meta/import/packageName.expected.kt @@ -0,0 +1,3 @@ +package com.example.subexample + +fun f() = 1 diff --git a/core/testData/format/meta/import/packageName.kt b/core/testData/format/meta/import/packageName.kt new file mode 100644 index 00000000..a2d561d7 --- /dev/null +++ b/core/testData/format/meta/import/packageName.kt @@ -0,0 +1,3 @@ + package com .example. subexample + +fun f() = 1 diff --git a/core/testData/format/meta/import/packageNameWithEscapes.expected.kt b/core/testData/format/meta/import/packageNameWithEscapes.expected.kt new file mode 100644 index 00000000..445a0edc --- /dev/null +++ b/core/testData/format/meta/import/packageNameWithEscapes.expected.kt @@ -0,0 +1,5 @@ +package com.`fun times`.`with package names` + +import `nothing stops`.`us`.`from doing this` + +fun f() = `from doing this`() diff --git a/core/testData/format/meta/import/packageNameWithEscapes.kt b/core/testData/format/meta/import/packageNameWithEscapes.kt new file mode 100644 index 00000000..445a0edc --- /dev/null +++ b/core/testData/format/meta/import/packageNameWithEscapes.kt @@ -0,0 +1,5 @@ +package com.`fun times`.`with package names` + +import `nothing stops`.`us`.`from doing this` + +fun f() = `from doing this`() diff --git a/core/testData/format/meta/import/packageNamesNotBroken.expected.kt b/core/testData/format/meta/import/packageNamesNotBroken.expected.kt new file mode 100644 index 00000000..13ecef3b --- /dev/null +++ b/core/testData/format/meta/import/packageNamesNotBroken.expected.kt @@ -0,0 +1,14 @@ +fun f() { + com.facebook.Foo + .format() + org.facebook.Foo + .format() + java.lang.stuff.Foo + .format() + javax.lang.stuff.Foo + .format() + kotlin.lang.Foo + .format() + foo.facebook.Foo + .format() +} diff --git a/core/testData/format/meta/import/packageNamesNotBroken.kt b/core/testData/format/meta/import/packageNamesNotBroken.kt new file mode 100644 index 00000000..aafac04c --- /dev/null +++ b/core/testData/format/meta/import/packageNamesNotBroken.kt @@ -0,0 +1,16 @@ +// MAX_WIDTH 25 + +fun f() { + com.facebook.Foo + .format() + org.facebook.Foo + .format() + java.lang.stuff.Foo + .format() + javax.lang.stuff.Foo + .format() + kotlin.lang.Foo + .format() + foo.facebook.Foo + .format() +} diff --git a/core/testData/format/meta/import/unusedImports.expected.kt b/core/testData/format/meta/import/unusedImports.expected.kt new file mode 100644 index 00000000..33cd8e24 --- /dev/null +++ b/core/testData/format/meta/import/unusedImports.expected.kt @@ -0,0 +1,12 @@ +import com.used.FooBarBaz as Baz +import com.used.a.* +import com.used.b as `if` +import com.used.b as we +import com.used.bar // test +import com.used.`class` + +fun test(input: we) { + Baz(`class`) + `if` { bar } + val x = unused() +} diff --git a/core/testData/format/meta/import/unusedImports.kt b/core/testData/format/meta/import/unusedImports.kt new file mode 100644 index 00000000..276a1224 --- /dev/null +++ b/core/testData/format/meta/import/unusedImports.kt @@ -0,0 +1,15 @@ +import com.unused.Sample +import com.used.FooBarBaz as Baz +import com.used.bar // test +import com.used.`class` +import com.used.a.* +import com.used.b as `if` +import com.used.b as we +import com.unused.a as `when` +import com.unused.a as wow + +fun test(input: we) { + Baz(`class`) + `if` { bar } + val x = unused() +} diff --git a/core/testData/format/meta/import/unusedImportsOverloaded.expected.kt b/core/testData/format/meta/import/unusedImportsOverloaded.expected.kt new file mode 100644 index 00000000..3b16db50 --- /dev/null +++ b/core/testData/format/meta/import/unusedImportsOverloaded.expected.kt @@ -0,0 +1,11 @@ +package com.example + +import com.example.a +import com.example.c +import com.notexample.a +import com.notexample.notC as c + +fun test() { + a("hello") + c("hello") +} diff --git a/core/testData/format/meta/import/unusedImportsOverloaded.kt b/core/testData/format/meta/import/unusedImportsOverloaded.kt new file mode 100644 index 00000000..56839e1a --- /dev/null +++ b/core/testData/format/meta/import/unusedImportsOverloaded.kt @@ -0,0 +1,13 @@ +package com.example + +import com.example.a +import com.example.b +import com.example.c +import com.notexample.a +import com.notexample.b +import com.notexample.notC as c + +fun test() { + a("hello") + c("hello") +} diff --git a/core/testData/format/meta/import/unusedImportsWithBackticks.expected.kt b/core/testData/format/meta/import/unusedImportsWithBackticks.expected.kt new file mode 100644 index 00000000..f881bfd8 --- /dev/null +++ b/core/testData/format/meta/import/unusedImportsWithBackticks.expected.kt @@ -0,0 +1,4 @@ +import `com.example.Foo.bar` +import `com.example.Foo.baz` as qux + +fun test() = bar + qux diff --git a/core/testData/format/meta/import/unusedImportsWithBackticks.kt b/core/testData/format/meta/import/unusedImportsWithBackticks.kt new file mode 100644 index 00000000..6f64d8d5 --- /dev/null +++ b/core/testData/format/meta/import/unusedImportsWithBackticks.kt @@ -0,0 +1,5 @@ +import `com.example.Foo.bar` +import `com.example.Foo.baz` as qux +import `com.example.unused.Quux` + +fun test() = bar + qux diff --git a/core/testData/format/meta/import/usedImportsFromSamePackage.expected.kt b/core/testData/format/meta/import/usedImportsFromSamePackage.expected.kt new file mode 100644 index 00000000..3d7b96d7 --- /dev/null +++ b/core/testData/format/meta/import/usedImportsFromSamePackage.expected.kt @@ -0,0 +1,8 @@ +package com.example + +import com.example.Sample.CONSTANT +import com.example.a.foo + +fun test() { + foo(CONSTANT, Sample()) +} diff --git a/core/testData/format/meta/import/usedImportsFromSamePackage.kt b/core/testData/format/meta/import/usedImportsFromSamePackage.kt new file mode 100644 index 00000000..58f66084 --- /dev/null +++ b/core/testData/format/meta/import/usedImportsFromSamePackage.kt @@ -0,0 +1,9 @@ +package com.example + +import com.example.Sample +import com.example.Sample.CONSTANT +import com.example.a.foo + +fun test() { + foo(CONSTANT, Sample()) +} diff --git a/core/testData/format/meta/kdoc/basic.expected.kt b/core/testData/format/meta/kdoc/basic.expected.kt new file mode 100644 index 00000000..ee037c35 --- /dev/null +++ b/core/testData/format/meta/kdoc/basic.expected.kt @@ -0,0 +1,2 @@ +/** foo */ +class F {} diff --git a/core/testData/format/meta/kdoc/basic.kt b/core/testData/format/meta/kdoc/basic.kt new file mode 100644 index 00000000..30c4f416 --- /dev/null +++ b/core/testData/format/meta/kdoc/basic.kt @@ -0,0 +1,5 @@ +/** + * foo + */ class F { + + } diff --git a/core/testData/format/meta/kdoc/htmlTags.expected.kt b/core/testData/format/meta/kdoc/htmlTags.expected.kt new file mode 100644 index 00000000..99358b4a --- /dev/null +++ b/core/testData/format/meta/kdoc/htmlTags.expected.kt @@ -0,0 +1,8 @@ +/** + * Bla bla bla bla + * + * This is an inferred paragraph, and as you can see, we don't add a p tag to it, even though bla + * bla. + * + *