Added range iteration test with non-literal ranges.

This commit is contained in:
Evgeny Gerashchenko
2013-02-08 13:32:32 +04:00
parent 814cb6e255
commit 5a4ae00970
5 changed files with 160 additions and 3 deletions
@@ -0,0 +1,69 @@
// Auto-generated by org.jetbrains.jet.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
import java.util.ArrayList
fun box(): String {
val list1 = ArrayList<Int>()
val range1 = (1 + 2)..(10 - 1)
for (i in range1) {
list1.add(i)
}
if (list1 != listOf<Int>(3, 4, 5, 6, 7, 8, 9)) {
return "Wrong elements for (1 + 2)..(10 - 1): $list1"
}
val list2 = ArrayList<Byte>()
val range2 = (1.toByte() + 2.toByte()).toByte()..(10.toByte() - 1.toByte()).toByte()
for (i in range2) {
list2.add(i)
}
if (list2 != listOf<Byte>(3, 4, 5, 6, 7, 8, 9)) {
return "Wrong elements for (1.toByte() + 2.toByte()).toByte()..(10.toByte() - 1.toByte()).toByte(): $list2"
}
val list3 = ArrayList<Short>()
val range3 = (1.toShort() + 2.toShort()).toShort()..(10.toShort() - 1.toShort()).toShort()
for (i in range3) {
list3.add(i)
}
if (list3 != listOf<Short>(3, 4, 5, 6, 7, 8, 9)) {
return "Wrong elements for (1.toShort() + 2.toShort()).toShort()..(10.toShort() - 1.toShort()).toShort(): $list3"
}
val list4 = ArrayList<Long>()
val range4 = (1.toLong() + 2.toLong())..(10.toLong() - 1.toLong())
for (i in range4) {
list4.add(i)
}
if (list4 != listOf<Long>(3, 4, 5, 6, 7, 8, 9)) {
return "Wrong elements for (1.toLong() + 2.toLong())..(10.toLong() - 1.toLong()): $list4"
}
val list5 = ArrayList<Char>()
val range5 = ("ace"[1])..("age"[1])
for (i in range5) {
list5.add(i)
}
if (list5 != listOf<Char>('c', 'd', 'e', 'f', 'g')) {
return "Wrong elements for (\"ace\"[1])..(\"age\"[1]): $list5"
}
val list6 = ArrayList<Double>()
val range6 = (1.5 * 2)..(3.0 * 3.0)
for (i in range6) {
list6.add(i)
}
if (list6 != listOf<Double>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)) {
return "Wrong elements for (1.5 * 2)..(3.0 * 3.0): $list6"
}
val list7 = ArrayList<Float>()
val range7 = (1.5.toFloat() * 2.toFloat())..(3.0.toFloat() * 3.0.toFloat())
for (i in range7) {
list7.add(i)
}
if (list7 != listOf<Float>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)) {
return "Wrong elements for (1.5.toFloat() * 2.toFloat())..(3.0.toFloat() * 3.0.toFloat()): $list7"
}
return "OK"
}
@@ -0,0 +1,62 @@
// Auto-generated by org.jetbrains.jet.generators.tests.GenerateRangesCodegenTestData. DO NOT EDIT!
import java.util.ArrayList
fun box(): String {
val list1 = ArrayList<Int>()
for (i in (1 + 2)..(10 - 1)) {
list1.add(i)
}
if (list1 != listOf<Int>(3, 4, 5, 6, 7, 8, 9)) {
return "Wrong elements for (1 + 2)..(10 - 1): $list1"
}
val list2 = ArrayList<Byte>()
for (i in (1.toByte() + 2.toByte()).toByte()..(10.toByte() - 1.toByte()).toByte()) {
list2.add(i)
}
if (list2 != listOf<Byte>(3, 4, 5, 6, 7, 8, 9)) {
return "Wrong elements for (1.toByte() + 2.toByte()).toByte()..(10.toByte() - 1.toByte()).toByte(): $list2"
}
val list3 = ArrayList<Short>()
for (i in (1.toShort() + 2.toShort()).toShort()..(10.toShort() - 1.toShort()).toShort()) {
list3.add(i)
}
if (list3 != listOf<Short>(3, 4, 5, 6, 7, 8, 9)) {
return "Wrong elements for (1.toShort() + 2.toShort()).toShort()..(10.toShort() - 1.toShort()).toShort(): $list3"
}
val list4 = ArrayList<Long>()
for (i in (1.toLong() + 2.toLong())..(10.toLong() - 1.toLong())) {
list4.add(i)
}
if (list4 != listOf<Long>(3, 4, 5, 6, 7, 8, 9)) {
return "Wrong elements for (1.toLong() + 2.toLong())..(10.toLong() - 1.toLong()): $list4"
}
val list5 = ArrayList<Char>()
for (i in ("ace"[1])..("age"[1])) {
list5.add(i)
}
if (list5 != listOf<Char>('c', 'd', 'e', 'f', 'g')) {
return "Wrong elements for (\"ace\"[1])..(\"age\"[1]): $list5"
}
val list6 = ArrayList<Double>()
for (i in (1.5 * 2)..(3.0 * 3.0)) {
list6.add(i)
}
if (list6 != listOf<Double>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)) {
return "Wrong elements for (1.5 * 2)..(3.0 * 3.0): $list6"
}
val list7 = ArrayList<Float>()
for (i in (1.5.toFloat() * 2.toFloat())..(3.0.toFloat() * 3.0.toFloat())) {
list7.add(i)
}
if (list7 != listOf<Float>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0)) {
return "Wrong elements for (1.5.toFloat() * 2.toFloat())..(3.0.toFloat() * 3.0.toFloat()): $list7"
}
return "OK"
}
@@ -466,6 +466,11 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/ranges/expression/simpleRange.kt");
}
@TestMetadata("simpleRangeWithNonConstantEnds.kt")
public void testSimpleRangeWithNonConstantEnds() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/ranges/expression/simpleRangeWithNonConstantEnds.kt");
}
@TestMetadata("simpleSteppedDownTo.kt")
public void testSimpleSteppedDownTo() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/ranges/expression/simpleSteppedDownTo.kt");
@@ -554,6 +559,11 @@ public class BlackBoxWithStdlibCodegenTestGenerated extends AbstractBlackBoxCode
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/ranges/literal/simpleRange.kt");
}
@TestMetadata("simpleRangeWithNonConstantEnds.kt")
public void testSimpleRangeWithNonConstantEnds() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/ranges/literal/simpleRangeWithNonConstantEnds.kt");
}
@TestMetadata("simpleSteppedDownTo.kt")
public void testSimpleSteppedDownTo() throws Exception {
doTestWithStdlib("compiler/testData/codegen/boxWithStdlib/ranges/literal/simpleSteppedDownTo.kt");
@@ -17,6 +17,7 @@
package org.jetbrains.jet.generators.tests;
import com.intellij.openapi.util.io.FileUtil;
import com.intellij.openapi.util.text.StringUtil;
import com.intellij.util.LineSeparator;
import java.io.File;
@@ -40,7 +41,7 @@ public class GenerateRangesCodegenTestData {
" $LIST.add(i)\n" +
" }\n" +
" if ($LIST != listOf<$TYPE>($LIST_ELEMENTS)) {\n" +
" return \"Wrong elements for $RANGE_EXPR: $$LIST\"\n" +
" return \"Wrong elements for $RANGE_EXPR_ESCAPED: $$LIST\"\n" +
" }\n" +
"\n";
@@ -50,7 +51,7 @@ public class GenerateRangesCodegenTestData {
" $LIST.add(i)\n" +
" }\n" +
" if ($LIST != listOf<$TYPE>($LIST_ELEMENTS)) {\n" +
" return \"Wrong elements for $RANGE_EXPR: $$LIST\"\n" +
" return \"Wrong elements for $RANGE_EXPR_ESCAPED: $$LIST\"\n" +
" }\n" +
"\n";
@@ -59,7 +60,7 @@ public class GenerateRangesCodegenTestData {
if (matcher.find()) {
return matcher.group(1);
}
if (rangeExpression.contains("'")) {
if (rangeExpression.contains("'") || rangeExpression.contains("\"")) {
return "Char";
}
if (Pattern.compile("\\d\\.\\d").matcher(rangeExpression).find()) {
@@ -70,6 +71,7 @@ public class GenerateRangesCodegenTestData {
private static String renderTemplate(String template, int number, String elementType, String rangeExpression, String expectedListElements) {
return template
.replace("$RANGE_EXPR_ESCAPED", StringUtil.escapeStringCharacters(rangeExpression))
.replace("$RANGE_EXPR", rangeExpression)
.replace("$LIST_ELEMENTS", expectedListElements)
.replace("$LIST", "list" + number)
@@ -69,6 +69,20 @@ public class RangeIterationTest {
}
test fun simpleRangeWithNonConstantEnds() {
doTest((1 + 2)..(10 - 1), 3, 9, 1, listOf(3, 4, 5, 6, 7, 8, 9))
doTest((1.toByte() + 2.toByte()).toByte()..(10.toByte() - 1.toByte()).toByte(), 3.toByte(), 9.toByte(), 1, listOf<Byte>(3, 4, 5, 6, 7, 8, 9))
doTest((1.toShort() + 2.toShort()).toShort()..(10.toShort() - 1.toShort()).toShort(), 3.toShort(), 9.toShort(), 1, listOf<Short>(3, 4, 5, 6, 7, 8, 9))
doTest((1.toLong() + 2.toLong())..(10.toLong() - 1.toLong()), 3.toLong(), 9.toLong(), 1.toLong(), listOf<Long>(3, 4, 5, 6, 7, 8, 9))
doTest(("ace"[1])..("age"[1]), 'c', 'g', 1, listOf('c', 'd', 'e', 'f', 'g'))
doTest((1.5 * 2)..(3.0 * 3.0), 3.0, 9.0, 1.0, listOf(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))
doTest((1.5.toFloat() * 2.toFloat())..(3.0.toFloat() * 3.0.toFloat()), 3.0.toFloat(), 9.0.toFloat(), 1.toFloat(),
listOf<Float>(3.0, 4.0, 5.0, 6.0, 7.0, 8.0, 9.0))
}
test fun emptyDownto() {
doTest(5 downTo 10, 5, 10, -1, listOf())
doTest(5.toByte() downTo 10.toByte(), 5.toByte(), 10.toByte(), -1, listOf())