diff --git a/plugins/stream-debugger/src/test/java/com/intellij/debugger/streams/trace/dsl/DslTestCase.kt b/plugins/stream-debugger/src/test/java/com/intellij/debugger/streams/trace/dsl/DslTestCase.kt new file mode 100644 index 000000000000..0c19462d89df --- /dev/null +++ b/plugins/stream-debugger/src/test/java/com/intellij/debugger/streams/trace/dsl/DslTestCase.kt @@ -0,0 +1,154 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.debugger.streams.trace.dsl + +import com.intellij.testFramework.UsefulTestCase +import com.intellij.testFramework.fixtures.LightCodeInsightFixtureTestCase + +/** + * @author Vitaliy.Bibaev + */ +abstract class DslTestCase(private val directoryName: String, private val dsl: Dsl) : LightCodeInsightFixtureTestCase() { + fun testCall() { + doTest { + call(+"this", "method") + } + } + + fun testCallOneArg() { + doTest { + call(+"this", "method", +"10") + } + } + + fun testCallManyArgs() { + doTest { + call(+"this", "method", +"10", +"20", +"30") + } + } + + fun testDeclareMutableVariable() { + doTest { + declare(variable("int", "a"), true) + } + } + + fun testDeclareImmutableVariable() { + doTest { + +variable("int", "a") + } + } + + fun testDeclareVariableAndInit() { + doTest { + declare(variable("int", "a"), +"10", false) + } + } + + fun testUseVariable() { + doTest { + declare(variable("int", "a"), +"100", true) + declare(variable("int", "b"), +"a", false) + } + } + + fun testIf() { + doTest { + ifBranch(+"true") { + call(+"receiver", "success") + } + } + } + + fun testIfElse() { + doTest { + ifBranch(+"false") { + call(+"this", "success") + }.elseBranch { + call(+"this", "fail") + } + } + } + + fun testIfElseIf() { + doTest { + ifBranch(+"false") { + call(+"this", "success") + }.elseIfBranch(+"true") { + call(+"this", "failSuccess") + } + } + } + + fun testIfElseIfElse() { + doTest { + ifBranch(+"false") { + call(+"this", "success") + }.elseIfBranch(+"true") { + call(+"this", "failSuccess") + }.elseBranch { + call(+"this", "failFail") + } + } + } + + fun testForEach() { + doTest { + val objects = declare(variable("List", "objects"), +"getObjects()", false) + forEachLoop(variable("Object", "object"), objects) { + +(variable.call("toString")) + } + } + } + + fun testForLoop() { + doTest { + val objects = declare(variable("List", "objects"), +"getObjects()", false) + val i = variable("int", "i") + forLoop(declaration(i, +"0", true), +"i < $objects.size()", +"i++") { + +(variable.call("toString")) + } + } + } + + fun testLambdaWithExpression() { + doTest { + +lambda("x") { + +(+argName).call("method") + } + } + } + + fun testLambdaWithCodeBlock() { + doTest { + +lambda("y") { + +(+argName).call("method1") + +(+argName).call("method2") + } + } + } + + private fun doTest(block: Dsl.() -> Unit) { + dsl.block() + check() + } + + private fun check() { + val actualText = dsl.toCode() + val testName = getTestName(true) + UsefulTestCase.assertSameLinesWithFile("testData/dsl/$directoryName/$testName.out", actualText, false) + } +} diff --git a/plugins/stream-debugger/src/test/java/com/intellij/debugger/streams/trace/dsl/JavaDslTest.kt b/plugins/stream-debugger/src/test/java/com/intellij/debugger/streams/trace/dsl/JavaDslTest.kt new file mode 100644 index 000000000000..d46ce511de44 --- /dev/null +++ b/plugins/stream-debugger/src/test/java/com/intellij/debugger/streams/trace/dsl/JavaDslTest.kt @@ -0,0 +1,24 @@ +/* + * Copyright 2000-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package com.intellij.debugger.streams.trace.dsl + +import com.intellij.debugger.streams.trace.dsl.impl.DslImpl +import com.intellij.debugger.streams.trace.dsl.impl.java.JavaStatementFactory + +/** + * @author Vitaliy.Bibaev + */ +class JavaDslTest : DslTestCase("java", DslImpl(JavaStatementFactory())) \ No newline at end of file diff --git a/plugins/stream-debugger/testData/dsl/java/call.out b/plugins/stream-debugger/testData/dsl/java/call.out new file mode 100644 index 000000000000..b07bc378f4bd --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/call.out @@ -0,0 +1 @@ +this.method(); diff --git a/plugins/stream-debugger/testData/dsl/java/callManyArgs.out b/plugins/stream-debugger/testData/dsl/java/callManyArgs.out new file mode 100644 index 000000000000..410318a48e9d --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/callManyArgs.out @@ -0,0 +1 @@ +this.method(10, 20, 30); diff --git a/plugins/stream-debugger/testData/dsl/java/callOneArg.out b/plugins/stream-debugger/testData/dsl/java/callOneArg.out new file mode 100644 index 000000000000..da332243c5f7 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/callOneArg.out @@ -0,0 +1 @@ +this.method(10); diff --git a/plugins/stream-debugger/testData/dsl/java/declareImmutableVariable.out b/plugins/stream-debugger/testData/dsl/java/declareImmutableVariable.out new file mode 100644 index 000000000000..4e610c04d583 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/declareImmutableVariable.out @@ -0,0 +1 @@ +int a; diff --git a/plugins/stream-debugger/testData/dsl/java/declareMutableVariable.out b/plugins/stream-debugger/testData/dsl/java/declareMutableVariable.out new file mode 100644 index 000000000000..4e610c04d583 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/declareMutableVariable.out @@ -0,0 +1 @@ +int a; diff --git a/plugins/stream-debugger/testData/dsl/java/declareVariableAndInit.out b/plugins/stream-debugger/testData/dsl/java/declareVariableAndInit.out new file mode 100644 index 000000000000..dee0e0daaa80 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/declareVariableAndInit.out @@ -0,0 +1 @@ +final int a = 10; diff --git a/plugins/stream-debugger/testData/dsl/java/forEach.out b/plugins/stream-debugger/testData/dsl/java/forEach.out new file mode 100644 index 000000000000..1a1a985cfa17 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/forEach.out @@ -0,0 +1,4 @@ +final List objects = getObjects(); +for (Object object : objects) { + object.toString(); +}; diff --git a/plugins/stream-debugger/testData/dsl/java/forLoop.out b/plugins/stream-debugger/testData/dsl/java/forLoop.out new file mode 100644 index 000000000000..5d79191a20ba --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/forLoop.out @@ -0,0 +1,4 @@ +final List objects = getObjects(); +for (int i = 0; i < objects.size(); i++) { + i.toString(); +}; diff --git a/plugins/stream-debugger/testData/dsl/java/if.out b/plugins/stream-debugger/testData/dsl/java/if.out new file mode 100644 index 000000000000..16ff7eb510e1 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/if.out @@ -0,0 +1,3 @@ +if(true) { + receiver.success(); +} ; diff --git a/plugins/stream-debugger/testData/dsl/java/ifElse.out b/plugins/stream-debugger/testData/dsl/java/ifElse.out new file mode 100644 index 000000000000..43a4918f3aa4 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/ifElse.out @@ -0,0 +1,5 @@ +if(false) { + this.success(); +} else { + this.fail(); +}; diff --git a/plugins/stream-debugger/testData/dsl/java/ifElseIf.out b/plugins/stream-debugger/testData/dsl/java/ifElseIf.out new file mode 100644 index 000000000000..d2b8b7bb11b1 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/ifElseIf.out @@ -0,0 +1,7 @@ +if(false) { + this.success(); +} else { + if(true) { + this.failSuccess(); + } ; +}; diff --git a/plugins/stream-debugger/testData/dsl/java/ifElseIfElse.out b/plugins/stream-debugger/testData/dsl/java/ifElseIfElse.out new file mode 100644 index 000000000000..685f166ce3f0 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/ifElseIfElse.out @@ -0,0 +1,9 @@ +if(false) { + this.success(); +} else { + if(true) { + this.failSuccess(); + } else { + this.failFail(); + }; +}; diff --git a/plugins/stream-debugger/testData/dsl/java/lambdaWithCodeBlock.out b/plugins/stream-debugger/testData/dsl/java/lambdaWithCodeBlock.out new file mode 100644 index 000000000000..ebf9ae18b5c5 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/lambdaWithCodeBlock.out @@ -0,0 +1,3 @@ +y -> { y.method1(); + y.method2(); +}; diff --git a/plugins/stream-debugger/testData/dsl/java/lambdaWithExpression.out b/plugins/stream-debugger/testData/dsl/java/lambdaWithExpression.out new file mode 100644 index 000000000000..079f7102d574 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/lambdaWithExpression.out @@ -0,0 +1 @@ +x -> x.method(); diff --git a/plugins/stream-debugger/testData/dsl/java/useVariable.out b/plugins/stream-debugger/testData/dsl/java/useVariable.out new file mode 100644 index 000000000000..7c2f946a91f5 --- /dev/null +++ b/plugins/stream-debugger/testData/dsl/java/useVariable.out @@ -0,0 +1,2 @@ +int a = 100; +final int b = a;