From 85827b488043c856d7dd051af34df6ff1db1c894 Mon Sep 17 00:00:00 2001 From: Ilya Matveev Date: Tue, 4 Apr 2017 18:20:09 +0700 Subject: [PATCH] tests: Copy stdlib tests from Kotlin/JVM This patch copies Kotlin/JVM stdlib tests (libraries/stdlib/test) excepting ones with explicit java dependencies. It also transforms the tests to use them as box-tests. --- .../stdlib/OrderingTest/combineComparators.kt | 26 ++++ .../stdlib/OrderingTest/compareByCompareTo.kt | 16 +++ .../stdlib/OrderingTest/compareByNameFirst.kt | 16 +++ .../OrderingTest/compareByRatingFirst.kt | 16 +++ .../stdlib/OrderingTest/compareNullables.kt | 21 +++ .../compareSameObjectsByRatingFirst.kt | 15 ++ .../external/stdlib/OrderingTest/maxOf.kt | 14 ++ .../external/stdlib/OrderingTest/maxOfWith.kt | 19 +++ .../external/stdlib/OrderingTest/minOf.kt | 14 ++ .../external/stdlib/OrderingTest/minOfWith.kt | 19 +++ .../OrderingTest/naturalOrderComparator.kt | 21 +++ .../stdlib/OrderingTest/reversedComparator.kt | 18 +++ .../stdlib/OrderingTest/sortByThenBy.kt | 21 +++ .../OrderingTest/sortByThenByDescending.kt | 21 +++ .../sortComparatorThenComparator.kt | 21 +++ .../OrderingTest/sortUsingCustomComparator.kt | 28 ++++ .../sortUsingFunctionalComparator.kt | 20 +++ .../external/stdlib/TuplesTest/pairEquals.kt | 14 ++ .../stdlib/TuplesTest/pairFirstAndSecond.kt | 11 ++ .../stdlib/TuplesTest/pairHashCode.kt | 14 ++ .../external/stdlib/TuplesTest/pairHashSet.kt | 12 ++ .../stdlib/TuplesTest/pairMultiAssignment.kt | 12 ++ .../external/stdlib/TuplesTest/pairToList.kt | 11 ++ .../stdlib/TuplesTest/pairToString.kt | 10 ++ .../stdlib/TuplesTest/tripleEquals.kt | 15 ++ .../stdlib/TuplesTest/tripleFirstAndSecond.kt | 11 ++ .../stdlib/TuplesTest/tripleHashCode.kt | 15 ++ .../stdlib/TuplesTest/tripleHashSet.kt | 12 ++ .../TuplesTest/tripleMultiAssignment.kt | 12 ++ .../stdlib/TuplesTest/tripleToList.kt | 12 ++ .../stdlib/TuplesTest/tripleToString.kt | 9 ++ .../collections/ArraysTest/arrayLastIndex.kt | 11 ++ .../collections/ArraysTest/asIterable.kt | 23 +++ .../stdlib/collections/ArraysTest/asList.kt | 109 ++++++++++++++ .../collections/ArraysTest/asListObjects.kt | 34 +++++ .../ArraysTest/asListPrimitives.kt | 33 +++++ .../stdlib/collections/ArraysTest/average.kt | 12 ++ .../collections/ArraysTest/booleanArray.kt | 8 ++ .../ArraysTest/booleanArrayInit.kt | 9 ++ .../collections/ArraysTest/byteArray.kt | 10 ++ .../collections/ArraysTest/byteArrayInit.kt | 9 ++ .../collections/ArraysTest/charArray.kt | 10 ++ .../collections/ArraysTest/charArrayInit.kt | 9 ++ .../stdlib/collections/ArraysTest/contains.kt | 7 + .../ArraysTest/contentDeepEquals.kt | 10 ++ .../ArraysTest/contentDeepHashCode.kt | 10 ++ .../ArraysTest/contentDeepToString.kt | 12 ++ .../contentDeepToStringNoRecursion.kt | 15 ++ .../collections/ArraysTest/contentEquals.kt | 9 ++ .../collections/ArraysTest/contentHashCode.kt | 11 ++ .../collections/ArraysTest/contentToString.kt | 6 + .../collections/ArraysTest/copyAndResize.kt | 51 +++++++ .../stdlib/collections/ArraysTest/copyOf.kt | 48 +++++++ .../collections/ArraysTest/copyOfRange.kt | 48 +++++++ .../collections/ArraysTest/doubleArray.kt | 9 ++ .../collections/ArraysTest/doubleArrayInit.kt | 9 ++ .../stdlib/collections/ArraysTest/drop.kt | 19 +++ .../stdlib/collections/ArraysTest/dropLast.kt | 19 +++ .../collections/ArraysTest/dropLastWhile.kt | 15 ++ .../collections/ArraysTest/dropWhile.kt | 15 ++ .../ArraysTest/emptyArrayLastIndex.kt | 9 ++ .../stdlib/collections/ArraysTest/filter.kt | 15 ++ .../collections/ArraysTest/filterIndexed.kt | 10 ++ .../collections/ArraysTest/filterNot.kt | 15 ++ .../collections/ArraysTest/filterNotNull.kt | 5 + .../stdlib/collections/ArraysTest/first.kt | 6 + .../collections/ArraysTest/flattenArray.kt | 14 ++ .../collections/ArraysTest/floatArray.kt | 10 ++ .../collections/ArraysTest/floatArrayInit.kt | 9 ++ .../stdlib/collections/ArraysTest/indexOf.kt | 19 +++ .../ArraysTest/indexOfInPrimitiveArrays.kt | 42 ++++++ .../stdlib/collections/ArraysTest/intArray.kt | 9 ++ .../collections/ArraysTest/intArrayInit.kt | 9 ++ .../stdlib/collections/ArraysTest/isEmpty.kt | 22 +++ .../collections/ArraysTest/isNotEmpty.kt | 6 + .../collections/ArraysTest/joinToString.kt | 15 ++ .../stdlib/collections/ArraysTest/last.kt | 6 + .../collections/ArraysTest/lastIndexOf.kt | 21 +++ .../collections/ArraysTest/longArray.kt | 10 ++ .../collections/ArraysTest/longArrayInit.kt | 9 ++ .../stdlib/collections/ArraysTest/map.kt | 8 ++ .../collections/ArraysTest/mapIndexed.kt | 7 + .../ArraysTest/mapIndexedNotNull.kt | 5 + .../collections/ArraysTest/mapNotNull.kt | 5 + .../stdlib/collections/ArraysTest/max.kt | 10 ++ .../stdlib/collections/ArraysTest/maxBy.kt | 9 ++ .../ArraysTest/maxByEvaluateOnce.kt | 7 + .../ArraysTest/maxByInPrimitiveArrays.kt | 12 ++ .../ArraysTest/maxInPrimitiveArrays.kt | 13 ++ .../stdlib/collections/ArraysTest/maxIndex.kt | 6 + .../stdlib/collections/ArraysTest/maxWith.kt | 7 + .../ArraysTest/maxWithInPrimitiveArrays.kt | 7 + .../stdlib/collections/ArraysTest/min.kt | 10 ++ .../stdlib/collections/ArraysTest/minBy.kt | 9 ++ .../ArraysTest/minByEvaluateOnce.kt | 7 + .../ArraysTest/minByInPrimitiveArrays.kt | 12 ++ .../ArraysTest/minInPrimitiveArrays.kt | 13 ++ .../stdlib/collections/ArraysTest/minIndex.kt | 6 + .../stdlib/collections/ArraysTest/minWith.kt | 7 + .../ArraysTest/minWithInPrimitiveArrays.kt | 7 + .../collections/ArraysTest/orEmptyNotNull.kt | 9 ++ .../collections/ArraysTest/orEmptyNull.kt | 10 ++ .../stdlib/collections/ArraysTest/plus.kt | 47 ++++++ .../collections/ArraysTest/plusAssign.kt | 46 ++++++ .../collections/ArraysTest/plusInference.kt | 14 ++ .../collections/ArraysTest/plusVararg.kt | 47 ++++++ .../stdlib/collections/ArraysTest/reduce.kt | 17 +++ .../collections/ArraysTest/reduceIndexed.kt | 17 +++ .../collections/ArraysTest/reduceRight.kt | 17 +++ .../ArraysTest/reduceRightIndexed.kt | 17 +++ .../collections/ArraysTest/reverseInPlace.kt | 25 ++++ .../stdlib/collections/ArraysTest/reversed.kt | 13 ++ .../collections/ArraysTest/reversedArray.kt | 50 +++++++ .../collections/ArraysTest/shortArray.kt | 10 ++ .../collections/ArraysTest/shortArrayInit.kt | 9 ++ .../stdlib/collections/ArraysTest/slice.kt | 18 +++ .../collections/ArraysTest/sliceArray.kt | 56 ++++++++ .../stdlib/collections/ArraysTest/sort.kt | 64 +++++++++ .../collections/ArraysTest/sortByInPlace.kt | 49 +++++++ .../stdlib/collections/ArraysTest/sortedBy.kt | 8 ++ .../ArraysTest/sortedNullableBy.kt | 10 ++ .../collections/ArraysTest/sortedTests.kt | 51 +++++++ .../collections/ArraysTest/sortedWith.kt | 24 ++++ .../stdlib/collections/ArraysTest/sum.kt | 11 ++ .../ArraysTest/sumInPrimitiveArrays.kt | 11 ++ .../stdlib/collections/ArraysTest/take.kt | 19 +++ .../stdlib/collections/ArraysTest/takeLast.kt | 19 +++ .../collections/ArraysTest/takeLastWhile.kt | 15 ++ .../collections/ArraysTest/takeWhile.kt | 15 ++ .../ArraysTest/toPrimitiveArray.kt | 13 ++ .../collections/ArraysTest/toTypedArray.kt | 8 ++ .../abstractCollectionToArray.kt | 30 ++++ .../collections/CollectionTest/average.kt | 12 ++ .../collections/CollectionTest/contains.kt | 11 ++ .../collections/CollectionTest/copyToArray.kt | 9 ++ .../collections/CollectionTest/count.kt | 9 ++ .../CollectionTest/createListWithInit.kt | 8 ++ .../CollectionTest/decomposeArray.kt | 11 ++ .../CollectionTest/decomposeFirst.kt | 7 + .../CollectionTest/decomposeIntArray.kt | 11 ++ .../CollectionTest/decomposeList.kt | 11 ++ .../CollectionTest/decomposeSplit.kt | 8 ++ .../stdlib/collections/CollectionTest/drop.kt | 8 ++ .../collections/CollectionTest/dropLast.kt | 13 ++ .../CollectionTest/dropLastWhile.kt | 10 ++ .../collections/CollectionTest/dropWhile.kt | 7 + .../CollectionTest/filterIntoSet.kt | 17 +++ .../CollectionTest/filterIsInstanceArray.kt | 23 +++ .../CollectionTest/filterIsInstanceList.kt | 23 +++ .../CollectionTest/filterNotNull.kt | 14 ++ .../collections/CollectionTest/first.kt | 10 ++ .../stdlib/collections/CollectionTest/fold.kt | 21 +++ .../collections/CollectionTest/foldIndexed.kt | 19 +++ .../foldIndexedWithDifferentTypes.kt | 14 ++ .../foldIndexedWithNonCommutativeOperation.kt | 9 ++ .../collections/CollectionTest/foldRight.kt | 9 ++ .../CollectionTest/foldRightIndexed.kt | 9 ++ .../foldRightIndexedWithDifferentTypes.kt | 9 ++ ...RightIndexedWithNonCommutativeOperation.kt | 9 ++ .../foldRightWithDifferentTypes.kt | 9 ++ .../foldRightWithNonCommutativeOperation.kt | 9 ++ .../CollectionTest/foldWithDifferentTypes.kt | 14 ++ .../foldWithNonCommutativeOperation.kt | 9 ++ .../collections/CollectionTest/groupBy.kt | 19 +++ .../CollectionTest/groupByKeysAndValues.kt | 17 +++ .../collections/CollectionTest/indices.kt | 10 ++ .../collections/CollectionTest/joinTo.kt | 9 ++ .../CollectionTest/joinToString.kt | 12 ++ .../stdlib/collections/CollectionTest/last.kt | 10 ++ .../CollectionTest/listOfNotNull.kt | 14 ++ .../collections/CollectionTest/mapRanges.kt | 7 + .../stdlib/collections/CollectionTest/max.kt | 13 ++ .../collections/CollectionTest/maxBy.kt | 12 ++ .../CollectionTest/maxByEvaluateOnce.kt | 11 ++ .../collections/CollectionTest/maxWith.kt | 10 ++ .../stdlib/collections/CollectionTest/min.kt | 13 ++ .../collections/CollectionTest/minBy.kt | 12 ++ .../CollectionTest/minByEvaluateOnce.kt | 11 ++ .../collections/CollectionTest/minWith.kt | 10 ++ .../collections/CollectionTest/minusAssign.kt | 23 +++ .../CollectionTest/minusIsEager.kt | 13 ++ .../collections/CollectionTest/partition.kt | 10 ++ .../collections/CollectionTest/plusAssign.kt | 21 +++ .../CollectionTest/plusCollectionBug.kt | 7 + .../CollectionTest/plusCollectionInference.kt | 15 ++ .../collections/CollectionTest/plusRanges.kt | 9 ++ .../CollectionTest/randomAccess.kt | 9 ++ .../collections/CollectionTest/reduce.kt | 13 ++ .../CollectionTest/reduceIndexed.kt | 22 +++ .../collections/CollectionTest/reduceRight.kt | 13 ++ .../CollectionTest/reduceRightIndexed.kt | 22 +++ .../CollectionTest/requireNoNulls.kt | 15 ++ .../CollectionTest/reverseInPlace.kt | 20 +++ .../collections/CollectionTest/reversed.kt | 9 ++ .../CollectionTest/sortByInPlace.kt | 14 ++ .../collections/CollectionTest/sortInPlace.kt | 14 ++ .../collections/CollectionTest/sorted.kt | 8 ++ .../collections/CollectionTest/sortedBy.kt | 8 ++ .../CollectionTest/sortedByNullable.kt | 11 ++ .../CollectionTest/sortedNullableBy.kt | 11 ++ .../collections/CollectionTest/sortedWith.kt | 11 ++ .../CollectionTest/specialLists.kt | 101 +++++++++++++ .../collections/CollectionTest/specialMaps.kt | 135 ++++++++++++++++++ .../collections/CollectionTest/specialSets.kt | 116 +++++++++++++++ .../collections/CollectionTest/subscript.kt | 25 ++++ .../stdlib/collections/CollectionTest/sum.kt | 11 ++ .../stdlib/collections/CollectionTest/take.kt | 13 ++ .../collections/CollectionTest/takeLast.kt | 14 ++ .../CollectionTest/takeLastWhile.kt | 10 ++ .../takeReturnsFirstNElements.kt | 13 ++ .../collections/CollectionTest/takeWhile.kt | 10 ++ .../CollectionTest/toStringTest.kt | 7 + .../collections/CollectionTest/unzipArray.kt | 9 ++ .../collections/CollectionTest/unzipList.kt | 9 ++ .../stdlib/collections/CollectionTest/zip.kt | 8 ++ .../CollectionTest/zipTransform.kt | 8 ++ .../collections/GroupingTest/countEach.kt | 14 ++ .../foldWithComputedInitialValue.kt | 25 ++++ .../foldWithConstantInitialValue.kt | 15 ++ .../GroupingTest/groupingProducers.kt | 26 ++++ .../stdlib/collections/GroupingTest/reduce.kt | 17 +++ .../IteratorsTest/iterationOverIterator.kt | 11 ++ .../binarySearchByElement.kt | 30 ++++ .../binarySearchByElementNullable.kt | 19 +++ .../ListBinarySearchTest/binarySearchByKey.kt | 31 ++++ .../binarySearchByKeyWithComparator.kt | 34 +++++ .../binarySearchByMultipleKeys.kt | 23 +++ .../binarySearchWithComparator.kt | 30 ++++ .../collections/ListSpecificTest/_toString.kt | 41 ++++++ .../collections/ListSpecificTest/getOr.kt | 20 +++ .../ListSpecificTest/indexOfLast.kt | 9 ++ .../collections/ListSpecificTest/lastIndex.kt | 8 ++ .../ListSpecificTest/mutableList.kt | 13 ++ .../collections/ListSpecificTest/slice.kt | 13 ++ .../collections/ListSpecificTest/tail.kt | 8 ++ .../ListSpecificTest/testNullToString.kt | 5 + .../stdlib/collections/MapTest/all.kt | 11 ++ .../stdlib/collections/MapTest/any.kt | 14 ++ .../stdlib/collections/MapTest/contains.kt | 8 ++ .../stdlib/collections/MapTest/countBy.kt | 13 ++ .../stdlib/collections/MapTest/createFrom.kt | 19 +++ .../collections/MapTest/createLinkedMap.kt | 10 ++ .../collections/MapTest/createMutableMap.kt | 8 ++ .../collections/MapTest/createUsingTo.kt | 9 ++ .../MapTest/createWithPairSelector.kt | 10 ++ .../collections/MapTest/createWithSelector.kt | 10 ++ .../MapTest/createWithSelectorAndOverwrite.kt | 9 ++ .../createWithSelectorForKeyAndValue.kt | 10 ++ .../stdlib/collections/MapTest/filter.kt | 17 +++ .../stdlib/collections/MapTest/filterNot.kt | 15 ++ .../MapTest/filterOutProjectedTo.kt | 23 +++ .../stdlib/collections/MapTest/getOrElse.kt | 22 +++ .../stdlib/collections/MapTest/getOrPut.kt | 20 +++ .../stdlib/collections/MapTest/getValue.kt | 25 ++++ .../stdlib/collections/MapTest/iterate.kt | 14 ++ .../MapTest/iterateWithExtraction.kt | 14 ++ .../MapTest/iterateWithProperties.kt | 14 ++ .../stdlib/collections/MapTest/map.kt | 9 ++ .../stdlib/collections/MapTest/mapKeys.kt | 15 ++ .../stdlib/collections/MapTest/mapNotNull.kt | 8 ++ .../stdlib/collections/MapTest/mapValues.kt | 15 ++ .../stdlib/collections/MapTest/onEach.kt | 13 ++ .../stdlib/collections/MapTest/plusAny.kt | 17 +++ .../stdlib/collections/MapTest/populateTo.kt | 22 +++ .../MapTest/setViaIndexOperators.kt | 14 ++ .../collections/MapTest/sizeAndEmpty.kt | 8 ++ .../stdlib/collections/MapTest/stream.kt | 8 ++ .../MutableCollectionsTest/addAll.kt | 29 ++++ .../MutableCollectionsTest/removeAll.kt | 36 +++++ .../MutableCollectionsTest/retainAll.kt | 47 ++++++ .../ReversedViewsTest/testAddIOOB.kt | 16 +++ .../ReversedViewsTest/testBehavior.kt | 105 ++++++++++++++ .../testBidirectionalModifications.kt | 18 +++ .../ReversedViewsTest/testContains.kt | 10 ++ .../ReversedViewsTest/testDoubleReverse.kt | 10 ++ .../ReversedViewsTest/testEmpty.kt | 9 ++ .../ReversedViewsTest/testGetIOOB.kt | 16 +++ .../ReversedViewsTest/testIndexOf.kt | 10 ++ .../ReversedViewsTest/testMutableAdd.kt | 18 +++ .../ReversedViewsTest/testMutableClear.kt | 15 ++ .../testMutableDoubleReverse.kt | 10 ++ .../ReversedViewsTest/testMutableEmpty.kt | 9 ++ .../ReversedViewsTest/testMutableRemove.kt | 20 +++ .../testMutableRemoveByObj.kt | 14 ++ .../testMutableReversedSubList.kt | 10 ++ .../ReversedViewsTest/testMutableSet.kt | 17 +++ .../ReversedViewsTest/testMutableSimple.kt | 10 ++ .../ReversedViewsTest/testMutableSubList.kt | 19 +++ .../ReversedViewsTest/testNullToString.kt | 9 ++ .../ReversedViewsTest/testRandomAccess.kt | 13 ++ .../ReversedViewsTest/testRemoveIOOB.kt | 16 +++ .../ReversedViewsTest/testReversedSubList.kt | 10 ++ .../ReversedViewsTest/testSetIOOB.kt | 16 +++ .../ReversedViewsTest/testSimple.kt | 10 ++ .../SequenceJVMTest/filterIsInstance.kt | 21 +++ .../collections/SequenceTest/distinct.kt | 14 ++ .../collections/SequenceTest/distinctBy.kt | 14 ++ .../stdlib/collections/SequenceTest/drop.kt | 17 +++ .../collections/SequenceTest/dropWhile.kt | 14 ++ ...dTakeWhileExtractTheElementsWithinRange.kt | 13 ++ .../SequenceTest/filterEmptySequence.kt | 10 ++ .../collections/SequenceTest/filterIndexed.kt | 13 ++ .../collections/SequenceTest/filterNot.kt | 9 ++ .../collections/SequenceTest/filterNotNull.kt | 9 ++ .../SequenceTest/filterNullable.kt | 9 ++ .../collections/SequenceTest/flatMap.kt | 8 ++ ...MapAndTakeExtractTheTransformedElements.kt | 23 +++ .../SequenceTest/flatMapOnEmpty.kt | 8 ++ .../SequenceTest/flatMapWithEmptyItems.kt | 8 ++ .../collections/SequenceTest/flatten.kt | 19 +++ .../foldReducesTheFirstNElements.kt | 14 ++ .../SequenceTest/iterationOverSequence.kt | 11 ++ ...tenatesTheFirstNElementsAboveAThreshold.kt | 13 ++ .../makeSequenceOneTimeConstrained.kt | 18 +++ .../SequenceTest/mapAndJoinToString.kt | 13 ++ ...dTakeWhileExtractTheTransformedElements.kt | 13 ++ .../SequenceTest/mapEmptySequence.kt | 9 ++ .../collections/SequenceTest/mapIndexed.kt | 13 ++ .../SequenceTest/mapIndexedNotNull.kt | 17 +++ .../collections/SequenceTest/mapNotNull.kt | 13 ++ .../collections/SequenceTest/minusAssign.kt | 16 +++ .../SequenceTest/minusIsLazyIterated.kt | 14 ++ .../stdlib/collections/SequenceTest/onEach.kt | 31 ++++ .../collections/SequenceTest/plusAssign.kt | 13 ++ .../SequenceTest/requireNoNulls.kt | 16 +++ .../SequenceTest/sequenceExtensions.kt | 14 ++ .../SequenceTest/sequenceFromFunction.kt | 19 +++ .../sequenceFromFunctionWithInitialValue.kt | 10 ++ ...equenceFromFunctionWithLazyInitialValue.kt | 21 +++ .../SequenceTest/sequenceFromIterator.kt | 13 ++ .../stdlib/collections/SequenceTest/sorted.kt | 10 ++ .../collections/SequenceTest/sortedBy.kt | 15 ++ .../collections/SequenceTest/sortedWith.kt | 8 ++ .../collections/SequenceTest/subSequence.kt | 23 +++ .../stdlib/collections/SequenceTest/take.kt | 23 +++ .../takeExtractsTheFirstNElements.kt | 13 ++ ...tringJoinsNoMoreThanTheFirstTenElements.kt | 15 ++ .../stdlib/collections/SequenceTest/unzip.kt | 10 ++ .../collections/SequenceTest/withIndex.kt | 9 ++ .../stdlib/collections/SequenceTest/zip.kt | 9 ++ .../collections/SequenceTest/zipPairs.kt | 14 ++ .../META-INF/main.kotlin_module | Bin 0 -> 57 bytes .../SetOperationsTest/UnionKt.class | Bin 0 -> 1137 bytes .../collections/SetOperationsTest/distinct.kt | 7 + .../SetOperationsTest/distinctBy.kt | 7 + .../SetOperationsTest/intersect.kt | 9 ++ .../kotlin/test/Assert$Companion.class | Bin 0 -> 1770 bytes .../kotlin/test/Assert.class | Bin 0 -> 706 bytes .../SetOperationsTest/kotlin/test/Test.class | Bin 0 -> 451 bytes .../kotlin/test/TestFailedException.class | Bin 0 -> 1051 bytes .../kotlin/test/TestUtilsKt.class | Bin 0 -> 8126 bytes .../SetOperationsTest/plusAssign.kt | 21 +++ .../collections/SetOperationsTest/subtract.kt | 9 ++ .../collections/SetOperationsTest/union.kt | 7 + .../CoroutineContextTest/testEquals.kt | 28 ++++ .../CoroutineContextTest/testGetPlusFold.kt | 63 ++++++++ .../testLastDispatcher.kt | 49 +++++++ .../CoroutineContextTest/testMinusKey.kt | 58 ++++++++ .../CoroutineContextTest/testPlusCombined.kt | 33 +++++ .../testBadClass.kt | 47 ++++++ .../testCallHasNextSeveralTimes.kt | 24 ++++ .../SequenceBuilderTest/testEmptySequence.kt | 14 ++ .../testExceptionInCoroutine.kt | 27 ++++ .../testInfiniteYieldAll.kt | 18 +++ .../SequenceBuilderTest/testLaziness.kt | 35 +++++ .../testManualIteration.kt | 31 ++++ .../testParallelIteration.kt | 16 +++ .../SequenceBuilderTest/testSimple.kt | 16 +++ .../testYieldAllCollection.kt | 11 ++ .../testYieldAllCollectionManyEmpty.kt | 13 ++ .../testYieldAllCollectionMixedBoth.kt | 13 ++ .../testYieldAllCollectionMixedFirst.kt | 12 ++ .../testYieldAllCollectionMixedLast.kt | 12 ++ .../testYieldAllCollectionMixedLong.kt | 18 +++ .../testYieldAllCollectionOneEmpty.kt | 11 ++ .../testYieldAllIterator.kt | 11 ++ .../testYieldAllSequence.kt | 11 ++ .../testYieldAllSideEffects.kt | 42 ++++++ .../EscapedTestNamesTest/numbersEqual.kt | 10 ++ .../EscapedTestNamesTest/stringsEqual.kt | 10 ++ .../BitwiseOperationsTest/andForInt.kt | 6 + .../BitwiseOperationsTest/invForInt.kt | 6 + .../numbers/BitwiseOperationsTest/orForInt.kt | 6 + .../BitwiseOperationsTest/shlForInt.kt | 6 + .../BitwiseOperationsTest/shrForInt.kt | 6 + .../BitwiseOperationsTest/ushrForInt.kt | 6 + .../BitwiseOperationsTest/xorForInt.kt | 6 + .../numbers/NaNPropagationTest/arrayMax.kt | 29 ++++ .../numbers/NaNPropagationTest/arrayMin.kt | 29 ++++ .../numbers/NaNPropagationTest/arrayTMax.kt | 16 +++ .../numbers/NaNPropagationTest/arrayTMin.kt | 16 +++ .../numbers/NaNPropagationTest/listMax.kt | 29 ++++ .../numbers/NaNPropagationTest/listMin.kt | 29 ++++ .../numbers/NaNPropagationTest/listTMax.kt | 16 +++ .../numbers/NaNPropagationTest/listTMin.kt | 16 +++ .../numbers/NaNPropagationTest/maxOf.kt | 47 ++++++ .../numbers/NaNPropagationTest/maxOfT.kt | 16 +++ .../numbers/NaNPropagationTest/minOf.kt | 47 ++++++ .../numbers/NaNPropagationTest/minOfT.kt | 16 +++ .../NaNPropagationTest/primitiveArrayMax.kt | 29 ++++ .../NaNPropagationTest/primitiveArrayMin.kt | 29 ++++ .../numbers/NaNPropagationTest/sequenceMax.kt | 29 ++++ .../numbers/NaNPropagationTest/sequenceMin.kt | 29 ++++ .../NaNPropagationTest/sequenceTMax.kt | 16 +++ .../NaNPropagationTest/sequenceTMin.kt | 16 +++ .../numbers/NumbersTest/byteMinMaxValues.kt | 31 ++++ .../numbers/NumbersTest/doubleMinMaxValues.kt | 12 ++ .../numbers/NumbersTest/doubleProperties.kt | 15 ++ .../numbers/NumbersTest/floatMinMaxValues.kt | 12 ++ .../numbers/NumbersTest/floatProperties.kt | 16 +++ .../numbers/NumbersTest/intMinMaxValues.kt | 31 ++++ .../numbers/NumbersTest/longMinMaxValues.kt | 31 ++++ .../numbers/NumbersTest/shortMinMaxValues.kt | 31 ++++ .../properties/META-INF/main.kotlin_module | Bin 0 -> 74 bytes .../VarByMapExtensionsTest$a2$2.class | Bin 0 -> 1370 bytes .../properties/VarByMapExtensionsTest.class | Bin 0 -> 6990 bytes .../properties/VarByMapExtensionsTestKt.class | Bin 0 -> 462 bytes .../DelegationTest/NotNullVarTest.kt | 19 +++ .../DelegationTest/ObservablePropertyTest.kt | 23 +++ .../DelegationTest/VetoablePropertyTest.kt | 33 +++++ .../ValByMapExtensionsTest.kt | 32 +++++ .../VarByMapExtensionsTest.kt | 40 ++++++ ...entityEqualsIsUsedToUnescapeLazyValTest.kt | 24 ++++ .../lazy/LazyValuesTest/LazyValTest.kt | 18 +++ .../LazyValuesTest/NullableLazyValTest.kt | 29 ++++ .../lazy/LazyValuesTest/UnsafeLazyValTest.kt | 18 +++ .../UnsafeNullableLazyValTest.kt | 29 ++++ .../kotlin/test/Assert$Companion.class | Bin 0 -> 1770 bytes .../properties/kotlin/test/Assert.class | Bin 0 -> 706 bytes .../stdlib/properties/kotlin/test/Test.class | Bin 0 -> 451 bytes .../kotlin/test/TestFailedException.class | Bin 0 -> 1051 bytes .../properties/kotlin/test/TestUtilsKt.class | Bin 0 -> 8126 bytes .../CoercionTest/coercionsComparable.kt | 34 +++++ .../ranges/CoercionTest/coercionsDouble.kt | 33 +++++ .../ranges/CoercionTest/coercionsInt.kt | 24 ++++ .../ranges/CoercionTest/coercionsLong.kt | 25 ++++ .../calculateFinalElement.kt | 55 +++++++ .../iterateToFinalElement.kt | 41 ++++++ .../RangeIterationTest/emptyConstant.kt | 91 ++++++++++++ .../ranges/RangeIterationTest/emptyDownto.kt | 93 ++++++++++++ .../ranges/RangeIterationTest/emptyRange.kt | 93 ++++++++++++ .../inexactSteppedDownTo.kt | 93 ++++++++++++ .../RangeIterationTest/inexactSteppedRange.kt | 93 ++++++++++++ .../RangeIterationTest/oneElementDownTo.kt | 93 ++++++++++++ .../RangeIterationTest/oneElementRange.kt | 93 ++++++++++++ .../ranges/RangeIterationTest/openRange.kt | 92 ++++++++++++ .../reversedBackSequence.kt | 103 +++++++++++++ .../reversedEmptyBackSequence.kt | 93 ++++++++++++ .../RangeIterationTest/reversedEmptyRange.kt | 93 ++++++++++++ .../reversedInexactSteppedDownTo.kt | 93 ++++++++++++ .../RangeIterationTest/reversedRange.kt | 93 ++++++++++++ .../ranges/RangeIterationTest/simpleDownTo.kt | 93 ++++++++++++ .../ranges/RangeIterationTest/simpleRange.kt | 103 +++++++++++++ .../RangeIterationTest/simpleSteppedDownTo.kt | 93 ++++++++++++ .../RangeIterationTest/simpleSteppedRange.kt | 93 ++++++++++++ .../stdlib/ranges/RangeTest/byteRange.kt | 37 +++++ .../stdlib/ranges/RangeTest/charRange.kt | 29 ++++ .../ranges/RangeTest/comparableRange.kt | 17 +++ .../stdlib/ranges/RangeTest/doubleRange.kt | 48 +++++++ .../stdlib/ranges/RangeTest/emptyEquals.kt | 27 ++++ .../stdlib/ranges/RangeTest/emptyHashCode.kt | 21 +++ .../stdlib/ranges/RangeTest/floatRange.kt | 49 +++++++ .../stdlib/ranges/RangeTest/intRange.kt | 37 +++++ .../stdlib/ranges/RangeTest/isEmpty.kt | 21 +++ .../stdlib/ranges/RangeTest/longRange.kt | 39 +++++ .../stdlib/ranges/RangeTest/shortRange.kt | 35 +++++ .../stdlib/text/RegexTest/escapeLiteral.kt | 10 ++ .../stdlib/text/RegexTest/matchAllSequence.kt | 13 ++ .../stdlib/text/RegexTest/matchEntire.kt | 15 ++ .../text/RegexTest/matchEntireLazyQuantor.kt | 12 ++ .../stdlib/text/RegexTest/matchGroups.kt | 38 +++++ .../stdlib/text/RegexTest/matchIgnoreCase.kt | 9 ++ .../stdlib/text/RegexTest/matchMultiline.kt | 10 ++ .../text/RegexTest/matchOptionalGroup.kt | 34 +++++ .../stdlib/text/RegexTest/matchResult.kt | 32 +++++ .../stdlib/text/RegexTest/matchSequence.kt | 18 +++ .../external/stdlib/text/RegexTest/replace.kt | 13 ++ .../stdlib/text/RegexTest/replaceEvaluator.kt | 10 ++ .../external/stdlib/text/RegexTest/split.kt | 16 +++ .../stdlib/text/StringBuilderTest/append.kt | 9 ++ .../text/StringBuilderTest/appendMany.kt | 8 ++ .../text/StringBuilderTest/asCharSequence.kt | 17 +++ .../text/StringBuilderTest/constructors.kt | 24 ++++ .../text/StringBuilderTest/stringBuild.kt | 10 ++ .../byteToStringWithRadix.kt | 13 ++ .../intToStringWithRadix.kt | 11 ++ .../longToStringWithRadix.kt | 12 ++ .../shortToStringWithRadix.kt | 12 ++ .../StringNumberConversionTest/toBoolean.kt | 8 ++ .../text/StringNumberConversionTest/toByte.kt | 69 +++++++++ .../StringNumberConversionTest/toDouble.kt | 74 ++++++++++ .../StringNumberConversionTest/toFloat.kt | 63 ++++++++ .../StringNumberConversionTest/toHexDouble.kt | 62 ++++++++ .../text/StringNumberConversionTest/toInt.kt | 88 ++++++++++++ .../toIntArabicDigits.kt | 57 ++++++++ .../text/StringNumberConversionTest/toLong.kt | 89 ++++++++++++ .../toLongArabicDigits.kt | 34 +++++ .../StringNumberConversionTest/toShort.kt | 70 +++++++++ .../stdlib/text/StringTest/capitalize.kt | 10 ++ .../stdlib/text/StringTest/decapitalize.kt | 11 ++ .../external/stdlib/text/StringTest/drop.kt | 12 ++ .../stdlib/text/StringTest/dropWhile.kt | 13 ++ .../stdlib/text/StringTest/endsWithString.kt | 14 ++ .../text/StringTest/equalsIgnoreCase.kt | 12 ++ .../external/stdlib/text/StringTest/filter.kt | 11 ++ .../stdlib/text/StringTest/filterIndexed.kt | 8 ++ .../stdlib/text/StringTest/filterNot.kt | 11 ++ .../external/stdlib/text/StringTest/joinTo.kt | 10 ++ .../stdlib/text/StringTest/joinToString.kt | 17 +++ .../stdlib/text/StringTest/orEmpty.kt | 11 ++ .../stdlib/text/StringTest/partition.kt | 13 ++ .../stdlib/text/StringTest/replace.kt | 14 ++ .../text/StringTest/replaceDelimited.kt | 26 ++++ .../stdlib/text/StringTest/replaceFirst.kt | 16 +++ .../stdlib/text/StringTest/reverse.kt | 9 ++ .../external/stdlib/text/StringTest/slice.kt | 12 ++ .../text/StringTest/startsWithString.kt | 17 +++ .../text/StringTest/substringDelimited.kt | 27 ++++ .../external/stdlib/text/StringTest/take.kt | 12 ++ .../stdlib/text/StringTest/takeWhile.kt | 13 ++ .../stdlib/text/StringTest/testIndent.kt | 11 ++ .../stdlib/text/StringTest/trimIndent.kt | 67 +++++++++ .../stdlib/text/StringTest/trimMargin.kt | 50 +++++++ .../KotlinVersionTest/componentValidation.kt | 17 +++ .../utils/KotlinVersionTest/currentVersion.kt | 14 ++ .../utils/LazyTest/alreadyInitialized.kt | 10 ++ .../LazyTest/initializationCalledOnce.kt | 17 +++ .../stdlib/utils/LazyTest/lazyToString.kt | 15 ++ .../external/stdlib/utils/TODOTest/usage.kt | 45 ++++++ backend.native/tests/testUtils.kt | 104 +++++++++++++- 530 files changed, 11027 insertions(+), 4 deletions(-) create mode 100644 backend.native/tests/external/stdlib/OrderingTest/combineComparators.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/compareByCompareTo.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/compareByNameFirst.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/compareByRatingFirst.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/compareNullables.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/compareSameObjectsByRatingFirst.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/maxOf.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/maxOfWith.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/minOf.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/minOfWith.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/naturalOrderComparator.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/reversedComparator.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/sortByThenBy.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/sortByThenByDescending.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/sortComparatorThenComparator.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/sortUsingCustomComparator.kt create mode 100644 backend.native/tests/external/stdlib/OrderingTest/sortUsingFunctionalComparator.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairEquals.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairFirstAndSecond.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairHashCode.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairHashSet.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairMultiAssignment.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairToList.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairToString.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleEquals.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleFirstAndSecond.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleHashCode.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleHashSet.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleMultiAssignment.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleToList.kt create mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleToString.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/arrayLastIndex.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/asIterable.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/asList.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/asListObjects.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/asListPrimitives.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/average.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/booleanArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/booleanArrayInit.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/byteArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/byteArrayInit.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/charArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/charArrayInit.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contains.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepEquals.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepHashCode.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToString.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToStringNoRecursion.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentEquals.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentHashCode.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentToString.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/copyAndResize.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/copyOf.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/copyOfRange.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/doubleArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/doubleArrayInit.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/drop.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/dropLast.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/dropLastWhile.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/dropWhile.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/emptyArrayLastIndex.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/filter.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/filterIndexed.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/filterNot.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/filterNotNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/first.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/flattenArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/floatArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/floatArrayInit.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/indexOf.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/indexOfInPrimitiveArrays.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/intArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/intArrayInit.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/isEmpty.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/isNotEmpty.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/joinToString.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/last.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/lastIndexOf.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/longArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/longArrayInit.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/map.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexed.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexedNotNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/mapNotNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/max.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxByEvaluateOnce.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxByInPrimitiveArrays.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxInPrimitiveArrays.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxIndex.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxWith.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxWithInPrimitiveArrays.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/min.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minByEvaluateOnce.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minByInPrimitiveArrays.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minInPrimitiveArrays.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minIndex.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minWith.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minWithInPrimitiveArrays.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNotNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/plus.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/plusAssign.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/plusInference.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/plusVararg.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reduce.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reduceIndexed.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reduceRight.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reduceRightIndexed.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reverseInPlace.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reversed.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reversedArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/shortArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/shortArrayInit.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/slice.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sliceArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sort.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sortByInPlace.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sortedBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sortedNullableBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sortedTests.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sortedWith.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sum.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sumInPrimitiveArrays.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/take.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/takeLast.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/takeLastWhile.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/takeWhile.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/toPrimitiveArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/toTypedArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/abstractCollectionToArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/average.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/contains.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/copyToArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/count.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/createListWithInit.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/decomposeArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/decomposeFirst.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/decomposeIntArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/decomposeList.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/decomposeSplit.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/drop.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/dropLast.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/dropLastWhile.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/dropWhile.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/filterIntoSet.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceList.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/filterNotNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/first.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/fold.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexed.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithDifferentTypes.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithNonCommutativeOperation.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRight.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexed.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithDifferentTypes.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithNonCommutativeOperation.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithDifferentTypes.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithNonCommutativeOperation.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldWithDifferentTypes.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldWithNonCommutativeOperation.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/groupBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/groupByKeysAndValues.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/indices.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/joinTo.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/joinToString.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/last.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/listOfNotNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/mapRanges.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/max.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/maxBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/maxByEvaluateOnce.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/maxWith.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/min.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/minBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/minByEvaluateOnce.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/minWith.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/minusAssign.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/minusIsEager.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/partition.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/plusAssign.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionBug.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionInference.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/plusRanges.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/randomAccess.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reduce.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reduceIndexed.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reduceRight.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reduceRightIndexed.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/requireNoNulls.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reverseInPlace.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reversed.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortByInPlace.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortInPlace.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sorted.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortedBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortedByNullable.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortedNullableBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortedWith.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/specialLists.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/specialMaps.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/specialSets.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/subscript.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sum.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/take.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/takeLast.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/takeLastWhile.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/takeReturnsFirstNElements.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/takeWhile.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/toStringTest.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/unzipArray.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/unzipList.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/zip.kt create mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/zipTransform.kt create mode 100644 backend.native/tests/external/stdlib/collections/GroupingTest/countEach.kt create mode 100644 backend.native/tests/external/stdlib/collections/GroupingTest/foldWithComputedInitialValue.kt create mode 100644 backend.native/tests/external/stdlib/collections/GroupingTest/foldWithConstantInitialValue.kt create mode 100644 backend.native/tests/external/stdlib/collections/GroupingTest/groupingProducers.kt create mode 100644 backend.native/tests/external/stdlib/collections/GroupingTest/reduce.kt create mode 100644 backend.native/tests/external/stdlib/collections/IteratorsTest/iterationOverIterator.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElement.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElementNullable.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKey.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKeyWithComparator.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByMultipleKeys.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchWithComparator.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/_toString.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/getOr.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/indexOfLast.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/lastIndex.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/mutableList.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/slice.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/tail.kt create mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/testNullToString.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/all.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/any.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/contains.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/countBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createFrom.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createLinkedMap.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createMutableMap.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createUsingTo.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createWithPairSelector.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createWithSelector.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorAndOverwrite.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorForKeyAndValue.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/filter.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/filterNot.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/filterOutProjectedTo.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/getOrElse.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/getOrPut.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/getValue.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/iterate.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/iterateWithExtraction.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/iterateWithProperties.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/map.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/mapKeys.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/mapNotNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/mapValues.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/onEach.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/plusAny.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/populateTo.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/setViaIndexOperators.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/sizeAndEmpty.kt create mode 100644 backend.native/tests/external/stdlib/collections/MapTest/stream.kt create mode 100644 backend.native/tests/external/stdlib/collections/MutableCollectionsTest/addAll.kt create mode 100644 backend.native/tests/external/stdlib/collections/MutableCollectionsTest/removeAll.kt create mode 100644 backend.native/tests/external/stdlib/collections/MutableCollectionsTest/retainAll.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testAddIOOB.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBehavior.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBidirectionalModifications.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testContains.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testDoubleReverse.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testEmpty.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testGetIOOB.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testIndexOf.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableAdd.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableClear.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableDoubleReverse.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableEmpty.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemove.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemoveByObj.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableReversedSubList.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSet.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSimple.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSubList.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testNullToString.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRandomAccess.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRemoveIOOB.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testReversedSubList.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSetIOOB.kt create mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSimple.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceJVMTest/filterIsInstance.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/distinct.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/distinctBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/drop.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/dropWhile.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterAndTakeWhileExtractTheElementsWithinRange.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterEmptySequence.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterIndexed.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterNot.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterNotNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterNullable.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/flatMap.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/flatMapAndTakeExtractTheTransformedElements.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/flatMapOnEmpty.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/flatMapWithEmptyItems.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/flatten.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/foldReducesTheFirstNElements.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/iterationOverSequence.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/joinConcatenatesTheFirstNElementsAboveAThreshold.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/makeSequenceOneTimeConstrained.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapAndJoinToString.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapAndTakeWhileExtractTheTransformedElements.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapEmptySequence.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexed.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexedNotNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapNotNull.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/minusAssign.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/minusIsLazyIterated.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/onEach.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/plusAssign.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/requireNoNulls.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sequenceExtensions.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunction.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithInitialValue.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithLazyInitialValue.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromIterator.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sorted.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sortedBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sortedWith.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/subSequence.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/take.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/takeExtractsTheFirstNElements.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/toStringJoinsNoMoreThanTheFirstTenElements.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/unzip.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/withIndex.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/zip.kt create mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/zipPairs.kt create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/META-INF/main.kotlin_module create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/UnionKt.class create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/distinct.kt create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/distinctBy.kt create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/intersect.kt create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/kotlin/test/Assert$Companion.class create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/kotlin/test/Assert.class create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/kotlin/test/Test.class create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/kotlin/test/TestFailedException.class create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/kotlin/test/TestUtilsKt.class create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/plusAssign.kt create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/subtract.kt create mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/union.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testEquals.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testGetPlusFold.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testLastDispatcher.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testMinusKey.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testPlusCombined.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutinesReferenceValuesTest/testBadClass.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testCallHasNextSeveralTimes.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testEmptySequence.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testExceptionInCoroutine.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testInfiniteYieldAll.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testLaziness.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testManualIteration.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testParallelIteration.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testSimple.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollection.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionManyEmpty.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedBoth.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedFirst.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLast.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLong.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionOneEmpty.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllIterator.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSequence.kt create mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSideEffects.kt create mode 100644 backend.native/tests/external/stdlib/language/EscapedTestNamesTest/numbersEqual.kt create mode 100644 backend.native/tests/external/stdlib/language/EscapedTestNamesTest/stringsEqual.kt create mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/andForInt.kt create mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/invForInt.kt create mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/orForInt.kt create mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shlForInt.kt create mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shrForInt.kt create mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/ushrForInt.kt create mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/xorForInt.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMax.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMin.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMax.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMin.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMax.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMin.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMax.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMin.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOf.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOfT.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOf.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOfT.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMax.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMin.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMax.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMin.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMax.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMin.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/byteMinMaxValues.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/doubleMinMaxValues.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/doubleProperties.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/floatMinMaxValues.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/floatProperties.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/intMinMaxValues.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/longMinMaxValues.kt create mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/shortMinMaxValues.kt create mode 100644 backend.native/tests/external/stdlib/properties/META-INF/main.kotlin_module create mode 100644 backend.native/tests/external/stdlib/properties/VarByMapExtensionsTest$a2$2.class create mode 100644 backend.native/tests/external/stdlib/properties/VarByMapExtensionsTest.class create mode 100644 backend.native/tests/external/stdlib/properties/VarByMapExtensionsTestKt.class create mode 100644 backend.native/tests/external/stdlib/properties/delegation/DelegationTest/NotNullVarTest.kt create mode 100644 backend.native/tests/external/stdlib/properties/delegation/DelegationTest/ObservablePropertyTest.kt create mode 100644 backend.native/tests/external/stdlib/properties/delegation/DelegationTest/VetoablePropertyTest.kt create mode 100644 backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/ValByMapExtensionsTest.kt create mode 100644 backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/VarByMapExtensionsTest.kt create mode 100644 backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/IdentityEqualsIsUsedToUnescapeLazyValTest.kt create mode 100644 backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/LazyValTest.kt create mode 100644 backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/NullableLazyValTest.kt create mode 100644 backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeLazyValTest.kt create mode 100644 backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeNullableLazyValTest.kt create mode 100644 backend.native/tests/external/stdlib/properties/kotlin/test/Assert$Companion.class create mode 100644 backend.native/tests/external/stdlib/properties/kotlin/test/Assert.class create mode 100644 backend.native/tests/external/stdlib/properties/kotlin/test/Test.class create mode 100644 backend.native/tests/external/stdlib/properties/kotlin/test/TestFailedException.class create mode 100644 backend.native/tests/external/stdlib/properties/kotlin/test/TestUtilsKt.class create mode 100644 backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsComparable.kt create mode 100644 backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsDouble.kt create mode 100644 backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsInt.kt create mode 100644 backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsLong.kt create mode 100644 backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/calculateFinalElement.kt create mode 100644 backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/iterateToFinalElement.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyConstant.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyDownto.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedDownTo.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementDownTo.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/openRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedBackSequence.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyBackSequence.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedInexactSteppedDownTo.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleDownTo.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedDownTo.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/byteRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/charRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/comparableRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/doubleRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/emptyEquals.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/emptyHashCode.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/floatRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/intRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/isEmpty.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/longRange.kt create mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/shortRange.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/escapeLiteral.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchAllSequence.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchEntire.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchEntireLazyQuantor.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchGroups.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchIgnoreCase.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchMultiline.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchOptionalGroup.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchResult.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchSequence.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/replace.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/replaceEvaluator.kt create mode 100644 backend.native/tests/external/stdlib/text/RegexTest/split.kt create mode 100644 backend.native/tests/external/stdlib/text/StringBuilderTest/append.kt create mode 100644 backend.native/tests/external/stdlib/text/StringBuilderTest/appendMany.kt create mode 100644 backend.native/tests/external/stdlib/text/StringBuilderTest/asCharSequence.kt create mode 100644 backend.native/tests/external/stdlib/text/StringBuilderTest/constructors.kt create mode 100644 backend.native/tests/external/stdlib/text/StringBuilderTest/stringBuild.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/byteToStringWithRadix.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/intToStringWithRadix.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/longToStringWithRadix.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/shortToStringWithRadix.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toBoolean.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toByte.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toDouble.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toFloat.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toHexDouble.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toInt.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toIntArabicDigits.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLong.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLongArabicDigits.kt create mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toShort.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/capitalize.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/decapitalize.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/drop.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/dropWhile.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/endsWithString.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/equalsIgnoreCase.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/filter.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/filterIndexed.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/filterNot.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/joinTo.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/joinToString.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/orEmpty.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/partition.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/replace.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/replaceDelimited.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/replaceFirst.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/reverse.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/slice.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/startsWithString.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/substringDelimited.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/take.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/takeWhile.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/testIndent.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/trimIndent.kt create mode 100644 backend.native/tests/external/stdlib/text/StringTest/trimMargin.kt create mode 100644 backend.native/tests/external/stdlib/utils/KotlinVersionTest/componentValidation.kt create mode 100644 backend.native/tests/external/stdlib/utils/KotlinVersionTest/currentVersion.kt create mode 100644 backend.native/tests/external/stdlib/utils/LazyTest/alreadyInitialized.kt create mode 100644 backend.native/tests/external/stdlib/utils/LazyTest/initializationCalledOnce.kt create mode 100644 backend.native/tests/external/stdlib/utils/LazyTest/lazyToString.kt create mode 100644 backend.native/tests/external/stdlib/utils/TODOTest/usage.kt diff --git a/backend.native/tests/external/stdlib/OrderingTest/combineComparators.kt b/backend.native/tests/external/stdlib/OrderingTest/combineComparators.kt new file mode 100644 index 00000000000..0b670c4e4ed --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/combineComparators.kt @@ -0,0 +1,26 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +val v3 = Item("apple", 20) +fun box() { + val byName = compareBy { it.name } + val byRating = compareBy { it.rating } + val v3 = Item(v1.name, v1.rating + 1) + val v4 = Item(v2.name + "_", v2.rating) + assertTrue((byName then byRating).compare(v1, v2) > 0) + assertTrue((byName then byRating).compare(v1, v3) < 0) + assertTrue((byName thenDescending byRating).compare(v1, v3) > 0) + + assertTrue((byRating then byName).compare(v1, v2) < 0) + assertTrue((byRating then byName).compare(v4, v2) > 0) + assertTrue((byRating thenDescending byName).compare(v4, v2) < 0) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/compareByCompareTo.kt b/backend.native/tests/external/stdlib/OrderingTest/compareByCompareTo.kt new file mode 100644 index 00000000000..e163826c641 --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/compareByCompareTo.kt @@ -0,0 +1,16 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +fun box() { + val diff = v1.compareTo(v2) + assertTrue(diff < 0) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/compareByNameFirst.kt b/backend.native/tests/external/stdlib/OrderingTest/compareByNameFirst.kt new file mode 100644 index 00000000000..c9a351e7cca --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/compareByNameFirst.kt @@ -0,0 +1,16 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +fun box() { + val diff = compareValuesBy(v1, v2, { it.name }, { it.rating }) + assertTrue(diff > 0) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/compareByRatingFirst.kt b/backend.native/tests/external/stdlib/OrderingTest/compareByRatingFirst.kt new file mode 100644 index 00000000000..907abcca324 --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/compareByRatingFirst.kt @@ -0,0 +1,16 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +fun box() { + val diff = compareValuesBy(v1, v2, { it.rating }, { it.name }) + assertTrue(diff < 0) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/compareNullables.kt b/backend.native/tests/external/stdlib/OrderingTest/compareNullables.kt new file mode 100644 index 00000000000..13fff370946 --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/compareNullables.kt @@ -0,0 +1,21 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) + +fun box() { + val v1: Item? = v1 + val v2: Item? = null + val diff = compareValuesBy(v1, v2) { it?.rating } + assertTrue(diff > 0) + val diff2 = nullsLast(compareBy { it.rating }.thenBy { it.name }).compare(v1, v2) + assertTrue(diff2 < 0) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/compareSameObjectsByRatingFirst.kt b/backend.native/tests/external/stdlib/OrderingTest/compareSameObjectsByRatingFirst.kt new file mode 100644 index 00000000000..a10475539f4 --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/compareSameObjectsByRatingFirst.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +fun box() { + val diff = compareValuesBy(v1, v1, { it.rating }, { it.name }) + assertTrue(diff == 0) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/maxOf.kt b/backend.native/tests/external/stdlib/OrderingTest/maxOf.kt new file mode 100644 index 00000000000..65e7d74afa3 --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/maxOf.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + assertEquals(Int.MAX_VALUE, maxOf(Int.MAX_VALUE, Int.MIN_VALUE)) + assertEquals(Int.MAX_VALUE, maxOf(Int.MAX_VALUE, Int.MIN_VALUE, 0)) + + assertEquals(Long.MAX_VALUE, maxOf(Long.MAX_VALUE, Long.MIN_VALUE)) + assertEquals(Long.MAX_VALUE, maxOf(Long.MAX_VALUE, Long.MIN_VALUE, 0)) + + assertEquals(Double.POSITIVE_INFINITY, maxOf(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)) + assertEquals(Double.POSITIVE_INFINITY, maxOf(Double.POSITIVE_INFINITY, Double.MAX_VALUE, Double.MIN_VALUE)) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/maxOfWith.kt b/backend.native/tests/external/stdlib/OrderingTest/maxOfWith.kt new file mode 100644 index 00000000000..b5d3a510c03 --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/maxOfWith.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +val v3 = Item("apple", 20) +fun box() { + assertEquals(v1, maxOf(v1, v2, compareBy { it.name })) + assertEquals(v1, maxOf(v3, v2, v1, compareBy { it.name })) + assertEquals(v2, maxOf(v1, v2, compareBy { it.rating })) + assertEquals(v3, maxOf(v1, v2, v3, compareBy { it.rating })) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/minOf.kt b/backend.native/tests/external/stdlib/OrderingTest/minOf.kt new file mode 100644 index 00000000000..b4fbbcfa8aa --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/minOf.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + assertEquals(Int.MIN_VALUE, minOf(Int.MAX_VALUE, Int.MIN_VALUE)) + assertEquals(Int.MIN_VALUE, minOf(Int.MAX_VALUE, Int.MIN_VALUE, 0)) + + assertEquals(Long.MIN_VALUE, minOf(Long.MAX_VALUE, Long.MIN_VALUE)) + assertEquals(Long.MIN_VALUE, minOf(Long.MAX_VALUE, Long.MIN_VALUE, 0)) + + assertEquals(Double.NEGATIVE_INFINITY, minOf(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)) + assertEquals(Double.MIN_VALUE, minOf(Double.POSITIVE_INFINITY, Double.MAX_VALUE, Double.MIN_VALUE)) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/minOfWith.kt b/backend.native/tests/external/stdlib/OrderingTest/minOfWith.kt new file mode 100644 index 00000000000..076c82903ca --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/minOfWith.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +val v3 = Item("apple", 20) +fun box() { + assertEquals(v2, minOf(v1, v2, compareBy { it.name })) + assertEquals(v3, minOf(v3, v2, v1, compareBy { it.name })) + assertEquals(v1, minOf(v1, v2, compareBy { it.rating })) + assertEquals(v1, minOf(v1, v2, v3, compareBy { it.rating })) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/naturalOrderComparator.kt b/backend.native/tests/external/stdlib/OrderingTest/naturalOrderComparator.kt new file mode 100644 index 00000000000..e17f48a84de --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/naturalOrderComparator.kt @@ -0,0 +1,21 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +fun box() { + val v1 = "a" + val v2 = "beta" + + assertTrue(naturalOrder().compare(v1, v2) < 0) + assertTrue(reverseOrder().compare(v1, v2) > 0) + assertTrue(reverseOrder() === naturalOrder().reversed()) + assertTrue(naturalOrder() === reverseOrder().reversed()) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/reversedComparator.kt b/backend.native/tests/external/stdlib/OrderingTest/reversedComparator.kt new file mode 100644 index 00000000000..a1643541294 --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/reversedComparator.kt @@ -0,0 +1,18 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +fun box() { + val comparator = compareBy { it.name } + val reversed = comparator.reversed() + assertEquals(comparator.compare(v2, v1), reversed.compare(v1, v2)) + assertEquals(comparator, reversed.reversed()) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/sortByThenBy.kt b/backend.native/tests/external/stdlib/OrderingTest/sortByThenBy.kt new file mode 100644 index 00000000000..33d8d4c2aeb --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/sortByThenBy.kt @@ -0,0 +1,21 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +fun box() { + val comparator = compareBy { it.rating }.thenBy { it.name } + + val diff = comparator.compare(v1, v2) + assertTrue(diff < 0) + val items = arrayListOf(v1, v2).sortedWith(comparator) + assertEquals(v1, items[0]) + assertEquals(v2, items[1]) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/sortByThenByDescending.kt b/backend.native/tests/external/stdlib/OrderingTest/sortByThenByDescending.kt new file mode 100644 index 00000000000..ee28f05de6f --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/sortByThenByDescending.kt @@ -0,0 +1,21 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +fun box() { + val comparator = compareBy { it.rating }.thenByDescending { it.name } + + val diff = comparator.compare(v1, v2) + assertTrue(diff < 0) + val items = arrayListOf(v1, v2).sortedWith(comparator) + assertEquals(v1, items[0]) + assertEquals(v2, items[1]) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/sortComparatorThenComparator.kt b/backend.native/tests/external/stdlib/OrderingTest/sortComparatorThenComparator.kt new file mode 100644 index 00000000000..81e2a514ed1 --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/sortComparatorThenComparator.kt @@ -0,0 +1,21 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +fun box() { + val comparator = Comparator { a, b -> a.name.compareTo(b.name) }.thenComparator { a, b -> a.rating.compareTo(b.rating) } + + val diff = comparator.compare(v1, v2) + assertTrue(diff > 0) + val items = arrayListOf(v1, v2).sortedWith(comparator) + assertEquals(v2, items[0]) + assertEquals(v1, items[1]) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/sortUsingCustomComparator.kt b/backend.native/tests/external/stdlib/OrderingTest/sortUsingCustomComparator.kt new file mode 100644 index 00000000000..8971c8b40a6 --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/sortUsingCustomComparator.kt @@ -0,0 +1,28 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +fun box() { + val comparator = object : Comparator { + override fun compare(o1: Item, o2: Item): Int { + return compareValuesBy(o1, o2, { it.name }, { it.rating }) + } + + override fun equals(other: Any?): Boolean { + return this == other + } + } + val diff = comparator.compare(v1, v2) + assertTrue(diff > 0) + val items = arrayListOf(v1, v2).sortedWith(comparator) + assertEquals(v2, items[0]) + assertEquals(v1, items[1]) +} diff --git a/backend.native/tests/external/stdlib/OrderingTest/sortUsingFunctionalComparator.kt b/backend.native/tests/external/stdlib/OrderingTest/sortUsingFunctionalComparator.kt new file mode 100644 index 00000000000..c2aeef396e2 --- /dev/null +++ b/backend.native/tests/external/stdlib/OrderingTest/sortUsingFunctionalComparator.kt @@ -0,0 +1,20 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +data class Item(val name: String, val rating: Int) : Comparable { + public override fun compareTo(other: Item): Int { + return compareValuesBy(this, other, { it.rating }, { it.name }) + } +} + +val v1 = Item("wine", 9) +val v2 = Item("beer", 10) +fun box() { + val comparator = compareBy({ it.name }, { it.rating }) + val diff = comparator.compare(v1, v2) + assertTrue(diff > 0) + val items = arrayListOf(v1, v2).sortedWith(comparator) + assertEquals(v2, items[0]) + assertEquals(v1, items[1]) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/pairEquals.kt b/backend.native/tests/external/stdlib/TuplesTest/pairEquals.kt new file mode 100644 index 00000000000..fa777005f0d --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/pairEquals.kt @@ -0,0 +1,14 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val p = Pair(1, "a") +val t = Triple(1, "a", 0.07) +fun box() { + assertEquals(Pair(1, "a"), p) + assertNotEquals(Pair(2, "a"), p) + assertNotEquals(Pair(1, "b"), p) + assertTrue(!p.equals(null)) + assertNotEquals("", (p as Any)) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/pairFirstAndSecond.kt b/backend.native/tests/external/stdlib/TuplesTest/pairFirstAndSecond.kt new file mode 100644 index 00000000000..bc1eea18123 --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/pairFirstAndSecond.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val p = Pair(1, "a") +val t = Triple(1, "a", 0.07) +fun box() { + assertEquals(1, p.first) + assertEquals("a", p.second) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/pairHashCode.kt b/backend.native/tests/external/stdlib/TuplesTest/pairHashCode.kt new file mode 100644 index 00000000000..0285585e92f --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/pairHashCode.kt @@ -0,0 +1,14 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val p = Pair(1, "a") +val t = Triple(1, "a", 0.07) +fun box() { + assertEquals(Pair(1, "a").hashCode(), p.hashCode()) + assertNotEquals(Pair(2, "a").hashCode(), p.hashCode()) + assertNotEquals(0, Pair(null, "b").hashCode()) + assertNotEquals(0, Pair("b", null).hashCode()) + assertEquals(0, Pair(null, null).hashCode()) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/pairHashSet.kt b/backend.native/tests/external/stdlib/TuplesTest/pairHashSet.kt new file mode 100644 index 00000000000..91ff3479e67 --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/pairHashSet.kt @@ -0,0 +1,12 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val p = Pair(1, "a") +val t = Triple(1, "a", 0.07) +fun box() { + val s = hashSetOf(Pair(1, "a"), Pair(1, "b"), Pair(1, "a")) + assertEquals(2, s.size) + assertTrue(s.contains(p)) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/pairMultiAssignment.kt b/backend.native/tests/external/stdlib/TuplesTest/pairMultiAssignment.kt new file mode 100644 index 00000000000..13fd1843d17 --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/pairMultiAssignment.kt @@ -0,0 +1,12 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val p = Pair(1, "a") +val t = Triple(1, "a", 0.07) +fun box() { + val (a, b) = p + assertEquals(1, a) + assertEquals("a", b) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/pairToList.kt b/backend.native/tests/external/stdlib/TuplesTest/pairToList.kt new file mode 100644 index 00000000000..76b67071520 --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/pairToList.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val t = Triple(1, "a", 0.07) +fun box() { + assertEquals(listOf(1, 2), (1 to 2).toList()) + assertEquals(listOf(1, null), (1 to null).toList()) + assertEquals(listOf(1, "2"), (1 to "2").toList()) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/pairToString.kt b/backend.native/tests/external/stdlib/TuplesTest/pairToString.kt new file mode 100644 index 00000000000..2d15e02384e --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/pairToString.kt @@ -0,0 +1,10 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val p = Pair(1, "a") +val t = Triple(1, "a", 0.07) +fun box() { + assertEquals("(1, a)", p.toString()) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/tripleEquals.kt b/backend.native/tests/external/stdlib/TuplesTest/tripleEquals.kt new file mode 100644 index 00000000000..a2b29923061 --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/tripleEquals.kt @@ -0,0 +1,15 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val p = Pair(1, "a") +val t = Triple(1, "a", 0.07) +fun box() { + assertEquals(Triple(1, "a", 0.07), t) + assertNotEquals(Triple(2, "a", 0.07), t) + assertNotEquals(Triple(1, "b", 0.07), t) + assertNotEquals(Triple(1, "a", 0.1), t) + assertTrue(!t.equals(null)) + assertNotEquals("", (t as Any)) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/tripleFirstAndSecond.kt b/backend.native/tests/external/stdlib/TuplesTest/tripleFirstAndSecond.kt new file mode 100644 index 00000000000..534dbea12a8 --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/tripleFirstAndSecond.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val t = Triple(1, "a", 0.07) +fun box() { + assertEquals(1, t.first) + assertEquals("a", t.second) + assertEquals(0.07, t.third) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/tripleHashCode.kt b/backend.native/tests/external/stdlib/TuplesTest/tripleHashCode.kt new file mode 100644 index 00000000000..801839f454e --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/tripleHashCode.kt @@ -0,0 +1,15 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val p = Pair(1, "a") +val t = Triple(1, "a", 0.07) +fun box() { + assertEquals(Triple(1, "a", 0.07).hashCode(), t.hashCode()) + assertNotEquals(Triple(2, "a", 0.07).hashCode(), t.hashCode()) + assertNotEquals(0, Triple(null, "b", 0.07).hashCode()) + assertNotEquals(0, Triple("b", null, 0.07).hashCode()) + assertNotEquals(0, Triple("b", 1, null).hashCode()) + assertEquals(0, Triple(null, null, null).hashCode()) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/tripleHashSet.kt b/backend.native/tests/external/stdlib/TuplesTest/tripleHashSet.kt new file mode 100644 index 00000000000..14e097d075f --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/tripleHashSet.kt @@ -0,0 +1,12 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val p = Pair(1, "a") +val t = Triple(1, "a", 0.07) +fun box() { + val s = hashSetOf(Triple(1, "a", 0.07), Triple(1, "b", 0.07), Triple(1, "a", 0.07)) + assertEquals(2, s.size) + assertTrue(s.contains(t)) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/tripleMultiAssignment.kt b/backend.native/tests/external/stdlib/TuplesTest/tripleMultiAssignment.kt new file mode 100644 index 00000000000..bd8ea5f9647 --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/tripleMultiAssignment.kt @@ -0,0 +1,12 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val t = Triple(1, "a", 0.07) +fun box() { + val (a, b, c) = t + assertEquals(1, a) + assertEquals("a", b) + assertEquals(0.07, c) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/tripleToList.kt b/backend.native/tests/external/stdlib/TuplesTest/tripleToList.kt new file mode 100644 index 00000000000..8402b5849de --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/tripleToList.kt @@ -0,0 +1,12 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val p = Pair(1, "a") +val t = Triple(1, "a", 0.07) +fun box() { + assertEquals(listOf(1, 2, 3), (Triple(1, 2, 3)).toList()) + assertEquals(listOf(1, null, 3), (Triple(1, null, 3)).toList()) + assertEquals(listOf(1, 2, "3"), (Triple(1, 2, "3")).toList()) +} diff --git a/backend.native/tests/external/stdlib/TuplesTest/tripleToString.kt b/backend.native/tests/external/stdlib/TuplesTest/tripleToString.kt new file mode 100644 index 00000000000..6c3677160b5 --- /dev/null +++ b/backend.native/tests/external/stdlib/TuplesTest/tripleToString.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.test.assertEquals +import kotlin.test.assertNotEquals + +val t = Triple(1, "a", 0.07) +fun box() { + assertEquals("(1, a, 0.07)", t.toString()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/arrayLastIndex.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/arrayLastIndex.kt new file mode 100644 index 00000000000..415fe460b4c --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/arrayLastIndex.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +fun box() { + val arr1 = intArrayOf(0, 1, 2, 3, 4) + assertEquals(4, arr1.lastIndex) + assertEquals(4, arr1[arr1.lastIndex]) + + val arr2 = Array(5, { "$it" }) + assertEquals(4, arr2.lastIndex) + assertEquals("4", arr2[arr2.lastIndex]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/asIterable.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/asIterable.kt new file mode 100644 index 00000000000..a6d16ae3729 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/asIterable.kt @@ -0,0 +1,23 @@ +import kotlin.test.* + +fun box() { + val arr1 = intArrayOf(1, 2, 3, 4, 5) + val iter1 = arr1.asIterable() + assertEquals(arr1.toList(), iter1.toList()) + arr1[0] = 0 + assertEquals(arr1.toList(), iter1.toList()) + + val arr2 = arrayOf("one", "two", "three") + val iter2 = arr2.asIterable() + assertEquals(arr2.toList(), iter2.toList()) + arr2[0] = "" + assertEquals(arr2.toList(), iter2.toList()) + + val arr3 = IntArray(0) + val iter3 = arr3.asIterable() + assertEquals(iter3.toList(), emptyList()) + + val arr4 = Array(0, { "$it" }) + val iter4 = arr4.asIterable() + assertEquals(iter4.toList(), emptyList()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/asList.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/asList.kt new file mode 100644 index 00000000000..69e99f726dc --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/asList.kt @@ -0,0 +1,109 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.listBehavior() { + equalityBehavior() + collectionBehavior() + compareProperty({ listIterator() }, { listIteratorBehavior() }) + compareProperty({ listIterator(0) }, { listIteratorBehavior() }) + + propertyFails { listIterator(-1) } + propertyFails { listIterator(size + 1) } + + for (index in expected.indices) + propertyEquals { this[index] } + + propertyFails { this[size] } + + propertyEquals { indexOf(elementAtOrNull(0)) } + propertyEquals { lastIndexOf(elementAtOrNull(0)) } + + propertyFails { subList(0, size + 1) } + propertyFails { subList(-1, 0) } + propertyEquals { subList(0, size) } +} + +fun CompareContext.equalityBehavior(objectName: String = "") { + val prefix = objectName + if (objectName.isNotEmpty()) "." else "" + equals(objectName) + propertyEquals(prefix + "hashCode") { hashCode() } + propertyEquals(prefix + "toString") { toString() } +} + + +fun CompareContext>.collectionBehavior(objectName: String = "") { + val prefix = objectName + if (objectName.isNotEmpty()) "." else "" + propertyEquals(prefix + "size") { size } + propertyEquals(prefix + "isEmpty") { isEmpty() } + + (object {}).let { propertyEquals { contains(it as Any?) } } + propertyEquals { contains(firstOrNull()) } + propertyEquals { containsAll(this) } +} + +fun CompareContext>.listIteratorBehavior() { + listIteratorProperties() + + while (expected.hasNext()) { + propertyEquals { next() } + listIteratorProperties() + } + propertyFails { next() } + + while (expected.hasPrevious()) { + propertyEquals { previous() } + listIteratorProperties() + } + propertyFails { previous() } +} + +public fun CompareContext>.listIteratorProperties() { + propertyEquals { hasNext() } + propertyEquals { hasPrevious() } + propertyEquals { nextIndex() } + propertyEquals { previousIndex() } +} + +fun box() { + compare(listOf(1, 2, 3), intArrayOf(1, 2, 3).asList()) { listBehavior() } + compare(listOf(1, 2, 3), byteArrayOf(1, 2, 3).asList()) { listBehavior() } + compare(listOf(true, false), booleanArrayOf(true, false).asList()) { listBehavior() } + + compare(listOf(1, 2, 3), arrayOf(1, 2, 3).asList()) { listBehavior() } + compare(listOf("abc", "def"), arrayOf("abc", "def").asList()) { listBehavior() } + + val ints = intArrayOf(1, 5, 7) + val intsAsList = ints.asList() + assertEquals(5, intsAsList[1]) + ints[1] = 10 + assertEquals(10, intsAsList[1], "Should reflect changes in original array") +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/asListObjects.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/asListObjects.kt new file mode 100644 index 00000000000..26e8bf65240 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/asListObjects.kt @@ -0,0 +1,34 @@ +import kotlin.test.* + +fun box() { + val arr = arrayOf("a", "b", "c", "d", "b", "e") + val list = arr.asList() + + assertEquals(list, arr.toList()) + + assertTrue("b" in list) + assertFalse("z" in list) + + expect(1) { list.indexOf("b") } + expect(4) { list.lastIndexOf("b") } + expect(-1) { list.indexOf("x") } + + assertTrue(list.containsAll(listOf("e", "d", "c"))) + assertFalse(list.containsAll(listOf("e", "x", "c"))) + + assertEquals(list.subList(3, 5), listOf("d", "b")) + + val iter = list.listIterator(2) + expect(2) { iter.nextIndex() } + expect(1) { iter.previousIndex() } + expect("c") { + iter.next() + iter.previous() + iter.next() + } + + arr[2] = "xx" + assertEquals(list, arr.toList()) + + assertEquals(Array(0, { "" }).asList(), emptyList()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/asListPrimitives.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/asListPrimitives.kt new file mode 100644 index 00000000000..1e46b20314d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/asListPrimitives.kt @@ -0,0 +1,33 @@ +import kotlin.test.* + +fun box() { + // Array of primitives + val arr = intArrayOf(1, 2, 3, 4, 2, 5) + val list = arr.asList() + assertEquals(list, arr.toList()) + + assertTrue(2 in list) + assertFalse(0 in list) + assertTrue(list.containsAll(listOf(5, 4, 3))) + assertFalse(list.containsAll(listOf(5, 6, 3))) + + expect(1) { list.indexOf(2) } + expect(4) { list.lastIndexOf(2) } + expect(-1) { list.indexOf(6) } + + assertEquals(list.subList(3, 5), listOf(4, 2)) + + val iter = list.listIterator(2) + expect(2) { iter.nextIndex() } + expect(1) { iter.previousIndex() } + expect(3) { + iter.next() + iter.previous() + iter.next() + } + + arr[2] = 4 + assertEquals(list, arr.toList()) + + assertEquals(IntArray(0).asList(), emptyList()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/average.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/average.kt new file mode 100644 index 00000000000..a8687dd2117 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/average.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + +fun box() { + assertTrue() { arrayOf().average().isNaN() } + expect(3.8) { arrayOf(1, 2, 5, 8, 3).average() } + expect(2.1) { arrayOf(1.6, 2.6, 3.6, 0.6).average() } + expect(100.0) { arrayOf(100, 100, 100, 100, 100, 100).average() } + expect(0) { arrayOf(1, -1, 2, -2, 3, -3).average().toShort() } + // TODO: Property based tests + // for each arr with size 1 arr.average() == arr[0] + // for each arr with size > 0 arr.average() = arr.sum().toDouble() / arr.size() +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/booleanArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/booleanArray.kt new file mode 100644 index 00000000000..042a7ef214a --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/booleanArray.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +fun box() { + val arr = BooleanArray(2) + assertEquals(arr.size, 2) + assertEquals(false, arr[0]) + assertEquals(false, arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/booleanArrayInit.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/booleanArrayInit.kt new file mode 100644 index 00000000000..01c141aca05 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/booleanArrayInit.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr = BooleanArray(2) { it % 2 == 0 } + + assertEquals(2, arr.size) + assertEquals(true, arr[0]) + assertEquals(false, arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/byteArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/byteArray.kt new file mode 100644 index 00000000000..cb9c54f557f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/byteArray.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + val arr = ByteArray(2) + + val expected: Byte = 0 + assertEquals(arr.size, 2) + assertEquals(expected, arr[0]) + assertEquals(expected, arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/byteArrayInit.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/byteArrayInit.kt new file mode 100644 index 00000000000..9a81221294c --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/byteArrayInit.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr = ByteArray(2) { it.toByte() } + + assertEquals(2, arr.size) + assertEquals(0.toByte(), arr[0]) + assertEquals(1.toByte(), arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/charArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/charArray.kt new file mode 100644 index 00000000000..71b899a7c23 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/charArray.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + val arr = CharArray(2) + + val expected: Char = '\u0000' + assertEquals(arr.size, 2) + assertEquals(expected, arr[0]) + assertEquals(expected, arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/charArrayInit.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/charArrayInit.kt new file mode 100644 index 00000000000..38526d92749 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/charArrayInit.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr = CharArray(2) { 'a' + it } + + assertEquals(2, arr.size) + assertEquals('a', arr[0]) + assertEquals('b', arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/contains.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/contains.kt new file mode 100644 index 00000000000..90bc34adc79 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/contains.kt @@ -0,0 +1,7 @@ +import kotlin.test.* + +fun box() { + assertTrue(arrayOf("1", "2", "3", "4").contains("2")) + assertTrue("3" in arrayOf("1", "2", "3", "4")) + assertTrue("0" !in arrayOf("1", "2", "3", "4")) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepEquals.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepEquals.kt new file mode 100644 index 00000000000..61142a7fc28 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepEquals.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + val arr1 = arrayOf("a", 1, intArrayOf(2)) + val arr2 = arrayOf("a", 1, intArrayOf(2)) + assertFalse(arr1 contentEquals arr2) + assertTrue(arr1 contentDeepEquals arr2) + arr2[2] = arr1 + assertFalse(arr1 contentDeepEquals arr2) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepHashCode.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepHashCode.kt new file mode 100644 index 00000000000..979642810c6 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepHashCode.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +data class Value(val value: Int) { + override fun hashCode(): Int = value +} + +fun box() { + val arr = arrayOf(null, Value(2), arrayOf(Value(3))) + assertEquals(((1 * 31 + 0) * 31 + 2) * 31 + (1 * 31 + 3), arr.contentDeepHashCode()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToString.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToString.kt new file mode 100644 index 00000000000..d828b27bd6c --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToString.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + +fun box() { + // Don't run this test unless primitive array `is` checks are supported (KT-17137) + if ((intArrayOf() as Any) is Array<*>) { + assertTrue(true) + return + } + + val arr = arrayOf("aa", 1, null, charArrayOf('d')) + assertEquals("[aa, 1, null, [d]]", arr.contentDeepToString()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToStringNoRecursion.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToStringNoRecursion.kt new file mode 100644 index 00000000000..b08e26488ad --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToStringNoRecursion.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +fun box() { + // a[b[a, b]] + val b = arrayOfNulls(2) + val a = arrayOf(b) + b[0] = a + b[1] = b + a.toString() + assertTrue(true, "toString does not cycle") + a.contentToString() + assertTrue(true, "contentToString does not cycle") + val result = a.contentDeepToString() + assertEquals("[[[...], [...]]]", result) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/contentEquals.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/contentEquals.kt new file mode 100644 index 00000000000..0ebfb961a67 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/contentEquals.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr1 = arrayOf("a", 1, null) + val arr2 = arrayOf(*arr1) + assertTrue(arr1 contentEquals arr2) + val arr3 = arr2.reversedArray() + assertFalse(arr1 contentEquals arr3) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/contentHashCode.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/contentHashCode.kt new file mode 100644 index 00000000000..f21040484bc --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/contentHashCode.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +data class Value(val value: Int) { + override fun hashCode(): Int = value +} + +fun box() { + val arr = arrayOf("a", 1, null, Value(5)) + assertEquals(listOf(*arr).hashCode(), arr.contentHashCode()) + assertEquals((1 * 31 + 2) * 31 + 3, arrayOf(Value(2), Value(3)).contentHashCode()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/contentToString.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/contentToString.kt new file mode 100644 index 00000000000..ac01548b5b3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/contentToString.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + +fun box() { + val arr = arrayOf("a", 1, null) + assertEquals(arr.asList().toString(), arr.contentToString()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/copyAndResize.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/copyAndResize.kt new file mode 100644 index 00000000000..ea389b15e12 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/copyAndResize.kt @@ -0,0 +1,51 @@ +import kotlin.test.* + +fun assertArrayNotSameButEquals(expected: Array, actual: Array, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: IntArray, actual: IntArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: LongArray, actual: LongArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ShortArray, actual: ShortArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ByteArray, actual: ByteArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: DoubleArray, actual: DoubleArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: FloatArray, actual: FloatArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: CharArray, actual: CharArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun box() { + assertArrayNotSameButEquals(arrayOf("1", "2"), arrayOf("1", "2", "3").copyOf(2)) + assertArrayNotSameButEquals(arrayOf("1", "2", null), arrayOf("1", "2").copyOf(3)) + + assertArrayNotSameButEquals(longArrayOf(1, 2), longArrayOf(1, 2, 3).copyOf(2)) + assertArrayNotSameButEquals(longArrayOf(1, 2, 0), longArrayOf(1, 2).copyOf(3)) + + assertArrayNotSameButEquals(intArrayOf(1, 2), intArrayOf(1, 2, 3).copyOf(2)) + assertArrayNotSameButEquals(intArrayOf(1, 2, 0), intArrayOf(1, 2).copyOf(3)) + + assertArrayNotSameButEquals(charArrayOf('A', 'B'), charArrayOf('A', 'B', 'C').copyOf(2)) + assertArrayNotSameButEquals(charArrayOf('A', 'B', '\u0000'), charArrayOf('A', 'B').copyOf(3)) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/copyOf.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/copyOf.kt new file mode 100644 index 00000000000..ef9a642b786 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/copyOf.kt @@ -0,0 +1,48 @@ +import kotlin.test.* + +fun assertArrayNotSameButEquals(expected: Array, actual: Array, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: IntArray, actual: IntArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: LongArray, actual: LongArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ShortArray, actual: ShortArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ByteArray, actual: ByteArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: DoubleArray, actual: DoubleArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: FloatArray, actual: FloatArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: CharArray, actual: CharArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun box() { + booleanArrayOf(true, false, true).let { assertArrayNotSameButEquals(it, it.copyOf()) } + byteArrayOf(0, 1, 2, 3, 4, 5).let { assertArrayNotSameButEquals(it, it.copyOf()) } + shortArrayOf(0, 1, 2, 3, 4, 5).let { assertArrayNotSameButEquals(it, it.copyOf()) } + intArrayOf(0, 1, 2, 3, 4, 5).let { assertArrayNotSameButEquals(it, it.copyOf()) } + longArrayOf(0, 1, 2, 3, 4, 5).let { assertArrayNotSameButEquals(it, it.copyOf()) } + floatArrayOf(0F, 1F, 2F, 3F).let { assertArrayNotSameButEquals(it, it.copyOf()) } + doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0).let { assertArrayNotSameButEquals(it, it.copyOf()) } + charArrayOf('0', '1', '2', '3', '4', '5').let { assertArrayNotSameButEquals(it, it.copyOf()) } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/copyOfRange.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/copyOfRange.kt new file mode 100644 index 00000000000..9a7540b9f83 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/copyOfRange.kt @@ -0,0 +1,48 @@ +import kotlin.test.* + +fun assertArrayNotSameButEquals(expected: Array, actual: Array, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: IntArray, actual: IntArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: LongArray, actual: LongArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ShortArray, actual: ShortArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ByteArray, actual: ByteArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: DoubleArray, actual: DoubleArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: FloatArray, actual: FloatArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: CharArray, actual: CharArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun box() { + assertArrayNotSameButEquals(booleanArrayOf(true, false, true), booleanArrayOf(true, false, true, true).copyOfRange(0, 3)) + assertArrayNotSameButEquals(byteArrayOf(0, 1, 2), byteArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3)) + assertArrayNotSameButEquals(shortArrayOf(0, 1, 2), shortArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3)) + assertArrayNotSameButEquals(intArrayOf(0, 1, 2), intArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3)) + assertArrayNotSameButEquals(longArrayOf(0, 1, 2), longArrayOf(0, 1, 2, 3, 4, 5).copyOfRange(0, 3)) + assertArrayNotSameButEquals(floatArrayOf(0F, 1F, 2F), floatArrayOf(0F, 1F, 2F, 3F, 4F, 5F).copyOfRange(0, 3)) + assertArrayNotSameButEquals(doubleArrayOf(0.0, 1.0, 2.0), doubleArrayOf(0.0, 1.0, 2.0, 3.0, 4.0, 5.0).copyOfRange(0, 3)) + assertArrayNotSameButEquals(charArrayOf('0', '1', '2'), charArrayOf('0', '1', '2', '3', '4', '5').copyOfRange(0, 3)) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/doubleArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/doubleArray.kt new file mode 100644 index 00000000000..495a28c7598 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/doubleArray.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr = DoubleArray(2) + + assertEquals(arr.size, 2) + assertEquals(0.0, arr[0]) + assertEquals(0.0, arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/doubleArrayInit.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/doubleArrayInit.kt new file mode 100644 index 00000000000..926141d056e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/doubleArrayInit.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr = DoubleArray(2) { it.toDouble() } + + assertEquals(2, arr.size) + assertEquals(0.toDouble(), arr[0]) + assertEquals(1.toDouble(), arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/drop.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/drop.kt new file mode 100644 index 00000000000..da34b59199b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/drop.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + +fun box() { + expect(listOf(1), { intArrayOf(1).drop(0) }) + expect(listOf(), { intArrayOf().drop(1) }) + expect(listOf(), { intArrayOf(1).drop(1) }) + expect(listOf(3), { intArrayOf(2, 3).drop(1) }) + expect(listOf(2000000000000), { longArrayOf(3000000000000, 2000000000000).drop(1) }) + expect(listOf(3.toByte()), { byteArrayOf(2, 3).drop(1) }) + expect(listOf(3.toShort()), { shortArrayOf(2, 3).drop(1) }) + expect(listOf(3.0f), { floatArrayOf(2f, 3f).drop(1) }) + expect(listOf(3.0), { doubleArrayOf(2.0, 3.0).drop(1) }) + expect(listOf(false), { booleanArrayOf(true, false).drop(1) }) + expect(listOf('b'), { charArrayOf('a', 'b').drop(1) }) + expect(listOf("b"), { arrayOf("a", "b").drop(1) }) + assertFails { + listOf(2).drop(-1) + } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/dropLast.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/dropLast.kt new file mode 100644 index 00000000000..a3967312623 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/dropLast.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + +fun box() { + expect(listOf(), { intArrayOf().dropLast(1) }) + expect(listOf(), { intArrayOf(1).dropLast(1) }) + expect(listOf(1), { intArrayOf(1).dropLast(0) }) + expect(listOf(2), { intArrayOf(2, 3).dropLast(1) }) + expect(listOf(3000000000000), { longArrayOf(3000000000000, 2000000000000).dropLast(1) }) + expect(listOf(2.toByte()), { byteArrayOf(2, 3).dropLast(1) }) + expect(listOf(2.toShort()), { shortArrayOf(2, 3).dropLast(1) }) + expect(listOf(2.0f), { floatArrayOf(2f, 3f).dropLast(1) }) + expect(listOf(2.0), { doubleArrayOf(2.0, 3.0).dropLast(1) }) + expect(listOf(true), { booleanArrayOf(true, false).dropLast(1) }) + expect(listOf('a'), { charArrayOf('a', 'b').dropLast(1) }) + expect(listOf("a"), { arrayOf("a", "b").dropLast(1) }) + assertFails { + listOf(1).dropLast(-1) + } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/dropLastWhile.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/dropLastWhile.kt new file mode 100644 index 00000000000..0a4aee2bd96 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/dropLastWhile.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +fun box() { + expect(listOf(), { intArrayOf().dropLastWhile { it < 3 } }) + expect(listOf(), { intArrayOf(1).dropLastWhile { it < 3 } }) + expect(listOf(2, 3), { intArrayOf(2, 3, 1).dropLastWhile { it < 3 } }) + expect(listOf(3000000000000), { longArrayOf(3000000000000, 2000000000000).dropLastWhile { it < 3000000000000 } }) + expect(listOf(2.toByte(), 3.toByte()), { byteArrayOf(2, 3, 1).dropLastWhile { it < 3 } }) + expect(listOf(2.toShort(), 3.toShort()), { shortArrayOf(2, 3, 1).dropLastWhile { it < 3 } }) + expect(listOf(2f, 3f), { floatArrayOf(2f, 3f, 1f).dropLastWhile { it < 3 } }) + expect(listOf(2.0, 3.0), { doubleArrayOf(2.0, 3.0, 1.0).dropLastWhile { it < 3 } }) + expect(listOf(true, false), { booleanArrayOf(true, false, true).dropLastWhile { it } }) + expect(listOf('a', 'b'), { charArrayOf('a', 'b', 'a').dropLastWhile { it < 'b' } }) + expect(listOf("a", "b"), { arrayOf("a", "b", "a").dropLastWhile { it < "b" } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/dropWhile.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/dropWhile.kt new file mode 100644 index 00000000000..81055582fd0 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/dropWhile.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +fun box() { + expect(listOf(), { intArrayOf().dropWhile { it < 3 } }) + expect(listOf(), { intArrayOf(1).dropWhile { it < 3 } }) + expect(listOf(3, 1), { intArrayOf(2, 3, 1).dropWhile { it < 3 } }) + expect(listOf(2000000000000), { longArrayOf(3000000000000, 2000000000000).dropWhile { it > 2000000000000 } }) + expect(listOf(3.toByte(), 1.toByte()), { byteArrayOf(2, 3, 1).dropWhile { it < 3 } }) + expect(listOf(3.toShort(), 1.toShort()), { shortArrayOf(2, 3, 1).dropWhile { it < 3 } }) + expect(listOf(3f, 1f), { floatArrayOf(2f, 3f, 1f).dropWhile { it < 3 } }) + expect(listOf(3.0, 1.0), { doubleArrayOf(2.0, 3.0, 1.0).dropWhile { it < 3 } }) + expect(listOf(false, true), { booleanArrayOf(true, false, true).dropWhile { it } }) + expect(listOf('b', 'a'), { charArrayOf('a', 'b', 'a').dropWhile { it < 'b' } }) + expect(listOf("b", "a"), { arrayOf("a", "b", "a").dropWhile { it < "b" } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/emptyArrayLastIndex.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/emptyArrayLastIndex.kt new file mode 100644 index 00000000000..9b7386a959e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/emptyArrayLastIndex.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr1 = IntArray(0) + assertEquals(-1, arr1.lastIndex) + + val arr2 = emptyArray() + assertEquals(-1, arr2.lastIndex) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/filter.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/filter.kt new file mode 100644 index 00000000000..bf7db78f5d7 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/filter.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +fun box() { + expect(listOf(), { intArrayOf().filter { it > 2 } }) + expect(listOf(), { intArrayOf(1).filter { it > 2 } }) + expect(listOf(3), { intArrayOf(2, 3).filter { it > 2 } }) + expect(listOf(3000000000000), { longArrayOf(3000000000000, 2000000000000).filter { it > 2000000000000 } }) + expect(listOf(3.toByte()), { byteArrayOf(2, 3).filter { it > 2 } }) + expect(listOf(3.toShort()), { shortArrayOf(2, 3).filter { it > 2 } }) + expect(listOf(3.0f), { floatArrayOf(2f, 3f).filter { it > 2 } }) + expect(listOf(3.0), { doubleArrayOf(2.0, 3.0).filter { it > 2 } }) + expect(listOf(true), { booleanArrayOf(true, false).filter { it } }) + expect(listOf('b'), { charArrayOf('a', 'b').filter { it > 'a' } }) + expect(listOf("b"), { arrayOf("a", "b").filter { it > "a" } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/filterIndexed.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/filterIndexed.kt new file mode 100644 index 00000000000..7ea6fc7c7a6 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/filterIndexed.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + expect(listOf(), { intArrayOf().filterIndexed { i, v -> i > v } }) + expect(listOf(2, 5, 8), { intArrayOf(2, 4, 3, 5, 8).filterIndexed { index, value -> index % 2 == value % 2 } }) + expect(listOf(2, 5, 8), { longArrayOf(2, 4, 3, 5, 8).filterIndexed { index, value -> index % 2 == (value % 2).toInt() } }) + expect(listOf(2, 5, 8), { byteArrayOf(2, 4, 3, 5, 8).filterIndexed { index, value -> index % 2 == (value % 2).toInt() } }) + expect(listOf('9', 'e', 'a'), { charArrayOf('9', 'e', 'd', 'a').filterIndexed { index, c -> c == 'a' || index < 2 } }) + expect(listOf("a", "c", "d"), { arrayOf("a", "b", "c", "d").filterIndexed { index, s -> s == "a" || index >= 2 } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/filterNot.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/filterNot.kt new file mode 100644 index 00000000000..585b0a380ae --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/filterNot.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +fun box() { + expect(listOf(), { intArrayOf().filterNot { it > 2 } }) + expect(listOf(1), { intArrayOf(1).filterNot { it > 2 } }) + expect(listOf(2), { intArrayOf(2, 3).filterNot { it > 2 } }) + expect(listOf(2000000000000), { longArrayOf(3000000000000, 2000000000000).filterNot { it > 2000000000000 } }) + expect(listOf(2.toByte()), { byteArrayOf(2, 3).filterNot { it > 2 } }) + expect(listOf(2.toShort()), { shortArrayOf(2, 3).filterNot { it > 2 } }) + expect(listOf(2.0f), { floatArrayOf(2f, 3f).filterNot { it > 2 } }) + expect(listOf(2.0), { doubleArrayOf(2.0, 3.0).filterNot { it > 2 } }) + expect(listOf(false), { booleanArrayOf(true, false).filterNot { it } }) + expect(listOf('a'), { charArrayOf('a', 'b').filterNot { it > 'a' } }) + expect(listOf("a"), { arrayOf("a", "b").filterNot { it > "a" } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/filterNotNull.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/filterNotNull.kt new file mode 100644 index 00000000000..b306e890884 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/filterNotNull.kt @@ -0,0 +1,5 @@ +import kotlin.test.* + +fun box() { + expect(listOf("a"), { arrayOf("a", null).filterNotNull() }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/first.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/first.kt new file mode 100644 index 00000000000..f32b6a53438 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/first.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + +fun box() { + expect(1) { arrayOf(1, 2, 3).first() } + expect(2) { arrayOf(1, 2, 3).first { it % 2 == 0 } } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/flattenArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/flattenArray.kt new file mode 100644 index 00000000000..12bf608b736 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/flattenArray.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +fun box() { + val arr1: Array> = arrayOf(arrayOf(1, 2, 3), arrayOf(4, 5, 6)) + val arr2: Array> = arr1 + val arr3: Array> = arr1 + val arr4: Array> = arr1 as Array> + + val expected = listOf(1, 2, 3, 4, 5, 6) + assertEquals(expected, arr1.flatten()) + assertEquals(expected, arr2.flatten()) + assertEquals(expected, arr3.flatten()) + assertEquals(expected, arr4.flatten()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/floatArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/floatArray.kt new file mode 100644 index 00000000000..822bfcc6ff8 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/floatArray.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + val arr = FloatArray(2) + + val expected: Float = 0.0F + assertEquals(arr.size, 2) + assertEquals(expected, arr[0]) + assertEquals(expected, arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/floatArrayInit.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/floatArrayInit.kt new file mode 100644 index 00000000000..9c456126823 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/floatArrayInit.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr = FloatArray(2) { it.toFloat() } + + assertEquals(2, arr.size) + assertEquals(0.toFloat(), arr[0]) + assertEquals(1.toFloat(), arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/indexOf.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/indexOf.kt new file mode 100644 index 00000000000..fbedc5fd94a --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/indexOf.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + +fun box() { + expect(-1) { arrayOf("cat", "dog", "bird").indexOf("mouse") } + expect(0) { arrayOf("cat", "dog", "bird").indexOf("cat") } + expect(1) { arrayOf("cat", "dog", "bird").indexOf("dog") } + expect(2) { arrayOf("cat", "dog", "bird").indexOf("bird") } + expect(0) { arrayOf(null, "dog", null).indexOf(null as String?) } + + expect(-1) { arrayOf("cat", "dog", "bird").indexOfFirst { it.contains("p") } } + expect(0) { arrayOf("cat", "dog", "bird").indexOfFirst { it.startsWith('c') } } + expect(1) { arrayOf("cat", "dog", "bird").indexOfFirst { it.startsWith('d') } } + expect(2) { arrayOf("cat", "dog", "bird").indexOfFirst { it.endsWith('d') } } + + expect(-1) { sequenceOf("cat", "dog", "bird").indexOfFirst { it.contains("p") } } + expect(0) { sequenceOf("cat", "dog", "bird").indexOfFirst { it.startsWith('c') } } + expect(1) { sequenceOf("cat", "dog", "bird").indexOfFirst { it.startsWith('d') } } + expect(2) { sequenceOf("cat", "dog", "bird").indexOfFirst { it.endsWith('d') } } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/indexOfInPrimitiveArrays.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/indexOfInPrimitiveArrays.kt new file mode 100644 index 00000000000..c91a1f4b6aa --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/indexOfInPrimitiveArrays.kt @@ -0,0 +1,42 @@ +import kotlin.test.* + +fun box() { + expect(-1) { byteArrayOf(1, 2, 3).indexOf(0) } + expect(0) { byteArrayOf(1, 2, 3).indexOf(1) } + expect(1) { byteArrayOf(1, 2, 3).indexOf(2) } + expect(2) { byteArrayOf(1, 2, 3).indexOf(3) } + + expect(-1) { shortArrayOf(1, 2, 3).indexOf(0) } + expect(0) { shortArrayOf(1, 2, 3).indexOf(1) } + expect(1) { shortArrayOf(1, 2, 3).indexOf(2) } + expect(2) { shortArrayOf(1, 2, 3).indexOf(3) } + + expect(-1) { intArrayOf(1, 2, 3).indexOf(0) } + expect(0) { intArrayOf(1, 2, 3).indexOf(1) } + expect(1) { intArrayOf(1, 2, 3).indexOf(2) } + expect(2) { intArrayOf(1, 2, 3).indexOf(3) } + + expect(-1) { longArrayOf(1, 2, 3).indexOf(0) } + expect(0) { longArrayOf(1, 2, 3).indexOf(1) } + expect(1) { longArrayOf(1, 2, 3).indexOf(2) } + expect(2) { longArrayOf(1, 2, 3).indexOf(3) } + + expect(-1) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(0f) } + expect(0) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(1.0f) } + expect(1) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(2.0f) } + expect(2) { floatArrayOf(1.0f, 2.0f, 3.0f).indexOf(3.0f) } + + expect(-1) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(0.0) } + expect(0) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(1.0) } + expect(1) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(2.0) } + expect(2) { doubleArrayOf(1.0, 2.0, 3.0).indexOf(3.0) } + + expect(-1) { charArrayOf('a', 'b', 'c').indexOf('z') } + expect(0) { charArrayOf('a', 'b', 'c').indexOf('a') } + expect(1) { charArrayOf('a', 'b', 'c').indexOf('b') } + expect(2) { charArrayOf('a', 'b', 'c').indexOf('c') } + + expect(0) { booleanArrayOf(true, false).indexOf(true) } + expect(1) { booleanArrayOf(true, false).indexOf(false) } + expect(-1) { booleanArrayOf(true).indexOf(false) } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/intArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/intArray.kt new file mode 100644 index 00000000000..3cfb40a3dab --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/intArray.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr = IntArray(2) + + assertEquals(arr.size, 2) + assertEquals(0, arr[0]) + assertEquals(0, arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/intArrayInit.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/intArrayInit.kt new file mode 100644 index 00000000000..8fc44dffa33 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/intArrayInit.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr = IntArray(2) { it.toInt() } + + assertEquals(2, arr.size) + assertEquals(0.toInt(), arr[0]) + assertEquals(1.toInt(), arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/isEmpty.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/isEmpty.kt new file mode 100644 index 00000000000..29f9cd6731b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/isEmpty.kt @@ -0,0 +1,22 @@ +import kotlin.test.* + +fun box() { + assertTrue(emptyArray().isEmpty()) + assertFalse(arrayOf("").isEmpty()) + assertTrue(intArrayOf().isEmpty()) + assertFalse(intArrayOf(1).isEmpty()) + assertTrue(byteArrayOf().isEmpty()) + assertFalse(byteArrayOf(1).isEmpty()) + assertTrue(shortArrayOf().isEmpty()) + assertFalse(shortArrayOf(1).isEmpty()) + assertTrue(longArrayOf().isEmpty()) + assertFalse(longArrayOf(1).isEmpty()) + assertTrue(charArrayOf().isEmpty()) + assertFalse(charArrayOf('a').isEmpty()) + assertTrue(floatArrayOf().isEmpty()) + assertFalse(floatArrayOf(0.1F).isEmpty()) + assertTrue(doubleArrayOf().isEmpty()) + assertFalse(doubleArrayOf(0.1).isEmpty()) + assertTrue(booleanArrayOf().isEmpty()) + assertFalse(booleanArrayOf(false).isEmpty()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/isNotEmpty.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/isNotEmpty.kt new file mode 100644 index 00000000000..4a9c9b3759b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/isNotEmpty.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + +fun box() { + assertFalse(intArrayOf().isNotEmpty()) + assertTrue(intArrayOf(1).isNotEmpty()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/joinToString.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/joinToString.kt new file mode 100644 index 00000000000..8ef019bf180 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/joinToString.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +fun box() { + val text = arrayOf("foo", "bar").joinToString("-", "<", ">") + assertEquals("", text) + + val text2 = arrayOf('a', "b", StringBuilder("c"), null, "d", 'e', 'f').joinToString(limit = 4, truncated = "*") + assertEquals("a, b, c, null, *", text2) + + val text3 = intArrayOf(1, 2, 5, 8).joinToString("+", "[", "]") + assertEquals("[1+2+5+8]", text3) + + val text4 = charArrayOf('f', 'o', 'o').joinToString() + assertEquals("f, o, o", text4) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/last.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/last.kt new file mode 100644 index 00000000000..1491662a40f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/last.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + +fun box() { + expect(3) { arrayOf(1, 2, 3).last() } + expect(2) { arrayOf(1, 2, 3).last { it % 2 == 0 } } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/lastIndexOf.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/lastIndexOf.kt new file mode 100644 index 00000000000..c8b3f11d28d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/lastIndexOf.kt @@ -0,0 +1,21 @@ +import kotlin.test.* + +fun box() { + expect(-1) { arrayOf("cat", "dog", "bird").lastIndexOf("mouse") } + expect(0) { arrayOf("cat", "dog", "bird").lastIndexOf("cat") } + expect(1) { arrayOf("cat", "dog", "bird").lastIndexOf("dog") } + expect(2) { arrayOf(null, "dog", null).lastIndexOf(null as String?) } + expect(3) { arrayOf("cat", "dog", "bird", "dog").lastIndexOf("dog") } + + expect(-1) { arrayOf("cat", "dog", "bird").indexOfLast { it.contains("p") } } + expect(0) { arrayOf("cat", "dog", "bird").indexOfLast { it.startsWith('c') } } + expect(2) { arrayOf("cat", "dog", "cap", "bird").indexOfLast { it.startsWith('c') } } + expect(2) { arrayOf("cat", "dog", "bird").indexOfLast { it.endsWith('d') } } + expect(3) { arrayOf("cat", "dog", "bird", "red").indexOfLast { it.endsWith('d') } } + + expect(-1) { sequenceOf("cat", "dog", "bird").indexOfLast { it.contains("p") } } + expect(0) { sequenceOf("cat", "dog", "bird").indexOfLast { it.startsWith('c') } } + expect(2) { sequenceOf("cat", "dog", "cap", "bird").indexOfLast { it.startsWith('c') } } + expect(2) { sequenceOf("cat", "dog", "bird").indexOfLast { it.endsWith('d') } } + expect(3) { sequenceOf("cat", "dog", "bird", "red").indexOfLast { it.endsWith('d') } } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/longArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/longArray.kt new file mode 100644 index 00000000000..93999ec47b4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/longArray.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + val arr = LongArray(2) + + val expected: Long = 0 + assertEquals(arr.size, 2) + assertEquals(expected, arr[0]) + assertEquals(expected, arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/longArrayInit.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/longArrayInit.kt new file mode 100644 index 00000000000..93d5febf5d6 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/longArrayInit.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr = LongArray(2) { it.toLong() } + + assertEquals(2, arr.size) + assertEquals(0.toLong(), arr[0]) + assertEquals(1.toLong(), arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/map.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/map.kt new file mode 100644 index 00000000000..a173bcd5bf5 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/map.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +fun box() { + assertEquals(listOf(1, 2, 4), arrayOf("a", "bc", "test").map { it.length }) + assertEquals(listOf('a', 'b', 'c'), intArrayOf(1, 2, 3).map { 'a' + it - 1 }) + assertEquals(listOf(1, 2, 3), longArrayOf(1000, 2000, 3000).map { (it / 1000).toInt() }) + assertEquals(listOf(1.0, 0.5, 0.4, 0.2, 0.1), doubleArrayOf(1.0, 2.0, 2.5, 5.0, 10.0).map { 1 / it }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexed.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexed.kt new file mode 100644 index 00000000000..311f9903189 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexed.kt @@ -0,0 +1,7 @@ +import kotlin.test.* + +fun box() { + assertEquals(listOf(1, 1, 2), arrayOf("a", "bc", "test").mapIndexed { index, s -> s.length - index }) + assertEquals(listOf(0, 2, 2), intArrayOf(3, 2, 1).mapIndexed { index, i -> i * index }) + assertEquals(listOf("0;20", "1;21", "2;22"), longArrayOf(20, 21, 22).mapIndexed { index, it -> "$index;$it" }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexedNotNull.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexedNotNull.kt new file mode 100644 index 00000000000..8222603b60c --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexedNotNull.kt @@ -0,0 +1,5 @@ +import kotlin.test.* + +fun box() { + assertEquals(listOf(2), arrayOf("a", null, "test").mapIndexedNotNull { index, it -> it?.run { if (index != 0) length / index else null } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/mapNotNull.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/mapNotNull.kt new file mode 100644 index 00000000000..89300fba1af --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/mapNotNull.kt @@ -0,0 +1,5 @@ +import kotlin.test.* + +fun box() { + assertEquals(listOf(2, 3), arrayOf("", "bc", "def").mapNotNull { if (it.isEmpty()) null else it.length }) +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/max.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/max.kt new file mode 100644 index 00000000000..9ea8818caae --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/max.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + expect(null, { arrayOf().max() }) + expect(1, { arrayOf(1).max() }) + expect(3, { arrayOf(2, 3).max() }) + expect(3000000000000, { arrayOf(3000000000000, 2000000000000).max() }) + expect('b', { arrayOf('a', 'b').max() }) + expect("b", { arrayOf("a", "b").max() }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/maxBy.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/maxBy.kt new file mode 100644 index 00000000000..7184725db9b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/maxBy.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + expect(null, { arrayOf().maxBy { it } }) + expect(1, { arrayOf(1).maxBy { it } }) + expect(2, { arrayOf(2, 3).maxBy { -it } }) + expect('b', { arrayOf('a', 'b').maxBy { "x$it" } }) + expect("abc", { arrayOf("b", "abc").maxBy { it.length } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/maxByEvaluateOnce.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/maxByEvaluateOnce.kt new file mode 100644 index 00000000000..f147262d2a6 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/maxByEvaluateOnce.kt @@ -0,0 +1,7 @@ +import kotlin.test.* + +fun box() { + var c = 0 + expect(5, { arrayOf(5, 4, 3, 2, 1).maxBy { c++; it * it } }) + assertEquals(5, c) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/maxByInPrimitiveArrays.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/maxByInPrimitiveArrays.kt new file mode 100644 index 00000000000..1c3358d3da4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/maxByInPrimitiveArrays.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + +fun box() { + expect(null, { intArrayOf().maxBy { it } }) + expect(1, { intArrayOf(1).maxBy { it } }) + expect(2, { intArrayOf(2, 3).maxBy { -it } }) + expect(3000000000000, { longArrayOf(3000000000000, 2000000000000).maxBy { it + 1 } }) + expect(3, { byteArrayOf(1, 3, 2).maxBy { it * it } }) + expect(3, { shortArrayOf(3, 2).maxBy { "a" } }) + expect(3.0F, { floatArrayOf(3.0F, 2.0F).maxBy { it.toString() } }) + expect(3.0, { doubleArrayOf(2.0, 3.0).maxBy { it * it } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/maxInPrimitiveArrays.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/maxInPrimitiveArrays.kt new file mode 100644 index 00000000000..2a27afc0144 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/maxInPrimitiveArrays.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +fun box() { + expect(null, { intArrayOf().max() }) + expect(1, { intArrayOf(1).max() }) + expect(3, { intArrayOf(2, 3).max() }) + expect(3000000000000, { longArrayOf(3000000000000, 2000000000000).max() }) + expect(3, { byteArrayOf(1, 3, 2).max() }) + expect(3, { shortArrayOf(3, 2).max() }) + expect(3.0F, { floatArrayOf(3.0F, 2.0F).max() }) + expect(3.0, { doubleArrayOf(2.0, 3.0).max() }) + expect('b', { charArrayOf('a', 'b').max() }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/maxIndex.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/maxIndex.kt new file mode 100644 index 00000000000..2eeaa6e7e2d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/maxIndex.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + +fun box() { + val a = intArrayOf(1, 7, 9, 239, 54, 93) + expect(3, { a.indices.maxBy { a[it] } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/maxWith.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/maxWith.kt new file mode 100644 index 00000000000..82f02845cb2 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/maxWith.kt @@ -0,0 +1,7 @@ +import kotlin.test.* + +val STRING_CASE_INSENSITIVE_ORDER: Comparator = compareBy { it: String -> it.toUpperCase() }.thenBy { it.toLowerCase() }.thenBy { it } +fun box() { + assertEquals(null, arrayOf().maxWith(naturalOrder())) + assertEquals("B", arrayOf("a", "B").maxWith(STRING_CASE_INSENSITIVE_ORDER)) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/maxWithInPrimitiveArrays.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/maxWithInPrimitiveArrays.kt new file mode 100644 index 00000000000..e28798ffca9 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/maxWithInPrimitiveArrays.kt @@ -0,0 +1,7 @@ +import kotlin.test.* + +fun box() { + expect(null, { intArrayOf().maxWith(naturalOrder()) }) + expect(1, { intArrayOf(1).maxWith(naturalOrder()) }) + expect(-4, { intArrayOf(2, 3, -4).maxWith(compareBy { it * it }) }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/min.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/min.kt new file mode 100644 index 00000000000..95e53a40dfb --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/min.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + expect(null, { arrayOf().min() }) + expect(1, { arrayOf(1).min() }) + expect(2, { arrayOf(2, 3).min() }) + expect(2000000000000, { arrayOf(3000000000000, 2000000000000).min() }) + expect('a', { arrayOf('a', 'b').min() }) + expect("a", { arrayOf("a", "b").min() }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/minBy.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/minBy.kt new file mode 100644 index 00000000000..034c43c6b29 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/minBy.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + expect(null, { arrayOf().minBy { it } }) + expect(1, { arrayOf(1).minBy { it } }) + expect(3, { arrayOf(2, 3).minBy { -it } }) + expect('a', { arrayOf('a', 'b').minBy { "x$it" } }) + expect("b", { arrayOf("b", "abc").minBy { it.length } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/minByEvaluateOnce.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/minByEvaluateOnce.kt new file mode 100644 index 00000000000..2c511c248cc --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/minByEvaluateOnce.kt @@ -0,0 +1,7 @@ +import kotlin.test.* + +fun box() { + var c = 0 + expect(1, { arrayOf(5, 4, 3, 2, 1).minBy { c++; it * it } }) + assertEquals(5, c) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/minByInPrimitiveArrays.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/minByInPrimitiveArrays.kt new file mode 100644 index 00000000000..8e7ed026699 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/minByInPrimitiveArrays.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + +fun box() { + expect(null, { intArrayOf().minBy { it } }) + expect(1, { intArrayOf(1).minBy { it } }) + expect(3, { intArrayOf(2, 3).minBy { -it } }) + expect(2000000000000, { longArrayOf(3000000000000, 2000000000000).minBy { it + 1 } }) + expect(1, { byteArrayOf(1, 3, 2).minBy { it * it } }) + expect(3, { shortArrayOf(3, 2).minBy { "a" } }) + expect(2.0F, { floatArrayOf(3.0F, 2.0F).minBy { it.toString() } }) + expect(2.0, { doubleArrayOf(2.0, 3.0).minBy { it * it } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/minInPrimitiveArrays.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/minInPrimitiveArrays.kt new file mode 100644 index 00000000000..addaac4769a --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/minInPrimitiveArrays.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +fun box() { + expect(null, { intArrayOf().min() }) + expect(1, { intArrayOf(1).min() }) + expect(2, { intArrayOf(2, 3).min() }) + expect(2000000000000, { longArrayOf(3000000000000, 2000000000000).min() }) + expect(1, { byteArrayOf(1, 3, 2).min() }) + expect(2, { shortArrayOf(3, 2).min() }) + expect(2.0F, { floatArrayOf(3.0F, 2.0F).min() }) + expect(2.0, { doubleArrayOf(2.0, 3.0).min() }) + expect('a', { charArrayOf('a', 'b').min() }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/minIndex.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/minIndex.kt new file mode 100644 index 00000000000..f977da3b6cf --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/minIndex.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + +fun box() { + val a = intArrayOf(1, 7, 9, -42, 54, 93) + expect(3, { a.indices.minBy { a[it] } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/minWith.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/minWith.kt new file mode 100644 index 00000000000..96eba9a1a9b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/minWith.kt @@ -0,0 +1,7 @@ +import kotlin.test.* + +val STRING_CASE_INSENSITIVE_ORDER: Comparator = compareBy { it: String -> it.toUpperCase() }.thenBy { it.toLowerCase() }.thenBy { it } +fun box() { + assertEquals(null, arrayOf().minWith(naturalOrder())) + assertEquals("a", arrayOf("a", "B").minWith(STRING_CASE_INSENSITIVE_ORDER)) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/minWithInPrimitiveArrays.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/minWithInPrimitiveArrays.kt new file mode 100644 index 00000000000..22da478ac3f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/minWithInPrimitiveArrays.kt @@ -0,0 +1,7 @@ +import kotlin.test.* + +fun box() { + expect(null, { intArrayOf().minWith(naturalOrder()) }) + expect(1, { intArrayOf(1).minWith(naturalOrder()) }) + expect(4, { intArrayOf(2, 3, 4).minWith(compareBy { it % 4 }) }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNotNull.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNotNull.kt new file mode 100644 index 00000000000..5aa86dbbd8e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNotNull.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val x: Array? = arrayOf("1", "2") + val xArray = x.orEmpty() + expect(2) { xArray.size } + expect("1") { xArray[0] } + expect("2") { xArray[1] } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNull.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNull.kt new file mode 100644 index 00000000000..93e5fd65cb7 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNull.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + val x: Array? = null + val y: Array? = null + val xArray = x.orEmpty() + val yArray = y.orEmpty() + expect(0) { xArray.size } + expect(0) { yArray.size } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/plus.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/plus.kt new file mode 100644 index 00000000000..0ae56e98dae --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/plus.kt @@ -0,0 +1,47 @@ +import kotlin.test.* + +fun assertArrayNotSameButEquals(expected: Array, actual: Array, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: IntArray, actual: IntArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: LongArray, actual: LongArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ShortArray, actual: ShortArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ByteArray, actual: ByteArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: DoubleArray, actual: DoubleArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: FloatArray, actual: FloatArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: CharArray, actual: CharArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun box() { + assertEquals(listOf("1", "2", "3", "4"), listOf("1", "2") + arrayOf("3", "4")) + assertArrayNotSameButEquals(arrayOf("1", "2", "3"), arrayOf("1", "2") + "3") + assertArrayNotSameButEquals(arrayOf("1", "2", "3", "4"), arrayOf("1", "2") + arrayOf("3", "4")) + assertArrayNotSameButEquals(arrayOf("1", "2", "3", "4"), arrayOf("1", "2") + listOf("3", "4")) + assertArrayNotSameButEquals(intArrayOf(1, 2, 3), intArrayOf(1, 2) + 3) + assertArrayNotSameButEquals(intArrayOf(1, 2, 3, 4), intArrayOf(1, 2) + listOf(3, 4)) + assertArrayNotSameButEquals(intArrayOf(1, 2, 3, 4), intArrayOf(1, 2) + intArrayOf(3, 4)) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/plusAssign.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/plusAssign.kt new file mode 100644 index 00000000000..66e82d2407f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/plusAssign.kt @@ -0,0 +1,46 @@ +import kotlin.test.* + +fun assertArrayNotSameButEquals(expected: Array, actual: Array, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: IntArray, actual: IntArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: LongArray, actual: LongArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ShortArray, actual: ShortArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ByteArray, actual: ByteArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: DoubleArray, actual: DoubleArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: FloatArray, actual: FloatArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: CharArray, actual: CharArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun box() { + // lets use a mutable variable + var result = arrayOf("a") + result += "foo" + result += listOf("beer") + result += arrayOf("cheese", "wine") + assertArrayNotSameButEquals(arrayOf("a", "foo", "beer", "cheese", "wine"), result) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/plusInference.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/plusInference.kt new file mode 100644 index 00000000000..9be2f32e222 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/plusInference.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +fun box() { + val arrayOfArrays: Array> = arrayOf(arrayOf("s") as Array) + val elementArray = arrayOf("a") as Array + val arrayPlusElement: Array> = arrayOfArrays.plusElement(elementArray) + assertEquals("a", arrayPlusElement[1][0]) + // ambiguity + // val arrayPlusArray: Array> = arrayOfArrays + arrayOfArrays + + val arrayOfStringArrays = arrayOf(arrayOf("s")) + val arrayPlusArray = arrayOfStringArrays + arrayOfStringArrays + assertEquals("s", arrayPlusArray[1][0]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/plusVararg.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/plusVararg.kt new file mode 100644 index 00000000000..64f08888595 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/plusVararg.kt @@ -0,0 +1,47 @@ +import kotlin.test.* + +fun assertArrayNotSameButEquals(expected: Array, actual: Array, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: IntArray, actual: IntArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: LongArray, actual: LongArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ShortArray, actual: ShortArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ByteArray, actual: ByteArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: DoubleArray, actual: DoubleArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: FloatArray, actual: FloatArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: CharArray, actual: CharArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun box() { + fun stringOnePlus(vararg a: String) = arrayOf("1") + a + fun longOnePlus(vararg a: Long) = longArrayOf(1) + a + fun intOnePlus(vararg a: Int) = intArrayOf(1) + a + + assertArrayNotSameButEquals(arrayOf("1", "2"), stringOnePlus("2"), "Array.plus") + assertArrayNotSameButEquals(intArrayOf(1, 2), intOnePlus(2), "IntArray.plus") + assertArrayNotSameButEquals(longArrayOf(1, 2), longOnePlus(2), "LongArray.plus") +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/reduce.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/reduce.kt new file mode 100644 index 00000000000..5888b534211 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/reduce.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + +fun box() { + expect(-4) { intArrayOf(1, 2, 3).reduce { a, b -> a - b } } + expect(-4.toLong()) { longArrayOf(1, 2, 3).reduce { a, b -> a - b } } + expect(-4F) { floatArrayOf(1F, 2F, 3F).reduce { a, b -> a - b } } + expect(-4.0) { doubleArrayOf(1.0, 2.0, 3.0).reduce { a, b -> a - b } } + expect('3') { charArrayOf('1', '3', '2').reduce { a, b -> if (a > b) a else b } } + expect(false) { booleanArrayOf(true, true, false).reduce { a, b -> a && b } } + expect(true) { booleanArrayOf(true, true).reduce { a, b -> a && b } } + expect(0.toByte()) { byteArrayOf(3, 2, 1).reduce { a, b -> (a - b).toByte() } } + expect(0.toShort()) { shortArrayOf(3, 2, 1).reduce { a, b -> (a - b).toShort() } } + + assertFailsWith { + intArrayOf().reduce { a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/reduceIndexed.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/reduceIndexed.kt new file mode 100644 index 00000000000..f142524ed02 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/reduceIndexed.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + +fun box() { + expect(-1) { intArrayOf(1, 2, 3).reduceIndexed { index, a, b -> index + a - b } } + expect(-1.toLong()) { longArrayOf(1, 2, 3).reduceIndexed { index, a, b -> index + a - b } } + expect(-1F) { floatArrayOf(1F, 2F, 3F).reduceIndexed { index, a, b -> index + a - b } } + expect(-1.0) { doubleArrayOf(1.0, 2.0, 3.0).reduceIndexed { index, a, b -> index + a - b } } + expect('2') { charArrayOf('1', '3', '2').reduceIndexed { index, a, b -> if (a > b && index == 1) a else b } } + expect(true) { booleanArrayOf(true, true, false).reduceIndexed { index, a, b -> a && b || index == 2 } } + expect(false) { booleanArrayOf(true, true).reduceIndexed { index, a, b -> a && b && index != 1 } } + expect(1.toByte()) { byteArrayOf(3, 2, 1).reduceIndexed { index, a, b -> if (index != 2) (a - b).toByte() else a.toByte() } } + expect(1.toShort()) { shortArrayOf(3, 2, 1).reduceIndexed { index, a, b -> if (index != 2) (a - b).toShort() else a.toShort() } } + + assertFailsWith { + intArrayOf().reduceIndexed { index, a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/reduceRight.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/reduceRight.kt new file mode 100644 index 00000000000..92b7ddd1934 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/reduceRight.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + +fun box() { + expect(2) { intArrayOf(1, 2, 3).reduceRight { a, b -> a - b } } + expect(2.toLong()) { longArrayOf(1, 2, 3).reduceRight { a, b -> a - b } } + expect(2F) { floatArrayOf(1F, 2F, 3F).reduceRight { a, b -> a - b } } + expect(2.0) { doubleArrayOf(1.0, 2.0, 3.0).reduceRight { a, b -> a - b } } + expect('3') { charArrayOf('1', '3', '2').reduceRight { a, b -> if (a > b) a else b } } + expect(false) { booleanArrayOf(true, true, false).reduceRight { a, b -> a && b } } + expect(true) { booleanArrayOf(true, true).reduceRight { a, b -> a && b } } + expect(2.toByte()) { byteArrayOf(1, 2, 3).reduceRight { a, b -> (a - b).toByte() } } + expect(2.toShort()) { shortArrayOf(1, 2, 3).reduceRight { a, b -> (a - b).toShort() } } + + assertFailsWith { + intArrayOf().reduceRight { a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/reduceRightIndexed.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/reduceRightIndexed.kt new file mode 100644 index 00000000000..aca212570cb --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/reduceRightIndexed.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + +fun box() { + expect(1) { intArrayOf(1, 2, 3).reduceRightIndexed { index, a, b -> index + a - b } } + expect(1.toLong()) { longArrayOf(1, 2, 3).reduceRightIndexed { index, a, b -> index + a - b } } + expect(1F) { floatArrayOf(1F, 2F, 3F).reduceRightIndexed { index, a, b -> index + a - b } } + expect(1.0) { doubleArrayOf(1.0, 2.0, 3.0).reduceRightIndexed { index, a, b -> index + a - b } } + expect('2') { charArrayOf('1', '3', '2').reduceRightIndexed { index, a, b -> if (a > b && index == 0) a else b } } + expect(true) { booleanArrayOf(true, true, false).reduceRightIndexed { index, a, b -> a && b || index == 1 } } + expect(false) { booleanArrayOf(true, true).reduceRightIndexed { index, a, b -> a && b && index != 0 } } + expect(1.toByte()) { byteArrayOf(3, 2, 1).reduceRightIndexed { index, a, b -> if (index != 1) (a - b).toByte() else a.toByte() } } + expect(1.toShort()) { shortArrayOf(3, 2, 1).reduceRightIndexed { index, a, b -> if (index != 1) (a - b).toShort() else a.toShort() } } + + assertFailsWith { + intArrayOf().reduceRightIndexed { index, a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/reverseInPlace.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/reverseInPlace.kt new file mode 100644 index 00000000000..48ef9813513 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/reverseInPlace.kt @@ -0,0 +1,25 @@ +import kotlin.test.* + +fun box() { + + fun doTest(build: Iterable.() -> TArray, reverse: TArray.() -> Unit, snapshot: TArray.() -> List) { + val arrays = (0..4).map { n -> (1..n).build() } + for (array in arrays) { + val original = array.snapshot() + array.reverse() + val reversed = array.snapshot() + assertEquals(original.asReversed(), reversed) + } + } + + doTest(build = { map { it }.toIntArray() }, reverse = { reverse() }, snapshot = { toList() }) + doTest(build = { map { it.toLong() }.toLongArray() }, reverse = { reverse() }, snapshot = { toList() }) + doTest(build = { map { it.toByte() }.toByteArray() }, reverse = { reverse() }, snapshot = { toList() }) + doTest(build = { map { it.toShort() }.toShortArray() }, reverse = { reverse() }, snapshot = { toList() }) + doTest(build = { map { it.toFloat() }.toFloatArray() }, reverse = { reverse() }, snapshot = { toList() }) + doTest(build = { map { it.toDouble() }.toDoubleArray() }, reverse = { reverse() }, snapshot = { toList() }) + doTest(build = { map { 'a' + it }.toCharArray() }, reverse = { reverse() }, snapshot = { toList() }) + doTest(build = { map { it % 2 == 0 }.toBooleanArray() }, reverse = { reverse() }, snapshot = { toList() }) + doTest(build = { map { it.toString() }.toTypedArray() }, reverse = { reverse() }, snapshot = { toList() }) + doTest(build = { map { it.toString() }.toTypedArray() as Array }, reverse = { reverse() }, snapshot = { toList() }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/reversed.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/reversed.kt new file mode 100644 index 00000000000..962bf2ed7bd --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/reversed.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +fun box() { + expect(listOf(3, 2, 1)) { intArrayOf(1, 2, 3).reversed() } + expect(listOf(3, 2, 1)) { byteArrayOf(1, 2, 3).reversed() } + expect(listOf(3, 2, 1)) { shortArrayOf(1, 2, 3).reversed() } + expect(listOf(3, 2, 1)) { longArrayOf(1, 2, 3).reversed() } + expect(listOf(3F, 2F, 1F)) { floatArrayOf(1F, 2F, 3F).reversed() } + expect(listOf(3.0, 2.0, 1.0)) { doubleArrayOf(1.0, 2.0, 3.0).reversed() } + expect(listOf('3', '2', '1')) { charArrayOf('1', '2', '3').reversed() } + expect(listOf(false, false, true)) { booleanArrayOf(true, false, false).reversed() } + expect(listOf("3", "2", "1")) { arrayOf("1", "2", "3").reversed() } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/reversedArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/reversedArray.kt new file mode 100644 index 00000000000..78a8aa08a63 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/reversedArray.kt @@ -0,0 +1,50 @@ +import kotlin.test.* + +fun assertArrayNotSameButEquals(expected: Array, actual: Array, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: IntArray, actual: IntArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: LongArray, actual: LongArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ShortArray, actual: ShortArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ByteArray, actual: ByteArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: DoubleArray, actual: DoubleArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: FloatArray, actual: FloatArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: CharArray, actual: CharArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun box() { + assertArrayNotSameButEquals(intArrayOf(3, 2, 1), intArrayOf(1, 2, 3).reversedArray()) + assertArrayNotSameButEquals(byteArrayOf(3, 2, 1), byteArrayOf(1, 2, 3).reversedArray()) + assertArrayNotSameButEquals(shortArrayOf(3, 2, 1), shortArrayOf(1, 2, 3).reversedArray()) + assertArrayNotSameButEquals(longArrayOf(3, 2, 1), longArrayOf(1, 2, 3).reversedArray()) + assertArrayNotSameButEquals(floatArrayOf(3F, 2F, 1F), floatArrayOf(1F, 2F, 3F).reversedArray()) + assertArrayNotSameButEquals(doubleArrayOf(3.0, 2.0, 1.0), doubleArrayOf(1.0, 2.0, 3.0).reversedArray()) + assertArrayNotSameButEquals(charArrayOf('3', '2', '1'), charArrayOf('1', '2', '3').reversedArray()) + assertArrayNotSameButEquals(booleanArrayOf(false, false, true), booleanArrayOf(true, false, false).reversedArray()) + assertArrayNotSameButEquals(arrayOf("3", "2", "1"), arrayOf("1", "2", "3").reversedArray()) + assertArrayNotSameButEquals(arrayOf("3", "2", "1"), (arrayOf("1", "2", "3") as Array).reversedArray()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/shortArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/shortArray.kt new file mode 100644 index 00000000000..3338750bf47 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/shortArray.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + val arr = ShortArray(2) + + val expected: Short = 0 + assertEquals(arr.size, 2) + assertEquals(expected, arr[0]) + assertEquals(expected, arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/shortArrayInit.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/shortArrayInit.kt new file mode 100644 index 00000000000..3e5f27d3275 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/shortArrayInit.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +fun box() { + val arr = ShortArray(2) { it.toShort() } + + assertEquals(2, arr.size) + assertEquals(0.toShort(), arr[0]) + assertEquals(1.toShort(), arr[1]) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/slice.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/slice.kt new file mode 100644 index 00000000000..399fc1db13d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/slice.kt @@ -0,0 +1,18 @@ +import kotlin.test.* + +fun box() { + val iter: Iterable = listOf(3, 1, 2) + + assertEquals(listOf("B"), arrayOf("A", "B", "C").slice(1..1)) + assertEquals(listOf('E', 'B', 'C'), arrayOf('A', 'B', 'C', 'E').slice(iter)) + + assertEquals(listOf(), arrayOf().slice(5..4)) + assertEquals(listOf(), intArrayOf(1, 2, 3).slice(5..1)) + assertEquals(listOf(2, 3, 9), intArrayOf(2, 3, 9, 2, 3, 9).slice(iter)) + assertEquals(listOf(2.0, 3.0), doubleArrayOf(2.0, 3.0, 9.0).slice(0..1)) + assertEquals(listOf(2f, 3f), floatArrayOf(2f, 3f, 9f).slice(0..1)) + assertEquals(listOf(127, 100), byteArrayOf(50, 100, 127).slice(2 downTo 1)) + assertEquals(listOf(200, 100), shortArrayOf(50, 100, 200).slice(2 downTo 1)) + assertEquals(listOf(100L, 200L, 30L), longArrayOf(50L, 100L, 200L, 30L).slice(1..3)) + assertEquals(listOf(true, false, true), booleanArrayOf(true, false, true, true).slice(iter)) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/sliceArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/sliceArray.kt new file mode 100644 index 00000000000..d7e51fb56d5 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/sliceArray.kt @@ -0,0 +1,56 @@ +import kotlin.test.* + +fun assertArrayNotSameButEquals(expected: Array, actual: Array, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: IntArray, actual: IntArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: LongArray, actual: LongArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ShortArray, actual: ShortArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ByteArray, actual: ByteArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: DoubleArray, actual: DoubleArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: FloatArray, actual: FloatArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: CharArray, actual: CharArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun box() { + val coll: Collection = listOf(3, 1, 2) + + assertArrayNotSameButEquals(arrayOf("B"), arrayOf("A", "B", "C").sliceArray(1..1)) + assertArrayNotSameButEquals(arrayOf("B"), (arrayOf("A", "B", "C") as Array).sliceArray(1..1)) + assertArrayNotSameButEquals(arrayOf('E', 'B', 'C'), arrayOf('A', 'B', 'C', 'E').sliceArray(coll)) + + + assertArrayNotSameButEquals(arrayOf(), arrayOf().sliceArray(5..4)) + assertArrayNotSameButEquals(intArrayOf(), intArrayOf(1, 2, 3).sliceArray(5..1)) + assertArrayNotSameButEquals(intArrayOf(2, 3, 9), intArrayOf(2, 3, 9, 2, 3, 9).sliceArray(coll)) + assertArrayNotSameButEquals(doubleArrayOf(2.0, 3.0), doubleArrayOf(2.0, 3.0, 9.0).sliceArray(0..1)) + assertArrayNotSameButEquals(floatArrayOf(2f, 3f), floatArrayOf(2f, 3f, 9f).sliceArray(0..1)) +// assertArrayNotSameButEquals(byteArrayOf(127, 100), byteArrayOf(50, 100, 127).sliceArray(2 downTo 1)) +// assertArrayNotSameButEquals(shortArrayOf(200, 100), shortArrayOf(50, 100, 200).sliceArray(2 downTo 1)) + assertArrayNotSameButEquals(longArrayOf(100L, 200L, 30L), longArrayOf(50L, 100L, 200L, 30L).sliceArray(1..3)) + assertArrayNotSameButEquals(booleanArrayOf(true, false, true), booleanArrayOf(true, false, true, true).sliceArray(coll)) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/sort.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/sort.kt new file mode 100644 index 00000000000..72b40c760cd --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/sort.kt @@ -0,0 +1,64 @@ +import kotlin.test.* + +fun assertArrayNotSameButEquals(expected: Array, actual: Array, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: IntArray, actual: IntArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: LongArray, actual: LongArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ShortArray, actual: ShortArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ByteArray, actual: ByteArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: DoubleArray, actual: DoubleArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: FloatArray, actual: FloatArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: CharArray, actual: CharArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun box() { + val intArr = intArrayOf(5, 2, 1, 9, 80, Int.MIN_VALUE, Int.MAX_VALUE) + intArr.sort() + assertArrayNotSameButEquals(intArrayOf(Int.MIN_VALUE, 1, 2, 5, 9, 80, Int.MAX_VALUE), intArr) + intArr.sortDescending() + assertArrayNotSameButEquals(intArrayOf(Int.MAX_VALUE, 80, 9, 5, 2, 1, Int.MIN_VALUE), intArr) + + val longArr = longArrayOf(200, 2, 1, 4, 3, Long.MIN_VALUE, Long.MAX_VALUE) + longArr.sort() + assertArrayNotSameButEquals(longArrayOf(Long.MIN_VALUE, 1, 2, 3, 4, 200, Long.MAX_VALUE), longArr) + longArr.sortDescending() + assertArrayNotSameButEquals(longArrayOf(Long.MAX_VALUE, 200, 4, 3, 2, 1, Long.MIN_VALUE), longArr) + + val charArr = charArrayOf('d', 'c', 'E', 'a', '\u0000', '\uFFFF') + charArr.sort() + assertArrayNotSameButEquals(charArrayOf('\u0000', 'E', 'a', 'c', 'd', '\uFFFF'), charArr) + charArr.sortDescending() + assertArrayNotSameButEquals(charArrayOf('\uFFFF', 'd', 'c', 'a', 'E', '\u0000'), charArr) + + + val strArr = arrayOf("9", "80", "all", "Foo") + strArr.sort() + assertArrayNotSameButEquals(arrayOf("80", "9", "Foo", "all"), strArr) + strArr.sortDescending() + assertArrayNotSameButEquals(arrayOf("all", "Foo", "9", "80"), strArr) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/sortByInPlace.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/sortByInPlace.kt new file mode 100644 index 00000000000..e145aa909af --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/sortByInPlace.kt @@ -0,0 +1,49 @@ +import kotlin.test.* + +fun assertArrayNotSameButEquals(expected: Array, actual: Array, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: IntArray, actual: IntArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: LongArray, actual: LongArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ShortArray, actual: ShortArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: ByteArray, actual: ByteArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: DoubleArray, actual: DoubleArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: FloatArray, actual: FloatArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: CharArray, actual: CharArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun assertArrayNotSameButEquals(expected: BooleanArray, actual: BooleanArray, message: String = "") { + assertTrue(expected !== actual && expected contentEquals actual, message) +} + +fun box() { + val data = arrayOf("aa" to 20, "ab" to 3, "aa" to 3) + data.sortBy { it.second } + assertArrayNotSameButEquals(arrayOf("ab" to 3, "aa" to 3, "aa" to 20), data) + + data.sortBy { it.first } + assertArrayNotSameButEquals(arrayOf("aa" to 3, "aa" to 20, "ab" to 3), data) + + data.sortByDescending { (it.first + it.second).length } + assertArrayNotSameButEquals(arrayOf("aa" to 20, "aa" to 3, "ab" to 3), data) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/sortedBy.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/sortedBy.kt new file mode 100644 index 00000000000..c98b5849740 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/sortedBy.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +fun box() { + val values = arrayOf("ac", "aD", "aba") + val indices = values.indices.toList().toIntArray() + + assertEquals(listOf(1, 2, 0), indices.sortedBy { values[it] }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/sortedNullableBy.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/sortedNullableBy.kt new file mode 100644 index 00000000000..25d163bdf75 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/sortedNullableBy.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun box() { + fun String.nullIfEmpty() = if (this.isEmpty()) null else this + arrayOf(null, "").let { + expect(listOf(null, "")) { it.sortedWith(nullsFirst(compareBy { it })) } + expect(listOf("", null)) { it.sortedWith(nullsLast(compareByDescending { it })) } + expect(listOf("", null)) { it.sortedWith(nullsLast(compareByDescending { it.nullIfEmpty() })) } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/sortedTests.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/sortedTests.kt new file mode 100644 index 00000000000..8bac9065cb6 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/sortedTests.kt @@ -0,0 +1,51 @@ +import kotlin.test.* + +class ArraySortedChecker(val array: A, val comparator: Comparator) { + public fun checkSorted(sorted: A.() -> R, sortedDescending: A.() -> R, iterator: R.() -> Iterator) { + array.sorted().iterator().assertSorted { a, b -> comparator.compare(a, b) <= 0 } + array.sortedDescending().iterator().assertSorted { a, b -> comparator.compare(a, b) >= 0 } + } +} + +fun box() { + assertTrue(arrayOf().sorted().none()) + assertEquals(listOf(1), arrayOf(1).sorted()) + + fun > arrayData(vararg values: T, toArray: Array.() -> A) = ArraySortedChecker(values.toArray(), naturalOrder()) + + with(arrayData("ac", "aD", "aba") { toList().toTypedArray() }) { + checkSorted>({ sorted() }, { sortedDescending() }, { iterator() }) + checkSorted>({ sortedArray() }, { sortedArrayDescending() }, { iterator() }) + } + + with(arrayData("ac", "aD", "aba") { toList().toTypedArray() as Array }) { + checkSorted>({ sorted() }, { sortedDescending() }, { iterator() }) + checkSorted>({ sortedArray() }, { sortedArrayDescending() }, { iterator() }) + } + + with(arrayData(3, 7, 1) { toIntArray() }) { + checkSorted>({ sorted() }, { sortedDescending() }, { iterator() }) + checkSorted({ sortedArray() }, { sortedArrayDescending() }, { iterator() }) + } + + + with(arrayData(1L, Long.MIN_VALUE, Long.MAX_VALUE) { toLongArray() }) { + checkSorted>({ sorted() }, { sortedDescending() }, { iterator() }) + checkSorted({ sortedArray() }, { sortedArrayDescending() }, { iterator() }) + } + + with(arrayData('a', 'D', 'c') { toCharArray() }) { + checkSorted>({ sorted() }, { sortedDescending() }, { iterator() }) + checkSorted({ sortedArray() }, { sortedArrayDescending() }, { iterator() }) + } + + with(arrayData(1.toByte(), Byte.MAX_VALUE, Byte.MIN_VALUE) { toByteArray() }) { + checkSorted>({ sorted() }, { sortedDescending() }, { iterator() }) + checkSorted({ sortedArray() }, { sortedArrayDescending() }, { iterator() }) + } + + with(arrayData(Double.POSITIVE_INFINITY, 1.0, Double.MAX_VALUE) { toDoubleArray() }) { + checkSorted>({ sorted() }, { sortedDescending() }, { iterator() }) + checkSorted({ sortedArray() }, { sortedArrayDescending() }, { iterator() }) + } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/sortedWith.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/sortedWith.kt new file mode 100644 index 00000000000..567c85977f2 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/sortedWith.kt @@ -0,0 +1,24 @@ +import kotlin.test.* + +private class ArraySortedChecker(val array: A, val comparator: Comparator) { + public fun checkSorted(sorted: A.() -> R, sortedDescending: A.() -> R, iterator: R.() -> Iterator) { + array.sorted().iterator().assertSorted { a, b -> comparator.compare(a, b) <= 0 } + array.sortedDescending().iterator().assertSorted { a, b -> comparator.compare(a, b) >= 0 } + } +} + +fun box() { + val comparator = compareBy { it: Int -> it % 3 }.thenByDescending { it } + fun arrayData(array: A, comparator: Comparator) = ArraySortedChecker(array, comparator) + + arrayData(intArrayOf(0, 1, 2, 3, 4, 5), comparator) + .checkSorted>({ sortedWith(comparator) }, { sortedWith(comparator.reversed()) }, { iterator() }) + + arrayData(arrayOf(0, 1, 2, 3, 4, 5), comparator) + .checkSorted>({ sortedArrayWith(comparator) }, { sortedArrayWith(comparator.reversed()) }, { iterator() }) + + // in-place + val array = Array(6) { it } + array.sortWith(comparator) + array.iterator().assertSorted { a, b -> comparator.compare(a, b) <= 0 } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/sum.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/sum.kt new file mode 100644 index 00000000000..c3d317814ff --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/sum.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +fun box() { + expect(0) { arrayOf().sum() } + expect(14) { arrayOf(2, 3, 9).sum() } + expect(3.0) { arrayOf(1.0, 2.0).sum() } + expect(200) { arrayOf(100, 100).sum() } + expect(50000) { arrayOf(20000, 30000).sum() } + expect(3000000000000) { arrayOf(1000000000000, 2000000000000).sum() } + expect(3.0F) { arrayOf(1.0F, 2.0F).sum() } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/sumInPrimitiveArrays.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/sumInPrimitiveArrays.kt new file mode 100644 index 00000000000..0ae9c98a778 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/sumInPrimitiveArrays.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +fun box() { + expect(0) { intArrayOf().sum() } + expect(14) { intArrayOf(2, 3, 9).sum() } + expect(3.0) { doubleArrayOf(1.0, 2.0).sum() } + expect(200) { byteArrayOf(100, 100).sum() } + expect(50000) { shortArrayOf(20000, 30000).sum() } + expect(3000000000000) { longArrayOf(1000000000000, 2000000000000).sum() } + expect(3.0F) { floatArrayOf(1.0F, 2.0F).sum() } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/take.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/take.kt new file mode 100644 index 00000000000..53e32ac5dc0 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/take.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + +fun box() { + expect(listOf(), { intArrayOf().take(1) }) + expect(listOf(), { intArrayOf(1).take(0) }) + expect(listOf(1), { intArrayOf(1).take(1) }) + expect(listOf(2), { intArrayOf(2, 3).take(1) }) + expect(listOf(3000000000000), { longArrayOf(3000000000000, 2000000000000).take(1) }) + expect(listOf(2.toByte()), { byteArrayOf(2, 3).take(1) }) + expect(listOf(2.toShort()), { shortArrayOf(2, 3).take(1) }) + expect(listOf(2.0f), { floatArrayOf(2f, 3f).take(1) }) + expect(listOf(2.0), { doubleArrayOf(2.0, 3.0).take(1) }) + expect(listOf(true), { booleanArrayOf(true, false).take(1) }) + expect(listOf('a'), { charArrayOf('a', 'b').take(1) }) + expect(listOf("a"), { arrayOf("a", "b").take(1) }) + assertFails { + listOf(1).take(-1) + } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/takeLast.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/takeLast.kt new file mode 100644 index 00000000000..21db77d8652 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/takeLast.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + +fun box() { + expect(listOf(), { intArrayOf().takeLast(1) }) + expect(listOf(), { intArrayOf(1).takeLast(0) }) + expect(listOf(1), { intArrayOf(1).takeLast(1) }) + expect(listOf(3), { intArrayOf(2, 3).takeLast(1) }) + expect(listOf(2000000000000), { longArrayOf(3000000000000, 2000000000000).takeLast(1) }) + expect(listOf(3.toByte()), { byteArrayOf(2, 3).takeLast(1) }) + expect(listOf(3.toShort()), { shortArrayOf(2, 3).takeLast(1) }) + expect(listOf(3.0f), { floatArrayOf(2f, 3f).takeLast(1) }) + expect(listOf(3.0), { doubleArrayOf(2.0, 3.0).takeLast(1) }) + expect(listOf(false), { booleanArrayOf(true, false).takeLast(1) }) + expect(listOf('b'), { charArrayOf('a', 'b').takeLast(1) }) + expect(listOf("b"), { arrayOf("a", "b").takeLast(1) }) + assertFails { + listOf(1).takeLast(-1) + } +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/takeLastWhile.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/takeLastWhile.kt new file mode 100644 index 00000000000..4486bd24547 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/takeLastWhile.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +fun box() { + expect(listOf(), { intArrayOf().takeLastWhile { it < 3 } }) + expect(listOf(1), { intArrayOf(1).takeLastWhile { it < 3 } }) + expect(listOf(1), { intArrayOf(2, 3, 1).takeLastWhile { it < 3 } }) + expect(listOf(2000000000000), { longArrayOf(3000000000000, 2000000000000).takeLastWhile { it < 3000000000000 } }) + expect(listOf(1.toByte()), { byteArrayOf(2, 3, 1).takeLastWhile { it < 3 } }) + expect(listOf(1.toShort()), { shortArrayOf(2, 3, 1).takeLastWhile { it < 3 } }) + expect(listOf(1f), { floatArrayOf(2f, 3f, 1f).takeLastWhile { it < 3 } }) + expect(listOf(1.0), { doubleArrayOf(2.0, 3.0, 1.0).takeLastWhile { it < 3 } }) + expect(listOf(true), { booleanArrayOf(true, false, true).takeLastWhile { it } }) + expect(listOf('b'), { charArrayOf('a', 'c', 'b').takeLastWhile { it < 'c' } }) + expect(listOf("b"), { arrayOf("a", "c", "b").takeLastWhile { it < "c" } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/takeWhile.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/takeWhile.kt new file mode 100644 index 00000000000..a7276fc1882 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/takeWhile.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +fun box() { + expect(listOf(), { intArrayOf().takeWhile { it < 3 } }) + expect(listOf(1), { intArrayOf(1).takeWhile { it < 3 } }) + expect(listOf(2), { intArrayOf(2, 3, 1).takeWhile { it < 3 } }) + expect(listOf(3000000000000), { longArrayOf(3000000000000, 2000000000000).takeWhile { it > 2000000000000 } }) + expect(listOf(2.toByte()), { byteArrayOf(2, 3, 1).takeWhile { it < 3 } }) + expect(listOf(2.toShort()), { shortArrayOf(2, 3, 1).takeWhile { it < 3 } }) + expect(listOf(2f), { floatArrayOf(2f, 3f, 1f).takeWhile { it < 3 } }) + expect(listOf(2.0), { doubleArrayOf(2.0, 3.0, 1.0).takeWhile { it < 3 } }) + expect(listOf(true), { booleanArrayOf(true, false, true).takeWhile { it } }) + expect(listOf('a'), { charArrayOf('a', 'c', 'b').takeWhile { it < 'c' } }) + expect(listOf("a"), { arrayOf("a", "c", "b").takeWhile { it < "c" } }) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/toPrimitiveArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/toPrimitiveArray.kt new file mode 100644 index 00000000000..03eb8fcd60b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/toPrimitiveArray.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +fun box() { + val genericArray: Array = arrayOf(1, 2, 3) + val primitiveArray: IntArray = genericArray.toIntArray() + expect(3) { primitiveArray.size } + assertEquals(genericArray.asList(), primitiveArray.asList()) + + + val charList = listOf('a', 'b') + val charArray: CharArray = charList.toCharArray() + assertEquals(charList, charArray.asList()) +} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/toTypedArray.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/toTypedArray.kt new file mode 100644 index 00000000000..aac6212c5d3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ArraysTest/toTypedArray.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +fun box() { + val primitiveArray: LongArray = longArrayOf(1, 2, Long.MAX_VALUE) + val genericArray: Array = primitiveArray.toTypedArray() + expect(3) { genericArray.size } + assertEquals(primitiveArray.asList(), genericArray.asList()) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/abstractCollectionToArray.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/abstractCollectionToArray.kt new file mode 100644 index 00000000000..6418b8b4742 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/abstractCollectionToArray.kt @@ -0,0 +1,30 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + class TestCollection(val data: Collection) : AbstractCollection() { + val invocations = mutableListOf() + override val size get() = data.size + override fun iterator() = data.iterator() + + override fun toArray(): Array { + invocations += "toArray1" + return data.toTypedArray() + } + + public override fun toArray(array: Array): Array { + invocations += "toArray2" + return super.toArray(array) + } + } + + val data = listOf("abc", "def") + val coll = TestCollection(data) + + val arr1 = coll.toTypedArray() + assertEquals(data, arr1.asList()) + assertTrue("toArray1" in coll.invocations || "toArray2" in coll.invocations) + + val arr2: Array = coll.toArray(Array(coll.size + 1) { "" }) + assertEquals(data + listOf(null), arr2.asList()) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/average.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/average.kt new file mode 100644 index 00000000000..9c0ec28848a --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/average.kt @@ -0,0 +1,12 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + assertTrue { arrayListOf().average().isNaN() } + expect(3.8) { listOf(1, 2, 5, 8, 3).average() } + expect(2.1) { sequenceOf(1.6, 2.6, 3.6, 0.6).average() } + expect(100.0) { arrayListOf(100, 100, 100, 100, 100, 100).average() } + val n = 100 + val range = 0..n + expect(n.toDouble() / 2) { range.average() } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/contains.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/contains.kt new file mode 100644 index 00000000000..d8f4c9d56cc --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/contains.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun Iterable.toIterable(): Iterable = Iterable { this.iterator() } + +fun box() { + assertFalse(hashSetOf().contains(12)) + assertTrue(listOf(15, 19, 20).contains(15)) + + assertTrue(hashSetOf(45, 14, 13).toIterable().contains(14)) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/copyToArray.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/copyToArray.kt new file mode 100644 index 00000000000..a39385e1b7d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/copyToArray.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf("foo", "bar") + val arr = data.toTypedArray() + println("Got array ${arr}") + assertEquals(2, arr.size) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/count.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/count.kt new file mode 100644 index 00000000000..9fb7e4a0a51 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/count.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf("foo", "bar") + assertEquals(2, data.count()) + assertEquals(3, hashSetOf(12, 14, 15).count()) + assertEquals(0, ArrayList().count()) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/createListWithInit.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/createListWithInit.kt new file mode 100644 index 00000000000..21884c2cfe9 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/createListWithInit.kt @@ -0,0 +1,8 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val list = List(3) { index -> "x".repeat(index + 1) } + assertEquals(3, list.size) + assertEquals(listOf("x", "xx", "xxx"), list) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeArray.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeArray.kt new file mode 100644 index 00000000000..a4852c1aafd --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeArray.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val (a, b, c, d, e) = arrayOf(1, 2, 3, 4, 5) + assertEquals(a, 1) + assertEquals(b, 2) + assertEquals(c, 3) + assertEquals(d, 4) + assertEquals(e, 5) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeFirst.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeFirst.kt new file mode 100644 index 00000000000..076ee5e3544 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeFirst.kt @@ -0,0 +1,7 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val (first) = listOf(1, 2) + assertEquals(first, 1) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeIntArray.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeIntArray.kt new file mode 100644 index 00000000000..f5841dc2fab --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeIntArray.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val (a, b, c, d, e) = intArrayOf(1, 2, 3, 4, 5) + assertEquals(a, 1) + assertEquals(b, 2) + assertEquals(c, 3) + assertEquals(d, 4) + assertEquals(e, 5) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeList.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeList.kt new file mode 100644 index 00000000000..9ecb0580ee7 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeList.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val (a, b, c, d, e) = listOf(1, 2, 3, 4, 5) + assertEquals(a, 1) + assertEquals(b, 2) + assertEquals(c, 3) + assertEquals(d, 4) + assertEquals(e, 5) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeSplit.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeSplit.kt new file mode 100644 index 00000000000..07f89c74ea9 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeSplit.kt @@ -0,0 +1,8 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val (key, value) = "key = value".split("=").map { it.trim() } + assertEquals(key, "key") + assertEquals(value, "value") +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/drop.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/drop.kt new file mode 100644 index 00000000000..b30d0a9c675 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/drop.kt @@ -0,0 +1,8 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val coll = listOf("foo", "bar", "abc") + assertEquals(listOf("bar", "abc"), coll.drop(1)) + assertEquals(listOf("abc"), coll.drop(2)) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/dropLast.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/dropLast.kt new file mode 100644 index 00000000000..61182be85f5 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/dropLast.kt @@ -0,0 +1,13 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val coll = listOf("foo", "bar", "abc") + assertEquals(coll, coll.dropLast(0)) + assertEquals(emptyList(), coll.dropLast(coll.size)) + assertEquals(emptyList(), coll.dropLast(coll.size + 1)) + assertEquals(listOf("foo", "bar"), coll.dropLast(1)) + assertEquals(listOf("foo"), coll.dropLast(2)) + + assertFails { coll.dropLast(-1) } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/dropLastWhile.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/dropLastWhile.kt new file mode 100644 index 00000000000..32840d28eec --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/dropLastWhile.kt @@ -0,0 +1,10 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val coll = listOf("Foo", "bare", "abc") + assertEquals(coll, coll.dropLastWhile { false }) + assertEquals(listOf(), coll.dropLastWhile { true }) + assertEquals(listOf("Foo", "bare"), coll.dropLastWhile { it.length < 4 }) + assertEquals(listOf("Foo"), coll.dropLastWhile { it.all { it in 'a'..'z' } }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/dropWhile.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/dropWhile.kt new file mode 100644 index 00000000000..76a5861ebcb --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/dropWhile.kt @@ -0,0 +1,7 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val coll = listOf("foo", "bar", "abc") + assertEquals(listOf("bar", "abc"), coll.dropWhile { it.startsWith("f") }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/filterIntoSet.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/filterIntoSet.kt new file mode 100644 index 00000000000..ce2562b51cd --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/filterIntoSet.kt @@ -0,0 +1,17 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf("foo", "bar") + val foo = data.filterTo(hashSetOf()) { it.startsWith("f") } + + assertTrue { + foo.all { it.startsWith("f") } + } + assertEquals(1, foo.size) + assertEquals(hashSetOf("foo"), foo) + + assertTrue { + foo is HashSet + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceArray.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceArray.kt new file mode 100644 index 00000000000..5fe722539d5 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceArray.kt @@ -0,0 +1,23 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val src: Array = arrayOf(1, 2, 3.0, "abc", "cde") + + val numberValues: List = src.filterIsInstance() + assertEquals(listOf(1, 2, 3.0), numberValues) + + // doesn't distinguish double from int in JS +// val doubleValues: List = src.filterIsInstance() +// assertEquals(listOf(3.0), doubleValues) + + val stringValues: List = src.filterIsInstance() + assertEquals(listOf("abc", "cde"), stringValues) + + // is Any doesn't work in JS, see KT-7665 +// val anyValues: List = src.filterIsInstance() +// assertEquals(src.toList(), anyValues) + + val charValues: List = src.filterIsInstance() + assertEquals(0, charValues.size) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceList.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceList.kt new file mode 100644 index 00000000000..d95f94c17dd --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceList.kt @@ -0,0 +1,23 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val values: List = listOf(1, 2, 3.0, "abc", "cde") + + val numberValues: List = values.filterIsInstance() + assertEquals(listOf(1, 2, 3.0), numberValues) + + // doesn't distinguish double from int in JS +// val doubleValues: List = values.filterIsInstance() +// assertEquals(listOf(3.0), doubleValues) + + val stringValues: List = values.filterIsInstance() + assertEquals(listOf("abc", "cde"), stringValues) + + // is Any doesn't work in JS, see KT-7665 +// val anyValues: List = values.filterIsInstance() +// assertEquals(values.toList(), anyValues) + + val charValues: List = values.filterIsInstance() + assertEquals(0, charValues.size) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/filterNotNull.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/filterNotNull.kt new file mode 100644 index 00000000000..be8996860d2 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/filterNotNull.kt @@ -0,0 +1,14 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf(null, "foo", null, "bar") + val foo = data.filterNotNull() + + assertEquals(2, foo.size) + assertEquals(listOf("foo", "bar"), foo) + + assertTrue { + foo is List + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/first.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/first.kt new file mode 100644 index 00000000000..9efc924f2a5 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/first.kt @@ -0,0 +1,10 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf("foo", "bar") + assertEquals("foo", data.first()) + assertEquals(15, listOf(15, 19, 20, 25).first()) + assertEquals('a', listOf('a').first()) + assertFails { arrayListOf().first() } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/fold.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/fold.kt new file mode 100644 index 00000000000..c61c1c6baf3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/fold.kt @@ -0,0 +1,21 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + // lets calculate the sum of some numbers + expect(10) { + val numbers = listOf(1, 2, 3, 4) + numbers.fold(0) { a, b -> a + b } + } + + expect(0) { + val numbers = arrayListOf() + numbers.fold(0) { a, b -> a + b } + } + + // lets concatenate some strings + expect("1234") { + val numbers = listOf(1, 2, 3, 4) + numbers.map { it.toString() }.fold("") { a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexed.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexed.kt new file mode 100644 index 00000000000..8d9d6810ee3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexed.kt @@ -0,0 +1,19 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(42) { + val numbers = listOf(1, 2, 3, 4) + numbers.foldIndexed(0) { index, a, b -> index * (a + b) } + } + + expect(0) { + val numbers = arrayListOf() + numbers.foldIndexed(0) { index, a, b -> index * (a + b) } + } + + expect("11234") { + val numbers = listOf(1, 2, 3, 4) + numbers.map { it.toString() }.foldIndexed("") { index, a, b -> if (index == 0) a + b + b else a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithDifferentTypes.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithDifferentTypes.kt new file mode 100644 index 00000000000..2fd6abdff75 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithDifferentTypes.kt @@ -0,0 +1,14 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(10) { + val numbers = listOf("a", "ab", "abc") + numbers.foldIndexed(1) { index, a, b -> a + b.length + index } + } + + expect("11223344") { + val numbers = listOf(1, 2, 3, 4) + numbers.foldIndexed("") { index, a, b -> a + b + (index + 1) } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithNonCommutativeOperation.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithNonCommutativeOperation.kt new file mode 100644 index 00000000000..4a6d1ae7f40 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithNonCommutativeOperation.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(4) { + val numbers = listOf(1, 2, 3) + numbers.foldIndexed(7) { index, a, b -> index + a - b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRight.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRight.kt new file mode 100644 index 00000000000..e4669923e41 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRight.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect("1234") { + val numbers = listOf(1, 2, 3, 4) + numbers.map { it.toString() }.foldRight("") { a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexed.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexed.kt new file mode 100644 index 00000000000..03b0c632dde --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexed.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect("12343210") { + val numbers = listOf(1, 2, 3, 4) + numbers.map { it.toString() }.foldRightIndexed("") { index, a, b -> a + b + index } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithDifferentTypes.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithDifferentTypes.kt new file mode 100644 index 00000000000..8dafc2c2876 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithDifferentTypes.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect("12343210") { + val numbers = listOf(1, 2, 3, 4) + numbers.foldRightIndexed("") { index, a, b -> "" + a + b + index } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithNonCommutativeOperation.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithNonCommutativeOperation.kt new file mode 100644 index 00000000000..3ec4fff3ca0 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithNonCommutativeOperation.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(-4) { + val numbers = listOf(1, 2, 3) + numbers.foldRightIndexed(7) { index, a, b -> index + a - b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithDifferentTypes.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithDifferentTypes.kt new file mode 100644 index 00000000000..fd714ee3ec8 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithDifferentTypes.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect("1234") { + val numbers = listOf(1, 2, 3, 4) + numbers.foldRight("") { a, b -> "" + a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithNonCommutativeOperation.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithNonCommutativeOperation.kt new file mode 100644 index 00000000000..36fa9ffc44e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithNonCommutativeOperation.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(-5) { + val numbers = listOf(1, 2, 3) + numbers.foldRight(7) { a, b -> a - b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldWithDifferentTypes.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldWithDifferentTypes.kt new file mode 100644 index 00000000000..be81abea615 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldWithDifferentTypes.kt @@ -0,0 +1,14 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(7) { + val numbers = listOf("a", "ab", "abc") + numbers.fold(1) { a, b -> a + b.length } + } + + expect("1234") { + val numbers = listOf(1, 2, 3, 4) + numbers.fold("") { a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/foldWithNonCommutativeOperation.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/foldWithNonCommutativeOperation.kt new file mode 100644 index 00000000000..ca084d1c335 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/foldWithNonCommutativeOperation.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(1) { + val numbers = listOf(1, 2, 3) + numbers.fold(7) { a, b -> a - b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/groupBy.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/groupBy.kt new file mode 100644 index 00000000000..6234615c420 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/groupBy.kt @@ -0,0 +1,19 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val words = listOf("a", "abc", "ab", "def", "abcd") + val byLength = words.groupBy { it.length } + assertEquals(4, byLength.size) + + // verify that order of keys is preserved + assertEquals(listOf( + 1 to listOf("a"), + 3 to listOf("abc", "def"), + 2 to listOf("ab"), + 4 to listOf("abcd") + ), byLength.toList()) + + val l3 = byLength[3].orEmpty() + assertEquals(listOf("abc", "def"), l3) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/groupByKeysAndValues.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/groupByKeysAndValues.kt new file mode 100644 index 00000000000..33243e731e4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/groupByKeysAndValues.kt @@ -0,0 +1,17 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val nameToTeam = listOf("Alice" to "Marketing", "Bob" to "Sales", "Carol" to "Marketing") + val namesByTeam = nameToTeam.groupBy({ it.second }, { it.first }) + assertEquals( + listOf( + "Marketing" to listOf("Alice", "Carol"), + "Sales" to listOf("Bob") + ), + namesByTeam.toList()) + + + val mutableNamesByTeam = nameToTeam.groupByTo(HashMap(), { it.second }, { it.first }) + assertEquals(namesByTeam, mutableNamesByTeam) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/indices.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/indices.kt new file mode 100644 index 00000000000..c95f8e8b790 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/indices.kt @@ -0,0 +1,10 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf("foo", "bar") + val indices = data.indices + assertEquals(0, indices.start) + assertEquals(1, indices.endInclusive) + assertEquals(0..data.size - 1, indices) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/joinTo.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/joinTo.kt new file mode 100644 index 00000000000..370d002854f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/joinTo.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf("foo", "bar") + val buffer = StringBuilder() + data.joinTo(buffer, "-", "{", "}") + assertEquals("{foo-bar}", buffer.toString()) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/joinToString.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/joinToString.kt new file mode 100644 index 00000000000..c46b59ba7c4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/joinToString.kt @@ -0,0 +1,12 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf("foo", "bar") + val text = data.joinToString("-", "<", ">") + assertEquals("", text) + + val mixed = listOf('a', "b", StringBuilder("c"), null, "d", 'e', 'f') + val text2 = mixed.joinToString(limit = 4, truncated = "*") + assertEquals("a, b, c, null, *", text2) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/last.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/last.kt new file mode 100644 index 00000000000..295640098e4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/last.kt @@ -0,0 +1,10 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf("foo", "bar") + assertEquals("bar", data.last()) + assertEquals(25, listOf(15, 19, 20, 25).last()) + assertEquals('a', listOf('a').last()) + assertFails { arrayListOf().last() } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/listOfNotNull.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/listOfNotNull.kt new file mode 100644 index 00000000000..063db3566e3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/listOfNotNull.kt @@ -0,0 +1,14 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val l1: List = listOfNotNull(null) + assertTrue(l1.isEmpty()) + + val s: String? = "value" + val l2: List = listOfNotNull(s) + assertEquals(s, l2.single()) + + val l3: List = listOfNotNull("value1", null, "value2") + assertEquals(listOf("value1", "value2"), l3) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/mapRanges.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/mapRanges.kt new file mode 100644 index 00000000000..7413f41d85e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/mapRanges.kt @@ -0,0 +1,7 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val range = (1..3).map { it * 2 } + assertEquals(listOf(2, 4, 6), range) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/max.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/max.kt new file mode 100644 index 00000000000..b61edf48208 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/max.kt @@ -0,0 +1,13 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(null, { listOf().max() }) + expect(1, { listOf(1).max() }) + expect(3, { listOf(2, 3).max() }) + expect(3000000000000, { listOf(3000000000000, 2000000000000).max() }) + expect('b', { listOf('a', 'b').max() }) + expect("b", { listOf("a", "b").max() }) + expect(null, { listOf().asSequence().max() }) + expect(3, { listOf(2, 3).asSequence().max() }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/maxBy.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/maxBy.kt new file mode 100644 index 00000000000..2072d229881 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/maxBy.kt @@ -0,0 +1,12 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(null, { listOf().maxBy { it } }) + expect(1, { listOf(1).maxBy { it } }) + expect(2, { listOf(2, 3).maxBy { -it } }) + expect('b', { listOf('a', 'b').maxBy { "x$it" } }) + expect("abc", { listOf("b", "abc").maxBy { it.length } }) + expect(null, { listOf().asSequence().maxBy { it } }) + expect(2, { listOf(2, 3).asSequence().maxBy { -it } }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/maxByEvaluateOnce.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/maxByEvaluateOnce.kt new file mode 100644 index 00000000000..a72b195a7ec --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/maxByEvaluateOnce.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + var c = 0 + expect(5, { listOf(5, 4, 3, 2, 1).maxBy { c++; it * it } }) + assertEquals(5, c) + c = 0 + expect(5, { listOf(5, 4, 3, 2, 1).asSequence().maxBy { c++; it * it } }) + assertEquals(5, c) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/maxWith.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/maxWith.kt new file mode 100644 index 00000000000..27ebf7155cf --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/maxWith.kt @@ -0,0 +1,10 @@ +import kotlin.test.* +import kotlin.comparisons.* + +val STRING_CASE_INSENSITIVE_ORDER: Comparator = compareBy { it: String -> it.toUpperCase() }.thenBy { it.toLowerCase() }.thenBy { it } +fun box() { + expect(null, { listOf().maxWith(naturalOrder()) }) + expect(1, { listOf(1).maxWith(naturalOrder()) }) + expect("B", { listOf("a", "B").maxWith(STRING_CASE_INSENSITIVE_ORDER) }) + expect("B", { listOf("a", "B").asSequence().maxWith(STRING_CASE_INSENSITIVE_ORDER) }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/min.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/min.kt new file mode 100644 index 00000000000..da20bf435f9 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/min.kt @@ -0,0 +1,13 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(null, { listOf().min() }) + expect(1, { listOf(1).min() }) + expect(2, { listOf(2, 3).min() }) + expect(2000000000000, { listOf(3000000000000, 2000000000000).min() }) + expect('a', { listOf('a', 'b').min() }) + expect("a", { listOf("a", "b").min() }) + expect(null, { listOf().asSequence().min() }) + expect(2, { listOf(2, 3).asSequence().min() }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/minBy.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/minBy.kt new file mode 100644 index 00000000000..2288f3bf776 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/minBy.kt @@ -0,0 +1,12 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(null, { listOf().minBy { it } }) + expect(1, { listOf(1).minBy { it } }) + expect(3, { listOf(2, 3).minBy { -it } }) + expect('a', { listOf('a', 'b').minBy { "x$it" } }) + expect("b", { listOf("b", "abc").minBy { it.length } }) + expect(null, { listOf().asSequence().minBy { it } }) + expect(3, { listOf(2, 3).asSequence().minBy { -it } }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/minByEvaluateOnce.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/minByEvaluateOnce.kt new file mode 100644 index 00000000000..6aed50211b8 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/minByEvaluateOnce.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + var c = 0 + expect(1, { listOf(5, 4, 3, 2, 1).minBy { c++; it * it } }) + assertEquals(5, c) + c = 0 + expect(1, { listOf(5, 4, 3, 2, 1).asSequence().minBy { c++; it * it } }) + assertEquals(5, c) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/minWith.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/minWith.kt new file mode 100644 index 00000000000..3d25619c652 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/minWith.kt @@ -0,0 +1,10 @@ +import kotlin.test.* +import kotlin.comparisons.* + +val STRING_CASE_INSENSITIVE_ORDER: Comparator = compareBy { it: String -> it.toUpperCase() }.thenBy { it.toLowerCase() }.thenBy { it } +fun box() { + expect(null, { listOf().minWith(naturalOrder()) }) + expect(1, { listOf(1).minWith(naturalOrder()) }) + expect("a", { listOf("a", "B").minWith(STRING_CASE_INSENSITIVE_ORDER) }) + expect("a", { listOf("a", "B").asSequence().minWith(STRING_CASE_INSENSITIVE_ORDER) }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/minusAssign.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/minusAssign.kt new file mode 100644 index 00000000000..ea1fe870d5d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/minusAssign.kt @@ -0,0 +1,23 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + // lets use a mutable variable of readonly list + val data: List = listOf("cheese", "foo", "beer", "cheese", "wine") + var l = data + l -= "cheese" + assertEquals(listOf("foo", "beer", "cheese", "wine"), l) + l = data + l -= listOf("cheese", "beer") + assertEquals(listOf("foo", "wine"), l) + l -= arrayOf("wine", "bar") + assertEquals(listOf("foo"), l) + + val ml = arrayListOf("cheese", "cheese", "foo", "beer", "cheese", "wine") + ml -= "cheese" + assertEquals(listOf("cheese", "foo", "beer", "cheese", "wine"), ml) + ml -= listOf("cheese", "beer") + assertEquals(listOf("foo", "wine"), ml) + ml -= arrayOf("wine", "bar") + assertEquals(listOf("foo"), ml) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/minusIsEager.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/minusIsEager.kt new file mode 100644 index 00000000000..4a7a8856be4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/minusIsEager.kt @@ -0,0 +1,13 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val source = listOf("foo", "bar") + val list = arrayListOf() + val result = source - list + + list += "foo" + assertEquals(source, result) + list += "bar" + assertEquals(source, result) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/partition.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/partition.kt new file mode 100644 index 00000000000..3abecfc1a9d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/partition.kt @@ -0,0 +1,10 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf("foo", "bar", "something", "xyz") + val pair = data.partition { it.length == 3 } + + assertEquals(listOf("foo", "bar", "xyz"), pair.first, "pair.first") + assertEquals(listOf("something"), pair.second, "pair.second") +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/plusAssign.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/plusAssign.kt new file mode 100644 index 00000000000..10a62642b0f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/plusAssign.kt @@ -0,0 +1,21 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + // lets use a mutable variable of readonly list + var l: List = listOf("cheese") + val lOriginal = l + l += "foo" + l += listOf("beer") + l += arrayOf("cheese", "wine") + l += sequenceOf("bar", "foo") + assertEquals(listOf("cheese", "foo", "beer", "cheese", "wine", "bar", "foo"), l) + assertTrue(l !== lOriginal) + + val ml = arrayListOf("cheese") + ml += "foo" + ml += listOf("beer") + ml += arrayOf("cheese", "wine") + ml += sequenceOf("bar", "foo") + assertEquals(l, ml) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionBug.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionBug.kt new file mode 100644 index 00000000000..a0310a32fe3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionBug.kt @@ -0,0 +1,7 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val list = listOf("foo", "bar") + listOf("cheese", "wine") + assertEquals(listOf("foo", "bar", "cheese", "wine"), list) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionInference.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionInference.kt new file mode 100644 index 00000000000..49501ad06ab --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionInference.kt @@ -0,0 +1,15 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val listOfLists = listOf(listOf("s")) + val elementList = listOf("a") + val result: List> = listOfLists.plusElement(elementList) + assertEquals(listOf(listOf("s"), listOf("a")), result, "should be list + element") + + val listOfAny = listOf("a") + listOf("b") + assertEquals(listOf("a", "b"), listOfAny, "should be list + list") + + val listOfAnyAndList = listOf("a") + listOf("b") as Any + assertEquals(listOf("a", listOf("b")), listOfAnyAndList, "should be list + Any") +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/plusRanges.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/plusRanges.kt new file mode 100644 index 00000000000..b6eea0a04d2 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/plusRanges.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val range1 = 1..3 + val range2 = 4..7 + val combined = range1 + range2 + assertEquals((1..7).toList(), combined) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/randomAccess.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/randomAccess.kt new file mode 100644 index 00000000000..dd70bf77a9f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/randomAccess.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + assertTrue(arrayListOf(1) is RandomAccess, "ArrayList is RandomAccess") + assertTrue(listOf(1, 2) is RandomAccess, "Default read-only list implementation is RandomAccess") + assertTrue(listOf(1) is RandomAccess, "Default singleton list is RandomAccess") + assertTrue(emptyList() is RandomAccess, "Empty list is RandomAccess") +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/reduce.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/reduce.kt new file mode 100644 index 00000000000..cd90175ad85 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/reduce.kt @@ -0,0 +1,13 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect("1234") { + val list = listOf("1", "2", "3", "4") + list.reduce { a, b -> a + b } + } + + assertFailsWith { + arrayListOf().reduce { a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/reduceIndexed.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/reduceIndexed.kt new file mode 100644 index 00000000000..8ede5abbdbf --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/reduceIndexed.kt @@ -0,0 +1,22 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect("123") { + val list = listOf("1", "2", "3", "4") + list.reduceIndexed { index, a, b -> if (index == 3) a else a + b } + } + + expect(5) { + listOf(2, 3).reduceIndexed { index, acc: Number, e -> + assertEquals(1, index) + assertEquals(2, acc) + assertEquals(3, e) + acc.toInt() + e + } + } + + assertFailsWith { + arrayListOf().reduceIndexed { index, a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/reduceRight.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/reduceRight.kt new file mode 100644 index 00000000000..dbadeee9858 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/reduceRight.kt @@ -0,0 +1,13 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect("1234") { + val list = listOf("1", "2", "3", "4") + list.reduceRight { a, b -> a + b } + } + + assertFailsWith { + arrayListOf().reduceRight { a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/reduceRightIndexed.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/reduceRightIndexed.kt new file mode 100644 index 00000000000..ca334c0cd2b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/reduceRightIndexed.kt @@ -0,0 +1,22 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect("234") { + val list = listOf("1", "2", "3", "4") + list.reduceRightIndexed { index, a, b -> if (index == 0) b else a + b } + } + + expect(1) { + listOf(2, 3).reduceRightIndexed { index, e, acc: Number -> + assertEquals(0, index) + assertEquals(3, acc) + assertEquals(2, e) + acc.toInt() - e + } + } + + assertFailsWith { + arrayListOf().reduceRightIndexed { index, a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/requireNoNulls.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/requireNoNulls.kt new file mode 100644 index 00000000000..6bf95627b86 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/requireNoNulls.kt @@ -0,0 +1,15 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = arrayListOf("foo", "bar") + val notNull = data.requireNoNulls() + assertEquals(listOf("foo", "bar"), notNull) + + val hasNulls = listOf("foo", null, "bar") + + assertFailsWith { + // should throw an exception as we have a null + hasNulls.requireNoNulls() + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/reverseInPlace.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/reverseInPlace.kt new file mode 100644 index 00000000000..10bc7fbbccd --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/reverseInPlace.kt @@ -0,0 +1,20 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = arrayListOf() + data.reverse() + assertTrue(data.isEmpty()) + + data.add("foo") + data.reverse() + assertEquals(listOf("foo"), data) + + data.add("bar") + data.reverse() + assertEquals(listOf("bar", "foo"), data) + + data.add("zoo") + data.reverse() + assertEquals(listOf("zoo", "foo", "bar"), data) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/reversed.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/reversed.kt new file mode 100644 index 00000000000..139db62f66f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/reversed.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf("foo", "bar") + val rev = data.reversed() + assertEquals(listOf("bar", "foo"), rev) + assertNotEquals(data, rev) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/sortByInPlace.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/sortByInPlace.kt new file mode 100644 index 00000000000..36b53c7f096 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/sortByInPlace.kt @@ -0,0 +1,14 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = arrayListOf("aa" to 20, "ab" to 3, "aa" to 3) + data.sortBy { it.second } + assertEquals(listOf("ab" to 3, "aa" to 3, "aa" to 20), data) + + data.sortBy { it.first } + assertEquals(listOf("aa" to 3, "aa" to 20, "ab" to 3), data) + + data.sortByDescending { (it.first + it.second).length } + assertEquals(listOf("aa" to 20, "aa" to 3, "ab" to 3), data) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/sortInPlace.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/sortInPlace.kt new file mode 100644 index 00000000000..7c0da8770a3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/sortInPlace.kt @@ -0,0 +1,14 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf(11, 3, 7) + + val asc = data.toMutableList() + asc.sort() + assertEquals(listOf(3, 7, 11), asc) + + val desc = data.toMutableList() + desc.sortDescending() + assertEquals(listOf(11, 7, 3), desc) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/sorted.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/sorted.kt new file mode 100644 index 00000000000..472734896b4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/sorted.kt @@ -0,0 +1,8 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val data = listOf(11, 3, 7) + assertEquals(listOf(3, 7, 11), data.sorted()) + assertEquals(listOf(11, 7, 3), data.sortedDescending()) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/sortedBy.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/sortedBy.kt new file mode 100644 index 00000000000..76bd0495489 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/sortedBy.kt @@ -0,0 +1,8 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + assertEquals(listOf("two" to 3, "three" to 20), listOf("three" to 20, "two" to 3).sortedBy { it.second }) + assertEquals(listOf("three" to 20, "two" to 3), listOf("three" to 20, "two" to 3).sortedBy { it.first }) + assertEquals(listOf("three", "two"), listOf("two", "three").sortedByDescending { it.length }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/sortedByNullable.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/sortedByNullable.kt new file mode 100644 index 00000000000..4717f8b23ed --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/sortedByNullable.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + fun String.nonEmptyLength() = if (isEmpty()) null else length + listOf("", "sort", "abc").let { + assertEquals(listOf("", "abc", "sort"), it.sortedBy { it.nonEmptyLength() }) + assertEquals(listOf("sort", "abc", ""), it.sortedByDescending { it.nonEmptyLength() }) + assertEquals(listOf("abc", "sort", ""), it.sortedWith(compareBy(nullsLast()) { it.nonEmptyLength() })) + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/sortedNullableBy.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/sortedNullableBy.kt new file mode 100644 index 00000000000..47e18cc16af --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/sortedNullableBy.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + fun String.nullIfEmpty() = if (isEmpty()) null else this + listOf(null, "", "a").let { + expect(listOf(null, "", "a")) { it.sortedWith(nullsFirst(compareBy { it })) } + expect(listOf("a", "", null)) { it.sortedWith(nullsLast(compareByDescending { it })) } + expect(listOf(null, "a", "")) { it.sortedWith(nullsFirst(compareByDescending { it.nullIfEmpty() })) } + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/sortedWith.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/sortedWith.kt new file mode 100644 index 00000000000..8a958f2fc23 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/sortedWith.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val comparator = compareBy { it.toUpperCase().reversed() } + val data = listOf("cat", "dad", "BAD") + + expect(listOf("BAD", "dad", "cat")) { data.sortedWith(comparator) } + expect(listOf("cat", "dad", "BAD")) { data.sortedWith(comparator.reversed()) } + expect(listOf("BAD", "dad", "cat")) { data.sortedWith(comparator.reversed().reversed()) } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/specialLists.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/specialLists.kt new file mode 100644 index 00000000000..a552348dcfe --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/specialLists.kt @@ -0,0 +1,101 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext.equalityBehavior(objectName: String = "") { + val prefix = objectName + if (objectName.isNotEmpty()) "." else "" + equals(objectName) + propertyEquals(prefix + "hashCode") { hashCode() } + propertyEquals(prefix + "toString") { toString() } +} + +fun CompareContext>.listIteratorProperties() { + propertyEquals { hasNext() } + propertyEquals { hasPrevious() } + propertyEquals { nextIndex() } + propertyEquals { previousIndex() } +} + +fun CompareContext>.collectionBehavior(objectName: String = "") { + val prefix = objectName + if (objectName.isNotEmpty()) "." else "" + propertyEquals(prefix + "size") { size } + propertyEquals(prefix + "isEmpty") { isEmpty() } + + (object {}).let { propertyEquals { contains(it as Any?) } } + propertyEquals { contains(firstOrNull()) } + propertyEquals { containsAll(this) } +} + +fun CompareContext>.listIteratorBehavior() { + listIteratorProperties() + + while (expected.hasNext()) { + propertyEquals { next() } + listIteratorProperties() + } + propertyFails { next() } + + while (expected.hasPrevious()) { + propertyEquals { previous() } + listIteratorProperties() + } + propertyFails { previous() } +} + + +fun CompareContext>.listBehavior() { + equalityBehavior() + collectionBehavior() + compareProperty({ listIterator() }, { listIteratorBehavior() }) + compareProperty({ listIterator(0) }, { listIteratorBehavior() }) + + propertyFails { listIterator(-1) } + propertyFails { listIterator(size + 1) } + + for (index in expected.indices) + propertyEquals { this[index] } + + propertyFails { this[size] } + + propertyEquals { indexOf(elementAtOrNull(0)) } + propertyEquals { lastIndexOf(elementAtOrNull(0)) } + + propertyFails { subList(0, size + 1) } + propertyFails { subList(-1, 0) } + propertyEquals { subList(0, size) } +} + +fun box() { + compare(arrayListOf(), listOf()) { listBehavior() } + compare(arrayListOf(), emptyList()) { listBehavior() } + compare(arrayListOf("value"), listOf("value")) { listBehavior() } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/specialMaps.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/specialMaps.kt new file mode 100644 index 00000000000..b67e588037f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/specialMaps.kt @@ -0,0 +1,135 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext.equalityBehavior(objectName: String = "") { + val prefix = objectName + if (objectName.isNotEmpty()) "." else "" + equals(objectName) + propertyEquals(prefix + "hashCode") { hashCode() } + propertyEquals(prefix + "toString") { toString() } +} + +public fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +fun CompareContext>.listIteratorProperties() { + propertyEquals { hasNext() } + propertyEquals { hasPrevious() } + propertyEquals { nextIndex() } + propertyEquals { previousIndex() } +} + +fun CompareContext>.setBehavior(objectName: String = "") { + equalityBehavior(objectName) + collectionBehavior(objectName) + compareProperty({ iterator() }, { iteratorBehavior() }) +} + +fun CompareContext>.collectionBehavior(objectName: String = "") { + val prefix = objectName + if (objectName.isNotEmpty()) "." else "" + propertyEquals(prefix + "size") { size } + propertyEquals(prefix + "isEmpty") { isEmpty() } + + (object {}).let { propertyEquals { contains(it as Any?) } } + propertyEquals { contains(firstOrNull()) } + propertyEquals { containsAll(this) } +} + +fun CompareContext>.listIteratorBehavior() { + listIteratorProperties() + + while (expected.hasNext()) { + propertyEquals { next() } + listIteratorProperties() + } + propertyFails { next() } + + while (expected.hasPrevious()) { + propertyEquals { previous() } + listIteratorProperties() + } + propertyFails { previous() } +} + +fun CompareContext>.listBehavior() { + equalityBehavior() + collectionBehavior() + compareProperty({ listIterator() }, { listIteratorBehavior() }) + compareProperty({ listIterator(0) }, { listIteratorBehavior() }) + + propertyFails { listIterator(-1) } + propertyFails { listIterator(size + 1) } + + for (index in expected.indices) + propertyEquals { this[index] } + + propertyFails { this[size] } + + propertyEquals { indexOf(elementAtOrNull(0)) } + propertyEquals { lastIndexOf(elementAtOrNull(0)) } + + propertyFails { subList(0, size + 1) } + propertyFails { subList(-1, 0) } + propertyEquals { subList(0, size) } +} + +public fun CompareContext>.mapBehavior() { + equalityBehavior() + propertyEquals { size } + propertyEquals { isEmpty() } + + (object {}).let { propertyEquals { containsKey(it as Any?) } } + + if (expected.isEmpty().not()) + propertyEquals { contains(keys.first()) } + + propertyEquals { containsKey(keys.firstOrNull()) } + propertyEquals { containsValue(values.firstOrNull()) } + propertyEquals { get(null as Any?) } + + compareProperty({ keys }, { setBehavior("keySet") }) + compareProperty({ entries }, { setBehavior("entrySet") }) + compareProperty({ values }, { collectionBehavior("values") }) +} + +fun box() { + compare(hashMapOf(), mapOf()) { mapBehavior() } + compare(linkedMapOf(), emptyMap()) { mapBehavior() } + compare(linkedMapOf(2 to 3), mapOf(2 to 3)) { mapBehavior() } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/specialSets.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/specialSets.kt new file mode 100644 index 00000000000..025014977d0 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/specialSets.kt @@ -0,0 +1,116 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext.equalityBehavior(objectName: String = "") { + val prefix = objectName + if (objectName.isNotEmpty()) "." else "" + equals(objectName) + propertyEquals(prefix + "hashCode") { hashCode() } + propertyEquals(prefix + "toString") { toString() } +} + +fun CompareContext>.listIteratorProperties() { + propertyEquals { hasNext() } + propertyEquals { hasPrevious() } + propertyEquals { nextIndex() } + propertyEquals { previousIndex() } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +fun CompareContext>.collectionBehavior(objectName: String = "") { + val prefix = objectName + if (objectName.isNotEmpty()) "." else "" + propertyEquals(prefix + "size") { size } + propertyEquals(prefix + "isEmpty") { isEmpty() } + + (object {}).let { propertyEquals { contains(it as Any?) } } + propertyEquals { contains(firstOrNull()) } + propertyEquals { containsAll(this) } +} + +fun CompareContext>.listIteratorBehavior() { + listIteratorProperties() + + while (expected.hasNext()) { + propertyEquals { next() } + listIteratorProperties() + } + propertyFails { next() } + + while (expected.hasPrevious()) { + propertyEquals { previous() } + listIteratorProperties() + } + propertyFails { previous() } +} + +fun CompareContext>.setBehavior(objectName: String = "") { + equalityBehavior(objectName) + collectionBehavior(objectName) + compareProperty({ iterator() }, { iteratorBehavior() }) +} + +fun CompareContext>.listBehavior() { + equalityBehavior() + collectionBehavior() + compareProperty({ listIterator() }, { listIteratorBehavior() }) + compareProperty({ listIterator(0) }, { listIteratorBehavior() }) + + propertyFails { listIterator(-1) } + propertyFails { listIterator(size + 1) } + + for (index in expected.indices) + propertyEquals { this[index] } + + propertyFails { this[size] } + + propertyEquals { indexOf(elementAtOrNull(0)) } + propertyEquals { lastIndexOf(elementAtOrNull(0)) } + + propertyFails { subList(0, size + 1) } + propertyFails { subList(-1, 0) } + propertyEquals { subList(0, size) } +} + +fun box() { + compare(linkedSetOf(), setOf()) { setBehavior() } + compare(hashSetOf(), emptySet()) { setBehavior() } + compare(listOf("value").toMutableSet(), setOf("value")) { setBehavior() } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/subscript.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/subscript.kt new file mode 100644 index 00000000000..134f36c1f59 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/subscript.kt @@ -0,0 +1,25 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val list = arrayListOf("foo", "bar") + assertEquals("foo", list[0]) + assertEquals("bar", list[1]) + + // lists throw an exception if out of range + assertFails { + val outOfBounds = list[2] + } + + // lets try update the list + list[0] = "new" + list[1] = "thing" + + // lists don't allow you to set past the end of the list + assertFails { + list[2] = "works" + } + + list.add("works") + assertEquals(listOf("new", "thing", "works"), list) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/sum.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/sum.kt new file mode 100644 index 00000000000..e6ddda9e7c2 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/sum.kt @@ -0,0 +1,11 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(0) { arrayListOf().sum() } + expect(14) { listOf(2, 3, 9).sum() } + expect(3.0) { listOf(1.0, 2.0).sum() } + expect(3000000000000) { arrayListOf(1000000000000, 2000000000000).sum() } + expect(3.0.toFloat()) { arrayListOf(1.0.toFloat(), 2.0.toFloat()).sum() } + expect(3.0.toFloat()) { sequenceOf(1.0.toFloat(), 2.0.toFloat()).sum() } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/take.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/take.kt new file mode 100644 index 00000000000..f040d718845 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/take.kt @@ -0,0 +1,13 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val coll = listOf("foo", "bar", "abc") + assertEquals(emptyList(), coll.take(0)) + assertEquals(listOf("foo"), coll.take(1)) + assertEquals(listOf("foo", "bar"), coll.take(2)) + assertEquals(coll, coll.take(coll.size)) + assertEquals(coll, coll.take(coll.size + 1)) + + assertFails { coll.take(-1) } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/takeLast.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/takeLast.kt new file mode 100644 index 00000000000..0e297cddba5 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/takeLast.kt @@ -0,0 +1,14 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val coll = listOf("foo", "bar", "abc") + + assertEquals(emptyList(), coll.takeLast(0)) + assertEquals(listOf("abc"), coll.takeLast(1)) + assertEquals(listOf("bar", "abc"), coll.takeLast(2)) + assertEquals(coll, coll.takeLast(coll.size)) + assertEquals(coll, coll.takeLast(coll.size + 1)) + + assertFails { coll.takeLast(-1) } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/takeLastWhile.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/takeLastWhile.kt new file mode 100644 index 00000000000..21367cfc915 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/takeLastWhile.kt @@ -0,0 +1,10 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val coll = listOf("foo", "bar", "abc") + assertEquals(emptyList(), coll.takeLastWhile { false }) + assertEquals(coll, coll.takeLastWhile { true }) + assertEquals(listOf("abc"), coll.takeLastWhile { it.startsWith("a") }) + assertEquals(listOf("bar", "abc"), coll.takeLastWhile { it[0] < 'c' }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/takeReturnsFirstNElements.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/takeReturnsFirstNElements.kt new file mode 100644 index 00000000000..8cbc72dd2d3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/takeReturnsFirstNElements.kt @@ -0,0 +1,13 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(listOf(1, 2, 3, 4, 5)) { (1..10).take(5) } + expect(listOf(1, 2, 3, 4, 5)) { (1..10).toList().take(5) } + expect(listOf(1, 2)) { (1..10).take(2) } + expect(listOf(1, 2)) { (1..10).toList().take(2) } + expect(true) { (0L..5L).take(0).none() } + expect(true) { listOf(1L).take(0).none() } + expect(listOf(1)) { (1..1).take(10) } + expect(listOf(1)) { listOf(1).take(10) } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/takeWhile.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/takeWhile.kt new file mode 100644 index 00000000000..ffb95611e17 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/takeWhile.kt @@ -0,0 +1,10 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val coll = listOf("foo", "bar", "abc") + assertEquals(emptyList(), coll.takeWhile { false }) + assertEquals(coll, coll.takeWhile { true }) + assertEquals(listOf("foo"), coll.takeWhile { it.startsWith("f") }) + assertEquals(listOf("foo", "bar", "abc"), coll.takeWhile { it.length == 3 }) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/toStringTest.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/toStringTest.kt new file mode 100644 index 00000000000..ba108d0296f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/toStringTest.kt @@ -0,0 +1,7 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + // we need toString() inside pattern because of KT-8666 + assertEquals("[1, a, null, ${Long.MAX_VALUE.toString()}]", listOf(1, "a", null, Long.MAX_VALUE).toString()) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/unzipArray.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/unzipArray.kt new file mode 100644 index 00000000000..6251d798b8e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/unzipArray.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val array = arrayOf(1 to 'a', 2 to 'b', 3 to 'c') + val (ints, chars) = array.unzip() + assertEquals(listOf(1, 2, 3), ints) + assertEquals(listOf('a', 'b', 'c'), chars) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/unzipList.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/unzipList.kt new file mode 100644 index 00000000000..3f355096bd7 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/unzipList.kt @@ -0,0 +1,9 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + val list = listOf(1 to 'a', 2 to 'b', 3 to 'c') + val (ints, chars) = list.unzip() + assertEquals(listOf(1, 2, 3), ints) + assertEquals(listOf('a', 'b', 'c'), chars) +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/zip.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/zip.kt new file mode 100644 index 00000000000..c59760d0146 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/zip.kt @@ -0,0 +1,8 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(listOf("a" to "b", "b" to "c", "c" to "d")) { + listOf("a", "b", "c").zip(listOf("b", "c", "d")) + } +} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/zipTransform.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/zipTransform.kt new file mode 100644 index 00000000000..905c0b39c71 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/CollectionTest/zipTransform.kt @@ -0,0 +1,8 @@ +import kotlin.test.* +import kotlin.comparisons.* + +fun box() { + expect(listOf("ab", "bc", "cd")) { + listOf("a", "b", "c").zip(listOf("b", "c", "d")) { a, b -> a + b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/GroupingTest/countEach.kt b/backend.native/tests/external/stdlib/collections/GroupingTest/countEach.kt new file mode 100644 index 00000000000..bbd74e97386 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/GroupingTest/countEach.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + + +fun box() { + val elements = listOf("foo", "bar", "flea", "zoo", "biscuit") + val counts = elements.groupingBy { it.first() }.eachCount() + + assertEquals(mapOf('f' to 2, 'b' to 2, 'z' to 1), counts) + + val elements2 = arrayOf("zebra", "baz", "cab") + val counts2 = elements2.groupingBy { it.last() }.eachCountTo(HashMap(counts)) + + assertEquals(mapOf('f' to 2, 'b' to 3, 'a' to 1, 'z' to 2), counts2) +} diff --git a/backend.native/tests/external/stdlib/collections/GroupingTest/foldWithComputedInitialValue.kt b/backend.native/tests/external/stdlib/collections/GroupingTest/foldWithComputedInitialValue.kt new file mode 100644 index 00000000000..31420b6705b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/GroupingTest/foldWithComputedInitialValue.kt @@ -0,0 +1,25 @@ +import kotlin.test.* + +data class Collector(val key: K, val values: MutableList = mutableListOf()) + +fun box() { + + fun Collector.accumulateIfEven(e: String) = apply { if (e.length % 2 == 0) values.add(e) } + fun Collector.toPair() = key to values as List + + val elements = listOf("foo", "bar", "flea", "zoo", "biscuit") + val result = elements.groupingBy { it.first() } + .fold({ k, e -> Collector(k) }, { k, acc, e -> acc.accumulateIfEven(e) }) + + val ordered = result.values.sortedBy { it.key }.map { it.toPair() } + assertEquals(listOf('b' to emptyList(), 'f' to listOf("flea"), 'z' to emptyList()), ordered) + + val moreElements = listOf("fire", "zero") + val result2 = moreElements.groupingBy { it.first() } + .foldTo(HashMap(result), + { k, e -> error("should not be called for $k") }, + { k, acc, e -> acc.accumulateIfEven(e) }) + + val ordered2 = result2.values.sortedBy { it.key }.map { it.toPair() } + assertEquals(listOf('b' to emptyList(), 'f' to listOf("flea", "fire"), 'z' to listOf("zero")), ordered2) +} diff --git a/backend.native/tests/external/stdlib/collections/GroupingTest/foldWithConstantInitialValue.kt b/backend.native/tests/external/stdlib/collections/GroupingTest/foldWithConstantInitialValue.kt new file mode 100644 index 00000000000..8db6034c0a7 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/GroupingTest/foldWithConstantInitialValue.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + + +fun box() { + val elements = listOf("foo", "bar", "flea", "zoo", "biscuit") + // only collect strings with even length + val result = elements.groupingBy { it.first() }.fold(listOf()) { acc, e -> if (e.length % 2 == 0) acc + e else acc } + + assertEquals(mapOf('f' to listOf("flea"), 'b' to emptyList(), 'z' to emptyList()), result) + + val moreElements = listOf("fire", "zero", "abstract") + val result2 = moreElements.groupingBy { it.first() }.foldTo(HashMap(result), listOf()) { acc, e -> if (e.length % 2 == 0) acc + e else acc } + + assertEquals(mapOf('f' to listOf("flea", "fire"), 'b' to emptyList(), 'z' to listOf("zero"), 'a' to listOf("abstract")), result2) +} diff --git a/backend.native/tests/external/stdlib/collections/GroupingTest/groupingProducers.kt b/backend.native/tests/external/stdlib/collections/GroupingTest/groupingProducers.kt new file mode 100644 index 00000000000..d8d0a64c771 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/GroupingTest/groupingProducers.kt @@ -0,0 +1,26 @@ +import kotlin.test.* + + +fun box() { + + fun verifyGrouping(grouping: Grouping, expectedElements: List, expectedKeys: List) { + val elements = grouping.sourceIterator().asSequence().toList() + val keys = elements.map { grouping.keyOf(it) } // TODO: replace with grouping::keyOf when supported in JS + + assertEquals(expectedElements, elements) + assertEquals(expectedKeys, keys) + } + + val elements = listOf("foo", "bar", "value", "x") + val keySelector: (String) -> Int = { it.length } + val keys = elements.map(keySelector) + + fun verifyGrouping(grouping: Grouping) = verifyGrouping(grouping, elements, keys) + + verifyGrouping(elements.groupingBy { it.length }) + verifyGrouping(elements.toTypedArray().groupingBy(keySelector)) + verifyGrouping(elements.asSequence().groupingBy(keySelector)) + + val charSeq = "some sequence of chars" + verifyGrouping(charSeq.groupingBy { it.toInt() }, charSeq.toList(), charSeq.map { it.toInt() }) +} diff --git a/backend.native/tests/external/stdlib/collections/GroupingTest/reduce.kt b/backend.native/tests/external/stdlib/collections/GroupingTest/reduce.kt new file mode 100644 index 00000000000..acd88de57cf --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/GroupingTest/reduce.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + +inline fun > maxOfBy(a: T, b: T, keySelector: (T) -> K) = if (keySelector(a) >= keySelector(b)) a else b + +fun box() { + val elements = listOf("foo", "bar", "flea", "zoo", "biscuit") + fun Char.isVowel() = this in "aeiou" + fun String.countVowels() = count(Char::isVowel) + val maxVowels = elements.groupingBy { it.first() }.reduce { k, a, b -> maxOfBy(a, b, String::countVowels) } + + assertEquals(mapOf('f' to "foo", 'b' to "biscuit", 'z' to "zoo"), maxVowels) + + val elements2 = listOf("bar", "z", "fork") + val concats = elements2.groupingBy { it.first() }.reduceTo(HashMap(maxVowels)) { k, acc, e -> acc + e } + + assertEquals(mapOf('f' to "foofork", 'b' to "biscuitbar", 'z' to "zooz"), concats) +} diff --git a/backend.native/tests/external/stdlib/collections/IteratorsTest/iterationOverIterator.kt b/backend.native/tests/external/stdlib/collections/IteratorsTest/iterationOverIterator.kt new file mode 100644 index 00000000000..01428365ffb --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/IteratorsTest/iterationOverIterator.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + + +fun box() { + val c = listOf(0, 1, 2, 3, 4, 5) + var s = "" + for (i in c.iterator()) { + s = s + i.toString() + } + assertEquals("012345", s) +} diff --git a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElement.kt b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElement.kt new file mode 100644 index 00000000000..742ba2b3ea7 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElement.kt @@ -0,0 +1,30 @@ +import kotlin.test.* +import kotlin.test.assertEquals +import kotlin.comparisons.* + +val values = listOf(1, 3, 7, 10, 12, 15, 22, 45) + +fun notFound(index: Int) = -(index + 1) + +val comparator = compareBy?> { it?.value } + +data class IncomparableDataItem(public val value: T) + +fun IncomparableDataItem.pred(): IncomparableDataItem = IncomparableDataItem(value - 1) +fun IncomparableDataItem.succ(): IncomparableDataItem = IncomparableDataItem(value + 1) +fun Int.pred() = dec() +fun Int.succ() = inc() + +fun box() { + val list = values + list.forEachIndexed { index, item -> + assertEquals(index, list.binarySearch(item)) + assertEquals(notFound(index), list.binarySearch(item.pred())) + assertEquals(notFound(index + 1), list.binarySearch(item.succ())) + + if (index > 0) { + index.let { from -> assertEquals(notFound(from), list.binarySearch(list.first(), fromIndex = from)) } + (list.size - index).let { to -> assertEquals(notFound(to), list.binarySearch(list.last(), toIndex = to)) } + } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElementNullable.kt b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElementNullable.kt new file mode 100644 index 00000000000..7682e03463c --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElementNullable.kt @@ -0,0 +1,19 @@ +import kotlin.test.* +import kotlin.test.assertEquals +import kotlin.comparisons.* + +val values = listOf(1, 3, 7, 10, 12, 15, 22, 45) + +fun notFound(index: Int) = -(index + 1) + +fun box() { + val list = listOf(null) + values + list.forEachIndexed { index, item -> + assertEquals(index, list.binarySearch(item)) + + if (index > 0) { + index.let { from -> assertEquals(notFound(from), list.binarySearch(list.first(), fromIndex = from)) } + (list.size - index).let { to -> assertEquals(notFound(to), list.binarySearch(list.last(), toIndex = to)) } + } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKey.kt b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKey.kt new file mode 100644 index 00000000000..d9690e52323 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKey.kt @@ -0,0 +1,31 @@ +import kotlin.test.* +import kotlin.test.assertEquals +import kotlin.comparisons.* + +val values = listOf(1, 3, 7, 10, 12, 15, 22, 45) + +fun notFound(index: Int) = -(index + 1) + +val comparator = compareBy?> { it?.value } + +data class IncomparableDataItem(public val value: T) + +fun IncomparableDataItem.pred(): IncomparableDataItem = IncomparableDataItem(value - 1) +fun IncomparableDataItem.succ(): IncomparableDataItem = IncomparableDataItem(value + 1) +fun Int.pred() = dec() +fun Int.succ() = inc() + +fun box() { + val list = values.map { IncomparableDataItem(it) } + + list.forEachIndexed { index, item -> + assertEquals(index, list.binarySearchBy(item.value) { it.value }) + assertEquals(notFound(index), list.binarySearchBy(item.value.pred()) { it.value }) + assertEquals(notFound(index + 1), list.binarySearchBy(item.value.succ()) { it.value }) + + if (index > 0) { + index.let { from -> assertEquals(notFound(from), list.binarySearchBy(list.first().value, fromIndex = from) { it.value }) } + (list.size - index).let { to -> assertEquals(notFound(to), list.binarySearchBy(list.last().value, toIndex = to) { it.value }) } + } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKeyWithComparator.kt b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKeyWithComparator.kt new file mode 100644 index 00000000000..c0db07ac499 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKeyWithComparator.kt @@ -0,0 +1,34 @@ +import kotlin.test.* +import kotlin.test.assertEquals +import kotlin.comparisons.* + +fun notFound(index: Int) = -(index + 1) + +val comparator = compareBy?> { it?.value } + +data class IncomparableDataItem(public val value: T) + +fun IncomparableDataItem.pred(): IncomparableDataItem = IncomparableDataItem(value - 1) +fun IncomparableDataItem.succ(): IncomparableDataItem = IncomparableDataItem(value + 1) +fun Int.pred() = dec() +fun Int.succ() = inc() + +val values = listOf(1, 3, 7, 10, 12, 15, 22, 45) +fun box() { + val list = values.map { IncomparableDataItem(IncomparableDataItem(it)) } + + list.forEachIndexed { index, item -> + assertEquals(index, list.binarySearch { comparator.compare(it.value, item.value) }) + assertEquals(notFound(index), list.binarySearch { comparator.compare(it.value, item.value.pred()) }) + assertEquals(notFound(index + 1), list.binarySearch { comparator.compare(it.value, item.value.succ()) }) + + if (index > 0) { + index.let { from -> + assertEquals(notFound(from), list.binarySearch(fromIndex = from) { comparator.compare(it.value, list.first().value) }) + } + (list.size - index).let { to -> + assertEquals(notFound(to), list.binarySearch(toIndex = to) { comparator.compare(it.value, list.last().value) }) + } + } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByMultipleKeys.kt b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByMultipleKeys.kt new file mode 100644 index 00000000000..93e46e0a3fc --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByMultipleKeys.kt @@ -0,0 +1,23 @@ +import kotlin.test.* +import kotlin.test.assertEquals +import kotlin.comparisons.* + +fun notFound(index: Int) = -(index + 1) + +val comparator = compareBy?> { it?.value } + +data class IncomparableDataItem(public val value: T) + +fun IncomparableDataItem.pred(): IncomparableDataItem = IncomparableDataItem(value - 1) +fun IncomparableDataItem.succ(): IncomparableDataItem = IncomparableDataItem(value + 1) +fun Int.pred() = dec() +fun Int.succ() = inc() + +val values = listOf(1, 3, 7, 10, 12, 15, 22, 45) +fun box() { + val list = values.flatMap { v1 -> values.map { v2 -> Pair(v1, v2) } } + + list.forEachIndexed { index, item -> + assertEquals(index, list.binarySearch { compareValuesBy(it, item, { it.first }, { it.second }) }) + } +} diff --git a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchWithComparator.kt b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchWithComparator.kt new file mode 100644 index 00000000000..e0191eb656e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchWithComparator.kt @@ -0,0 +1,30 @@ +import kotlin.test.* +import kotlin.test.assertEquals +import kotlin.comparisons.* + +fun notFound(index: Int) = -(index + 1) + +val comparator = compareBy?> { it?.value } + +data class IncomparableDataItem(public val value: T) + +fun IncomparableDataItem.pred(): IncomparableDataItem = IncomparableDataItem(value - 1) +fun IncomparableDataItem.succ(): IncomparableDataItem = IncomparableDataItem(value + 1) +fun Int.pred() = dec() +fun Int.succ() = inc() + +val values = listOf(1, 3, 7, 10, 12, 15, 22, 45) +fun box() { + val list = values.map { IncomparableDataItem(it) } + + list.forEachIndexed { index, item -> + assertEquals(index, list.binarySearch(item, comparator)) + assertEquals(notFound(index), list.binarySearch(item.pred(), comparator)) + assertEquals(notFound(index + 1), list.binarySearch(item.succ(), comparator)) + + if (index > 0) { + index.let { from -> assertEquals(notFound(from), list.binarySearch(list.first(), comparator, fromIndex = from)) } + (list.size - index).let { to -> assertEquals(notFound(to), list.binarySearch(list.last(), comparator, toIndex = to)) } + } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ListSpecificTest/_toString.kt b/backend.native/tests/external/stdlib/collections/ListSpecificTest/_toString.kt new file mode 100644 index 00000000000..7016b530220 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListSpecificTest/_toString.kt @@ -0,0 +1,41 @@ +import kotlin.test.* + +val data = listOf("foo", "bar") +val empty = listOf() + +fun box() { + assertEquals("[foo, bar]", data.toString()) +} + +fun tail() { + val data = listOf("foo", "bar", "whatnot") + val actual = data.drop(1) + assertEquals(listOf("bar", "whatnot"), actual) +} + +fun slice() { + val list = listOf('A', 'B', 'C', 'D') + // ABCD + // 0123 + assertEquals(listOf('B', 'C', 'D'), list.slice(1..3)) + assertEquals(listOf('D', 'C', 'B'), list.slice(3 downTo 1)) + + val iter = listOf(2, 0, 3) + assertEquals(listOf('C', 'A', 'D'), list.slice(iter)) +} + +fun getOr() { + expect("foo") { data.get(0) } + expect("bar") { data.get(1) } + assertFails { data.get(2) } + assertFails { data.get(-1) } + assertFails { empty.get(0) } + + expect("foo") { data.getOrElse(0, { "" }) } + expect("zoo") { data.getOrElse(-1, { "zoo" }) } + expect("zoo") { data.getOrElse(2, { "zoo" }) } + expect("zoo") { empty.getOrElse(0) { "zoo" } } + + expect(null) { empty.getOrNull(0) } + +} diff --git a/backend.native/tests/external/stdlib/collections/ListSpecificTest/getOr.kt b/backend.native/tests/external/stdlib/collections/ListSpecificTest/getOr.kt new file mode 100644 index 00000000000..4b64843c1c5 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListSpecificTest/getOr.kt @@ -0,0 +1,20 @@ +import kotlin.test.* + +val data = listOf("foo", "bar") +val empty = listOf() + +fun box() { + expect("foo") { data.get(0) } + expect("bar") { data.get(1) } + assertFails { data.get(2) } + assertFails { data.get(-1) } + assertFails { empty.get(0) } + + expect("foo") { data.getOrElse(0, { "" }) } + expect("zoo") { data.getOrElse(-1, { "zoo" }) } + expect("zoo") { data.getOrElse(2, { "zoo" }) } + expect("zoo") { empty.getOrElse(0) { "zoo" } } + + expect(null) { empty.getOrNull(0) } + +} diff --git a/backend.native/tests/external/stdlib/collections/ListSpecificTest/indexOfLast.kt b/backend.native/tests/external/stdlib/collections/ListSpecificTest/indexOfLast.kt new file mode 100644 index 00000000000..828fb364c07 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListSpecificTest/indexOfLast.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +val data = listOf("foo", "bar") +val empty = listOf() +fun box() { + expect(-1) { data.indexOfLast { it.contains("p") } } + expect(1) { data.indexOfLast { it.length == 3 } } + expect(-1) { empty.indexOfLast { it.startsWith('f') } } +} diff --git a/backend.native/tests/external/stdlib/collections/ListSpecificTest/lastIndex.kt b/backend.native/tests/external/stdlib/collections/ListSpecificTest/lastIndex.kt new file mode 100644 index 00000000000..329657fa1a6 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListSpecificTest/lastIndex.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +val data = listOf("foo", "bar") +val empty = listOf() +fun box() { + assertEquals(-1, empty.lastIndex) + assertEquals(1, data.lastIndex) +} diff --git a/backend.native/tests/external/stdlib/collections/ListSpecificTest/mutableList.kt b/backend.native/tests/external/stdlib/collections/ListSpecificTest/mutableList.kt new file mode 100644 index 00000000000..997ec4ab342 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListSpecificTest/mutableList.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +fun box() { + val items = listOf("beverage", "location", "name") + + var list = listOf() + for (item in items) { + list += item + } + + assertEquals(3, list.size) + assertEquals("beverage,location,name", list.joinToString(",")) +} diff --git a/backend.native/tests/external/stdlib/collections/ListSpecificTest/slice.kt b/backend.native/tests/external/stdlib/collections/ListSpecificTest/slice.kt new file mode 100644 index 00000000000..4e5438b457e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListSpecificTest/slice.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + + +fun box() { + val list = listOf('A', 'B', 'C', 'D') + // ABCD + // 0123 + assertEquals(listOf('B', 'C', 'D'), list.slice(1..3)) + assertEquals(listOf('D', 'C', 'B'), list.slice(3 downTo 1)) + + val iter = listOf(2, 0, 3) + assertEquals(listOf('C', 'A', 'D'), list.slice(iter)) +} diff --git a/backend.native/tests/external/stdlib/collections/ListSpecificTest/tail.kt b/backend.native/tests/external/stdlib/collections/ListSpecificTest/tail.kt new file mode 100644 index 00000000000..041f8256464 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListSpecificTest/tail.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + + +fun box() { + val data = listOf("foo", "bar", "whatnot") + val actual = data.drop(1) + assertEquals(listOf("bar", "whatnot"), actual) +} diff --git a/backend.native/tests/external/stdlib/collections/ListSpecificTest/testNullToString.kt b/backend.native/tests/external/stdlib/collections/ListSpecificTest/testNullToString.kt new file mode 100644 index 00000000000..7927567acc2 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ListSpecificTest/testNullToString.kt @@ -0,0 +1,5 @@ +import kotlin.test.* + +fun box() { + assertEquals("[null]", listOf(null).toString()) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/all.kt b/backend.native/tests/external/stdlib/collections/MapTest/all.kt new file mode 100644 index 00000000000..53bed2a1fc3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/all.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2)) + assertTrue(map.all { it.key != "d" }) + assertTrue(emptyMap().all { it.key == "d" }) + + assertTrue(map.all { it.value > 0 }) + assertFalse(map.all { it.value == 2 }) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/any.kt b/backend.native/tests/external/stdlib/collections/MapTest/any.kt new file mode 100644 index 00000000000..0422fcd51e4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/any.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2)) + assertTrue(map.any()) + assertFalse(emptyMap().any()) + + assertTrue(map.any { it.key == "b" }) + assertFalse(emptyMap().any { it.key == "b" }) + + assertTrue(map.any { it.value == 2 }) + assertFalse(map.any { it.value == 5 }) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/contains.kt b/backend.native/tests/external/stdlib/collections/MapTest/contains.kt new file mode 100644 index 00000000000..3c41c9c48c4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/contains.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf("a" to 1, "b" to 2) + assertTrue("a" in map) + assertTrue("c" !in map) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/countBy.kt b/backend.native/tests/external/stdlib/collections/MapTest/countBy.kt new file mode 100644 index 00000000000..d80b749e71b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/countBy.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2)) + assertEquals(3, map.count()) + + val filteredByKey = map.count { it.key == "b" } + assertEquals(1, filteredByKey) + + val filteredByValue = map.count { it.value == 2 } + assertEquals(2, filteredByValue) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/createFrom.kt b/backend.native/tests/external/stdlib/collections/MapTest/createFrom.kt new file mode 100644 index 00000000000..2801e8092ee --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/createFrom.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + + +fun box() { + val pairs = arrayOf("a" to 1, "b" to 2) + val expected = mapOf(*pairs) + + assertEquals(expected, pairs.toMap()) + assertEquals(expected, pairs.asIterable().toMap()) + assertEquals(expected, pairs.asSequence().toMap()) + assertEquals(expected, expected.toMap()) + assertEquals(mapOf("a" to 1), expected.filterKeys { it == "a" }.toMap()) + assertEquals(emptyMap(), expected.filter { false }.toMap()) + + val mutableMap = expected.toMutableMap() + assertEquals(expected, mutableMap) + mutableMap += "c" to 3 + assertNotEquals(expected, mutableMap) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/createLinkedMap.kt b/backend.native/tests/external/stdlib/collections/MapTest/createLinkedMap.kt new file mode 100644 index 00000000000..7d222467795 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/createLinkedMap.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + + +fun box() { + val map = linkedMapOf(Pair("c", 3), Pair("b", 2), Pair("a", 1)) + assertEquals(1, map["a"]) + assertEquals(2, map["b"]) + assertEquals(3, map["c"]) + assertEquals(listOf("c", "b", "a"), map.keys.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/createMutableMap.kt b/backend.native/tests/external/stdlib/collections/MapTest/createMutableMap.kt new file mode 100644 index 00000000000..8ac9df0e653 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/createMutableMap.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + + +fun box() { + val map = mutableMapOf("b" to 1, "c" to 2) + map.put("a", 3) + assertEquals(listOf("b" to 1, "c" to 2, "a" to 3), map.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/createUsingTo.kt b/backend.native/tests/external/stdlib/collections/MapTest/createUsingTo.kt new file mode 100644 index 00000000000..16769fba3f3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/createUsingTo.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf("a" to 1, "b" to 2) + assertEquals(2, map.size) + assertEquals(1, map["a"]) + assertEquals(2, map["b"]) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/createWithPairSelector.kt b/backend.native/tests/external/stdlib/collections/MapTest/createWithPairSelector.kt new file mode 100644 index 00000000000..cef9d5cd15b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/createWithPairSelector.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + + +fun box() { + val map = listOf("a", "bb", "ccc").associate { it.length to it.toUpperCase() } + assertEquals(3, map.size) + assertEquals("A", map[1]) + assertEquals("BB", map[2]) + assertEquals("CCC", map[3]) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/createWithSelector.kt b/backend.native/tests/external/stdlib/collections/MapTest/createWithSelector.kt new file mode 100644 index 00000000000..b25e4e2866d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/createWithSelector.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + + +fun box() { + val map = listOf("a", "bb", "ccc").associateBy { it.length } + assertEquals(3, map.size) + assertEquals("a", map.get(1)) + assertEquals("bb", map.get(2)) + assertEquals("ccc", map.get(3)) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorAndOverwrite.kt b/backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorAndOverwrite.kt new file mode 100644 index 00000000000..90932bf5ad8 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorAndOverwrite.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + + +fun box() { + val map = listOf("aa", "bb", "ccc").associateBy { it.length } + assertEquals(2, map.size) + assertEquals("bb", map.get(2)) + assertEquals("ccc", map.get(3)) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorForKeyAndValue.kt b/backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorForKeyAndValue.kt new file mode 100644 index 00000000000..963a1c37bdc --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorForKeyAndValue.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + + +fun box() { + val map = listOf("a", "bb", "ccc").associateBy({ it.length }, { it.toUpperCase() }) + assertEquals(3, map.size) + assertEquals("A", map[1]) + assertEquals("BB", map[2]) + assertEquals("CCC", map[3]) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/filter.kt b/backend.native/tests/external/stdlib/collections/MapTest/filter.kt new file mode 100644 index 00000000000..9ebc707445b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/filter.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2)) + val filteredByKey = map.filter { it.key[0] == 'b' } + assertEquals(mapOf("b" to 3), filteredByKey) + + val filteredByKey2 = map.filterKeys { it[0] == 'b' } + assertEquals(mapOf("b" to 3), filteredByKey2) + + val filteredByValue = map.filter { it.value == 2 } + assertEquals(mapOf("a" to 2, "c" to 2), filteredByValue) + + val filteredByValue2 = map.filterValues { it % 2 == 0 } + assertEquals(mapOf("a" to 2, "c" to 2), filteredByValue2) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/filterNot.kt b/backend.native/tests/external/stdlib/collections/MapTest/filterNot.kt new file mode 100644 index 00000000000..943f573a945 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/filterNot.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2)) + val filteredByKey = map.filterNot { it.key == "b" } + assertEquals(2, filteredByKey.size) + assertEquals(null, filteredByKey["b"]) + assertEquals(2, filteredByKey["c"]) + assertEquals(2, filteredByKey["a"]) + + val filteredByValue = map.filterNot { it.value == 2 } + assertEquals(1, filteredByValue.size) + assertEquals(3, filteredByValue["b"]) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/filterOutProjectedTo.kt b/backend.native/tests/external/stdlib/collections/MapTest/filterOutProjectedTo.kt new file mode 100644 index 00000000000..694a65d8eef --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/filterOutProjectedTo.kt @@ -0,0 +1,23 @@ +import kotlin.test.* + + +fun assertStaticTypeIs(value: T) {} +fun box() { + val map: Map = mapOf(Pair("b", 3), Pair("c", 2), Pair("a", 2)) + + val filteredByKey = map.filterTo(mutableMapOf()) { it.key[0] == 'b' } + assertStaticTypeIs>(filteredByKey) + assertEquals(mapOf("b" to 3), filteredByKey) + + val filteredByKey2 = map.filterKeys { it[0] == 'b' } + assertStaticTypeIs>(filteredByKey2) + assertEquals(mapOf("b" to 3), filteredByKey2) + + val filteredByValue = map.filterNotTo(hashMapOf()) { it.value != 2 } + assertStaticTypeIs>(filteredByValue) + assertEquals(mapOf("a" to 2, "c" to 2), filteredByValue) + + val filteredByValue2 = map.filterValues { it % 2 == 0 } + assertStaticTypeIs>(filteredByValue2) + assertEquals(mapOf("a" to 2, "c" to 2), filteredByValue2) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/getOrElse.kt b/backend.native/tests/external/stdlib/collections/MapTest/getOrElse.kt new file mode 100644 index 00000000000..95747a65013 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/getOrElse.kt @@ -0,0 +1,22 @@ +import kotlin.test.* + + +fun box() { + val data = mapOf() + val a = data.getOrElse("foo") { 2 } + assertEquals(2, a) + val a1 = data.getOrElse("foo") { data.get("bar") } ?: 1 + assertEquals(1, a1) + + val b = data.getOrElse("foo") { 3 } + assertEquals(3, b) + assertEquals(0, data.size) + + val empty = mapOf() + val c = empty.getOrElse("") { null } + assertEquals(null, c) + + val nullable = mapOf(1 to null) + val d = nullable.getOrElse(1) { "x" } + assertEquals("x", d) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/getOrPut.kt b/backend.native/tests/external/stdlib/collections/MapTest/getOrPut.kt new file mode 100644 index 00000000000..04fdb6d60d7 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/getOrPut.kt @@ -0,0 +1,20 @@ +import kotlin.test.* + + +fun box() { + val data = hashMapOf() + val a = data.getOrPut("foo") { 2 } + assertEquals(2, a) + + val b = data.getOrPut("foo") { 3 } + assertEquals(2, b) + + assertEquals(1, data.size) + + val empty = hashMapOf() + val c = empty.getOrPut("") { null } + assertEquals(null, c) + + val d = empty.getOrPut("") { 1 } + assertEquals(1, d) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/getValue.kt b/backend.native/tests/external/stdlib/collections/MapTest/getValue.kt new file mode 100644 index 00000000000..c869bc81c9e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/getValue.kt @@ -0,0 +1,25 @@ +import kotlin.test.* + + +fun box() { + val data: MutableMap = hashMapOf("bar" to 1) + assertFailsWith { data.getValue("foo") }.let { e -> + assertTrue("foo" in e.message!!) + } + assertEquals(1, data.getValue("bar")) + + val mutableWithDefault = data.withDefault { 42 } + assertEquals(42, mutableWithDefault.getValue("foo")) + + // verify that it is wrapper + mutableWithDefault["bar"] = 2 + assertEquals(2, data["bar"]) + data["bar"] = 3 + assertEquals(3, mutableWithDefault["bar"]) + + val readonlyWithDefault = (data as Map).withDefault { it.length } + assertEquals(4, readonlyWithDefault.getValue("loop")) + + val withReplacedDefault = readonlyWithDefault.withDefault { 42 } + assertEquals(42, withReplacedDefault.getValue("loop")) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/iterate.kt b/backend.native/tests/external/stdlib/collections/MapTest/iterate.kt new file mode 100644 index 00000000000..bc1cb9c3bbf --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/iterate.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James") + val list = arrayListOf() + for (e in map) { + list.add(e.key) + list.add(e.value) + } + + assertEquals(6, list.size) + assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(",")) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/iterateWithExtraction.kt b/backend.native/tests/external/stdlib/collections/MapTest/iterateWithExtraction.kt new file mode 100644 index 00000000000..ad3bd7a4a3b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/iterateWithExtraction.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James") + val list = arrayListOf() + for ((key, value) in map) { + list.add(key) + list.add(value) + } + + assertEquals(6, list.size) + assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(",")) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/iterateWithProperties.kt b/backend.native/tests/external/stdlib/collections/MapTest/iterateWithProperties.kt new file mode 100644 index 00000000000..bc1cb9c3bbf --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/iterateWithProperties.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James") + val list = arrayListOf() + for (e in map) { + list.add(e.key) + list.add(e.value) + } + + assertEquals(6, list.size) + assertEquals("beverage,beer,location,Mells,name,James", list.joinToString(",")) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/map.kt b/backend.native/tests/external/stdlib/collections/MapTest/map.kt new file mode 100644 index 00000000000..1324faea415 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/map.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + + +fun box() { + val m1 = mapOf("beverage" to "beer", "location" to "Mells") + val list = m1.map { it.value + " rocks" } + + assertEquals(listOf("beer rocks", "Mells rocks"), list) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/mapKeys.kt b/backend.native/tests/external/stdlib/collections/MapTest/mapKeys.kt new file mode 100644 index 00000000000..69476b7e8c1 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/mapKeys.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + + +fun assertStaticTypeIs(value: T) {} +fun box() { + val m1 = mapOf("beverage" to "beer", "location" to "Mells") + val m2 = m1.mapKeys { it.key + "2" } + + assertEquals(mapOf("beverage2" to "beer", "location2" to "Mells"), m2) + + val m1p: Map = m1 + val m3 = m1p.mapKeysTo(mutableMapOf()) { it.key.length } + assertStaticTypeIs>(m3) + assertEquals(mapOf(8 to "Mells"), m3) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/mapNotNull.kt b/backend.native/tests/external/stdlib/collections/MapTest/mapNotNull.kt new file mode 100644 index 00000000000..0201636e292 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/mapNotNull.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + + +fun box() { + val m1 = mapOf("a" to 1, "b" to null) + val list = m1.mapNotNull { it.value?.let { v -> "${it.key}$v" } } + assertEquals(listOf("a1"), list) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/mapValues.kt b/backend.native/tests/external/stdlib/collections/MapTest/mapValues.kt new file mode 100644 index 00000000000..934efa2785a --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/mapValues.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + + +fun assertStaticTypeIs(value: T) {} +fun box() { + val m1 = mapOf("beverage" to "beer", "location" to "Mells") + val m2 = m1.mapValues { it.value + "2" } + + assertEquals(mapOf("beverage" to "beer2", "location" to "Mells2"), m2) + + val m1p: Map = m1 + val m3 = m1p.mapValuesTo(hashMapOf()) { it.value.length } + assertStaticTypeIs>(m3) + assertEquals(mapOf("beverage" to 4, "location" to 5), m3) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/onEach.kt b/backend.native/tests/external/stdlib/collections/MapTest/onEach.kt new file mode 100644 index 00000000000..98425833983 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/onEach.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + + +fun box() { + val map = mutableMapOf("beverage" to "beer", "location" to "Mells") + val result = StringBuilder() + val newMap = map.onEach { result.append(it.key).append("=").append(it.value).append(";") } + assertEquals("beverage=beer;location=Mells;", result.toString()) + assertTrue(map === newMap) + + // static types test + val m: HashMap = hashMapOf("a" to "b").onEach { } +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/plusAny.kt b/backend.native/tests/external/stdlib/collections/MapTest/plusAny.kt new file mode 100644 index 00000000000..ca49946590b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/plusAny.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + +fun testPlusAny(mapObject: Any, pair: Pair) { + val map = mapObject as Map<*, *> + fun assertContains(map: Map<*, *>) = assertEquals(pair.second, map[pair.first]) + + assertContains(map + pair) + assertContains(map + listOf(pair)) + assertContains(map + arrayOf(pair)) + assertContains(map + sequenceOf(pair)) + assertContains(map + mapOf(pair)) +} + +fun box() { + testPlusAny(emptyMap(), 1 to "A") + testPlusAny(mapOf("A" to null), "A" as CharSequence to 2) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/populateTo.kt b/backend.native/tests/external/stdlib/collections/MapTest/populateTo.kt new file mode 100644 index 00000000000..1b16792941d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/populateTo.kt @@ -0,0 +1,22 @@ +import kotlin.test.* + + +fun box() { + val pairs = arrayOf("a" to 1, "b" to 2) + val expected = mapOf(*pairs) + + val linkedMap: LinkedHashMap = pairs.toMap(linkedMapOf()) + assertEquals(expected, linkedMap) + + val hashMap: HashMap = pairs.asIterable().toMap(hashMapOf()) + assertEquals(expected, hashMap) + + val mutableMap: MutableMap = pairs.asSequence().toMap(mutableMapOf()) + assertEquals(expected, mutableMap) + + val mutableMap2 = mutableMap.toMap(mutableMapOf()) + assertEquals(expected, mutableMap2) + + val mutableMap3 = mutableMap.toMap(hashMapOf()) + assertEquals>(expected, mutableMap3) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/setViaIndexOperators.kt b/backend.native/tests/external/stdlib/collections/MapTest/setViaIndexOperators.kt new file mode 100644 index 00000000000..013d120f6fd --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/setViaIndexOperators.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + + +fun box() { + val map = hashMapOf() + assertTrue { map.none() } + assertEquals(map.size, 0) + + map["name"] = "James" + + assertTrue { map.any() } + assertEquals(map.size, 1) + assertEquals("James", map["name"]) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/sizeAndEmpty.kt b/backend.native/tests/external/stdlib/collections/MapTest/sizeAndEmpty.kt new file mode 100644 index 00000000000..876fd6d0d4b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/sizeAndEmpty.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + + +fun box() { + val data = hashMapOf() + assertTrue { data.none() } + assertEquals(data.size, 0) +} diff --git a/backend.native/tests/external/stdlib/collections/MapTest/stream.kt b/backend.native/tests/external/stdlib/collections/MapTest/stream.kt new file mode 100644 index 00000000000..7a07996f926 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MapTest/stream.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + + +fun box() { + val map = mapOf("beverage" to "beer", "location" to "Mells", "name" to "James") + val named = map.asSequence().filter { it.key == "name" }.single() + assertEquals("James", named.value) +} diff --git a/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/addAll.kt b/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/addAll.kt new file mode 100644 index 00000000000..ab70a139499 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/addAll.kt @@ -0,0 +1,29 @@ +import kotlin.test.* + +fun > testOperation(before: List, after: List, expectedModified: Boolean, toMutableCollection: (List) -> C) + = fun(operation: (C.() -> Boolean)) { + val list = toMutableCollection(before) + assertEquals(expectedModified, list.operation()) + assertEquals(toMutableCollection(after), list) +} + +fun testOperation(before: List, after: List, expectedModified: Boolean) + = testOperation(before, after, expectedModified, { it.toMutableList() }) + +fun box() { + val data = listOf("foo", "bar") + + testOperation(emptyList(), data, true).let { assertAdd -> + assertAdd { addAll(data) } + assertAdd { addAll(data.toTypedArray()) } + assertAdd { addAll(data.toTypedArray().asIterable()) } + assertAdd { addAll(data.asSequence()) } + } + + testOperation(data, data, false, { it.toCollection(LinkedHashSet()) }).let { assertAdd -> + assertAdd { addAll(data) } + assertAdd { addAll(data.toTypedArray()) } + assertAdd { addAll(data.toTypedArray().asIterable()) } + assertAdd { addAll(data.asSequence()) } + } +} diff --git a/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/removeAll.kt b/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/removeAll.kt new file mode 100644 index 00000000000..3e21bb400b4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/removeAll.kt @@ -0,0 +1,36 @@ +import kotlin.test.* + +fun > testOperation(before: List, after: List, expectedModified: Boolean, toMutableCollection: (List) -> C) + = fun(operation: (C.() -> Boolean)) { + val list = toMutableCollection(before) + assertEquals(expectedModified, list.operation()) + assertEquals(toMutableCollection(after), list) +} + +fun testOperation(before: List, after: List, expectedModified: Boolean) + = testOperation(before, after, expectedModified, { it.toMutableList() }) + +fun box() { + val content = listOf("foo", "bar", "bar") + val data = listOf("bar") + val expected = listOf("foo") + + testOperation(content, expected, true).let { assertRemove -> + assertRemove { removeAll(data) } + assertRemove { removeAll(data.toTypedArray()) } + assertRemove { removeAll(data.toTypedArray().asIterable()) } + assertRemove { removeAll { it in data } } + assertRemove { (this as MutableIterable).removeAll { it in data } } + val predicate = { cs: CharSequence -> cs.first() == 'b' } + assertRemove { removeAll(predicate) } + } + + + testOperation(content, content, false).let { assertRemove -> + assertRemove { removeAll(emptyList()) } + assertRemove { removeAll(emptyArray()) } + assertRemove { removeAll(emptySequence()) } + assertRemove { removeAll { false } } + assertRemove { (this as MutableIterable).removeAll { false } } + } +} diff --git a/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/retainAll.kt b/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/retainAll.kt new file mode 100644 index 00000000000..20eec783fe7 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/retainAll.kt @@ -0,0 +1,47 @@ +import kotlin.test.* + +fun > testOperation(before: List, after: List, expectedModified: Boolean, toMutableCollection: (List) -> C) + = fun(operation: (C.() -> Boolean)) { + val list = toMutableCollection(before) + assertEquals(expectedModified, list.operation()) + assertEquals(toMutableCollection(after), list) +} + +fun testOperation(before: List, after: List, expectedModified: Boolean) + = testOperation(before, after, expectedModified, { it.toMutableList() }) + +fun box() { + val content = listOf("foo", "bar", "bar") + val expected = listOf("bar", "bar") + + testOperation(content, expected, true).let { assertRetain -> + val data = listOf("bar") + assertRetain { retainAll(data) } + assertRetain { retainAll(data.toTypedArray()) } + assertRetain { retainAll(data.toTypedArray().asIterable()) } + assertRetain { retainAll(data.asSequence()) } + assertRetain { retainAll { it in data } } + assertRetain { (this as MutableIterable).retainAll { it in data } } + + val predicate = { cs: CharSequence -> cs.first() == 'b' } + assertRetain { retainAll(predicate) } + } + testOperation(content, emptyList(), true).let { assertRetain -> + val data = emptyList() + assertRetain { retainAll(data) } + assertRetain { retainAll(data.toTypedArray()) } + assertRetain { retainAll(data.toTypedArray().asIterable()) } + assertRetain { retainAll(data.asSequence()) } + assertRetain { retainAll { it in data } } + assertRetain { (this as MutableIterable).retainAll { it in data } } + } + testOperation(emptyList(), emptyList(), false).let { assertRetain -> + val data = emptyList() + assertRetain { retainAll(data) } + assertRetain { retainAll(data.toTypedArray()) } + assertRetain { retainAll(data.toTypedArray().asIterable()) } + assertRetain { retainAll(data.asSequence()) } + assertRetain { retainAll { it in data } } + assertRetain { (this as MutableIterable).retainAll { it in data } } + } +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testAddIOOB.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testAddIOOB.kt new file mode 100644 index 00000000000..f2a460e3278 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testAddIOOB.kt @@ -0,0 +1,16 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val success = try { + mutableListOf(1, 2, 3).asReversed().add(4, 0) + true + } catch(expected: IndexOutOfBoundsException) { + false + } + + assertFalse(success) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBehavior.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBehavior.kt new file mode 100644 index 00000000000..18cf862b5f4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBehavior.kt @@ -0,0 +1,105 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.listBehavior() { + equalityBehavior() + collectionBehavior() + compareProperty({ listIterator() }, { listIteratorBehavior() }) + compareProperty({ listIterator(0) }, { listIteratorBehavior() }) + + propertyFails { listIterator(-1) } + propertyFails { listIterator(size + 1) } + + for (index in expected.indices) + propertyEquals { this[index] } + + propertyFails { this[size] } + + propertyEquals { indexOf(elementAtOrNull(0)) } + propertyEquals { lastIndexOf(elementAtOrNull(0)) } + + propertyFails { subList(0, size + 1) } + propertyFails { subList(-1, 0) } + propertyEquals { subList(0, size) } +} + +fun CompareContext.equalityBehavior(objectName: String = "") { + val prefix = objectName + if (objectName.isNotEmpty()) "." else "" + equals(objectName) + propertyEquals(prefix + "hashCode") { hashCode() } + propertyEquals(prefix + "toString") { toString() } +} + + +fun CompareContext>.collectionBehavior(objectName: String = "") { + val prefix = objectName + if (objectName.isNotEmpty()) "." else "" + propertyEquals(prefix + "size") { size } + propertyEquals(prefix + "isEmpty") { isEmpty() } + + (object {}).let { propertyEquals { contains(it as Any?) } } + propertyEquals { contains(firstOrNull()) } + propertyEquals { containsAll(this) } +} + +public fun CompareContext>.listIteratorProperties() { + propertyEquals { hasNext() } + propertyEquals { hasPrevious() } + propertyEquals { nextIndex() } + propertyEquals { previousIndex() } +} + +fun CompareContext>.listIteratorBehavior() { + listIteratorProperties() + + while (expected.hasNext()) { + propertyEquals { next() } + listIteratorProperties() + } + propertyFails { next() } + + while (expected.hasPrevious()) { + propertyEquals { previous() } + listIteratorProperties() + } + propertyFails { previous() } +} + +fun box() { + val original = listOf(2L, 3L, Long.MAX_VALUE) + val reversed = original.reversed() + compare(reversed, original.asReversed()) { + listBehavior() + } +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBidirectionalModifications.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBidirectionalModifications.kt new file mode 100644 index 00000000000..217cf9fe861 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBidirectionalModifications.kt @@ -0,0 +1,18 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val original = mutableListOf(1, 2, 3, 4) + val reversed = original.asReversed() + + original.removeAt(3) + assertEquals(listOf(1, 2, 3), original) + assertEquals(listOf(3, 2, 1), reversed) + + reversed.removeAt(2) + assertEquals(listOf(2, 3), original) + assertEquals(listOf(3, 2), reversed) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testContains.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testContains.kt new file mode 100644 index 00000000000..7fc03534986 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testContains.kt @@ -0,0 +1,10 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + assertTrue { 1 in listOf(1, 2, 3).asReversed() } + assertTrue { 1 in mutableListOf(1, 2, 3).asReversed() } +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testDoubleReverse.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testDoubleReverse.kt new file mode 100644 index 00000000000..00718994f43 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testDoubleReverse.kt @@ -0,0 +1,10 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + assertEquals(listOf(1, 2, 3), listOf(1, 2, 3).asReversed().asReversed()) + assertEquals(listOf(2, 3), listOf(1, 2, 3, 4).asReversed().subList(1, 3).asReversed()) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testEmpty.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testEmpty.kt new file mode 100644 index 00000000000..dab00d8c34c --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testEmpty.kt @@ -0,0 +1,9 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + assertEquals(emptyList(), emptyList().asReversed()) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testGetIOOB.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testGetIOOB.kt new file mode 100644 index 00000000000..05c2382d367 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testGetIOOB.kt @@ -0,0 +1,16 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val success = try { + listOf(1, 2, 3).asReversed().get(3) + true + } catch (expected: IndexOutOfBoundsException) { + false + } + + assertFalse(success) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testIndexOf.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testIndexOf.kt new file mode 100644 index 00000000000..f29674d2835 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testIndexOf.kt @@ -0,0 +1,10 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + assertEquals(2, listOf(1, 2, 3).asReversed().indexOf(1)) + assertEquals(2, mutableListOf(1, 2, 3).asReversed().indexOf(1)) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableAdd.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableAdd.kt new file mode 100644 index 00000000000..14b903d31fe --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableAdd.kt @@ -0,0 +1,18 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val original = mutableListOf(1, 2, 3) + val reversed = original.asReversed() + + reversed.add(0) // add zero at end of reversed + assertEquals(listOf(3, 2, 1, 0), reversed) + assertEquals(listOf(0, 1, 2, 3), original) + + reversed.add(0, 4) // add four at position 0 + assertEquals(listOf(4, 3, 2, 1, 0), reversed) + assertEquals(listOf(0, 1, 2, 3, 4), original) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableClear.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableClear.kt new file mode 100644 index 00000000000..7743d6d7a20 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableClear.kt @@ -0,0 +1,15 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val original = mutableListOf(1, 2, 3) + val reversed = original.asReversed() + + reversed.clear() + + assertEquals(emptyList(), reversed) + assertEquals(emptyList(), original) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableDoubleReverse.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableDoubleReverse.kt new file mode 100644 index 00000000000..cfb0d29808e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableDoubleReverse.kt @@ -0,0 +1,10 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + assertEquals(listOf(1, 2, 3), mutableListOf(1, 2, 3).asReversed().asReversed()) + assertEquals(listOf(2, 3), mutableListOf(1, 2, 3, 4).asReversed().subList(1, 3).asReversed()) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableEmpty.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableEmpty.kt new file mode 100644 index 00000000000..f3b4767ab4f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableEmpty.kt @@ -0,0 +1,9 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + assertEquals(emptyList(), mutableListOf().asReversed()) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemove.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemove.kt new file mode 100644 index 00000000000..f862384acf4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemove.kt @@ -0,0 +1,20 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val original = mutableListOf("a", "b", "c") + val reversed = original.asReversed() + + reversed.removeAt(0) // remove c + assertEquals(listOf("a", "b"), original) + assertEquals(listOf("b", "a"), reversed) + + reversed.removeAt(1) // remove a + assertEquals(listOf("b"), original) + + reversed.removeAt(0) // remove remaining b + assertEquals(emptyList(), original) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemoveByObj.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemoveByObj.kt new file mode 100644 index 00000000000..32c59bc3d69 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemoveByObj.kt @@ -0,0 +1,14 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val original = mutableListOf("a", "b", "c") + val reversed = original.asReversed() + + reversed.remove("c") + assertEquals(listOf("a", "b"), original) + assertEquals(listOf("b", "a"), reversed) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableReversedSubList.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableReversedSubList.kt new file mode 100644 index 00000000000..faf4257dee3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableReversedSubList.kt @@ -0,0 +1,10 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val reversed = (1..10).toMutableList().asReversed() + assertEquals(listOf(9, 8, 7), reversed.subList(1, 4)) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSet.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSet.kt new file mode 100644 index 00000000000..0623f75dfec --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSet.kt @@ -0,0 +1,17 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val original = mutableListOf(1, 2, 3) + val reversed = original.asReversed() + + reversed.set(0, 300) + reversed.set(1, 200) + reversed.set(2, 100) + + assertEquals(listOf(100, 200, 300), original) + assertEquals(listOf(300, 200, 100), reversed) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSimple.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSimple.kt new file mode 100644 index 00000000000..975e95efdde --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSimple.kt @@ -0,0 +1,10 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + assertEquals(listOf(3, 2, 1), mutableListOf(1, 2, 3).asReversed()) + assertEquals(listOf(3, 2, 1), mutableListOf(1, 2, 3).asReversed().toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSubList.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSubList.kt new file mode 100644 index 00000000000..e4c4207502d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSubList.kt @@ -0,0 +1,19 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val original = arrayListOf(1, 2, 3, 4) + val reversedSubList = original.asReversed().subList(1, 3) + + assertEquals(listOf(3, 2), reversedSubList) + reversedSubList.clear() + assertEquals(emptyList(), reversedSubList) + assertEquals(listOf(1, 4), original) + + reversedSubList.add(100) + assertEquals(listOf(100), reversedSubList) + assertEquals(listOf(1, 100, 4), original) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testNullToString.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testNullToString.kt new file mode 100644 index 00000000000..03516c776f1 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testNullToString.kt @@ -0,0 +1,9 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + assertEquals("[null]", listOf(null).asReversed().toString()) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRandomAccess.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRandomAccess.kt new file mode 100644 index 00000000000..fbd0ca111c2 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRandomAccess.kt @@ -0,0 +1,13 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val reversed = listOf(1, 2, 3).asReversed() + + assertEquals(3, reversed[0]) + assertEquals(2, reversed[1]) + assertEquals(1, reversed[2]) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRemoveIOOB.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRemoveIOOB.kt new file mode 100644 index 00000000000..c391ea91cfc --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRemoveIOOB.kt @@ -0,0 +1,16 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val success = try { + mutableListOf(1, 2, 3).asReversed().removeAt(3) + true + } catch(expected: IndexOutOfBoundsException) { + false + } + + assertFalse(success) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testReversedSubList.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testReversedSubList.kt new file mode 100644 index 00000000000..7ff2f67f07c --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testReversedSubList.kt @@ -0,0 +1,10 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val reversed = (1..10).toList().asReversed() + assertEquals(listOf(9, 8, 7), reversed.subList(1, 4)) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSetIOOB.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSetIOOB.kt new file mode 100644 index 00000000000..e1d17160b1f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSetIOOB.kt @@ -0,0 +1,16 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + val success = try { + mutableListOf(1, 2, 3).asReversed().set(3, 0) + true + } catch(expected: IndexOutOfBoundsException) { + false + } + + assertFalse(success) +} diff --git a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSimple.kt b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSimple.kt new file mode 100644 index 00000000000..b04de95d064 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSimple.kt @@ -0,0 +1,10 @@ +import kotlin.test.assertEquals +import kotlin.test.assertFalse +import kotlin.test.assertTrue +import kotlin.test.* + + +fun box() { + assertEquals(listOf(3, 2, 1), listOf(1, 2, 3).asReversed()) + assertEquals(listOf(3, 2, 1), listOf(1, 2, 3).asReversed().toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceJVMTest/filterIsInstance.kt b/backend.native/tests/external/stdlib/collections/SequenceJVMTest/filterIsInstance.kt new file mode 100644 index 00000000000..90dcba9a9c4 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceJVMTest/filterIsInstance.kt @@ -0,0 +1,21 @@ +import kotlin.test.* +import kotlin.test.assertEquals + +fun box() { + val src: Sequence = listOf(1, 2, 3.toDouble(), "abc", "cde").asSequence() + + val intValues: Sequence = src.filterIsInstance() + assertEquals(listOf(1, 2), intValues.toList()) + + val doubleValues: Sequence = src.filterIsInstance() + assertEquals(listOf(3.0), doubleValues.toList()) + + val stringValues: Sequence = src.filterIsInstance() + assertEquals(listOf("abc", "cde"), stringValues.toList()) + + val anyValues: Sequence = src.filterIsInstance() + assertEquals(src.toList(), anyValues.toList()) + + val charValues: Sequence = src.filterIsInstance() + assertEquals(0, charValues.toList().size) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/distinct.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/distinct.kt new file mode 100644 index 00000000000..3fc2772eeff --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/distinct.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + val sequence = fibonacci().dropWhile { it < 10 }.take(20) + assertEquals(listOf(1, 2, 3, 0), sequence.map { it % 4 }.distinct().toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/distinctBy.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/distinctBy.kt new file mode 100644 index 00000000000..0c30c748e88 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/distinctBy.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + val sequence = fibonacci().dropWhile { it < 10 }.take(20) + assertEquals(listOf(13, 34, 55, 144), sequence.distinctBy { it % 4 }.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/drop.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/drop.kt new file mode 100644 index 00000000000..398709def71 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/drop.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals(emptyList(), emptySequence().drop(1).toList()) + listOf(2, 3, 4, 5).let { assertEquals(it, it.asSequence().drop(0).toList()) } + assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(7).joinToString(limit = 10)) + assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().drop(3).drop(4).joinToString(limit = 10)) + assertFailsWith { fibonacci().drop(-1) } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/dropWhile.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/dropWhile.kt new file mode 100644 index 00000000000..c9449ef04f8 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/dropWhile.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals("233, 377, 610", fibonacci().dropWhile { it < 200 }.take(3).joinToString(limit = 10)) + assertEquals("", sequenceOf(1).dropWhile { it < 200 }.joinToString(limit = 10)) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/filterAndTakeWhileExtractTheElementsWithinRange.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/filterAndTakeWhileExtractTheElementsWithinRange.kt new file mode 100644 index 00000000000..40796b2e832 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/filterAndTakeWhileExtractTheElementsWithinRange.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals(listOf(144, 233, 377, 610, 987), fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/filterEmptySequence.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/filterEmptySequence.kt new file mode 100644 index 00000000000..ebea48b4085 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/filterEmptySequence.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + for (sequence in listOf(emptySequence(), sequenceOf())) { + assertEquals(0, sequence.filter { false }.count()) + assertEquals(0, sequence.filter { true }.count()) + } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/filterIndexed.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/filterIndexed.kt new file mode 100644 index 00000000000..f67a00a86b9 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/filterIndexed.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals(listOf(1, 2, 5, 13, 34), fibonacci().filterIndexed { index, value -> index % 2 == 1 }.take(5).toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/filterNot.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/filterNot.kt new file mode 100644 index 00000000000..02313a891a2 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/filterNot.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val data = sequenceOf(null, "foo", null, "bar") + val filtered = data.filterNot { it == null } + assertEquals(listOf("foo", "bar"), filtered.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/filterNotNull.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/filterNotNull.kt new file mode 100644 index 00000000000..4c355fe4900 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/filterNotNull.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val data = sequenceOf(null, "foo", null, "bar") + val filtered = data.filterNotNull() + assertEquals(listOf("foo", "bar"), filtered.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/filterNullable.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/filterNullable.kt new file mode 100644 index 00000000000..3751a50c95a --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/filterNullable.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val data = sequenceOf(null, "foo", null, "bar") + val filtered = data.filter { it == null || it == "foo" } + assertEquals(listOf(null, "foo", null), filtered.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/flatMap.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/flatMap.kt new file mode 100644 index 00000000000..e265c16cf60 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/flatMap.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val result = sequenceOf(1, 2).flatMap { (0..it).asSequence() } + assertEquals(listOf(0, 1, 0, 1, 2), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapAndTakeExtractTheTransformedElements.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapAndTakeExtractTheTransformedElements.kt new file mode 100644 index 00000000000..b5292d129f5 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapAndTakeExtractTheTransformedElements.kt @@ -0,0 +1,23 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + val expected = listOf( + '3', // fibonacci(4) = 3 + '5', // fibonacci(5) = 5 + '8', // fibonacci(6) = 8 + '1', '3', // fibonacci(7) = 13 + '2', '1', // fibonacci(8) = 21 + '3', '4', // fibonacci(9) = 34 + '5' // fibonacci(10) = 55 + ) + + assertEquals(expected, fibonacci().drop(4).flatMap { it.toString().asSequence() }.take(10).toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapOnEmpty.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapOnEmpty.kt new file mode 100644 index 00000000000..459ccc7bb53 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapOnEmpty.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val result = sequenceOf().flatMap { (0..it).asSequence() } + assertTrue(result.none()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapWithEmptyItems.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapWithEmptyItems.kt new file mode 100644 index 00000000000..79466f22779 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapWithEmptyItems.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val result = sequenceOf(1, 2, 4).flatMap { if (it == 2) sequenceOf() else (it - 1..it).asSequence() } + assertEquals(listOf(0, 1, 3, 4), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/flatten.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/flatten.kt new file mode 100644 index 00000000000..877380dff89 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/flatten.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val expected = listOf(0, 1, 0, 1, 2) + + val seq = sequenceOf((0..1).asSequence(), (0..2).asSequence()).flatten() + assertEquals(expected, seq.toList()) + + val seqMappedSeq = sequenceOf(1, 2).map { (0..it).asSequence() }.flatten() + assertEquals(expected, seqMappedSeq.toList()) + + val seqOfIterable = sequenceOf(0..1, 0..2).flatten() + assertEquals(expected, seqOfIterable.toList()) + + val seqMappedIterable = sequenceOf(1, 2).map { 0..it }.flatten() + assertEquals(expected, seqMappedIterable.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/foldReducesTheFirstNElements.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/foldReducesTheFirstNElements.kt new file mode 100644 index 00000000000..40b23c16a99 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/foldReducesTheFirstNElements.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + val sum = { a: Int, b: Int -> a + b } + assertEquals(listOf(13, 21, 34, 55, 89).fold(0, sum), fibonacci().filter { it > 10 }.take(5).fold(0, sum)) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/iterationOverSequence.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/iterationOverSequence.kt new file mode 100644 index 00000000000..b89c59a7d67 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/iterationOverSequence.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + var s = "" + for (i in sequenceOf(0, 1, 2, 3, 4, 5)) { + s += i.toString() + } + assertEquals("012345", s) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/joinConcatenatesTheFirstNElementsAboveAThreshold.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/joinConcatenatesTheFirstNElementsAboveAThreshold.kt new file mode 100644 index 00000000000..cd526af8ee3 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/joinConcatenatesTheFirstNElementsAboveAThreshold.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals("13, 21, 34, 55, 89, ...", fibonacci().filter { it > 10 }.joinToString(separator = ", ", limit = 5)) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/makeSequenceOneTimeConstrained.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/makeSequenceOneTimeConstrained.kt new file mode 100644 index 00000000000..6e09049bd07 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/makeSequenceOneTimeConstrained.kt @@ -0,0 +1,18 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val sequence = sequenceOf(1, 2, 3, 4) + sequence.toList() + sequence.toList() + + val oneTime = sequence.constrainOnce() + oneTime.toList() + assertTrue("should fail with IllegalStateException") { + assertFails { + oneTime.toList() + } is IllegalStateException + } + +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/mapAndJoinToString.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/mapAndJoinToString.kt new file mode 100644 index 00000000000..1a920467204 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/mapAndJoinToString.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals("3, 5, 8", fibonacci().withIndex().filter { it.index > 3 }.take(3).joinToString { it.value.toString() }) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/mapAndTakeWhileExtractTheTransformedElements.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/mapAndTakeWhileExtractTheTransformedElements.kt new file mode 100644 index 00000000000..7d96a2946d8 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/mapAndTakeWhileExtractTheTransformedElements.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals(listOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile { i: Int -> i < 20 }.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/mapEmptySequence.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/mapEmptySequence.kt new file mode 100644 index 00000000000..f2a708c4958 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/mapEmptySequence.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + for (sequence in listOf(emptySequence(), sequenceOf())) { + assertEquals(0, sequence.map { true }.count()) + } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexed.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexed.kt new file mode 100644 index 00000000000..42ecd81c38a --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexed.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals(listOf(0, 1, 2, 6, 12), fibonacci().mapIndexed { index, value -> index * value }.takeWhile { i: Int -> i < 20 }.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexedNotNull.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexedNotNull.kt new file mode 100644 index 00000000000..773e06f90ac --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexedNotNull.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + // find which terms are divisible by their index + assertEquals(listOf("1/1", "5/5", "144/12", "46368/24", "75025/25"), + fibonacci().mapIndexedNotNull { index, value -> + if (index > 0 && (value % index) == 0) "$value/$index" else null + }.take(5).toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/mapNotNull.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/mapNotNull.kt new file mode 100644 index 00000000000..a7db52f17ca --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/mapNotNull.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals(listOf(0, 10, 110, 1220), fibonacci().mapNotNull { if (it % 5 == 0) it * 2 else null }.take(4).toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/minusAssign.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/minusAssign.kt new file mode 100644 index 00000000000..b42f7d4f58b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/minusAssign.kt @@ -0,0 +1,16 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + // lets use a mutable variable of readonly list + val data = sequenceOf("cheese", "foo", "beer", "cheese", "wine") + var l = data + l -= "cheese" + assertEquals(listOf("foo", "beer", "cheese", "wine"), l.toList()) + l = data + l -= listOf("cheese", "beer") + assertEquals(listOf("foo", "wine"), l.toList()) + l -= arrayOf("wine", "bar") + assertEquals(listOf("foo"), l.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/minusIsLazyIterated.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/minusIsLazyIterated.kt new file mode 100644 index 00000000000..0b37421e2a6 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/minusIsLazyIterated.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val seq = sequenceOf("foo", "bar") + val list = arrayListOf() + val result = seq - list + + list += "foo" + assertEquals(listOf("bar"), result.toList()) + list += "bar" + assertEquals(emptyList(), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/onEach.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/onEach.kt new file mode 100644 index 00000000000..d7b266ea340 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/onEach.kt @@ -0,0 +1,31 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun onEach() { + var count = 0 + val data = sequenceOf("foo", "bar") + val newData = data.onEach { count += it.length } + assertFalse(data === newData) + assertEquals(0, count, "onEach should be executed lazily") + + data.forEach { } + assertEquals(0, count, "onEach should be executed only when resulting sequence is iterated") + + val sum = newData.sumBy { it.length } + assertEquals(sum, count) +} + +fun box() { + var count = 0 + val data = sequenceOf("foo", "bar") + val newData = data.onEach { count += it.length } + assertFalse(data === newData) + assertEquals(0, count, "onEach should be executed lazily") + + data.forEach { } + assertEquals(0, count, "onEach should be executed only when resulting sequence is iterated") + + val sum = newData.sumBy { it.length } + assertEquals(sum, count) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/plusAssign.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/plusAssign.kt new file mode 100644 index 00000000000..2241fbe1e1d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/plusAssign.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + // lets use a mutable variable + var seq = sequenceOf("a") + seq += "foo" + seq += listOf("beer") + seq += arrayOf("cheese", "wine") + seq += sequenceOf("bar", "foo") + assertEquals(listOf("a", "foo", "beer", "cheese", "wine", "bar", "foo"), seq.toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/requireNoNulls.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/requireNoNulls.kt new file mode 100644 index 00000000000..e6b4f7302cf --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/requireNoNulls.kt @@ -0,0 +1,16 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val sequence = sequenceOf("foo", "bar") + val notNull = sequence.requireNoNulls() + assertEquals(listOf("foo", "bar"), notNull.toList()) + + val sequenceWithNulls = sequenceOf("foo", null, "bar") + val notNull2 = sequenceWithNulls.requireNoNulls() // shouldn't fail yet + assertFails { + // should throw an exception as we have a null + notNull2.toList() + } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceExtensions.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceExtensions.kt new file mode 100644 index 00000000000..e26da0c533d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceExtensions.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun > Sequence.takeWhileTo(result: C, predicate: (T) -> Boolean): C { + for (element in this) if (predicate(element)) result.add(element) else break + return result +} + +fun box() { + val d = ArrayList() + sequenceOf(0, 1, 2, 3, 4, 5).takeWhileTo(d, { i -> i < 4 }) + assertEquals(4, d.size) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunction.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunction.kt new file mode 100644 index 00000000000..49f2bc9ccae --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunction.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + var count = 3 + + val sequence = generateSequence { + count-- + if (count >= 0) count else null + } + + val list = sequence.toList() + assertEquals(listOf(2, 1, 0), list) + + assertFails { + sequence.toList() + } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithInitialValue.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithInitialValue.kt new file mode 100644 index 00000000000..f3e12c2812e --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithInitialValue.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val values = generateSequence(3) { n -> if (n > 0) n - 1 else null } + val expected = listOf(3, 2, 1, 0) + assertEquals(expected, values.toList()) + assertEquals(expected, values.toList(), "Iterating sequence second time yields the same result") +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithLazyInitialValue.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithLazyInitialValue.kt new file mode 100644 index 00000000000..faaaf6d8693 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithLazyInitialValue.kt @@ -0,0 +1,21 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + var start = 3 + val values = generateSequence({ start }, { n -> if (n > 0) n - 1 else null }) + val expected = listOf(3, 2, 1, 0) + assertEquals(expected, values.toList()) + assertEquals(expected, values.toList(), "Iterating sequence second time yields the same result") + + start = 2 + assertEquals(expected.drop(1), values.toList(), "Initial value function is called on each iterator request") + + // does not throw on construction + val errorValues = generateSequence({ (throw IllegalStateException()) }, { null }) + // does not throw on iteration + val iterator = errorValues.iterator() + // throws on advancing + assertFails { iterator.next() } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromIterator.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromIterator.kt new file mode 100644 index 00000000000..02f8d1da637 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromIterator.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val list = listOf(3, 2, 1, 0) + val iterator = list.iterator() + val sequence = iterator.asSequence() + assertEquals(list, sequence.toList()) + assertFails { + sequence.toList() + } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/sorted.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/sorted.kt new file mode 100644 index 00000000000..92a9850f58d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/sorted.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + sequenceOf(3, 7, 5).let { + it.sorted().iterator().assertSorted { a, b -> a <= b } + it.sortedDescending().iterator().assertSorted { a, b -> a >= b } + } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/sortedBy.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/sortedBy.kt new file mode 100644 index 00000000000..9dc1164f6c0 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/sortedBy.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + sequenceOf("it", "greater", "less").let { + it.sortedBy { it.length }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length } <= 0 } + it.sortedByDescending { it.length }.iterator().assertSorted { a, b -> compareValuesBy(a, b) { it.length } >= 0 } + } + + sequenceOf('a', 'd', 'c', null).let { + it.sortedBy { it }.iterator().assertSorted { a, b -> compareValues(a, b) <= 0 } + it.sortedByDescending { it }.iterator().assertSorted { a, b -> compareValues(a, b) >= 0 } + } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/sortedWith.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/sortedWith.kt new file mode 100644 index 00000000000..775fcee8378 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/sortedWith.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val comparator = compareBy { s: String -> s.reversed() } + assertEquals(listOf("act", "wast", "test"), sequenceOf("act", "test", "wast").sortedWith(comparator).toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/subSequence.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/subSequence.kt new file mode 100644 index 00000000000..c3ca9f2566c --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/subSequence.kt @@ -0,0 +1,23 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals(listOf(2, 3, 5, 8), fibonacci().drop(3).take(4).toList()) + assertEquals(listOf(2, 3, 5, 8), fibonacci().take(7).drop(3).toList()) + + val seq = fibonacci().drop(3).take(4) + + assertEquals(listOf(2, 3, 5, 8), seq.take(5).toList()) + assertEquals(listOf(2, 3, 5), seq.take(3).toList()) + + assertEquals(emptyList(), seq.drop(5).toList()) + assertEquals(listOf(8), seq.drop(3).toList()) + +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/take.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/take.kt new file mode 100644 index 00000000000..076fdce1314 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/take.kt @@ -0,0 +1,23 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals(emptyList(), emptySequence().take(1).toList()) + assertEquals(emptyList(), fibonacci().take(0).toList()) + + assertEquals("0, 1, 1, 2, 3, 5, 8", fibonacci().take(7).joinToString()) + assertEquals("0, 1, 1, 2", fibonacci().take(7).take(4).joinToString()) + assertEquals("0, 1, 1, 2", fibonacci().take(4).take(5).joinToString()) + + assertEquals(emptyList(), fibonacci().take(1).drop(1).toList()) + assertEquals(emptyList(), fibonacci().take(1).drop(2).toList()) + + assertFailsWith { fibonacci().take(-1) } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/takeExtractsTheFirstNElements.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/takeExtractsTheFirstNElements.kt new file mode 100644 index 00000000000..8d448587a5d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/takeExtractsTheFirstNElements.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals(listOf(0, 1, 1, 2, 3, 5, 8, 13, 21, 34), fibonacci().take(10).toList()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/toStringJoinsNoMoreThanTheFirstTenElements.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/toStringJoinsNoMoreThanTheFirstTenElements.kt new file mode 100644 index 00000000000..906f977f091 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/toStringJoinsNoMoreThanTheFirstTenElements.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + assertEquals("0, 1, 1, 2, 3, 5, 8, 13, 21, 34, ...", fibonacci().joinToString(limit = 10)) + assertEquals("13, 21, 34, 55, 89, 144, 233, 377, 610, 987, ...", fibonacci().filter { it > 10 }.joinToString(limit = 10)) + assertEquals("144, 233, 377, 610, 987", fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.joinToString()) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/unzip.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/unzip.kt new file mode 100644 index 00000000000..944539bc55b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/unzip.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val seq = sequenceOf(1 to 'a', 2 to 'b', 3 to 'c') + val (ints, chars) = seq.unzip() + assertEquals(listOf(1, 2, 3), ints) + assertEquals(listOf('a', 'b', 'c'), chars) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/withIndex.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/withIndex.kt new file mode 100644 index 00000000000..13ae651147f --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/withIndex.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + val data = sequenceOf("foo", "bar") + val indexed = data.withIndex().map { it.value.substring(0..it.index) }.toList() + assertEquals(listOf("f", "ba"), indexed) +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/zip.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/zip.kt new file mode 100644 index 00000000000..fe289eb8f34 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/zip.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun box() { + expect(listOf("ab", "bc", "cd")) { + sequenceOf("a", "b", "c").zip(sequenceOf("b", "c", "d")) { a, b -> a + b }.toList() + } +} diff --git a/backend.native/tests/external/stdlib/collections/SequenceTest/zipPairs.kt b/backend.native/tests/external/stdlib/collections/SequenceTest/zipPairs.kt new file mode 100644 index 00000000000..f957c360657 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SequenceTest/zipPairs.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +import kotlin.comparisons.* + +fun fibonacci(): Sequence { + // fibonacci terms + // 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181, 6765, 10946, ... + return generateSequence(Pair(0, 1), { Pair(it.second, it.first + it.second) }).map { it.first } +} + +fun box() { + val pairStr = (fibonacci() zip fibonacci().map { i -> i * 2 }).joinToString(limit = 10) + assertEquals("(0, 0), (1, 2), (1, 2), (2, 4), (3, 6), (5, 10), (8, 16), (13, 26), (21, 42), (34, 68), ...", pairStr) +} diff --git a/backend.native/tests/external/stdlib/collections/SetOperationsTest/META-INF/main.kotlin_module b/backend.native/tests/external/stdlib/collections/SetOperationsTest/META-INF/main.kotlin_module new file mode 100644 index 0000000000000000000000000000000000000000..0a3b07f6d4afb538ff045136dd3788d022a455df GIT binary patch literal 57 zcmZQzU|?ooU|@t|RxWNX1|jy)yv+PO?-DL4F7E97lAO#uy^_@85+UvoAQ@VcnN#dt F0sz{k3{U_7 literal 0 HcmV?d00001 diff --git a/backend.native/tests/external/stdlib/collections/SetOperationsTest/UnionKt.class b/backend.native/tests/external/stdlib/collections/SetOperationsTest/UnionKt.class new file mode 100644 index 0000000000000000000000000000000000000000..a68744f96d12ccc6e3382fa17b38069f66e51da6 GIT binary patch literal 1137 zcma)6%TC)s6g}g_Ntn_S0);|fX?ZjWlo0v?(hY(jMVL}GfP}Jg$PgJEyN$<`?)Z@Y zM0Zi8R$2F>s@`!7SPF|u_T0IzbI-jq_Mg8$e*;*-dxqqJW4X?bOoB0_Pt9|)Xq!%} zxYsxp$7GE$#2W4et-1Um!{|*!)sdnlI!Po6<=nJ=v3J5Sk*ns7fuQm*hQK*exWkY= zbER!L#bejDsRotzikmlk#pNzT!nQoA5a)9B2wsqep-odq(p6L$=5K|I zriLv&!ef>DgkdtAnG~KZ?$dHWoqK9jS%z`b^F&8hzWAo?%{Ik}>DyGsh?WWG7U4W- zsmYGzw93`Np#0%5o@0jN8D<%VMEkS+*6$^gyM^~WUMSuuvjCHhPPNJS*h)A zeB@WN;yb~Y#|yRW)oz().distinct().isEmpty()) +} diff --git a/backend.native/tests/external/stdlib/collections/SetOperationsTest/distinctBy.kt b/backend.native/tests/external/stdlib/collections/SetOperationsTest/distinctBy.kt new file mode 100644 index 00000000000..1915eefdaa0 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SetOperationsTest/distinctBy.kt @@ -0,0 +1,7 @@ +import kotlin.test.* + + +fun box() { + assertEquals(listOf("some", "cat", "do"), arrayOf("some", "case", "cat", "do", "dog", "it").distinctBy { it.length }) + assertTrue(charArrayOf().distinctBy { it }.isEmpty()) +} diff --git a/backend.native/tests/external/stdlib/collections/SetOperationsTest/intersect.kt b/backend.native/tests/external/stdlib/collections/SetOperationsTest/intersect.kt new file mode 100644 index 00000000000..f88c6ee2e1b --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SetOperationsTest/intersect.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + + +fun box() { + assertTrue(listOf(1, 3).intersect(listOf(5)).none()) + assertEquals(listOf(5), listOf(1, 3, 5).intersect(listOf(5)).toList()) + assertEquals(listOf(1, 3, 5), listOf(1, 3, 5).intersect(listOf(1, 3, 5)).toList()) + assertTrue(listOf().intersect(listOf(1)).none()) +} diff --git a/backend.native/tests/external/stdlib/collections/SetOperationsTest/kotlin/test/Assert$Companion.class b/backend.native/tests/external/stdlib/collections/SetOperationsTest/kotlin/test/Assert$Companion.class new file mode 100644 index 0000000000000000000000000000000000000000..9f2641bdc33f24f24e6e07024b5cca495df09d9d GIT binary patch literal 1770 zcma)6-EZ4e6#re@u^l&C)AWNjbln&kOF!Kd26QQfF6%^4TM*5PMjy~kVlpR=Q|z0< z6RLRNf7mN8NWAgF5J)510}uRBjB}kdNf%K~y1wV@p6_$~&%b{>1F(TzhWSQIc&={? zClvNh7&?K-6k5#_?z=7D0Aonj`6;(O?$_*3%XOzB45$nV9=+ZDrp>*OVKck;^0WM< zoI??~el5Rv#E{u*1vR_wh;qPPKeV~;w*(jDKeP|pp2y3clV@1yMOr^?+O990z~`P_ z^rfB9t%L?l29pO)6cWSjSBhxy%LFWpS%@RSaDBKKC922+?s`sj_q&R7BI7Y|l>sJ_ z4EmPqyJDMRde~1ts{~S*v@nh-hRH!?N{@rqw=y3CGYpz|>{9I(_J-ZQ+yly-afZ}r zHAzrrP@7@xqPQ2th0b+(2Cg$q4RxXfn&-c4w7HB3!(5{G9u+M{r6VL!jL!>yFsSJc)H6tm*+Idp1 zW{qLuTw&i4yvhZq`YX*-mG*_nD@J5FB0=?U5LL}FIGwY!rOYaplI)yWiYXELOpV}G zt8->P|52UooNXxU?4DsN&wtWM{>f@mO)Kl#P0j3_C1V?UQco)%OK3#UGL@v6)@Ipy zJW{ZvvkmfEqJEE#jDhzU;{DyF6_q>vP`F;W)}RJ!g;v#(lhUei?}!JkoWqj57{>Qp z-#KVE%TCbaTsaiH(%9!GJvx5q)_gA70lm&`mF|xAbvs)s<>?GbdP5K``R8q4xJ{?% zpSqz-PCw%TZ#uNbJA-v+unt@8pyE8BwW9=zzV8GDPYx{Y$z0FGQP;qb9&$7T8g&PB zPsr(liab%j5H0y{EU)~IE7}iFF!v|MAFV$68~V@Czer6y#dHU+{q-w7Qn5w%Qda@9 zm?Mf*k;d!PYl+PhrbO5^EYSN82-hQ79NUEFp}xQjGy{quZ#p-iny}~)`a(weKQbL3 zk^u!DVTa(D95tFa7(lW}o^KK^6S_mu=>(^yHRJmy^vmnu#=+9^%Ia^($Q+b@Oa}eZ zWK1epg4ncSJrg!TnNDo!DQKY(OaNYopy`La=+U8zGNEh#ZQ9ocpLPVY72~+#aE{Kj1f(jpcSa`6P`_ z4PpB~)s53U_pPrAj+B!_=_GSvG7DHd`H*MWUqTRQ%xKsoG#2wH6jc$5%3>ahlBh1` zJ3&i4q(>Ay&Hwyd5EbETTf}p)byo5}5k=Gp&E1ub(QFcH<5Xs35{&Y4F`e{P_Lm7?r_*epo@<|u4vkS+JCVFFw!QXhYMh>^uC|)n4~$8jbnLN3lb_Cc zzfki^_$K(yi{p5MQOqaXfc*Vql)fy}H#tTpB+3XG-QwRj07aB=?zFiIzXh)Tj`}+~ z#WCEK$TBb6r8t+;E4+O1zKoD$?3ILnqWc#Y7lIw7TB1D5nqL zBLasrr}@t}QJE)!xS*SPk{SX+c{z5q z2A<0k3Mub7ZEStw2;O5fdl{-*Z8&|kGvg0U)swb*VAOgIw#HMj!R?!z2wYbdc#JCF r4d%RKAJ_~{f3be`suNV_GkkpiF0D0lX>2^}4-R_#5Y2#ymi@!h< zjm8Jl_~?%^-YHwY6O-<}Id{&SJ==5t{Qdb0zz#MUmRf=Kr0-~>>#W0zs25`+z>DReF5(pL`m z{Xlc0tek3~s~yiHRAvgSn1EG1HYfhf6b~i@RFjL5$RU1Gsuoj{EHpAd8ehPHd~ruK4O*qu2iz-i5HiFQ+lt0x-gp(xZFG8q2$Ck zHicoLB7ITqv}+=aCaX8KE;6_#Y99ri&=vc%x8ydub8_qL*rpANn?IL=poOBoM#%IO zbqhJ9VYY0YkV8{OJyHCM(a(e94XT;*A@wmrMS9G2qFs|>CgezHkGe&STq&RZf$3uD zJ7$ZeZy5bTLkmW9`kWAn5;bx+lur^a5s&g3T75FO{1{KES7M_5Z!_5`ZrJOG5o*UeBtzl&)xcYLtilx|-GY=mAI)qQ~VKIhB=j6REvp$CWfk zy%Hj_rYQxz@2;Yp)g)ZkGFUmS=aM5MdO^)i^lUmHp?NT0m`EL0^s$1h=CqWY%jI=h zSM$6cE@rdxSXSwg5OW*3)6gD3P{NWM@>A1tj?*Qq9-Kd^x%9jzf)K(>umlkaO_!P( zz_JKx;16Lrq7o#T>gU7ZgE0x-DQ%+sv4u@SotvcQj5014v$}-AcSzR2d=mtJE(e*K z185AvBMc9j28O9gsf7qQM+5h2r7CgGYYva7+YR2RWkTrE&{ zlUK#?orJA!VP-b>*eP>-W-2va%%#o5+ihKS7%5samd&RpgP?m?Tfrixt2tdM zAScpUQ`1@iJ6KQB$CUKsKDi)IDV#B&4V&mBY^-L06ArF$>BS8p?8L5eja3W`U^fw} zxtaVVU0T<&$;E^PF@k;!gmEKoil811f|WrDL6a3FBO$RE2@-C6OO`JtN91cM23cbb z|GF5hg0II7sFW`ZlmWLz7ITa0cah`Bir{992v$ZV^leU*vO>-!6uSu62`>^h*OnM7 z>WRB$Es8gs66dwmtaUtZdCHB|f)v56I3z-W zH9?|>S5$={VY!{Fr1hYxALH!NAda%`6%=(`RWf_0m4eY$hUCJeQV<2vok*_OlQAX~ zrWwhOh350#qMFSpg#c)Yw`J1-QP(Cy7zg#;v=DXq@q~VIT1li*qkDJl?M}#W6h zLyHtSTOc!}tR7p$E@qo3A+=6e_U7|hMP`pa#nv%q-W(7e+KA7?5xgG{gm6DTAff*< zF~Oj3!hND%JXlIQR(KnJP%fBMEL!euCTQh{@ez@7A7$THvsq;f#GmPFe=jo=}% zHS^#TrG4l~zQ7t((JcqqdyLKFr77()THKQ6f|6F$8Kn@!quf=h+CXk^fvFzEW88u` zgxgXB_$;$T6*~01QBACrEOPUlGG=j{+4wj<7seSp;aFEbV{z*ucm!V%fS+UzxXPbx z3Y)hgiXjh&GM$oVdhXP&(A=qzC+Z1#fA0` z9$hZ%qd`%gYu#&Te5~B|D=gbNl^9&&E!*SKx&?(LtY@xOE)2EA*c4r1tPVz38W`)l zf;38SQ{NwmZ;UpS8?(|dqC``_rz32b(HQTnKD7#WrA6_0EV_#Fo7|}49nmXYI+KPw zxMX!#Lv&5NPB^FE;~YC`I}!^mS-bEO5qDh@1CuYQ)?U)tzE>F(#ULWy_4kX{{LPbm zCH38q&#+^}2J>k-dq6IzqHd0g11tQXnp1|0Q)5cO8d)-;PUK|0Sm4vnZKK`uGkSZ= z=x7iBTu-d_X1wv=Qq1YZ+l?+TdI=#;3wUdt+9h^(%VH+j&-e2sTG-+u&b`~X_3gLtZEsQZ(Q@dH z*6o);Ckf{M_?-xHShsdMmZzr6&9$0KnXPtvv>ajcP(2E|wzbnp@pDoCc2t&ikjteq zG?FhC(#mdrk727aZ+0nT#fiQXy22N3@zJZ%N{a(#F1eBdo!m3{*qVS9XcQl`;KeU^ z*UwSWvO>>cX|lELJZhiiod>_Fz)H^g6|eoq$Wr{8*B<-^ zZ}1!zB1IVr0MP;Qrp;@i?kb9`;W>6?;NCO*W;ciU5Y^6Nm8sSi=*Lq0mh-%j!nBv4 zZ75p^c!>6Tcy5aOoPJ)4j>M15Hov z%RmBGj5QfzTj03}PO)5sAPC5CQN<8`M~Najui;t13UGgBMdY=(&Z1f*hKSbaDxdAD zJ;_=0oa2}i;C_aV2oNJ4-EteT4cA-v1{q6&@w(R7yJyjtY`uUzR2h(FF=SFCvdWCf zIt*J`Rfp}^OT$Fy3y=A+mQU7M`Sg2tmoTd_C#2S-Sn4}(L!Vk5bOU4e);t0JZy-Z8|SY`k) zqbR{;F)qFhxARB=Ry>I-hw(U9`LUT{k>c78uIOYf=;H4x!{N-8n*-SBv5fxHJfoKi z4p`t z;4sr*Wf|al7vP~1;2{fexD0R?A^Hg=%$L9jCMf9`3!#c;9OrKm8(5AuAkQ_^{1y1q z4A7h43*SVz7m3=(!VbnO&$+e7-StN>OI8*a|&Zq4TW7??k?5 zz1LI!*BL!Lap(->Cf}XbShugWz0r38-|@l>2D^wn%OcWr9^Z?d7Z<*axSX{Li#cYG zH2UmXv$@eXeD>lK0;5@4w$Q9CY)Q}1Nj?_KW4OR8FWJuH1*4$QXfp63SBNWzfh64+ z!C^Y`2xs5MwYSs3cW?u7loId6Dad$$W2cce{IC?>m2Ywv7=Z7;OjDD%zf~j7i@#Hs z2e0EFJWq}c?c5h~zqf|=82`5pB}WqW)$UMhqBBu8$$BLgWA1-$hmwP#&h?#bogJOs zouRE)i_5LuogH1FWM2sXq{7GPzaNm6A0B~s052JTFJsQWdxZmdbpSuYkB>mo@Dsdt z1nV@^X!xmyqZ(ow>NKn{Zv7f=HZHbn_?d>JhC4KjXh>;jF~%R#@UVs^4fkjmHb%B- VxL(6P4O@-dM~vfR8h*};{{sp7l^Os5 literal 0 HcmV?d00001 diff --git a/backend.native/tests/external/stdlib/collections/SetOperationsTest/plusAssign.kt b/backend.native/tests/external/stdlib/collections/SetOperationsTest/plusAssign.kt new file mode 100644 index 00000000000..3000005ec4d --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SetOperationsTest/plusAssign.kt @@ -0,0 +1,21 @@ +import kotlin.test.* + + +fun box() { + // lets use a mutable variable + var set = setOf("a") + val setOriginal = set + set += "foo" + set += listOf("beer", "a") + set += arrayOf("cheese", "beer") + set += sequenceOf("bar", "foo") + assertEquals(setOf("a", "foo", "beer", "cheese", "bar"), set) + assertTrue(set !== setOriginal) + + val mset = mutableSetOf("a") + mset += "foo" + mset += listOf("beer", "a") + mset += arrayOf("cheese", "beer") + mset += sequenceOf("bar", "foo") + assertEquals(set, mset) +} diff --git a/backend.native/tests/external/stdlib/collections/SetOperationsTest/subtract.kt b/backend.native/tests/external/stdlib/collections/SetOperationsTest/subtract.kt new file mode 100644 index 00000000000..1dc7312d101 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SetOperationsTest/subtract.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + + +fun box() { + assertEquals(listOf(1, 3), listOf(1, 3).subtract(listOf(5)).toList()) + assertEquals(listOf(1, 3), listOf(1, 3, 5).subtract(listOf(5)).toList()) + assertTrue(listOf(1, 3, 5).subtract(listOf(1, 3, 5)).none()) + assertTrue(listOf().subtract(listOf(1)).none()) +} diff --git a/backend.native/tests/external/stdlib/collections/SetOperationsTest/union.kt b/backend.native/tests/external/stdlib/collections/SetOperationsTest/union.kt new file mode 100644 index 00000000000..4da8f95b830 --- /dev/null +++ b/backend.native/tests/external/stdlib/collections/SetOperationsTest/union.kt @@ -0,0 +1,7 @@ +import kotlin.test.* + + +fun box() { + assertEquals(listOf(1, 3, 5), listOf(1, 3).union(listOf(5)).toList()) + assertEquals(listOf(1), listOf().union(listOf(1)).toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testEquals.kt b/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testEquals.kt new file mode 100644 index 00000000000..4b8bf4489e7 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testEquals.kt @@ -0,0 +1,28 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.* + +data class CtxA(val i: Int) : AbstractCoroutineContextElement(CtxA) { + companion object Key : CoroutineContext.Key +} + +data class CtxB(val i: Int) : AbstractCoroutineContextElement(CtxB) { + companion object Key : CoroutineContext.Key +} + +data class CtxC(val i: Int) : AbstractCoroutineContextElement(CtxC) { + companion object Key : CoroutineContext.Key +} + +fun box() { + val ctx1 = CtxA(1) + CtxB(2) + CtxC(3) + val ctx2 = CtxB(2) + CtxC(3) + CtxA(1) // same + val ctx3 = CtxC(3) + CtxA(1) + CtxB(2) // same + val ctx4 = CtxA(1) + CtxB(2) + CtxC(4) // different + assertEquals(ctx1, ctx2) + assertEquals(ctx1, ctx3) + assertEquals(ctx2, ctx3) + assertNotEquals(ctx1, ctx4) + assertNotEquals(ctx2, ctx4) + assertNotEquals(ctx3, ctx4) +} diff --git a/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testGetPlusFold.kt b/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testGetPlusFold.kt new file mode 100644 index 00000000000..5bbfd4e101f --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testGetPlusFold.kt @@ -0,0 +1,63 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.* + +data class CtxA(val i: Int) : AbstractCoroutineContextElement(CtxA) { + companion object Key : CoroutineContext.Key +} + +data class CtxB(val i: Int) : AbstractCoroutineContextElement(CtxB) { + companion object Key : CoroutineContext.Key +} + +data class CtxC(val i: Int) : AbstractCoroutineContextElement(CtxC) { + companion object Key : CoroutineContext.Key +} + +private fun assertContents(ctx: CoroutineContext, vararg elements: CoroutineContext.Element) { + val set = ctx.fold(setOf()) { a, b -> a + b } + assertEquals(listOf(*elements), set.toList()) + for (elem in elements) + assertTrue(ctx[elem.key] == elem) +} + +fun box() { + var ctx: CoroutineContext = EmptyCoroutineContext + assertContents(ctx) + assertEquals("EmptyCoroutineContext", ctx.toString()) + + ctx += CtxA(1) + assertContents(ctx, CtxA(1)) + assertEquals("CtxA(i=1)", ctx.toString()) + assertEquals(CtxA(1), ctx[CtxA]) + assertEquals(null, ctx[CtxB]) + assertEquals(null, ctx[CtxC]) + + ctx += CtxB(2) + assertContents(ctx, CtxA(1), CtxB(2)) + assertEquals("[CtxA(i=1), CtxB(i=2)]", ctx.toString()) + assertEquals(CtxA(1), ctx[CtxA]) + assertEquals(CtxB(2), ctx[CtxB]) + assertEquals(null, ctx[CtxC]) + + ctx += CtxC(3) + assertContents(ctx, CtxA(1), CtxB(2), CtxC(3)) + assertEquals("[CtxA(i=1), CtxB(i=2), CtxC(i=3)]", ctx.toString()) + assertEquals(CtxA(1), ctx[CtxA]) + assertEquals(CtxB(2), ctx[CtxB]) + assertEquals(CtxC(3), ctx[CtxC]) + + ctx += CtxB(4) + assertContents(ctx, CtxA(1), CtxC(3), CtxB(4)) + assertEquals("[CtxA(i=1), CtxC(i=3), CtxB(i=4)]", ctx.toString()) + assertEquals(CtxA(1), ctx[CtxA]) + assertEquals(CtxB(4), ctx[CtxB]) + assertEquals(CtxC(3), ctx[CtxC]) + + ctx += CtxA(5) + assertContents(ctx, CtxC(3), CtxB(4), CtxA(5)) + assertEquals("[CtxC(i=3), CtxB(i=4), CtxA(i=5)]", ctx.toString()) + assertEquals(CtxA(5), ctx[CtxA]) + assertEquals(CtxB(4), ctx[CtxB]) + assertEquals(CtxC(3), ctx[CtxC]) +} diff --git a/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testLastDispatcher.kt b/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testLastDispatcher.kt new file mode 100644 index 00000000000..5be6f1a5d56 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testLastDispatcher.kt @@ -0,0 +1,49 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.* + +data class CtxA(val i: Int) : AbstractCoroutineContextElement(CtxA) { + companion object Key : CoroutineContext.Key +} + +data class CtxB(val i: Int) : AbstractCoroutineContextElement(CtxB) { + companion object Key : CoroutineContext.Key +} + +data class CtxC(val i: Int) : AbstractCoroutineContextElement(CtxC) { + companion object Key : CoroutineContext.Key +} + +object Disp1 : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor { + override fun interceptContinuation(continuation: Continuation): Continuation = continuation + override fun toString(): String = "Disp1" +} + +object Disp2 : AbstractCoroutineContextElement(ContinuationInterceptor), ContinuationInterceptor { + override fun interceptContinuation(continuation: Continuation): Continuation = continuation + override fun toString(): String = "Disp2" +} + +private fun assertContents(ctx: CoroutineContext, vararg elements: CoroutineContext.Element) { + val set = ctx.fold(setOf()) { a, b -> a + b } + assertEquals(listOf(*elements), set.toList()) + for (elem in elements) + assertTrue(ctx[elem.key] == elem) +} + +fun box() { + var ctx: CoroutineContext = EmptyCoroutineContext + assertContents(ctx) + ctx += CtxA(1) + assertContents(ctx, CtxA(1)) + ctx += Disp1 + assertContents(ctx, CtxA(1), Disp1) + ctx += CtxA(2) + assertContents(ctx, CtxA(2), Disp1) + ctx += CtxB(3) + assertContents(ctx, CtxA(2), CtxB(3), Disp1) + ctx += Disp2 + assertContents(ctx, CtxA(2), CtxB(3), Disp2) + ctx += (CtxB(4) + CtxC(5)) + assertContents(ctx, CtxA(2), CtxB(4), CtxC(5), Disp2) +} diff --git a/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testMinusKey.kt b/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testMinusKey.kt new file mode 100644 index 00000000000..bfb77512d83 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testMinusKey.kt @@ -0,0 +1,58 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.* + +data class CtxA(val i: Int) : AbstractCoroutineContextElement(CtxA) { + companion object Key : CoroutineContext.Key +} + +data class CtxB(val i: Int) : AbstractCoroutineContextElement(CtxB) { + companion object Key : CoroutineContext.Key +} + +data class CtxC(val i: Int) : AbstractCoroutineContextElement(CtxC) { + companion object Key : CoroutineContext.Key +} + +private fun assertContents(ctx: CoroutineContext, vararg elements: CoroutineContext.Element) { + val set = ctx.fold(setOf()) { a, b -> a + b } + assertEquals(listOf(*elements), set.toList()) + for (elem in elements) + assertTrue(ctx[elem.key] == elem) +} + +fun box() { + var ctx: CoroutineContext = CtxA(1) + CtxB(2) + CtxC(3) + assertContents(ctx, CtxA(1), CtxB(2), CtxC(3)) + assertEquals("[CtxA(i=1), CtxB(i=2), CtxC(i=3)]", ctx.toString()) + + ctx = ctx.minusKey(CtxA) + assertContents(ctx, CtxB(2), CtxC(3)) + assertEquals("[CtxB(i=2), CtxC(i=3)]", ctx.toString()) + assertEquals(null, ctx[CtxA]) + assertEquals(CtxB(2), ctx[CtxB]) + assertEquals(CtxC(3), ctx[CtxC]) + + ctx = ctx.minusKey(CtxC) + assertContents(ctx, CtxB(2)) + assertEquals("CtxB(i=2)", ctx.toString()) + assertEquals(null, ctx[CtxA]) + assertEquals(CtxB(2), ctx[CtxB]) + assertEquals(null, ctx[CtxC]) + + ctx = ctx.minusKey(CtxC) + assertContents(ctx, CtxB(2)) + assertEquals("CtxB(i=2)", ctx.toString()) + assertEquals(null, ctx[CtxA]) + assertEquals(CtxB(2), ctx[CtxB]) + assertEquals(null, ctx[CtxC]) + + ctx = ctx.minusKey(CtxB) + assertContents(ctx) + assertEquals("EmptyCoroutineContext", ctx.toString()) + assertEquals(null, ctx[CtxA]) + assertEquals(null, ctx[CtxB]) + assertEquals(null, ctx[CtxC]) + + assertEquals(EmptyCoroutineContext, ctx) +} diff --git a/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testPlusCombined.kt b/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testPlusCombined.kt new file mode 100644 index 00000000000..3fa8b1b7438 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testPlusCombined.kt @@ -0,0 +1,33 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.* + +data class CtxA(val i: Int) : AbstractCoroutineContextElement(CtxA) { + companion object Key : CoroutineContext.Key +} + +data class CtxB(val i: Int) : AbstractCoroutineContextElement(CtxB) { + companion object Key : CoroutineContext.Key +} + +data class CtxC(val i: Int) : AbstractCoroutineContextElement(CtxC) { + companion object Key : CoroutineContext.Key +} + +private fun assertContents(ctx: CoroutineContext, vararg elements: CoroutineContext.Element) { + val set = ctx.fold(setOf()) { a, b -> a + b } + assertEquals(listOf(*elements), set.toList()) + for (elem in elements) + assertTrue(ctx[elem.key] == elem) +} + +fun box() { + val ctx1 = CtxA(1) + CtxB(2) + val ctx2 = CtxB(3) + CtxC(4) + val ctx = ctx1 + ctx2 + assertContents(ctx, CtxA(1), CtxB(3), CtxC(4)) + assertEquals("[CtxA(i=1), CtxB(i=3), CtxC(i=4)]", ctx.toString()) + assertEquals(CtxA(1), ctx[CtxA]) + assertEquals(CtxB(3), ctx[CtxB]) + assertEquals(CtxC(4), ctx[CtxC]) +} diff --git a/backend.native/tests/external/stdlib/coroutines/CoroutinesReferenceValuesTest/testBadClass.kt b/backend.native/tests/external/stdlib/coroutines/CoroutinesReferenceValuesTest/testBadClass.kt new file mode 100644 index 00000000000..0698bd40b65 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/CoroutinesReferenceValuesTest/testBadClass.kt @@ -0,0 +1,47 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.* + +class BadClass { + override fun equals(other: Any?): Boolean = error("equals") + override fun hashCode(): Int = error("hashCode") + override fun toString(): String = error("toString") +} + +var counter = 0 + +// tail-suspend function via suspendCoroutine (test SafeContinuation) +suspend fun getBadClassViaSuspend(): BadClass = suspendCoroutine { cont -> + counter++ + cont.resume(BadClass()) +} + +// state machine +suspend fun checkBadClassTwice() { + assertTrue(getBadClassViaSuspend() is BadClass) + assertTrue(getBadClassViaSuspend() is BadClass) +} + +fun suspend(block: suspend () -> T) = block + +fun box() { + val bad = suspend { + checkBadClassTwice() + getBadClassViaSuspend() + } + var result: BadClass? = null + bad.startCoroutine(object : Continuation { + override val context: CoroutineContext = EmptyCoroutineContext + + override fun resume(value: BadClass) { + assertTrue(result == null) + result = value + } + + override fun resumeWithException(exception: Throwable) { + throw exception + } + }) + assertTrue(result is BadClass) + assertEquals(3, counter) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testCallHasNextSeveralTimes.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testCallHasNextSeveralTimes.kt new file mode 100644 index 00000000000..081e6dcef6b --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testCallHasNextSeveralTimes.kt @@ -0,0 +1,24 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yield(1) + } + + val iterator = result.iterator() + + assertTrue(iterator.hasNext()) + assertTrue(iterator.hasNext()) + assertTrue(iterator.hasNext()) + + assertEquals(1, iterator.next()) + + assertFalse(iterator.hasNext()) + assertFalse(iterator.hasNext()) + assertFalse(iterator.hasNext()) + + assertFailsWith { iterator.next() } +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testEmptySequence.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testEmptySequence.kt new file mode 100644 index 00000000000..a45ecea9ee0 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testEmptySequence.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence {} + val iterator = result.iterator() + + assertFalse(iterator.hasNext()) + assertFalse(iterator.hasNext()) + + assertFailsWith { iterator.next() } +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testExceptionInCoroutine.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testExceptionInCoroutine.kt new file mode 100644 index 00000000000..3c14bcced71 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testExceptionInCoroutine.kt @@ -0,0 +1,27 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + var sharedVar = -2 + val result = buildSequence { + while (true) { + when (sharedVar) { + -1 -> return@buildSequence + -2 -> throw UnsupportedOperationException("-2 is unsupported") + else -> yield(sharedVar) + } + } + } + + val iterator = result.iterator() + + sharedVar = 1 + assertEquals(1, iterator.next()) + + sharedVar = -2 + assertFailsWith { iterator.hasNext() } + assertFailsWith { iterator.hasNext() } + assertFailsWith { iterator.next() } +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testInfiniteYieldAll.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testInfiniteYieldAll.kt new file mode 100644 index 00000000000..acb58d4d562 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testInfiniteYieldAll.kt @@ -0,0 +1,18 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val values = buildIterator { + while (true) { + yieldAll((1..5).map { it }) + } + } + + var sum = 0 + repeat(10) { + sum += values.next() //.also(::println) + } + assertEquals(30, sum) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testLaziness.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testLaziness.kt new file mode 100644 index 00000000000..cb2b2fe45d5 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testLaziness.kt @@ -0,0 +1,35 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + var sharedVar = -2 + val result = buildSequence { + while (true) { + when (sharedVar) { + -1 -> return@buildSequence + -2 -> error("Invalid state: -2") + else -> yield(sharedVar) + } + } + } + + val iterator = result.iterator() + + sharedVar = 1 + assertTrue(iterator.hasNext()) + assertEquals(1, iterator.next()) + + sharedVar = 2 + assertTrue(iterator.hasNext()) + assertEquals(2, iterator.next()) + + sharedVar = 3 + assertTrue(iterator.hasNext()) + assertEquals(3, iterator.next()) + + sharedVar = -1 + assertFalse(iterator.hasNext()) + assertFailsWith { iterator.next() } +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testManualIteration.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testManualIteration.kt new file mode 100644 index 00000000000..91ae9984ef4 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testManualIteration.kt @@ -0,0 +1,31 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yield(1) + yield(2) + yield(3) + } + + val iterator = result.iterator() + + assertTrue(iterator.hasNext()) + assertTrue(iterator.hasNext()) + assertEquals(1, iterator.next()) + + assertTrue(iterator.hasNext()) + assertTrue(iterator.hasNext()) + assertEquals(2, iterator.next()) + + assertEquals(3, iterator.next()) + + assertFalse(iterator.hasNext()) + assertFalse(iterator.hasNext()) + + assertFailsWith { iterator.next() } + + assertEquals(1, result.iterator().next()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testParallelIteration.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testParallelIteration.kt new file mode 100644 index 00000000000..2712c971c93 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testParallelIteration.kt @@ -0,0 +1,16 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + var inc = 0 + val result = buildSequence { + for (i in 1..3) { + inc++ + yield(inc * i) + } + } + + assertEquals(listOf(Pair(1, 2), Pair(6, 8), Pair(15, 18)), result.zip(result).toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testSimple.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testSimple.kt new file mode 100644 index 00000000000..6961604fb92 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testSimple.kt @@ -0,0 +1,16 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + for (i in 1..3) { + yield(2 * i) + } + } + + assertEquals(listOf(2, 4, 6), result.toList()) + // Repeated calls also work + assertEquals(listOf(2, 4, 6), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollection.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollection.kt new file mode 100644 index 00000000000..fc8d7c62977 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollection.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yieldAll(listOf(1, 2, 3)) + } + assertEquals(listOf(1, 2, 3), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionManyEmpty.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionManyEmpty.kt new file mode 100644 index 00000000000..d3541b68331 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionManyEmpty.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yieldAll(listOf()) + yieldAll(listOf()) + yieldAll(listOf()) + } + assertEquals(listOf(), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedBoth.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedBoth.kt new file mode 100644 index 00000000000..7bb3587ba3b --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedBoth.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yield(0) + yieldAll(listOf(1, 2, 3)) + yield(4) + } + assertEquals(listOf(0, 1, 2, 3, 4), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedFirst.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedFirst.kt new file mode 100644 index 00000000000..ea8da0b5eb4 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedFirst.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yield(0) + yieldAll(listOf(1, 2, 3)) + } + assertEquals(listOf(0, 1, 2, 3), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLast.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLast.kt new file mode 100644 index 00000000000..a6137ee93b8 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLast.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yieldAll(listOf(1, 2, 3)) + yield(4) + } + assertEquals(listOf(1, 2, 3, 4), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLong.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLong.kt new file mode 100644 index 00000000000..73535e6e966 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLong.kt @@ -0,0 +1,18 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yield(0) + yieldAll(listOf(1, 2, 3)) + yield(4) + yield(5) + yieldAll(listOf(6)) + yield(7) + yieldAll(listOf()) + yield(8) + } + assertEquals(listOf(0, 1, 2, 3, 4, 5, 6, 7, 8), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionOneEmpty.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionOneEmpty.kt new file mode 100644 index 00000000000..72e87e97b93 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionOneEmpty.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yieldAll(listOf()) + } + assertEquals(listOf(), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllIterator.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllIterator.kt new file mode 100644 index 00000000000..57468ad7189 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllIterator.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yieldAll(listOf(1, 2, 3).iterator()) + } + assertEquals(listOf(1, 2, 3), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSequence.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSequence.kt new file mode 100644 index 00000000000..72ed0092537 --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSequence.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val result = buildSequence { + yieldAll(sequenceOf(1, 2, 3)) + } + assertEquals(listOf(1, 2, 3), result.toList()) +} diff --git a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSideEffects.kt b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSideEffects.kt new file mode 100644 index 00000000000..7e05e113cdf --- /dev/null +++ b/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSideEffects.kt @@ -0,0 +1,42 @@ +import kotlin.test.* + +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +fun box() { + val effects = arrayListOf() + val result = buildSequence { + effects.add("a") + yieldAll(listOf(1, 2)) + effects.add("b") + yieldAll(listOf()) + effects.add("c") + yieldAll(listOf(3)) + effects.add("d") + yield(4) + effects.add("e") + yieldAll(listOf()) + effects.add("f") + yield(5) + } + + for (res in result) { + effects.add("(") // marks step start + effects.add(res) + effects.add(")") // marks step end + } + assertEquals( + listOf( + "a", + "(", 1, ")", + "(", 2, ")", + "b", "c", + "(", 3, ")", + "d", + "(", 4, ")", + "e", "f", + "(", 5, ")" + ), + effects.toList() + ) +} diff --git a/backend.native/tests/external/stdlib/language/EscapedTestNamesTest/numbersEqual.kt b/backend.native/tests/external/stdlib/language/EscapedTestNamesTest/numbersEqual.kt new file mode 100644 index 00000000000..1fab750288f --- /dev/null +++ b/backend.native/tests/external/stdlib/language/EscapedTestNamesTest/numbersEqual.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun `numbers equal`() { + val actual = 5 + assertEquals(5, actual) +} + +fun box() { + `numbers equal`() +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/language/EscapedTestNamesTest/stringsEqual.kt b/backend.native/tests/external/stdlib/language/EscapedTestNamesTest/stringsEqual.kt new file mode 100644 index 00000000000..47c7ae5e3f6 --- /dev/null +++ b/backend.native/tests/external/stdlib/language/EscapedTestNamesTest/stringsEqual.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + +fun `strings equal`() { + val actual = "abc" + assertEquals("abc", actual) +} + +fun box() { + `strings equal`() +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/andForInt.kt b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/andForInt.kt new file mode 100644 index 00000000000..c773cb4278d --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/andForInt.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + + +fun box() { + assertEquals(0, 1 and 0) +} diff --git a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/invForInt.kt b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/invForInt.kt new file mode 100644 index 00000000000..bb8bb343f77 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/invForInt.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + + +fun box() { + assertEquals(0, (-1).inv()) +} diff --git a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/orForInt.kt b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/orForInt.kt new file mode 100644 index 00000000000..c214ec2f947 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/orForInt.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + + +fun box() { + assertEquals(3, 2 or 1) +} diff --git a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shlForInt.kt b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shlForInt.kt new file mode 100644 index 00000000000..f8ab44787a7 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shlForInt.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + + +fun box() { + assertEquals(4, 1 shl 2) +} diff --git a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shrForInt.kt b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shrForInt.kt new file mode 100644 index 00000000000..c96d856a6d7 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shrForInt.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + + +fun box() { + assertEquals(1, 2 shr 1) +} diff --git a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/ushrForInt.kt b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/ushrForInt.kt new file mode 100644 index 00000000000..0772d5bea8b --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/ushrForInt.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + + +fun box() { + assertEquals(2147483647, -1 ushr 1) +} diff --git a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/xorForInt.kt b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/xorForInt.kt new file mode 100644 index 00000000000..f5719ca07d9 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/xorForInt.kt @@ -0,0 +1,6 @@ +import kotlin.test.* + + +fun box() { + assertEquals(1, 2 xor 3) +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMax.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMax.kt new file mode 100644 index 00000000000..42fa813912d --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMax.kt @@ -0,0 +1,29 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +val Double.Companion.values get() = listOf(0.0, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +val Float.Companion.values get() = listOf(0.0f, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +private fun propagateOf2(f2d: (Double, Double) -> Double, + f2f: (Float, Float) -> Float, + function: String) { + with(Double) { + for (d in values) { + assertTrue(f2d(d, NaN).isNaN(), "$function($d, NaN)") + assertTrue(f2d(NaN, d).isNaN(), "$function(NaN, $d)") + } + } + with(Float) { + for (f in values) { + assertTrue(f2f(f, NaN).isNaN(), "$function($f, NaN)") + assertTrue(f2f(NaN, f).isNaN(), "$function(NaN, $f)") + } + } +} + +fun box() { + propagateOf2({ a, b -> arrayOf(a, b).max()!! }, + { a, b -> arrayOf(a, b).max()!! }, + "arrayOf().max()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMin.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMin.kt new file mode 100644 index 00000000000..39b89b32cf9 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMin.kt @@ -0,0 +1,29 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +val Double.Companion.values get() = listOf(0.0, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +val Float.Companion.values get() = listOf(0.0f, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +private fun propagateOf2(f2d: (Double, Double) -> Double, + f2f: (Float, Float) -> Float, + function: String) { + with(Double) { + for (d in values) { + assertTrue(f2d(d, NaN).isNaN(), "$function($d, NaN)") + assertTrue(f2d(NaN, d).isNaN(), "$function(NaN, $d)") + } + } + with(Float) { + for (f in values) { + assertTrue(f2f(f, NaN).isNaN(), "$function($f, NaN)") + assertTrue(f2f(NaN, f).isNaN(), "$function(NaN, $f)") + } + } +} + +fun box() { + propagateOf2({ a, b -> arrayOf(a, b).min()!! }, + { a, b -> arrayOf(a, b).min()!! }, + "arrayOf().min()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMax.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMax.kt new file mode 100644 index 00000000000..a89d71a9ce4 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMax.kt @@ -0,0 +1,16 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +private fun > totalOrderMaxOf2(f2t: (T, T) -> T, function: String) { + @Suppress("UNCHECKED_CAST") + with(Double) { + assertTrue((f2t(0.0 as T, NaN as T) as Double).isNaN(), "$function(0, NaN)") + assertTrue((f2t(NaN as T, 0.0 as T) as Double).isNaN(), "$function(NaN, 0)") + } +} + +fun box() { + totalOrderMaxOf2>({ a, b -> arrayOf(a, b).max()!! }, "arrayOf().max()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMin.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMin.kt new file mode 100644 index 00000000000..54824231fc1 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMin.kt @@ -0,0 +1,16 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +private fun > totalOrderMinOf2(f2t: (T, T) -> T, function: String) { + @Suppress("UNCHECKED_CAST") + with(Double) { + assertEquals(0.0, f2t(0.0 as T, NaN as T), "$function(0, NaN)") + assertEquals(0.0, f2t(NaN as T, 0.0 as T), "$function(NaN, 0)") + } +} + +fun box() { + totalOrderMinOf2>({ a, b -> arrayOf(a, b).min()!! }, "arrayOf().min()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMax.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMax.kt new file mode 100644 index 00000000000..5776efd7060 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMax.kt @@ -0,0 +1,29 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +val Double.Companion.values get() = listOf(0.0, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +val Float.Companion.values get() = listOf(0.0f, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +private fun propagateOf2(f2d: (Double, Double) -> Double, + f2f: (Float, Float) -> Float, + function: String) { + with(Double) { + for (d in values) { + assertTrue(f2d(d, NaN).isNaN(), "$function($d, NaN)") + assertTrue(f2d(NaN, d).isNaN(), "$function(NaN, $d)") + } + } + with(Float) { + for (f in values) { + assertTrue(f2f(f, NaN).isNaN(), "$function($f, NaN)") + assertTrue(f2f(NaN, f).isNaN(), "$function(NaN, $f)") + } + } +} + +fun box() { + propagateOf2({ a, b -> listOf(a, b).max()!! }, + { a, b -> listOf(a, b).max()!! }, + "listOf().max()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMin.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMin.kt new file mode 100644 index 00000000000..994e8aa1923 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMin.kt @@ -0,0 +1,29 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +val Double.Companion.values get() = listOf(0.0, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +val Float.Companion.values get() = listOf(0.0f, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +private fun propagateOf2(f2d: (Double, Double) -> Double, + f2f: (Float, Float) -> Float, + function: String) { + with(Double) { + for (d in values) { + assertTrue(f2d(d, NaN).isNaN(), "$function($d, NaN)") + assertTrue(f2d(NaN, d).isNaN(), "$function(NaN, $d)") + } + } + with(Float) { + for (f in values) { + assertTrue(f2f(f, NaN).isNaN(), "$function($f, NaN)") + assertTrue(f2f(NaN, f).isNaN(), "$function(NaN, $f)") + } + } +} + +fun box() { + propagateOf2({ a, b -> listOf(a, b).min()!! }, + { a, b -> listOf(a, b).min()!! }, + "listOf().min()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMax.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMax.kt new file mode 100644 index 00000000000..59449bbd2d4 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMax.kt @@ -0,0 +1,16 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +private fun > totalOrderMaxOf2(f2t: (T, T) -> T, function: String) { + @Suppress("UNCHECKED_CAST") + with(Double) { + assertTrue((f2t(0.0 as T, NaN as T) as Double).isNaN(), "$function(0, NaN)") + assertTrue((f2t(NaN as T, 0.0 as T) as Double).isNaN(), "$function(NaN, 0)") + } +} + +fun box() { + totalOrderMaxOf2>({ a, b -> listOf(a, b).max()!! }, "listOf().max()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMin.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMin.kt new file mode 100644 index 00000000000..03f34ad9a2a --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMin.kt @@ -0,0 +1,16 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +private fun > totalOrderMinOf2(f2t: (T, T) -> T, function: String) { + @Suppress("UNCHECKED_CAST") + with(Double) { + assertEquals(0.0, f2t(0.0 as T, NaN as T), "$function(0, NaN)") + assertEquals(0.0, f2t(NaN as T, 0.0 as T), "$function(NaN, 0)") + } +} + +fun box() { + totalOrderMinOf2>({ a, b -> listOf(a, b).min()!! }, "listOf().min()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOf.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOf.kt new file mode 100644 index 00000000000..b1e1d6b401b --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOf.kt @@ -0,0 +1,47 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +val Double.Companion.values get() = listOf(0.0, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +val Float.Companion.values get() = listOf(0.0f, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +private fun propagateOf2(f2d: (Double, Double) -> Double, + f2f: (Float, Float) -> Float, + function: String) { + with(Double) { + for (d in values) { + assertTrue(f2d(d, NaN).isNaN(), "$function($d, NaN)") + assertTrue(f2d(NaN, d).isNaN(), "$function(NaN, $d)") + } + } + with(Float) { + for (f in values) { + assertTrue(f2f(f, NaN).isNaN(), "$function($f, NaN)") + assertTrue(f2f(NaN, f).isNaN(), "$function(NaN, $f)") + } + } +} + +private fun propagateOf3(f3d: (Double, Double, Double) -> Double, + f3f: (Float, Float, Float) -> Float, function: String) { + + with(Double) { + for (d in values) { + assertTrue(f3d(NaN, d, POSITIVE_INFINITY).isNaN(), "$function(NaN, $d, +inf)") + assertTrue(f3d(d, NaN, POSITIVE_INFINITY).isNaN(), "$function($d, NaN, +inf)") + assertTrue(f3d(d, POSITIVE_INFINITY, NaN).isNaN(), "$function($d, +inf, NaN)") + } + } + with(Float) { + for (f in values) { + assertTrue(f3f(NaN, f, POSITIVE_INFINITY).isNaN(), "$function(NaN, $f, +inf)") + assertTrue(f3f(f, NaN, POSITIVE_INFINITY).isNaN(), "$function($f, NaN, +inf)") + assertTrue(f3f(f, POSITIVE_INFINITY, NaN).isNaN(), "$function($f, +inf, NaN)") + } + } +} + +fun box() { + propagateOf2(::maxOf, ::maxOf, "maxOf") + propagateOf3(::maxOf, ::maxOf, "maxOf") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOfT.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOfT.kt new file mode 100644 index 00000000000..4ffc9947d08 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOfT.kt @@ -0,0 +1,16 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +private fun > totalOrderMaxOf2(f2t: (T, T) -> T, function: String) { + @Suppress("UNCHECKED_CAST") + with(Double) { + assertTrue((f2t(0.0 as T, NaN as T) as Double).isNaN(), "$function(0, NaN)") + assertTrue((f2t(NaN as T, 0.0 as T) as Double).isNaN(), "$function(NaN, 0)") + } +} + +fun box() { + totalOrderMaxOf2>(::maxOf, "maxOf") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOf.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOf.kt new file mode 100644 index 00000000000..03a448a0897 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOf.kt @@ -0,0 +1,47 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +val Double.Companion.values get() = listOf(0.0, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +val Float.Companion.values get() = listOf(0.0f, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +private fun propagateOf2(f2d: (Double, Double) -> Double, + f2f: (Float, Float) -> Float, + function: String) { + with(Double) { + for (d in values) { + assertTrue(f2d(d, NaN).isNaN(), "$function($d, NaN)") + assertTrue(f2d(NaN, d).isNaN(), "$function(NaN, $d)") + } + } + with(Float) { + for (f in values) { + assertTrue(f2f(f, NaN).isNaN(), "$function($f, NaN)") + assertTrue(f2f(NaN, f).isNaN(), "$function(NaN, $f)") + } + } +} + +private fun propagateOf3(f3d: (Double, Double, Double) -> Double, + f3f: (Float, Float, Float) -> Float, function: String) { + + with(Double) { + for (d in values) { + assertTrue(f3d(NaN, d, POSITIVE_INFINITY).isNaN(), "$function(NaN, $d, +inf)") + assertTrue(f3d(d, NaN, POSITIVE_INFINITY).isNaN(), "$function($d, NaN, +inf)") + assertTrue(f3d(d, POSITIVE_INFINITY, NaN).isNaN(), "$function($d, +inf, NaN)") + } + } + with(Float) { + for (f in values) { + assertTrue(f3f(NaN, f, POSITIVE_INFINITY).isNaN(), "$function(NaN, $f, +inf)") + assertTrue(f3f(f, NaN, POSITIVE_INFINITY).isNaN(), "$function($f, NaN, +inf)") + assertTrue(f3f(f, POSITIVE_INFINITY, NaN).isNaN(), "$function($f, +inf, NaN)") + } + } +} + +fun box() { + propagateOf2(::minOf, ::minOf, "minOf") + propagateOf3(::minOf, ::minOf, "minOf") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOfT.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOfT.kt new file mode 100644 index 00000000000..a6b050eb784 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOfT.kt @@ -0,0 +1,16 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +private fun > totalOrderMinOf2(f2t: (T, T) -> T, function: String) { + @Suppress("UNCHECKED_CAST") + with(Double) { + assertEquals(0.0, f2t(0.0 as T, NaN as T), "$function(0, NaN)") + assertEquals(0.0, f2t(NaN as T, 0.0 as T), "$function(NaN, 0)") + } +} + +fun box() { + totalOrderMinOf2>(::minOf, "minOf") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMax.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMax.kt new file mode 100644 index 00000000000..a15da1f6a0d --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMax.kt @@ -0,0 +1,29 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +val Double.Companion.values get() = listOf(0.0, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +val Float.Companion.values get() = listOf(0.0f, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +private fun propagateOf2(f2d: (Double, Double) -> Double, + f2f: (Float, Float) -> Float, + function: String) { + with(Double) { + for (d in values) { + assertTrue(f2d(d, NaN).isNaN(), "$function($d, NaN)") + assertTrue(f2d(NaN, d).isNaN(), "$function(NaN, $d)") + } + } + with(Float) { + for (f in values) { + assertTrue(f2f(f, NaN).isNaN(), "$function($f, NaN)") + assertTrue(f2f(NaN, f).isNaN(), "$function(NaN, $f)") + } + } +} + +fun box() { + propagateOf2({ a, b -> doubleArrayOf(a, b).max()!! }, + { a, b -> floatArrayOf(a, b).max()!! }, + "primitiveArrayOf().max()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMin.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMin.kt new file mode 100644 index 00000000000..d8eca65586c --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMin.kt @@ -0,0 +1,29 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +val Double.Companion.values get() = listOf(0.0, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +val Float.Companion.values get() = listOf(0.0f, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +private fun propagateOf2(f2d: (Double, Double) -> Double, + f2f: (Float, Float) -> Float, + function: String) { + with(Double) { + for (d in values) { + assertTrue(f2d(d, NaN).isNaN(), "$function($d, NaN)") + assertTrue(f2d(NaN, d).isNaN(), "$function(NaN, $d)") + } + } + with(Float) { + for (f in values) { + assertTrue(f2f(f, NaN).isNaN(), "$function($f, NaN)") + assertTrue(f2f(NaN, f).isNaN(), "$function(NaN, $f)") + } + } +} + +fun box() { + propagateOf2({ a, b -> doubleArrayOf(a, b).min()!! }, + { a, b -> floatArrayOf(a, b).min()!! }, + "primitiveArrayOf().min()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMax.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMax.kt new file mode 100644 index 00000000000..65b17913052 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMax.kt @@ -0,0 +1,29 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +val Double.Companion.values get() = listOf(0.0, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +val Float.Companion.values get() = listOf(0.0f, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +private fun propagateOf2(f2d: (Double, Double) -> Double, + f2f: (Float, Float) -> Float, + function: String) { + with(Double) { + for (d in values) { + assertTrue(f2d(d, NaN).isNaN(), "$function($d, NaN)") + assertTrue(f2d(NaN, d).isNaN(), "$function(NaN, $d)") + } + } + with(Float) { + for (f in values) { + assertTrue(f2f(f, NaN).isNaN(), "$function($f, NaN)") + assertTrue(f2f(NaN, f).isNaN(), "$function(NaN, $f)") + } + } +} + +fun box() { + propagateOf2({ a, b -> sequenceOf(a, b).max()!! }, + { a, b -> sequenceOf(a, b).max()!! }, + "sequenceOf().max()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMin.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMin.kt new file mode 100644 index 00000000000..e30f7f7ec4c --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMin.kt @@ -0,0 +1,29 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +val Double.Companion.values get() = listOf(0.0, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +val Float.Companion.values get() = listOf(0.0f, NEGATIVE_INFINITY, MIN_VALUE, MAX_VALUE, POSITIVE_INFINITY, NaN) +private fun propagateOf2(f2d: (Double, Double) -> Double, + f2f: (Float, Float) -> Float, + function: String) { + with(Double) { + for (d in values) { + assertTrue(f2d(d, NaN).isNaN(), "$function($d, NaN)") + assertTrue(f2d(NaN, d).isNaN(), "$function(NaN, $d)") + } + } + with(Float) { + for (f in values) { + assertTrue(f2f(f, NaN).isNaN(), "$function($f, NaN)") + assertTrue(f2f(NaN, f).isNaN(), "$function(NaN, $f)") + } + } +} + +fun box() { + propagateOf2({ a, b -> sequenceOf(a, b).min()!! }, + { a, b -> sequenceOf(a, b).min()!! }, + "sequenceOf().min()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMax.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMax.kt new file mode 100644 index 00000000000..14f411c5c30 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMax.kt @@ -0,0 +1,16 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +private fun > totalOrderMaxOf2(f2t: (T, T) -> T, function: String) { + @Suppress("UNCHECKED_CAST") + with(Double) { + assertTrue((f2t(0.0 as T, NaN as T) as Double).isNaN(), "$function(0, NaN)") + assertTrue((f2t(NaN as T, 0.0 as T) as Double).isNaN(), "$function(NaN, 0)") + } +} + +fun box() { + totalOrderMaxOf2>({ a, b -> sequenceOf(a, b).max()!! }, "sequenceOf().max()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMin.kt b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMin.kt new file mode 100644 index 00000000000..78bf93b42c4 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMin.kt @@ -0,0 +1,16 @@ +import kotlin.test.* +import kotlin.test.assertTrue +import kotlin.comparisons.* +import kotlin.test.assertEquals + +private fun > totalOrderMinOf2(f2t: (T, T) -> T, function: String) { + @Suppress("UNCHECKED_CAST") + with(Double) { + assertEquals(0.0, f2t(0.0 as T, NaN as T), "$function(0, NaN)") + assertEquals(0.0, f2t(NaN as T, 0.0 as T), "$function(NaN, 0)") + } +} + +fun box() { + totalOrderMinOf2>({ a, b -> sequenceOf(a, b).min()!! }, "sequenceOf().min()") +} diff --git a/backend.native/tests/external/stdlib/numbers/NumbersTest/byteMinMaxValues.kt b/backend.native/tests/external/stdlib/numbers/NumbersTest/byteMinMaxValues.kt new file mode 100644 index 00000000000..7b2b56e3dbf --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NumbersTest/byteMinMaxValues.kt @@ -0,0 +1,31 @@ +import kotlin.test.* + +object NumbersTestConstants { + public const val byteMinSucc: Byte = (Byte.MIN_VALUE + 1).toByte() + public const val byteMaxPred: Byte = (Byte.MAX_VALUE - 1).toByte() + + public const val shortMinSucc: Short = (Short.MIN_VALUE + 1).toShort() + public const val shortMaxPred: Short = (Short.MAX_VALUE - 1).toShort() + + public const val intMinSucc: Int = Int.MIN_VALUE + 1 + public const val intMaxPred: Int = Int.MAX_VALUE - 1 + + public const val longMinSucc: Long = Long.MIN_VALUE + 1L + public const val longMaxPred: Long = Long.MAX_VALUE - 1L +} + +var one: Int = 1 +var oneS: Short = 1 +var oneB: Byte = 1 + +fun box() { + assertTrue(Byte.MIN_VALUE < 0) + assertTrue(Byte.MAX_VALUE > 0) + + assertEquals(NumbersTestConstants.byteMinSucc, Byte.MIN_VALUE.inc()) + assertEquals(NumbersTestConstants.byteMaxPred, Byte.MAX_VALUE.dec()) + + // overflow behavior + expect(Byte.MIN_VALUE) { (Byte.MAX_VALUE + oneB).toByte() } + expect(Byte.MAX_VALUE) { (Byte.MIN_VALUE - oneB).toByte() } +} diff --git a/backend.native/tests/external/stdlib/numbers/NumbersTest/doubleMinMaxValues.kt b/backend.native/tests/external/stdlib/numbers/NumbersTest/doubleMinMaxValues.kt new file mode 100644 index 00000000000..1c0bc7545e1 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NumbersTest/doubleMinMaxValues.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + + +fun box() { + assertTrue(Double.MIN_VALUE > 0) + assertTrue(Double.MAX_VALUE > 0) + + // overflow behavior + expect(Double.POSITIVE_INFINITY) { Double.MAX_VALUE * 2 } + expect(Double.NEGATIVE_INFINITY) { -Double.MAX_VALUE * 2 } + expect(0.0) { Double.MIN_VALUE / 2 } +} diff --git a/backend.native/tests/external/stdlib/numbers/NumbersTest/doubleProperties.kt b/backend.native/tests/external/stdlib/numbers/NumbersTest/doubleProperties.kt new file mode 100644 index 00000000000..3e5109ac6bc --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NumbersTest/doubleProperties.kt @@ -0,0 +1,15 @@ +import kotlin.test.* + +private fun doTestNumber(value: Double, isNaN: Boolean = false, isInfinite: Boolean = false) { + assertEquals(isNaN, value.isNaN(), "Expected $value to have isNaN: $isNaN") + assertEquals(isInfinite, value.isInfinite(), "Expected $value to have isInfinite: $isInfinite") + assertEquals(!isNaN && !isInfinite, value.isFinite()) +} + +fun box() { + for (value in listOf(1.0, 0.0, Double.MIN_VALUE, Double.MAX_VALUE)) + doTestNumber(value) + for (value in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY)) + doTestNumber(value, isInfinite = true) + doTestNumber(Double.NaN, isNaN = true) +} diff --git a/backend.native/tests/external/stdlib/numbers/NumbersTest/floatMinMaxValues.kt b/backend.native/tests/external/stdlib/numbers/NumbersTest/floatMinMaxValues.kt new file mode 100644 index 00000000000..22c2b009a83 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NumbersTest/floatMinMaxValues.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + + +fun box() { + assertTrue(Float.MIN_VALUE > 0) + assertTrue(Float.MAX_VALUE > 0) + + // overflow behavior + expect(Float.POSITIVE_INFINITY) { Float.MAX_VALUE * 2 } + expect(Float.NEGATIVE_INFINITY) { -Float.MAX_VALUE * 2 } + expect(0.0F) { Float.MIN_VALUE / 2.0F } +} diff --git a/backend.native/tests/external/stdlib/numbers/NumbersTest/floatProperties.kt b/backend.native/tests/external/stdlib/numbers/NumbersTest/floatProperties.kt new file mode 100644 index 00000000000..c8f1edf41ab --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NumbersTest/floatProperties.kt @@ -0,0 +1,16 @@ +import kotlin.test.* + + +private fun doTestNumber(value: Float, isNaN: Boolean = false, isInfinite: Boolean = false) { + assertEquals(isNaN, value.isNaN(), "Expected $value to have isNaN: $isNaN") + assertEquals(isInfinite, value.isInfinite(), "Expected $value to have isInfinite: $isInfinite") + assertEquals(!isNaN && !isInfinite, value.isFinite()) +} + +fun box() { + for (value in listOf(1.0F, 0.0F, Float.MAX_VALUE, Float.MIN_VALUE)) + doTestNumber(value) + for (value in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY)) + doTestNumber(value, isInfinite = true) + doTestNumber(Float.NaN, isNaN = true) +} diff --git a/backend.native/tests/external/stdlib/numbers/NumbersTest/intMinMaxValues.kt b/backend.native/tests/external/stdlib/numbers/NumbersTest/intMinMaxValues.kt new file mode 100644 index 00000000000..781e8a88352 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NumbersTest/intMinMaxValues.kt @@ -0,0 +1,31 @@ +import kotlin.test.* + +object NumbersTestConstants { + public const val byteMinSucc: Byte = (Byte.MIN_VALUE + 1).toByte() + public const val byteMaxPred: Byte = (Byte.MAX_VALUE - 1).toByte() + + public const val shortMinSucc: Short = (Short.MIN_VALUE + 1).toShort() + public const val shortMaxPred: Short = (Short.MAX_VALUE - 1).toShort() + + public const val intMinSucc: Int = Int.MIN_VALUE + 1 + public const val intMaxPred: Int = Int.MAX_VALUE - 1 + + public const val longMinSucc: Long = Long.MIN_VALUE + 1L + public const val longMaxPred: Long = Long.MAX_VALUE - 1L +} + +var one: Int = 1 +var oneS: Short = 1 +var oneB: Byte = 1 + +fun box() { + assertTrue(Int.MIN_VALUE < 0) + assertTrue(Int.MAX_VALUE > 0) + + assertEquals(NumbersTestConstants.intMinSucc, Int.MIN_VALUE + one) + assertEquals(NumbersTestConstants.intMaxPred, Int.MAX_VALUE - one) + + // overflow behavior + expect(Int.MIN_VALUE) { Int.MAX_VALUE + one } + expect(Int.MAX_VALUE) { Int.MIN_VALUE - one } +} diff --git a/backend.native/tests/external/stdlib/numbers/NumbersTest/longMinMaxValues.kt b/backend.native/tests/external/stdlib/numbers/NumbersTest/longMinMaxValues.kt new file mode 100644 index 00000000000..4f9429f1da3 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NumbersTest/longMinMaxValues.kt @@ -0,0 +1,31 @@ +import kotlin.test.* + +object NumbersTestConstants { + public const val byteMinSucc: Byte = (Byte.MIN_VALUE + 1).toByte() + public const val byteMaxPred: Byte = (Byte.MAX_VALUE - 1).toByte() + + public const val shortMinSucc: Short = (Short.MIN_VALUE + 1).toShort() + public const val shortMaxPred: Short = (Short.MAX_VALUE - 1).toShort() + + public const val intMinSucc: Int = Int.MIN_VALUE + 1 + public const val intMaxPred: Int = Int.MAX_VALUE - 1 + + public const val longMinSucc: Long = Long.MIN_VALUE + 1L + public const val longMaxPred: Long = Long.MAX_VALUE - 1L +} + +var one: Int = 1 +var oneS: Short = 1 +var oneB: Byte = 1 + +fun box() { + assertTrue(Long.MIN_VALUE < 0) + assertTrue(Long.MAX_VALUE > 0) + + assertEquals(NumbersTestConstants.longMinSucc, Long.MIN_VALUE + one) + assertEquals(NumbersTestConstants.longMaxPred, Long.MAX_VALUE - one) + + // overflow behavior + expect(Long.MIN_VALUE) { Long.MAX_VALUE + one } + expect(Long.MAX_VALUE) { Long.MIN_VALUE - one } +} diff --git a/backend.native/tests/external/stdlib/numbers/NumbersTest/shortMinMaxValues.kt b/backend.native/tests/external/stdlib/numbers/NumbersTest/shortMinMaxValues.kt new file mode 100644 index 00000000000..938437e80d3 --- /dev/null +++ b/backend.native/tests/external/stdlib/numbers/NumbersTest/shortMinMaxValues.kt @@ -0,0 +1,31 @@ +import kotlin.test.* + +object NumbersTestConstants { + public const val byteMinSucc: Byte = (Byte.MIN_VALUE + 1).toByte() + public const val byteMaxPred: Byte = (Byte.MAX_VALUE - 1).toByte() + + public const val shortMinSucc: Short = (Short.MIN_VALUE + 1).toShort() + public const val shortMaxPred: Short = (Short.MAX_VALUE - 1).toShort() + + public const val intMinSucc: Int = Int.MIN_VALUE + 1 + public const val intMaxPred: Int = Int.MAX_VALUE - 1 + + public const val longMinSucc: Long = Long.MIN_VALUE + 1L + public const val longMaxPred: Long = Long.MAX_VALUE - 1L +} + +var one: Int = 1 +var oneS: Short = 1 +var oneB: Byte = 1 + +fun box() { + assertTrue(Short.MIN_VALUE < 0) + assertTrue(Short.MAX_VALUE > 0) + + assertEquals(NumbersTestConstants.shortMinSucc, Short.MIN_VALUE.inc()) + assertEquals(NumbersTestConstants.shortMaxPred, Short.MAX_VALUE.dec()) + + // overflow behavior + expect(Short.MIN_VALUE) { (Short.MAX_VALUE + oneS).toShort() } + expect(Short.MAX_VALUE) { (Short.MIN_VALUE - oneS).toShort() } +} diff --git a/backend.native/tests/external/stdlib/properties/META-INF/main.kotlin_module b/backend.native/tests/external/stdlib/properties/META-INF/main.kotlin_module new file mode 100644 index 0000000000000000000000000000000000000000..7fec79e73cb066581df5698461342be72411d13d GIT binary patch literal 74 zcmZQzU|?ooU|@t|RxTMX1|f;C#3H9k-^2pfijvg4;>`TK;*iwh67Lc&DK75p{F0o^ UJiQX2fDkuGIJ6`)r`Wp$01k>1I{*Lx literal 0 HcmV?d00001 diff --git a/backend.native/tests/external/stdlib/properties/VarByMapExtensionsTest$a2$2.class b/backend.native/tests/external/stdlib/properties/VarByMapExtensionsTest$a2$2.class new file mode 100644 index 0000000000000000000000000000000000000000..351c437c39991a3b2e8403443c67830358b6e6a4 GIT binary patch literal 1370 zcmaJ>ZBG+H5PtUh%2A#Mw&}H!UA7gsl1GPw)*Q=3la`S$ z?4R$WR=nYyVd%_p>C1zvUsIGK#p=Dd#2DsH(j%sK3klrBPzUYqGYnkpKU>jM>xy5d z(dsS;=@x6%k{fLDl1G+Q!FRYvH-*ug#-Z0WsYTVz%eqj4>`Q+Kf?@pp>1mtKxOHrZ z9m#bqAQXGUuLX{~CJbcvs&qVG(bq(b?)qhhL|#faSn;@0E;V(JXh6J4joMES51N!YE*58`%yt1T(!7gIBNvA!I#E&$d989K9!F+O#EU zlD1hb=}dRhLE9v47GOe#L%Nc->E1it>0aq3{qK8E@{?^K&G%V;_uYH$IsX~=+;iSD zryhA6K)vt@%-^YI8V_`+!!4tRmeLdHl-{f9h8IF0uvZ;Xqe(S25bf&QtHn55Bv3S@ z4hzg_Hy5);A{o6%)d$I;LEwU^vm2}_lS_}0Nu&lE95WW*hE3eNygi*6i0;*lzKohk z=}|S6N*k&n5k))GMrSseBvtW%W>A*EyvkKmg*Eu$LGcW@P$J+q1{1nKS^M-Vl9`*T z)CG8Yz(RXRES;2mO&<}BzMUbm zLSQksbY`k=zetLVmZpvY%w49=RDxd|6UxRZnTcTifN!Z-H{KmSK(R(uf(hUxXQA{ zYXw|ty${#XoEdE>J;ES(9j=vue*-P84GkLye7K3Lx_O!S@CHIseYn|=%PbbR3WO$- zWM{f38yjp%YC~GeXc>)Z!!liYaXXDZ;ULR2joCypE<@?fCQjOH$TA08`6waw|QnTno}8NJzg zF0B=E>&24_#&MEt2CeE&Ce`JY`HDj7(O_?NCIRmK6h1Al>CdnLnZEK0GoRLb@i_)z zTW3%2*3PCDfhDIY(@bJ=eFmSOfv53>!mGPKo3hJ~R(n+E#k0JT_S1WI;n9&bth!^1 zZP;8{*N`iZWDzh8rvm+~;_b`$iq!3^guWrh%8D6+sW8W!XCkM0m4D#vYv&34I1im89oy*@$d+aJ3 zKUnXo6^)*gcNeT*|Y&5o*ohfjBXaiB;(*R^hGz4YWwCvSI=E~vPDN}#0N z?JEv=E8IR`U^XQZDU2#|iJNk5D9(LiaryG+!IdLJd2qbV}xn=*odIg~LsFpo0I zC}V+*X~7iwB_{pCKso6b1r}4rQj@bgFJr16%gjCJn7Bg3RTrozuL!z>)HzrjG;!4~ z-y0~LxjIZM_>}R3RO#HniXBS=E6ZouBy#Jj+R6!nNT5nOiq|@wwm9cuXTdws_SD%& zv7nf=!!CCScWC`uMz#obvM%=GCxwB`lE}}9WPdb~4X{`y_1kSZynzg>{ zK>pi%QnF=XVI}IaLkb|P$v6q@|cZM%z%O-{FiT0QZcc> z6L}c^`#Eso6#x6JNzBA7zP-qw6alJfs>Y!cYAKbQGY!LeXJ_cK85ZhZDjO0)kq9^Q zDXqJV2+PNr03#g_B2-l0Sygi!=L(FWY8>uy)JS2%fqt2dz7XkZs%$atB4Q8stgH&w zjp2NoeMh9zWWU~Bz0hq6s5*{@BJ6q~&wf4`aGT9uj%u-ipQ+@mSDI70rBpUAwxkVw zN)?t;Mq^$D_aqf2<6k-nzjSOVn$T=>ZL{%9!$__ca(De%k>?CUn-Y186S*aW%@(zg z#&5Kdhbd!Q9=T@{@^Q2uMc2KgciKN}<1dvho6WDAn2SkQY4fu%dx&|_7c^+-?6trgz70V1)X z*OTAGykELIINA|>V`o)06N5alj4^BamJZ>VCB9vv-MvwCE_T1>PWS|KM>{}vx9vKN zs?M4x@uoZBtvQTH)d?KheGG36zWpfPRdW>YJ&F&E;X`BisCc3(`0?CuLejlXNmBpY zEaVT+PGfiiC(%!boZ<;sLwh~K-+hc?H=be=`2;@6wflJX?w9F=^c(R2SD98snH~2s z6KD7ZLZ)#)Q~UzPeQpf zh^2;dSF@jq@>h#z*(X0sT+ict{?_3IeslGsLM*^?vw3KQ=M=`gs1cqvFZy3Z3EW<| z-R|I{ z3?U9Y!BH7J=D0Zc`0Oz}CC6j<>=F1QZfn=|)-Fym431!4M7sV6%I#;P{oH0hFPG1G z58{jC_|h1@b_A+S?#`R<28X>X%zR!%FS)Uv9@|0OmvOF-*XUj@GTi=XM8OWB3(yd;S=HH-Dbz>oVHd}tm*ULrpsvI8UQ@TePFcHld3|-=+VyMdl}O732(vs>A}`BZcxV@9WlQC46XI8*hQx5{vW=-g*RX}?jlbkY6HN?f zf0S_+HAD)`less@1FqbSSOU4vVZh^AsoHl9IKm6Lh=9p6jB6dUmI-?vY3YBA`O>O5XR%P$o`@kLjJrH+O9UW z3uR>>t=uDs-Y~%qDGo`N{zQU6ofrv5!49D?9y#uKR7_maTq8J5lSexAR;6qRDJ+82wbWF literal 0 HcmV?d00001 diff --git a/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/NotNullVarTest.kt b/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/NotNullVarTest.kt new file mode 100644 index 00000000000..838b284a5a7 --- /dev/null +++ b/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/NotNullVarTest.kt @@ -0,0 +1,19 @@ +import kotlin.test.* + +import kotlin.properties.* + +private class NotNullVarTestGeneric(val a1: String, val b1: T) { + var a: String by Delegates.notNull() + var b by Delegates.notNull() + + public fun doTest() { + a = a1 + b = b1 + assertTrue(a == "a", "fail: a should be a, but was $a") + assertTrue(b == "b", "fail: b should be b, but was $b") + } +} + +fun box() { + NotNullVarTestGeneric("a", "b").doTest() +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/ObservablePropertyTest.kt b/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/ObservablePropertyTest.kt new file mode 100644 index 00000000000..cfbf2325011 --- /dev/null +++ b/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/ObservablePropertyTest.kt @@ -0,0 +1,23 @@ +import kotlin.test.* + +import kotlin.properties.* + +class ObservablePropertyTest { + var result = false + + var b: Int by Delegates.observable(1, { property, old, new -> + assertEquals("b", property.name) + result = true + assertEquals(new, b, "New value has already been set") + }) + + fun doTest() { + b = 4 + assertTrue(b == 4, "fail: b != 4") + assertTrue(result, "fail: result should be true") + } +} + +fun box() { + ObservablePropertyTest().doTest() +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/VetoablePropertyTest.kt b/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/VetoablePropertyTest.kt new file mode 100644 index 00000000000..02338e89fb1 --- /dev/null +++ b/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/VetoablePropertyTest.kt @@ -0,0 +1,33 @@ +import kotlin.test.* + +import kotlin.properties.* + +import kotlin.test.* + +import kotlin.properties.* + +class A(val p: Boolean) + +class VetoablePropertyTest { + var result = false + var b: A by Delegates.vetoable(A(true), { property, old, new -> + assertEquals("b", property.name) + assertEquals(old, b, "New value hasn't been set yet") + result = new.p == true; + result + }) + + fun doTest() { + val firstValue = A(true) + b = firstValue + assertTrue(b == firstValue, "fail1: b should be firstValue = A(true)") + assertTrue(result, "fail2: result should be true") + b = A(false) + assertTrue(b == firstValue, "fail3: b should be firstValue = A(true)") + assertFalse(result, "fail4: result should be false") + } +} + +fun box() { + VetoablePropertyTest().doTest() +} diff --git a/backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/ValByMapExtensionsTest.kt b/backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/ValByMapExtensionsTest.kt new file mode 100644 index 00000000000..179622791e1 --- /dev/null +++ b/backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/ValByMapExtensionsTest.kt @@ -0,0 +1,32 @@ +import kotlin.test.* + +class ValByMapExtensionsTest { + val map: Map = hashMapOf("a" to "all", "b" to "bar", "c" to "code") + val genericMap = mapOf("i" to 1, "x" to 1.0) + + val a by map + val b: String by map + val c: Any by map + val d: String? by map + val e: String by map.withDefault { "default" } + val f: String? by map.withDefault { null } + // val n: Int by map // prohibited by type system + val i: Int by genericMap + val x: Double by genericMap + + + fun doTest() { + assertEquals("all", a) + assertEquals("bar", b) + assertEquals("code", c) + assertEquals("default", e) + assertEquals(null, f) + assertEquals(1, i) + assertEquals(1.0, x) + assertFailsWith { d } + } +} + +fun box() { + ValByMapExtensionsTest().doTest() +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/VarByMapExtensionsTest.kt b/backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/VarByMapExtensionsTest.kt new file mode 100644 index 00000000000..57cfa992820 --- /dev/null +++ b/backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/VarByMapExtensionsTest.kt @@ -0,0 +1,40 @@ +import kotlin.test.* + +class VarByMapExtensionsTest { + val map = hashMapOf("a" to "all", "b" to null, "c" to 1, "xProperty" to 1.0) + val map2: MutableMap = hashMapOf("a2" to "all") + + var a: String by map + var b: Any? by map + var c: Int by map + var d: String? by map + var a2: String by map2.withDefault { "empty" } + //var x: Int by map2 // prohibited by type system + + fun doTest() { + assertEquals("all", a) + assertEquals(null, b) + assertEquals(1, c) + c = 2 + assertEquals(2, c) + assertEquals(2, map["c"]) + + assertEquals("all", a2) + map2.remove("a2") + assertEquals("empty", a2) + + map["c"] = "string" + // fails { c } // does not fail in JS due to KT-8135 + + map["a"] = null + a // fails { a } // does not fail due to KT-8135 + + assertFailsWith { d } + map["d"] = null + assertEquals(null, d) + } +} + +fun box() { + VarByMapExtensionsTest().doTest() +} diff --git a/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/IdentityEqualsIsUsedToUnescapeLazyValTest.kt b/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/IdentityEqualsIsUsedToUnescapeLazyValTest.kt new file mode 100644 index 00000000000..c089eff478c --- /dev/null +++ b/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/IdentityEqualsIsUsedToUnescapeLazyValTest.kt @@ -0,0 +1,24 @@ +import kotlin.test.* +import kotlin.properties.* + +class IdentityEqualsIsUsedToUnescapeLazyValTest { + var equalsCalled = 0 + private val a by lazy { ClassWithCustomEquality { equalsCalled++ } } + + fun doTest() { + a + a + assertTrue(equalsCalled == 0, "fail: equals called $equalsCalled times.") + } +} + +private class ClassWithCustomEquality(private val onEqualsCalled: () -> Unit) { + override fun equals(other: Any?): Boolean { + onEqualsCalled() + return super.equals(other) + } +} + +fun box() { + IdentityEqualsIsUsedToUnescapeLazyValTest().doTest() +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/LazyValTest.kt b/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/LazyValTest.kt new file mode 100644 index 00000000000..f314fa49974 --- /dev/null +++ b/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/LazyValTest.kt @@ -0,0 +1,18 @@ +import kotlin.test.* +import kotlin.properties.* + +class LazyValTest { + var result = 0 + val a by lazy { + ++result + } + + fun doTest() { + a + assertTrue(a == 1, "fail: initializer should be invoked only once") + } +} + +fun box() { + LazyValTest().doTest() +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/NullableLazyValTest.kt b/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/NullableLazyValTest.kt new file mode 100644 index 00000000000..16809d9ee64 --- /dev/null +++ b/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/NullableLazyValTest.kt @@ -0,0 +1,29 @@ +import kotlin.test.* +import kotlin.properties.* + +class NullableLazyValTest { + var resultA = 0 + var resultB = 0 + + val a: Int? by lazy { resultA++; null } + val b by lazy { foo() } + + fun doTest() { + a + b + + assertTrue(a == null, "fail: a should be null") + assertTrue(b == null, "fail: b should be null") + assertTrue(resultA == 1, "fail: initializer for a should be invoked only once") + assertTrue(resultB == 1, "fail: initializer for b should be invoked only once") + } + + fun foo(): String? { + resultB++ + return null + } +} + +fun box() { + NullableLazyValTest().doTest() +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeLazyValTest.kt b/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeLazyValTest.kt new file mode 100644 index 00000000000..f75816a98f9 --- /dev/null +++ b/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeLazyValTest.kt @@ -0,0 +1,18 @@ +import kotlin.test.* +import kotlin.properties.* + +class UnsafeLazyValTest { + var result = 0 + val a by lazy(LazyThreadSafetyMode.NONE) { + ++result + } + + fun doTest() { + a + assertTrue(a == 1, "fail: initializer should be invoked only once") + } +} + +fun box() { + UnsafeLazyValTest().doTest() +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeNullableLazyValTest.kt b/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeNullableLazyValTest.kt new file mode 100644 index 00000000000..35afbcbcd2b --- /dev/null +++ b/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeNullableLazyValTest.kt @@ -0,0 +1,29 @@ +import kotlin.test.* +import kotlin.properties.* + +class UnsafeNullableLazyValTest { + var resultA = 0 + var resultB = 0 + + val a: Int? by lazy(LazyThreadSafetyMode.NONE) { resultA++; null } + val b by lazy(LazyThreadSafetyMode.NONE) { foo() } + + fun doTest() { + a + b + + assertTrue(a == null, "fail: a should be null") + assertTrue(b == null, "fail: a should be null") + assertTrue(resultA == 1, "fail: initializer for a should be invoked only once") + assertTrue(resultB == 1, "fail: initializer for b should be invoked only once") + } + + fun foo(): String? { + resultB++ + return null + } +} + +fun box() { + UnsafeNullableLazyValTest().doTest() +} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/properties/kotlin/test/Assert$Companion.class b/backend.native/tests/external/stdlib/properties/kotlin/test/Assert$Companion.class new file mode 100644 index 0000000000000000000000000000000000000000..9f2641bdc33f24f24e6e07024b5cca495df09d9d GIT binary patch literal 1770 zcma)6-EZ4e6#re@u^l&C)AWNjbln&kOF!Kd26QQfF6%^4TM*5PMjy~kVlpR=Q|z0< z6RLRNf7mN8NWAgF5J)510}uRBjB}kdNf%K~y1wV@p6_$~&%b{>1F(TzhWSQIc&={? zClvNh7&?K-6k5#_?z=7D0Aonj`6;(O?$_*3%XOzB45$nV9=+ZDrp>*OVKck;^0WM< zoI??~el5Rv#E{u*1vR_wh;qPPKeV~;w*(jDKeP|pp2y3clV@1yMOr^?+O990z~`P_ z^rfB9t%L?l29pO)6cWSjSBhxy%LFWpS%@RSaDBKKC922+?s`sj_q&R7BI7Y|l>sJ_ z4EmPqyJDMRde~1ts{~S*v@nh-hRH!?N{@rqw=y3CGYpz|>{9I(_J-ZQ+yly-afZ}r zHAzrrP@7@xqPQ2th0b+(2Cg$q4RxXfn&-c4w7HB3!(5{G9u+M{r6VL!jL!>yFsSJc)H6tm*+Idp1 zW{qLuTw&i4yvhZq`YX*-mG*_nD@J5FB0=?U5LL}FIGwY!rOYaplI)yWiYXELOpV}G zt8->P|52UooNXxU?4DsN&wtWM{>f@mO)Kl#P0j3_C1V?UQco)%OK3#UGL@v6)@Ipy zJW{ZvvkmfEqJEE#jDhzU;{DyF6_q>vP`F;W)}RJ!g;v#(lhUei?}!JkoWqj57{>Qp z-#KVE%TCbaTsaiH(%9!GJvx5q)_gA70lm&`mF|xAbvs)s<>?GbdP5K``R8q4xJ{?% zpSqz-PCw%TZ#uNbJA-v+unt@8pyE8BwW9=zzV8GDPYx{Y$z0FGQP;qb9&$7T8g&PB zPsr(liab%j5H0y{EU)~IE7}iFF!v|MAFV$68~V@Czer6y#dHU+{q-w7Qn5w%Qda@9 zm?Mf*k;d!PYl+PhrbO5^EYSN82-hQ79NUEFp}xQjGy{quZ#p-iny}~)`a(weKQbL3 zk^u!DVTa(D95tFa7(lW}o^KK^6S_mu=>(^yHRJmy^vmnu#=+9^%Ia^($Q+b@Oa}eZ zWK1epg4ncSJrg!TnNDo!DQKY(OaNYopy`La=+U8zGNEh#ZQ9ocpLPVY72~+#aE{Kj1f(jpcSa`6P`_ z4PpB~)s53U_pPrAj+B!_=_GSvG7DHd`H*MWUqTRQ%xKsoG#2wH6jc$5%3>ahlBh1` zJ3&i4q(>Ay&Hwyd5EbETTf}p)byo5}5k=Gp&E1ub(QFcH<5Xs35{&Y4F`e{P_Lm7?r_*epo@<|u4vkS+JCVFFw!QXhYMh>^uC|)n4~$8jbnLN3lb_Cc zzfki^_$K(yi{p5MQOqaXfc*Vql)fy}H#tTpB+3XG-QwRj07aB=?zFiIzXh)Tj`}+~ z#WCEK$TBb6r8t+;E4+O1zKoD$?3ILnqWc#Y7lIw7TB1D5nqL zBLasrr}@t}QJE)!xS*SPk{SX+c{z5q z2A<0k3Mub7ZEStw2;O5fdl{-*Z8&|kGvg0U)swb*VAOgIw#HMj!R?!z2wYbdc#JCF r4d%RKAJ_~{f3be`suNV_GkkpiF0D0lX>2^}4-R_#5Y2#ymi@!h< zjm8Jl_~?%^-YHwY6O-<}Id{&SJ==5t{Qdb0zz#MUmRf=Kr0-~>>#W0zs25`+z>DReF5(pL`m z{Xlc0tek3~s~yiHRAvgSn1EG1HYfhf6b~i@RFjL5$RU1Gsuoj{EHpAd8ehPHd~ruK4O*qu2iz-i5HiFQ+lt0x-gp(xZFG8q2$Ck zHicoLB7ITqv}+=aCaX8KE;6_#Y99ri&=vc%x8ydub8_qL*rpANn?IL=poOBoM#%IO zbqhJ9VYY0YkV8{OJyHCM(a(e94XT;*A@wmrMS9G2qFs|>CgezHkGe&STq&RZf$3uD zJ7$ZeZy5bTLkmW9`kWAn5;bx+lur^a5s&g3T75FO{1{KES7M_5Z!_5`ZrJOG5o*UeBtzl&)xcYLtilx|-GY=mAI)qQ~VKIhB=j6REvp$CWfk zy%Hj_rYQxz@2;Yp)g)ZkGFUmS=aM5MdO^)i^lUmHp?NT0m`EL0^s$1h=CqWY%jI=h zSM$6cE@rdxSXSwg5OW*3)6gD3P{NWM@>A1tj?*Qq9-Kd^x%9jzf)K(>umlkaO_!P( zz_JKx;16Lrq7o#T>gU7ZgE0x-DQ%+sv4u@SotvcQj5014v$}-AcSzR2d=mtJE(e*K z185AvBMc9j28O9gsf7qQM+5h2r7CgGYYva7+YR2RWkTrE&{ zlUK#?orJA!VP-b>*eP>-W-2va%%#o5+ihKS7%5samd&RpgP?m?Tfrixt2tdM zAScpUQ`1@iJ6KQB$CUKsKDi)IDV#B&4V&mBY^-L06ArF$>BS8p?8L5eja3W`U^fw} zxtaVVU0T<&$;E^PF@k;!gmEKoil811f|WrDL6a3FBO$RE2@-C6OO`JtN91cM23cbb z|GF5hg0II7sFW`ZlmWLz7ITa0cah`Bir{992v$ZV^leU*vO>-!6uSu62`>^h*OnM7 z>WRB$Es8gs66dwmtaUtZdCHB|f)v56I3z-W zH9?|>S5$={VY!{Fr1hYxALH!NAda%`6%=(`RWf_0m4eY$hUCJeQV<2vok*_OlQAX~ zrWwhOh350#qMFSpg#c)Yw`J1-QP(Cy7zg#;v=DXq@q~VIT1li*qkDJl?M}#W6h zLyHtSTOc!}tR7p$E@qo3A+=6e_U7|hMP`pa#nv%q-W(7e+KA7?5xgG{gm6DTAff*< zF~Oj3!hND%JXlIQR(KnJP%fBMEL!euCTQh{@ez@7A7$THvsq;f#GmPFe=jo=}% zHS^#TrG4l~zQ7t((JcqqdyLKFr77()THKQ6f|6F$8Kn@!quf=h+CXk^fvFzEW88u` zgxgXB_$;$T6*~01QBACrEOPUlGG=j{+4wj<7seSp;aFEbV{z*ucm!V%fS+UzxXPbx z3Y)hgiXjh&GM$oVdhXP&(A=qzC+Z1#fA0` z9$hZ%qd`%gYu#&Te5~B|D=gbNl^9&&E!*SKx&?(LtY@xOE)2EA*c4r1tPVz38W`)l zf;38SQ{NwmZ;UpS8?(|dqC``_rz32b(HQTnKD7#WrA6_0EV_#Fo7|}49nmXYI+KPw zxMX!#Lv&5NPB^FE;~YC`I}!^mS-bEO5qDh@1CuYQ)?U)tzE>F(#ULWy_4kX{{LPbm zCH38q&#+^}2J>k-dq6IzqHd0g11tQXnp1|0Q)5cO8d)-;PUK|0Sm4vnZKK`uGkSZ= z=x7iBTu-d_X1wv=Qq1YZ+l?+TdI=#;3wUdt+9h^(%VH+j&-e2sTG-+u&b`~X_3gLtZEsQZ(Q@dH z*6o);Ckf{M_?-xHShsdMmZzr6&9$0KnXPtvv>ajcP(2E|wzbnp@pDoCc2t&ikjteq zG?FhC(#mdrk727aZ+0nT#fiQXy22N3@zJZ%N{a(#F1eBdo!m3{*qVS9XcQl`;KeU^ z*UwSWvO>>cX|lELJZhiiod>_Fz)H^g6|eoq$Wr{8*B<-^ zZ}1!zB1IVr0MP;Qrp;@i?kb9`;W>6?;NCO*W;ciU5Y^6Nm8sSi=*Lq0mh-%j!nBv4 zZ75p^c!>6Tcy5aOoPJ)4j>M15Hov z%RmBGj5QfzTj03}PO)5sAPC5CQN<8`M~Najui;t13UGgBMdY=(&Z1f*hKSbaDxdAD zJ;_=0oa2}i;C_aV2oNJ4-EteT4cA-v1{q6&@w(R7yJyjtY`uUzR2h(FF=SFCvdWCf zIt*J`Rfp}^OT$Fy3y=A+mQU7M`Sg2tmoTd_C#2S-Sn4}(L!Vk5bOU4e);t0JZy-Z8|SY`k) zqbR{;F)qFhxARB=Ry>I-hw(U9`LUT{k>c78uIOYf=;H4x!{N-8n*-SBv5fxHJfoKi z4p`t z;4sr*Wf|al7vP~1;2{fexD0R?A^Hg=%$L9jCMf9`3!#c;9OrKm8(5AuAkQ_^{1y1q z4A7h43*SVz7m3=(!VbnO&$+e7-StN>OI8*a|&Zq4TW7??k?5 zz1LI!*BL!Lap(->Cf}XbShugWz0r38-|@l>2D^wn%OcWr9^Z?d7Z<*axSX{Li#cYG zH2UmXv$@eXeD>lK0;5@4w$Q9CY)Q}1Nj?_KW4OR8FWJuH1*4$QXfp63SBNWzfh64+ z!C^Y`2xs5MwYSs3cW?u7loId6Dad$$W2cce{IC?>m2Ywv7=Z7;OjDD%zf~j7i@#Hs z2e0EFJWq}c?c5h~zqf|=82`5pB}WqW)$UMhqBBu8$$BLgWA1-$hmwP#&h?#bogJOs zouRE)i_5LuogH1FWM2sXq{7GPzaNm6A0B~s052JTFJsQWdxZmdbpSuYkB>mo@Dsdt z1nV@^X!xmyqZ(ow>NKn{Zv7f=HZHbn_?d>JhC4KjXh>;jF~%R#@UVs^4fkjmHb%B- VxL(6P4O@-dM~vfR8h*};{{sp7l^Os5 literal 0 HcmV?d00001 diff --git a/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsComparable.kt b/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsComparable.kt new file mode 100644 index 00000000000..b14ad3f8880 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsComparable.kt @@ -0,0 +1,34 @@ +import kotlin.test.* + + +private class ComparableNumber(val value: Int) : Comparable { + override fun compareTo(other: ComparableNumber): Int = this.value - other.value + override fun toString(): String = "CV$value" +} + +fun box() { + val v = (0..10).map { ComparableNumber(it) } + + expect(5) { v[5].coerceAtLeast(v[1]).value } + expect(5) { v[1].coerceAtLeast(v[5]).value } + expect(v[5]) { v[5].coerceAtLeast(ComparableNumber(5)) } + + expect(1) { v[5].coerceAtMost(v[1]).value } + expect(1) { v[1].coerceAtMost(v[5]).value } + expect(v[1]) { v[1].coerceAtMost(ComparableNumber(1)) } + + for (value in v) { + expect(value) { value.coerceIn(null, null) } + val min = v[2] + val max = v[5] + val range = min..max + expect(value.coerceAtLeast(min)) { value.coerceIn(min, null) } + expect(value.coerceAtMost(max)) { value.coerceIn(null, max) } + expect(value.coerceAtLeast(min).coerceAtMost(max)) { value.coerceIn(min, max) } + expect(value.coerceAtMost(max).coerceAtLeast(min)) { value.coerceIn(range) } + assertTrue((value.coerceIn(range)) in range) + } + + assertFails { v[1].coerceIn(v[1], v[0]) } + assertFails { v[1].coerceIn(v[1]..v[0]) } +} diff --git a/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsDouble.kt b/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsDouble.kt new file mode 100644 index 00000000000..781fe846d50 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsDouble.kt @@ -0,0 +1,33 @@ +import kotlin.test.* + + +fun box() { + expect(5.0) { 5.0.coerceAtLeast(1.0) } + expect(5.0) { 1.0.coerceAtLeast(5.0) } + assertTrue { Double.NaN.coerceAtLeast(1.0).isNaN() } + + expect(1.0) { 5.0.coerceAtMost(1.0) } + expect(1.0) { 1.0.coerceAtMost(5.0) } + assertTrue { Double.NaN.coerceAtMost(5.0).isNaN() } + + for (value in (0..10).map { it.toDouble() }) { + expect(value) { value.coerceIn(null, null) } + val min = 2.0 + val max = 5.0 + val range = min..max + expect(value.coerceAtLeast(min)) { value.coerceIn(min, null) } + expect(value.coerceAtMost(max)) { value.coerceIn(null, max) } + expect(value.coerceAtLeast(min).coerceAtMost(max)) { value.coerceIn(min, max) } + expect(value.coerceAtMost(max).coerceAtLeast(min)) { value.coerceIn(range) } + assertTrue((value.coerceIn(range)) in range) + } + + assertFails { 1.0.coerceIn(1.0, 0.0) } + assertFails { 1.0.coerceIn(1.0..0.0) } + + assertTrue(0.0.equals(0.0.coerceIn(0.0, -0.0))) + assertTrue((-0.0).equals((-0.0).coerceIn(0.0..-0.0))) + + assertTrue(Double.NaN.coerceIn(0.0, 1.0).isNaN()) + assertTrue(Double.NaN.coerceIn(0.0..1.0).isNaN()) +} diff --git a/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsInt.kt b/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsInt.kt new file mode 100644 index 00000000000..666700d10f0 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsInt.kt @@ -0,0 +1,24 @@ +import kotlin.test.* + + +fun box() { + expect(5) { 5.coerceAtLeast(1) } + expect(5) { 1.coerceAtLeast(5) } + expect(1) { 5.coerceAtMost(1) } + expect(1) { 1.coerceAtMost(5) } + + for (value in 0..10) { + expect(value) { value.coerceIn(null, null) } + val min = 2 + val max = 5 + val range = min..max + expect(value.coerceAtLeast(min)) { value.coerceIn(min, null) } + expect(value.coerceAtMost(max)) { value.coerceIn(null, max) } + expect(value.coerceAtLeast(min).coerceAtMost(max)) { value.coerceIn(min, max) } + expect(value.coerceAtMost(max).coerceAtLeast(min)) { value.coerceIn(range) } + assertTrue((value.coerceIn(range)) in range) + } + + assertFails { 1.coerceIn(1, 0) } + assertFails { 1.coerceIn(1..0) } +} diff --git a/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsLong.kt b/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsLong.kt new file mode 100644 index 00000000000..60c2231e8d3 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsLong.kt @@ -0,0 +1,25 @@ +import kotlin.test.* + + +fun box() { + expect(5L) { 5L.coerceAtLeast(1L) } + expect(5L) { 1L.coerceAtLeast(5L) } + expect(1L) { 5L.coerceAtMost(1L) } + expect(1L) { 1L.coerceAtMost(5L) } + + for (value in 0L..10L) { + expect(value) { value.coerceIn(null, null) } + val min = 2L + val max = 5L + val range = min..max + expect(value.coerceAtLeast(min)) { value.coerceIn(min, null) } + expect(value.coerceAtMost(max)) { value.coerceIn(null, max) } + expect(value.coerceAtLeast(min).coerceAtMost(max)) { value.coerceIn(min, max) } + expect(value.coerceAtMost(max).coerceAtLeast(min)) { value.coerceIn(range) } + assertTrue((value.coerceIn(range)) in range) + } + + assertFails { 1L.coerceIn(1L, 0L) } + assertFails { 1L.coerceIn(1L..0L) } + +} diff --git a/backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/calculateFinalElement.kt b/backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/calculateFinalElement.kt new file mode 100644 index 00000000000..dae7ff454de --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/calculateFinalElement.kt @@ -0,0 +1,55 @@ +import kotlin.test.* +import kotlin.comparisons.* +import kotlin.test.assertEquals + +private val MAX = Int.MAX_VALUE +private val MIN = Int.MIN_VALUE + +private val INTERESTING = intArrayOf(MIN, MIN / 2, -239, -23, -1, 0, 1, 42, 239, MAX / 2, MAX) + +private fun doTest(start: Int, end: Int, increment: Int, expected: Int) { + + val actualInt = IntProgression.fromClosedRange(start, end, increment).last + assertEquals(expected, actualInt) + + val actualLong = LongProgression.fromClosedRange(start.toLong(), end.toLong(), increment.toLong()).last + assertEquals(expected.toLong(), actualLong) +} + +fun box() { + // start == end + for (x in INTERESTING) { + for (increment in INTERESTING) + if (increment != 0) { + doTest(x, x, increment, x) + } + } + + // increment == 1 + for (start in INTERESTING.indices) { + for (end in start..INTERESTING.size - 1) { + doTest(INTERESTING[start], INTERESTING[end], 1, INTERESTING[end]) + } + } + + // increment == -1 + for (end in INTERESTING.indices) { + for (start in end..INTERESTING.size - 1) { + doTest(INTERESTING[start], INTERESTING[end], -1, INTERESTING[end]) + } + } + + // end == MAX + doTest(0, MAX, MAX, MAX) + doTest(0, MAX, MAX / 2, MAX - 1) + doTest(MIN + 1, MAX, MAX, MAX) + doTest(MAX - 7, MAX, 3, MAX - 1) + doTest(MAX - 7, MAX, MAX, MAX - 7) + + // end == MIN + doTest(0, MIN, MIN, MIN) + doTest(0, MIN, MIN / 2, MIN) + doTest(MAX, MIN, MIN, -1) + doTest(MIN + 7, MIN, -3, MIN + 1) + doTest(MIN + 7, MIN, MIN, MIN + 7) +} diff --git a/backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/iterateToFinalElement.kt b/backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/iterateToFinalElement.kt new file mode 100644 index 00000000000..fe735460ae3 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/iterateToFinalElement.kt @@ -0,0 +1,41 @@ +import kotlin.test.* +import kotlin.comparisons.* +import kotlin.test.assertEquals + +private val MAX = Int.MAX_VALUE +private val MIN = Int.MIN_VALUE + +private val INTERESTING = intArrayOf(MIN, MIN / 2, -239, -23, -1, 0, 1, 42, 239, MAX / 2, MAX) + +private fun doTest(start: Int, end: Int, increment: Int, expected: Int) { + + val actualInt = IntProgression.fromClosedRange(start, end, increment).last + assertEquals(expected, actualInt) + + val actualLong = LongProgression.fromClosedRange(start.toLong(), end.toLong(), increment.toLong()).last + assertEquals(expected.toLong(), actualLong) +} + +fun box() { + // Small tests + for (start in -5..4) { + for (end in -5..4) { + for (increment in -10..9) { + // Cut down incorrect test data + if (increment == 0) continue + if (increment > 0 != start <= end) continue + + // Iterate over the progression and obtain the expected result + // println("$start,$end,$increment") + var x = start + while (true) { + val next = x + increment + if (next !in minOf(start, end)..maxOf(start, end)) break + x = next + } + + doTest(start, end, increment, x) + } + } + } +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyConstant.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyConstant.kt new file mode 100644 index 00000000000..964fc692503 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyConstant.kt @@ -0,0 +1,91 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(IntRange.EMPTY, 1, 0, 1, listOf()) + doTest(LongRange.EMPTY, 1.toLong(), 0.toLong(), 1.toLong(), listOf()) + + doTest(CharRange.EMPTY, 1.toChar(), 0.toChar(), 1, listOf()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyDownto.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyDownto.kt new file mode 100644 index 00000000000..e9272132279 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyDownto.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(5 downTo 10, 5, 10, -1, listOf()) + doTest(5.toByte() downTo 10.toByte(), 5, 10, -1, listOf()) + doTest(5.toShort() downTo 10.toShort(), 5, 10, -1, listOf()) + doTest(5.toLong() downTo 10.toLong(), 5.toLong(), 10.toLong(), -1.toLong(), listOf()) + + doTest('a' downTo 'z', 'a', 'z', -1, listOf()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyRange.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyRange.kt new file mode 100644 index 00000000000..3b8059c7400 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyRange.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(10..5, 10, 5, 1, listOf()) + doTest(10.toByte()..(-5).toByte(), 10, (-5), 1, listOf()) + doTest(10.toShort()..(-5).toShort(), 10, (-5), 1, listOf()) + doTest(10.toLong()..-5.toLong(), 10.toLong(), -5.toLong(), 1.toLong(), listOf()) + + doTest('z'..'a', 'z', 'a', 1, listOf()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedDownTo.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedDownTo.kt new file mode 100644 index 00000000000..683543c95b0 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedDownTo.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(8 downTo 3 step 2, 8, 4, -2, listOf(8, 6, 4)) + doTest(8.toByte() downTo 3.toByte() step 2, 8, 4, -2, listOf(8, 6, 4)) + doTest(8.toShort() downTo 3.toShort() step 2, 8, 4, -2, listOf(8, 6, 4)) + doTest(8.toLong() downTo 3.toLong() step 2.toLong(), 8.toLong(), 4.toLong(), -2.toLong(), listOf(8, 6, 4)) + + doTest('d' downTo 'a' step 2, 'd', 'b', -2, listOf('d', 'b')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedRange.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedRange.kt new file mode 100644 index 00000000000..96f941f39f0 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedRange.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(3..8 step 2, 3, 7, 2, listOf(3, 5, 7)) + doTest(3.toByte()..8.toByte() step 2, 3, 7, 2, listOf(3, 5, 7)) + doTest(3.toShort()..8.toShort() step 2, 3, 7, 2, listOf(3, 5, 7)) + doTest(3.toLong()..8.toLong() step 2.toLong(), 3.toLong(), 7.toLong(), 2.toLong(), listOf(3, 5, 7)) + + doTest('a'..'d' step 2, 'a', 'c', 2, listOf('a', 'c')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementDownTo.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementDownTo.kt new file mode 100644 index 00000000000..12b5e1d944e --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementDownTo.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(5 downTo 5, 5, 5, -1, listOf(5)) + doTest(5.toByte() downTo 5.toByte(), 5, 5, -1, listOf(5)) + doTest(5.toShort() downTo 5.toShort(), 5, 5, -1, listOf(5)) + doTest(5.toLong() downTo 5.toLong(), 5.toLong(), 5.toLong(), -1.toLong(), listOf(5.toLong())) + + doTest('k' downTo 'k', 'k', 'k', -1, listOf('k')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementRange.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementRange.kt new file mode 100644 index 00000000000..992c112948b --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementRange.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(5..5, 5, 5, 1, listOf(5)) + doTest(5.toByte()..5.toByte(), 5, 5, 1, listOf(5)) + doTest(5.toShort()..5.toShort(), 5, 5, 1, listOf(5)) + doTest(5.toLong()..5.toLong(), 5.toLong(), 5.toLong(), 1.toLong(), listOf(5.toLong())) + + doTest('k'..'k', 'k', 'k', 1, listOf('k')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/openRange.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/openRange.kt new file mode 100644 index 00000000000..bc01d09f2a7 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/openRange.kt @@ -0,0 +1,92 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(1 until 5, 1, 4, 1, listOf(1, 2, 3, 4)) + doTest(1.toByte() until 5.toByte(), 1, 4, 1, listOf(1, 2, 3, 4)) + doTest(1.toShort() until 5.toShort(), 1, 4, 1, listOf(1, 2, 3, 4)) + doTest(1.toLong() until 5.toLong(), 1L, 4L, 1L, listOf(1, 2, 3, 4)) + doTest('a' until 'd', 'a', 'c', 1, listOf('a', 'b', 'c')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedBackSequence.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedBackSequence.kt new file mode 100644 index 00000000000..d68e8190f81 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedBackSequence.kt @@ -0,0 +1,103 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest((5 downTo 3).reversed(), 3, 5, 1, listOf(3, 4, 5)) + doTest((5.toByte() downTo 3.toByte()).reversed(), 3, 5, 1, listOf(3, 4, 5)) + doTest((5.toShort() downTo 3.toShort()).reversed(), 3, 5, 1, listOf(3, 4, 5)) + doTest((5.toLong() downTo 3.toLong()).reversed(), 3.toLong(), 5.toLong(), 1.toLong(), listOf(3, 4, 5)) + + doTest(('c' downTo 'a').reversed(), 'a', 'c', 1, listOf('a', 'b', 'c')) + +} + +fun reversedSimpleSteppedRange() { + doTest((3..9 step 2).reversed(), 9, 3, -2, listOf(9, 7, 5, 3)) + doTest((3.toByte()..9.toByte() step 2).reversed(), 9, 3, -2, listOf(9, 7, 5, 3)) + doTest((3.toShort()..9.toShort() step 2).reversed(), 9, 3, -2, listOf(9, 7, 5, 3)) + doTest((3.toLong()..9.toLong() step 2.toLong()).reversed(), 9.toLong(), 3.toLong(), -2.toLong(), listOf(9, 7, 5, 3)) + + doTest(('c'..'g' step 2).reversed(), 'g', 'c', -2, listOf('g', 'e', 'c')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyBackSequence.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyBackSequence.kt new file mode 100644 index 00000000000..5e52dcf3af9 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyBackSequence.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest((3 downTo 5).reversed(), 5, 3, 1, listOf()) + doTest((3.toByte() downTo 5.toByte()).reversed(), 5, 3, 1, listOf()) + doTest((3.toShort() downTo 5.toShort()).reversed(), 5, 3, 1, listOf()) + doTest((3.toLong() downTo 5.toLong()).reversed(), 5.toLong(), 3.toLong(), 1.toLong(), listOf()) + + doTest(('a' downTo 'c').reversed(), 'c', 'a', 1, listOf()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyRange.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyRange.kt new file mode 100644 index 00000000000..f5cbe91e8c9 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyRange.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest((5..3).reversed(), 3, 5, -1, listOf()) + doTest((5.toByte()..3.toByte()).reversed(), 3, 5, -1, listOf()) + doTest((5.toShort()..3.toShort()).reversed(), 3, 5, -1, listOf()) + doTest((5.toLong()..3.toLong()).reversed(), 3.toLong(), 5.toLong(), -1.toLong(), listOf()) + + doTest(('c'..'a').reversed(), 'a', 'c', -1, listOf()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedInexactSteppedDownTo.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedInexactSteppedDownTo.kt new file mode 100644 index 00000000000..7ba92565ddd --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedInexactSteppedDownTo.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest((8 downTo 3 step 2).reversed(), 4, 8, 2, listOf(4, 6, 8)) + doTest((8.toByte() downTo 3.toByte() step 2).reversed(), 4, 8, 2, listOf(4, 6, 8)) + doTest((8.toShort() downTo 3.toShort() step 2).reversed(), 4, 8, 2, listOf(4, 6, 8)) + doTest((8.toLong() downTo 3.toLong() step 2.toLong()).reversed(), 4.toLong(), 8.toLong(), 2.toLong(), listOf(4, 6, 8)) + + doTest(('d' downTo 'a' step 2).reversed(), 'b', 'd', 2, listOf('b', 'd')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedRange.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedRange.kt new file mode 100644 index 00000000000..097fbdbdd4b --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedRange.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest((3..5).reversed(), 5, 3, -1, listOf(5, 4, 3)) + doTest((3.toByte()..5.toByte()).reversed(), 5, 3, -1, listOf(5, 4, 3)) + doTest((3.toShort()..5.toShort()).reversed(), 5, 3, -1, listOf(5, 4, 3)) + doTest((3.toLong()..5.toLong()).reversed(), 5.toLong(), 3.toLong(), -1.toLong(), listOf(5, 4, 3)) + + doTest(('a'..'c').reversed(), 'c', 'a', -1, listOf('c', 'b', 'a')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleDownTo.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleDownTo.kt new file mode 100644 index 00000000000..8970d51f2c7 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleDownTo.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(9 downTo 3, 9, 3, -1, listOf(9, 8, 7, 6, 5, 4, 3)) + doTest(9.toByte() downTo 3.toByte(), 9, 3, -1, listOf(9, 8, 7, 6, 5, 4, 3)) + doTest(9.toShort() downTo 3.toShort(), 9, 3, -1, listOf(9, 8, 7, 6, 5, 4, 3)) + doTest(9.toLong() downTo 3.toLong(), 9.toLong(), 3.toLong(), -1.toLong(), listOf(9, 8, 7, 6, 5, 4, 3)) + + doTest('g' downTo 'c', 'g', 'c', -1, listOf('g', 'f', 'e', 'd', 'c')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleRange.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleRange.kt new file mode 100644 index 00000000000..79348c9f871 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleRange.kt @@ -0,0 +1,103 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(3..9, 3, 9, 1, listOf(3, 4, 5, 6, 7, 8, 9)) + doTest(3.toByte()..9.toByte(), 3, 9, 1, listOf(3, 4, 5, 6, 7, 8, 9)) + doTest(3.toShort()..9.toShort(), 3, 9, 1, listOf(3, 4, 5, 6, 7, 8, 9)) + doTest(3.toLong()..9.toLong(), 3.toLong(), 9.toLong(), 1.toLong(), listOf(3, 4, 5, 6, 7, 8, 9)) + + doTest('c'..'g', 'c', 'g', 1, listOf('c', 'd', 'e', 'f', 'g')) +} + + +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, 9, 1, listOf(3, 4, 5, 6, 7, 8, 9)) + doTest((1.toShort() + 2.toShort()).toShort()..(10.toShort() - 1.toShort()).toShort(), 3, 9, 1, listOf(3, 4, 5, 6, 7, 8, 9)) + doTest((1.toLong() + 2.toLong())..(10.toLong() - 1.toLong()), 3.toLong(), 9.toLong(), 1.toLong(), listOf(3, 4, 5, 6, 7, 8, 9)) + + doTest(("ace"[1])..("age"[1]), 'c', 'g', 1, listOf('c', 'd', 'e', 'f', 'g')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedDownTo.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedDownTo.kt new file mode 100644 index 00000000000..cae5d83366c --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedDownTo.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(9 downTo 3 step 2, 9, 3, -2, listOf(9, 7, 5, 3)) + doTest(9.toByte() downTo 3.toByte() step 2, 9, 3, -2, listOf(9, 7, 5, 3)) + doTest(9.toShort() downTo 3.toShort() step 2, 9, 3, -2, listOf(9, 7, 5, 3)) + doTest(9.toLong() downTo 3.toLong() step 2.toLong(), 9.toLong(), 3.toLong(), -2.toLong(), listOf(9, 7, 5, 3)) + + doTest('g' downTo 'c' step 2, 'g', 'c', -2, listOf('g', 'e', 'c')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedRange.kt b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedRange.kt new file mode 100644 index 00000000000..958c1ac268d --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedRange.kt @@ -0,0 +1,93 @@ +import kotlin.test.* + +fun compare(expected: T, actual: T, block: CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(message: String = "", getter: T.() -> P) { + assertEquals(expected.getter(), actual.getter(), message) + } + + public fun propertyFails(getter: T.() -> Unit) { + assertFailEquals({ expected.getter() }, { actual.getter() }) + } + + public fun

compareProperty(getter: T.() -> P, block: CompareContext

.() -> Unit) { + compare(expected.getter(), actual.getter(), block) + } + + private fun assertFailEquals(expected: () -> Unit, actual: () -> Unit) { + val expectedFail = assertFails(expected) + val actualFail = assertFails(actual) + //assertEquals(expectedFail != null, actualFail != null) + assertTypeEquals(expectedFail, actualFail) + } +} + +fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun doTest( + sequence: Iterable, + expectedFirst: N, + expectedLast: N, + expectedIncrement: Number, + expectedElements: List +) { + val first: Any + val last: Any + val increment: Number + when (sequence) { + is IntProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is LongProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + is CharProgression -> { + first = sequence.first + last = sequence.last + increment = sequence.step + } + else -> throw IllegalArgumentException("Unsupported sequence type: $sequence") + } + + assertEquals(expectedFirst, first) + assertEquals(expectedLast, last) + assertEquals(expectedIncrement, increment) + + if (expectedElements.isEmpty()) + assertTrue(sequence.none()) + else + assertEquals(expectedElements, sequence.toList()) + + compare(expectedElements.iterator(), sequence.iterator()) { + iteratorBehavior() + } +} + +fun box() { + doTest(3..9 step 2, 3, 9, 2, listOf(3, 5, 7, 9)) + doTest(3.toByte()..9.toByte() step 2, 3, 9, 2, listOf(3, 5, 7, 9)) + doTest(3.toShort()..9.toShort() step 2, 3, 9, 2, listOf(3, 5, 7, 9)) + doTest(3.toLong()..9.toLong() step 2.toLong(), 3.toLong(), 9.toLong(), 2.toLong(), listOf(3, 5, 7, 9)) + + doTest('c'..'g' step 2, 'c', 'g', 2, listOf('c', 'e', 'g')) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/byteRange.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/byteRange.kt new file mode 100644 index 00000000000..41de87a0def --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/byteRange.kt @@ -0,0 +1,37 @@ +import kotlin.test.* + + +fun box() { + val range = (-5).toByte()..9.toByte() + assertFalse((-100).toByte() in range) + assertFalse((-6).toByte() in range) + + assertTrue((-5).toByte() in range) + assertTrue((-4).toByte() in range) + assertTrue(0.toByte() in range) + assertTrue(3.toByte() in range) + assertTrue(8.toByte() in range) + assertTrue(9.toByte() in range) + + assertFalse(10.toByte() in range) + assertFalse(111.toByte() in range) + + assertFalse(range.isEmpty()) + + + assertTrue(1.toShort() in range) + assertTrue(1.toInt() in range) + assertTrue(1.toLong() in range) + assertTrue(1.toFloat() in range) + assertTrue(1.toDouble() in range) + + assertFalse(Long.MAX_VALUE in range) + + val openRange = 1.toByte() until 10.toByte() + assertTrue(9.toByte() in openRange) + assertFalse(10.toByte() in openRange) + + // byte arguments now construct IntRange so no overflow here + assertTrue((0.toByte() until Byte.MIN_VALUE).isEmpty()) + assertTrue((0.toByte() until Int.MIN_VALUE).isEmpty()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/charRange.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/charRange.kt new file mode 100644 index 00000000000..c83788d641d --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/charRange.kt @@ -0,0 +1,29 @@ +import kotlin.test.* + + +fun box() { + val range = 'c'..'w' + assertFalse('0' in range) + assertFalse('b' in range) + + assertTrue('c' in range) + assertTrue('d' in range) + assertTrue('h' in range) + assertTrue('m' in range) + assertTrue('v' in range) + assertTrue('w' in range) + + assertFalse('z' in range) + assertFalse('\u1000' in range) + + assertFalse(range.isEmpty()) + + assertTrue('v' in (range as ClosedRange)) + assertFalse((range as ClosedRange).isEmpty()) + + val openRange = 'A' until 'Z' + assertTrue('Y' in openRange) + assertFalse('Z' in openRange) + + assertTrue(('A' until '\u0000').isEmpty()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/comparableRange.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/comparableRange.kt new file mode 100644 index 00000000000..0b235a8a407 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/comparableRange.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + + +fun box() { + val range = "island".."isle" + assertFalse("apple" in range) + assertFalse("icicle" in range) + + assertTrue("island" in range) + assertTrue("isle" in range) + assertTrue("islandic" in range) + + assertFalse("item" in range) + assertFalse("trail" in range) + + assertFalse(range.isEmpty()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/doubleRange.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/doubleRange.kt new file mode 100644 index 00000000000..fb90643568f --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/doubleRange.kt @@ -0,0 +1,48 @@ +import kotlin.test.* + + +fun box() { + val range = -1.0..3.14159265358979 + assertFalse(-1e200 in range) + assertFalse(-100.0 in range) + assertFalse(-1.00000000001 in range) + + assertTrue(-1.0 in range) + assertTrue(-0.99999999999 in range) + assertTrue(0.0 in range) + assertTrue(1.5 in range) + assertTrue(3.1415 in range) + assertTrue(3.14159265358979 in range) + + assertFalse(3.15 in range) + assertFalse(10.0 in range) + assertFalse(1e200 in range) + + assertFalse(range.isEmpty()) + + assertTrue(1.toByte() in range) + assertTrue(1.toShort() in range) + assertTrue(1.toInt() in range) + assertTrue(1.toLong() in range) + assertTrue(1.toFloat() in range) + + val zeroRange = 0.0..-0.0 + assertFalse(zeroRange.isEmpty()) + assertTrue(-0.0 in zeroRange) + assertTrue(-0.0F in zeroRange) + val normalZeroRange = -0.0..0.0 + assertEquals(zeroRange, normalZeroRange) + assertEquals(zeroRange.hashCode(), normalZeroRange.hashCode()) + + val nanRange = 0.0..Double.NaN + assertFalse(1.0 in nanRange) + assertFalse(Double.NaN in nanRange) + assertFalse(Float.NaN in nanRange) + assertTrue(nanRange.isEmpty()) + + val halfInfRange = 0.0..Double.POSITIVE_INFINITY + assertTrue(Double.POSITIVE_INFINITY in halfInfRange) + assertFalse(Double.NEGATIVE_INFINITY in halfInfRange) + assertFalse(Double.NaN in halfInfRange) + assertTrue(Float.POSITIVE_INFINITY in halfInfRange) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/emptyEquals.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/emptyEquals.kt new file mode 100644 index 00000000000..7807b033ccd --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/emptyEquals.kt @@ -0,0 +1,27 @@ +import kotlin.test.* + + +fun box() { + assertTrue(IntRange.EMPTY == IntRange.EMPTY) + assertEquals(IntRange.EMPTY, IntRange.EMPTY) + assertEquals(0L..42L, 0L..42L) + assertEquals(0L..4200000042000000L, 0L..4200000042000000L) + assertEquals(3 downTo 0, 3 downTo 0) + + assertEquals(2..1, 1..0) + assertEquals(2L..1L, 1L..0L) + assertEquals(2.toShort()..1.toShort(), 1.toShort()..0.toShort()) + assertEquals(2.toByte()..1.toByte(), 1.toByte()..0.toByte()) + assertEquals(0f..-3.14f, 3.14f..0f) + assertEquals(-2.0..-3.0, 3.0..2.0) + assertEquals('b'..'a', 'c'..'b') + + assertTrue(1 downTo 2 == 2 downTo 3) + assertTrue(-1L downTo 0L == -2L downTo -1L) + assertEquals('j'..'a' step 4, 'u'..'q' step 2) + + assertFalse(0..1 == IntRange.EMPTY) + + assertEquals("range".."progression", "hashcode".."equals") + assertFalse(("aa".."bb") == ("aaa".."bbb")) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/emptyHashCode.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/emptyHashCode.kt new file mode 100644 index 00000000000..07a4f40ead3 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/emptyHashCode.kt @@ -0,0 +1,21 @@ +import kotlin.test.* + + +fun box() { + assertEquals((0..42).hashCode(), (0..42).hashCode()) + assertEquals((1.23..4.56).hashCode(), (1.23..4.56).hashCode()) + + assertEquals((0..-1).hashCode(), IntRange.EMPTY.hashCode()) + assertEquals((2L..1L).hashCode(), (1L..0L).hashCode()) + assertEquals((0.toShort()..-1.toShort()).hashCode(), (42.toShort()..0.toShort()).hashCode()) + assertEquals((0.toByte()..-1.toByte()).hashCode(), (42.toByte()..0.toByte()).hashCode()) + assertEquals((0f..-3.14f).hashCode(), (2.39f..1.41f).hashCode()) + assertEquals((0.0..-10.0).hashCode(), (10.0..0.0).hashCode()) + assertEquals(('z'..'x').hashCode(), ('l'..'k').hashCode()) + + assertEquals((1 downTo 2).hashCode(), (2 downTo 3).hashCode()) + assertEquals((1L downTo 2L).hashCode(), (2L downTo 3L).hashCode()) + assertEquals(('a' downTo 'b').hashCode(), ('c' downTo 'd').hashCode()) + + assertEquals(("range".."progression").hashCode(), ("hashcode".."equals").hashCode()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/floatRange.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/floatRange.kt new file mode 100644 index 00000000000..dc98c1fab69 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/floatRange.kt @@ -0,0 +1,49 @@ +import kotlin.test.* + + +fun box() { + val range = -1.0f..3.14159f + assertFalse(-1e30f in range) + assertFalse(-100.0f in range) + assertFalse(-1.00001f in range) + + assertTrue(-1.0f in range) + assertTrue(-0.99999f in range) + assertTrue(0.0f in range) + assertTrue(1.5f in range) + assertTrue(3.1415f in range) + assertTrue(3.14159f in range) + + assertFalse(3.15f in range) + assertFalse(10.0f in range) + assertFalse(1e30f in range) + + assertFalse(range.isEmpty()) + + assertTrue(1.toByte() in range) + assertTrue(1.toShort() in range) + assertTrue(1.toInt() in range) + assertTrue(1.toLong() in range) + assertTrue(1.toDouble() in range) + + assertFalse(Double.MAX_VALUE in range) + + val zeroRange = 0.0F..-0.0F + assertFalse(zeroRange.isEmpty()) + assertTrue(-0.0F in zeroRange) + val normalZeroRange = -0.0F..0.0F + assertEquals(zeroRange, normalZeroRange) + assertEquals(zeroRange.hashCode(), normalZeroRange.hashCode()) + + val nanRange = 0.0F..Float.NaN + assertFalse(1.0F in nanRange) + assertFalse(Float.NaN in nanRange) + assertTrue(nanRange.isEmpty()) + + val halfInfRange = 0.0F..Float.POSITIVE_INFINITY + assertTrue(Float.POSITIVE_INFINITY in halfInfRange) + assertFalse(Float.NEGATIVE_INFINITY in halfInfRange) + assertFalse(Float.NaN in halfInfRange) + assertTrue(Double.POSITIVE_INFINITY in halfInfRange) + assertTrue(Double.MAX_VALUE in halfInfRange) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/intRange.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/intRange.kt new file mode 100644 index 00000000000..b7ec53be94b --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/intRange.kt @@ -0,0 +1,37 @@ +import kotlin.test.* + + +fun box() { + val range = -5..9 + assertFalse(-1000 in range) + assertFalse(-6 in range) + + assertTrue(-5 in range) + assertTrue(-4 in range) + assertTrue(0 in range) + assertTrue(3 in range) + assertTrue(8 in range) + assertTrue(9 in range) + + assertFalse(10 in range) + assertFalse(9000 in range) + + assertFalse(range.isEmpty()) + + assertTrue(9 in (range as ClosedRange)) + assertFalse((range as ClosedRange).isEmpty()) + + assertTrue(1.toShort() in range) + assertTrue(1.toByte() in range) + assertTrue(1.toLong() in range) + assertTrue(1.toFloat() in range) + assertTrue(1.toDouble() in range) + + assertFalse(Long.MAX_VALUE in range) + + val openRange = 1 until 10 + assertTrue(9 in openRange) + assertFalse(10 in openRange) + + assertTrue((1 until Int.MIN_VALUE).isEmpty()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/isEmpty.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/isEmpty.kt new file mode 100644 index 00000000000..043490e81f2 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/isEmpty.kt @@ -0,0 +1,21 @@ +import kotlin.test.* + + +fun box() { + assertTrue((2..1).isEmpty()) + assertTrue((2L..0L).isEmpty()) + assertTrue((1.toShort()..-1.toShort()).isEmpty()) + assertTrue((0.toByte()..-1.toByte()).isEmpty()) + assertTrue((0f..-3.14f).isEmpty()) + assertTrue((-2.72..-3.14).isEmpty()) + assertTrue(('z'..'x').isEmpty()) + + assertTrue((1 downTo 2).isEmpty()) + assertTrue((0L downTo 2L).isEmpty()) + assertFalse((2 downTo 1).isEmpty()) + assertFalse((2L downTo 0L).isEmpty()) + assertTrue(('a' downTo 'z').isEmpty()) + assertTrue(('z'..'a' step 2).isEmpty()) + + assertTrue(("range".."progression").isEmpty()) +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/longRange.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/longRange.kt new file mode 100644 index 00000000000..b90455475a7 --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/longRange.kt @@ -0,0 +1,39 @@ +import kotlin.test.* + + +fun box() { + val range = -5L..9L + assertFalse(-10000000L in range) + assertFalse(-6L in range) + + assertTrue(-5L in range) + assertTrue(-4L in range) + assertTrue(0L in range) + assertTrue(3L in range) + assertTrue(8L in range) + assertTrue(9L in range) + + assertFalse(10L in range) + assertFalse(10000000L in range) + + assertFalse(range.isEmpty()) + + assertTrue(9 in (range as ClosedRange)) + assertFalse((range as ClosedRange).isEmpty()) + + assertTrue(1.toByte() in range) + assertTrue(1.toShort() in range) + assertTrue(1.toInt() in range) + assertTrue(1.toFloat() in range) + assertTrue(1.toDouble() in range) + + assertFalse(Double.MAX_VALUE in range) + + val openRange = 1L until 10L + assertTrue(9L in openRange) + assertFalse(10L in openRange) + + assertTrue((0 until Long.MIN_VALUE).isEmpty()) + assertTrue((0L until Long.MIN_VALUE).isEmpty()) + +} diff --git a/backend.native/tests/external/stdlib/ranges/RangeTest/shortRange.kt b/backend.native/tests/external/stdlib/ranges/RangeTest/shortRange.kt new file mode 100644 index 00000000000..b6106b813ff --- /dev/null +++ b/backend.native/tests/external/stdlib/ranges/RangeTest/shortRange.kt @@ -0,0 +1,35 @@ +import kotlin.test.* + + +fun box() { + val range = (-5).toShort()..9.toShort() + assertFalse((-1000).toShort() in range) + assertFalse((-6).toShort() in range) + + assertTrue((-5).toShort() in range) + assertTrue((-4).toShort() in range) + assertTrue(0.toShort() in range) + assertTrue(3.toShort() in range) + assertTrue(8.toShort() in range) + assertTrue(9.toShort() in range) + + assertFalse(10.toShort() in range) + assertFalse(239.toShort() in range) + + assertFalse(range.isEmpty()) + + assertTrue(1.toByte() in range) + assertTrue(1.toInt() in range) + assertTrue(1.toLong() in range) + assertTrue(1.toFloat() in range) + assertTrue(1.toDouble() in range) + + assertFalse(Long.MAX_VALUE in range) + + val openRange = 1.toShort() until 10.toShort() + assertTrue(9.toShort() in openRange) + assertFalse(10.toShort() in openRange) + + assertTrue((0.toShort() until Short.MIN_VALUE).isEmpty()) + assertTrue((0.toShort() until Int.MIN_VALUE).isEmpty()) +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/escapeLiteral.kt b/backend.native/tests/external/stdlib/text/RegexTest/escapeLiteral.kt new file mode 100644 index 00000000000..61763313388 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/escapeLiteral.kt @@ -0,0 +1,10 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val literal = """[-\/\\^$*+?.()|[\]{}]""" + assertTrue(Regex.fromLiteral(literal).matches(literal)) + assertTrue(Regex.escape(literal).toRegex().matches(literal)) +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/matchAllSequence.kt b/backend.native/tests/external/stdlib/text/RegexTest/matchAllSequence.kt new file mode 100644 index 00000000000..bde9c623951 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/matchAllSequence.kt @@ -0,0 +1,13 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val input = "test" + val pattern = ".*".toRegex() + val matches = pattern.findAll(input).toList() + assertEquals(input, matches[0].value) + assertEquals(input, matches.joinToString("") { it.value }) + assertEquals(2, matches.size) +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/matchEntire.kt b/backend.native/tests/external/stdlib/text/RegexTest/matchEntire.kt new file mode 100644 index 00000000000..b02771a0a7a --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/matchEntire.kt @@ -0,0 +1,15 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val regex = "(\\d)(\\w)".toRegex() + + assertNull(regex.matchEntire("1a 2b")) + assertNotNull(regex.matchEntire("3c")) { m -> + assertEquals("3c", m.value) + assertEquals(3, m.groups.size) + assertEquals(listOf("3c", "3", "c"), m.groups.map { it!!.value }) + } +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/matchEntireLazyQuantor.kt b/backend.native/tests/external/stdlib/text/RegexTest/matchEntireLazyQuantor.kt new file mode 100644 index 00000000000..938aba7d5ed --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/matchEntireLazyQuantor.kt @@ -0,0 +1,12 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val regex = "a+b+?".toRegex() + val input = StringBuilder("aaaabbbb") + + assertEquals("aaaab", regex.find(input)!!.value) + assertEquals("aaaabbbb", regex.matchEntire(input)!!.value) +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/matchGroups.kt b/backend.native/tests/external/stdlib/text/RegexTest/matchGroups.kt new file mode 100644 index 00000000000..272670c522c --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/matchGroups.kt @@ -0,0 +1,38 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val input = "1a 2b 3c" + val pattern = "(\\d)(\\w)".toRegex() + + val matches = pattern.findAll(input).toList() + assertTrue(matches.all { it.groups.size == 3 }) + + matches[0].let { m -> + assertEquals("1a", m.groups[0]?.value) + assertEquals("1", m.groups[1]?.value) + assertEquals("a", m.groups[2]?.value) + + assertEquals(listOf("1a", "1", "a"), m.groupValues) + + val (g1, g2) = m.destructured + assertEquals("1", g1) + assertEquals("a", g2) + assertEquals(listOf("1", "a"), m.destructured.toList()) + } + + matches[1].let { m -> + assertEquals("2b", m.groups[0]?.value) + assertEquals("2", m.groups[1]?.value) + assertEquals("b", m.groups[2]?.value) + + assertEquals(listOf("2b", "2", "b"), m.groupValues) + + val (g1, g2) = m.destructured + assertEquals("2", g1) + assertEquals("b", g2) + assertEquals(listOf("2", "b"), m.destructured.toList()) + } +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/matchIgnoreCase.kt b/backend.native/tests/external/stdlib/text/RegexTest/matchIgnoreCase.kt new file mode 100644 index 00000000000..cc0cdca2371 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/matchIgnoreCase.kt @@ -0,0 +1,9 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + for (input in listOf("ascii", "shrödinger")) + assertTrue(input.toUpperCase().matches(input.toLowerCase().toRegex(RegexOption.IGNORE_CASE))) +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/matchMultiline.kt b/backend.native/tests/external/stdlib/text/RegexTest/matchMultiline.kt new file mode 100644 index 00000000000..7d88671d148 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/matchMultiline.kt @@ -0,0 +1,10 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val regex = "^[a-z]*$".toRegex(setOf(RegexOption.IGNORE_CASE, RegexOption.MULTILINE)) + val matchedValues = regex.findAll("test\n\nLine").map { it.value }.toList() + assertEquals(listOf("test", "", "Line"), matchedValues) +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/matchOptionalGroup.kt b/backend.native/tests/external/stdlib/text/RegexTest/matchOptionalGroup.kt new file mode 100644 index 00000000000..f6c7f76d02c --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/matchOptionalGroup.kt @@ -0,0 +1,34 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val pattern = "(hi)|(bye)".toRegex(RegexOption.IGNORE_CASE) + + pattern.find("Hi!")!!.let { m -> + assertEquals(3, m.groups.size) + assertEquals("Hi", m.groups[1]?.value) + assertEquals(null, m.groups[2]) + + assertEquals(listOf("Hi", "Hi", ""), m.groupValues) + + val (g1, g2) = m.destructured + assertEquals("Hi", g1) + assertEquals("", g2) + assertEquals(listOf("Hi", ""), m.destructured.toList()) + } + + pattern.find("bye...")!!.let { m -> + assertEquals(3, m.groups.size) + assertEquals(null, m.groups[1]) + assertEquals("bye", m.groups[2]?.value) + + assertEquals(listOf("bye", "", "bye"), m.groupValues) + + val (g1, g2) = m.destructured + assertEquals("", g1) + assertEquals("bye", g2) + assertEquals(listOf("", "bye"), m.destructured.toList()) + } +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/matchResult.kt b/backend.native/tests/external/stdlib/text/RegexTest/matchResult.kt new file mode 100644 index 00000000000..e677ff806c7 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/matchResult.kt @@ -0,0 +1,32 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val p = "\\d+".toRegex() + val input = "123 456 789" + + assertFalse(input matches p) + assertFalse(p matches input) + + assertTrue(p in input) + + val first = p.find(input) + assertTrue(first != null); first!! + assertEquals("123", first.value) + + val second1 = first.next()!! + val second2 = first.next()!! + + assertEquals("456", second1.value) + assertEquals(second1.value, second2.value) + + assertEquals("56", p.find(input, startIndex = 5)?.value) + + val last = second1.next()!! + assertEquals("789", last.value) + + val noMatch = last.next() + assertEquals(null, noMatch) +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/matchSequence.kt b/backend.native/tests/external/stdlib/text/RegexTest/matchSequence.kt new file mode 100644 index 00000000000..e13ce0e36e6 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/matchSequence.kt @@ -0,0 +1,18 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val input = "123 456 789" + val pattern = "\\d+".toRegex() + + val matches = pattern.findAll(input) + val values = matches.map { it.value } + val expected = listOf("123", "456", "789") + assertEquals(expected, values.toList()) + assertEquals(expected, values.toList(), "running match sequence second time") + assertEquals(expected.drop(1), pattern.findAll(input, startIndex = 3).map { it.value }.toList()) + + assertEquals(listOf(0..2, 4..6, 8..10), matches.map { it.range }.toList()) +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/replace.kt b/backend.native/tests/external/stdlib/text/RegexTest/replace.kt new file mode 100644 index 00000000000..a7ca638bd35 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/replace.kt @@ -0,0 +1,13 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val input = "123-456" + val pattern = "(\\d+)".toRegex() + assertEquals("(123)-(456)", pattern.replace(input, "($1)")) + + assertEquals("$&-$&", pattern.replace(input, Regex.escapeReplacement("$&"))) + assertEquals("X-456", pattern.replaceFirst(input, "X")) +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/replaceEvaluator.kt b/backend.native/tests/external/stdlib/text/RegexTest/replaceEvaluator.kt new file mode 100644 index 00000000000..514e65c851c --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/replaceEvaluator.kt @@ -0,0 +1,10 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val input = "/12/456/7890/" + val pattern = "\\d+".toRegex() + assertEquals("/2/3/4/", pattern.replace(input, { it.value.length.toString() } )) +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/split.kt b/backend.native/tests/external/stdlib/text/RegexTest/split.kt new file mode 100644 index 00000000000..2b13b629d4d --- /dev/null +++ b/backend.native/tests/external/stdlib/text/RegexTest/split.kt @@ -0,0 +1,16 @@ +import kotlin.text.* + +import kotlin.test.* + + +fun box() { + val input = """ + some ${"\t"} word + split + """.trim() + + assertEquals(listOf("some", "word", "split"), "\\s+".toRegex().split(input)) + + assertEquals(listOf("name", "value=5"), "=".toRegex().split("name=value=5", limit = 2)) + +} diff --git a/backend.native/tests/external/stdlib/text/StringBuilderTest/append.kt b/backend.native/tests/external/stdlib/text/StringBuilderTest/append.kt new file mode 100644 index 00000000000..0c2adc46acf --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringBuilderTest/append.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + + +fun box() { + // this test is needed for JS implementation + assertEquals("em", buildString { + append("element", 2, 4) + }) +} diff --git a/backend.native/tests/external/stdlib/text/StringBuilderTest/appendMany.kt b/backend.native/tests/external/stdlib/text/StringBuilderTest/appendMany.kt new file mode 100644 index 00000000000..b5f91142f1a --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringBuilderTest/appendMany.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + + +fun box() { + assertEquals("a1", StringBuilder().append("a", "1").toString()) + assertEquals("a1", StringBuilder().append("a", 1).toString()) + assertEquals("a1", StringBuilder().append("a", StringBuilder().append("1")).toString()) +} diff --git a/backend.native/tests/external/stdlib/text/StringBuilderTest/asCharSequence.kt b/backend.native/tests/external/stdlib/text/StringBuilderTest/asCharSequence.kt new file mode 100644 index 00000000000..ef758c22c6d --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringBuilderTest/asCharSequence.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + + +fun box() { + val original = "Some test string" + val sb = StringBuilder(original) + val result = sb.toString() + val cs = sb as CharSequence + + assertEquals(result.length, cs.length) + assertEquals(result.length, sb.length) + for (index in result.indices) { + assertEquals(result[index], sb[index]) + assertEquals(result[index], cs[index]) + } + assertEquals(result.substring(2, 6), cs.subSequence(2, 6).toString()) +} diff --git a/backend.native/tests/external/stdlib/text/StringBuilderTest/constructors.kt b/backend.native/tests/external/stdlib/text/StringBuilderTest/constructors.kt new file mode 100644 index 00000000000..0742a19718c --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringBuilderTest/constructors.kt @@ -0,0 +1,24 @@ +import kotlin.test.* + + +fun box() { + StringBuilder().let { sb -> + assertEquals(0, sb.length) + assertEquals("", sb.toString()) + } + + StringBuilder(16).let { sb -> + assertEquals(0, sb.length) + assertEquals("", sb.toString()) + } + + StringBuilder("content").let { sb -> + assertEquals(7, sb.length) + assertEquals("content", sb.toString()) + } + + StringBuilder(StringBuilder("content")).let { sb -> + assertEquals(7, sb.length) + assertEquals("content", sb.toString()) + } +} diff --git a/backend.native/tests/external/stdlib/text/StringBuilderTest/stringBuild.kt b/backend.native/tests/external/stdlib/text/StringBuilderTest/stringBuild.kt new file mode 100644 index 00000000000..4bb0ce865d9 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringBuilderTest/stringBuild.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + + +fun box() { + val s = buildString { + append("a") + append(true) + } + assertEquals("atrue", s) +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/byteToStringWithRadix.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/byteToStringWithRadix.kt new file mode 100644 index 00000000000..83266e98013 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/byteToStringWithRadix.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + + + +fun box() { + assertEquals("7a", 0x7a.toByte().toString(16)) + assertEquals("-80", Byte.MIN_VALUE.toString(radix = 16)) + assertEquals("3v", Byte.MAX_VALUE.toString(radix = 32)) + assertEquals("-40", Byte.MIN_VALUE.toString(radix = 32)) + + assertFailsWith("Expected to fail with radix 37") { 37.toByte().toString(radix = 37) } + assertFailsWith("Expected to fail with radix 1") { 1.toByte().toString(radix = 1) } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/intToStringWithRadix.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/intToStringWithRadix.kt new file mode 100644 index 00000000000..ef453768ea8 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/intToStringWithRadix.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + + +fun box() { + assertEquals("-ff", (-255).toString(radix = 16)) + assertEquals("1100110", 102.toString(radix = 2)) + assertEquals("kona", 411787.toString(radix = 27)) + assertFailsWith("Expected to fail with radix 37") { 37.toString(radix = 37) } + assertFailsWith("Expected to fail with radix 1") { 1.toString(radix = 1) } + +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/longToStringWithRadix.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/longToStringWithRadix.kt new file mode 100644 index 00000000000..4653ae8fa5b --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/longToStringWithRadix.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + + + +fun box() { + assertEquals("7f11223344556677", 0x7F11223344556677.toString(radix = 16)) + assertEquals("hazelnut", 1356099454469L.toString(radix = 36)) + assertEquals("-8000000000000000", Long.MIN_VALUE.toString(radix = 16)) + + assertFailsWith("Expected to fail with radix 37") { 37L.toString(radix = 37) } + assertFailsWith("Expected to fail with radix 1") { 1L.toString(radix = 1) } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/shortToStringWithRadix.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/shortToStringWithRadix.kt new file mode 100644 index 00000000000..49626ad5eae --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/shortToStringWithRadix.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + + + +fun box() { + assertEquals("7FFF", 0x7FFF.toShort().toString(radix = 16).toUpperCase()) + assertEquals("-8000", (-0x8000).toShort().toString(radix = 16)) + assertEquals("-sfs", (-29180).toShort().toString(radix = 32)) + + assertFailsWith("Expected to fail with radix 37") { 37.toShort().toString(radix = 37) } + assertFailsWith("Expected to fail with radix 1") { 1.toShort().toString(radix = 1) } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toBoolean.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toBoolean.kt new file mode 100644 index 00000000000..d5791e3d085 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toBoolean.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + +fun box() { + assertEquals(true, "true".toBoolean()) + assertEquals(true, "True".toBoolean()) + assertEquals(false, "false".toBoolean()) + assertEquals(false, "not so true".toBoolean()) +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toByte.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toByte.kt new file mode 100644 index 00000000000..637245e053d --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toByte.kt @@ -0,0 +1,69 @@ +import kotlin.test.* + + +private fun compareConversion(convertOrFail: (String) -> T, + convertOrNull: (String) -> T?, + equality: (T, T?) -> Boolean = { a, b -> a == b }, + assertions: ConversionContext.() -> Unit) { + ConversionContext(convertOrFail, convertOrNull, equality).assertions() +} + +private fun compareConversionWithRadix(convertOrFail: String.(Int) -> T, + convertOrNull: String.(Int) -> T?, + assertions: ConversionWithRadixContext.() -> Unit) { + ConversionWithRadixContext(convertOrFail, convertOrNull).assertions() +} + +private class ConversionContext(val convertOrFail: (String) -> T, + val convertOrNull: (String) -> T?, + val equality: (T, T?) -> Boolean) { + + private fun assertEquals(expected: T, actual: T?, input: String, operation: String) { + assertTrue(equality(expected, actual), "Expected $operation('$input') to produce $expected but was $actual") + } + + fun assertProduces(input: String, output: T) { + assertEquals(output, convertOrFail(input), input, "convertOrFail") + assertEquals(output, convertOrNull(input), input, "convertOrNull") + } + + fun assertFailsOrNull(input: String) { + assertFailsWith("Expected to fail on input \"$input\"") { convertOrFail(input) } + assertNull(convertOrNull(input), message = "On input \"$input\"") + } +} + +private class ConversionWithRadixContext(val convertOrFail: (String, Int) -> T, + val convertOrNull: (String, Int) -> T?) { + fun assertProduces(radix: Int, input: String, output: T) { + assertEquals(output, convertOrFail(input, radix)) + assertEquals(output, convertOrNull(input, radix)) + } + + fun assertFailsOrNull(radix: Int, input: String) { + assertFailsWith("Expected to fail on input \"$input\" with radix $radix", + { convertOrFail(input, radix) }) + + assertNull(convertOrNull(input, radix), message = "On input \"$input\" with radix $radix") + } +} + +fun box() { + compareConversion({it.toByte()}, {it.toByteOrNull()}) { + assertProduces("127", Byte.MAX_VALUE) + assertProduces("+77", 77.toByte()) + assertProduces("-128", Byte.MIN_VALUE) + assertFailsOrNull("128") + assertFailsOrNull("") + assertFailsOrNull(" ") + } + + compareConversionWithRadix(String::toByte, String::toByteOrNull) { + assertProduces(16, "7a", 0x7a.toByte()) + assertProduces(16, "+7F", 127.toByte()) + assertProduces(16, "-80", (-128).toByte()) + assertFailsOrNull(2, "10000000") + assertFailsOrNull(8, "") + assertFailsOrNull(8, " ") + } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toDouble.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toDouble.kt new file mode 100644 index 00000000000..bbd42cff709 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toDouble.kt @@ -0,0 +1,74 @@ +import kotlin.test.* + + +private fun compareConversion(convertOrFail: (String) -> T, + convertOrNull: (String) -> T?, + equality: (T, T?) -> Boolean = { a, b -> a == b }, + assertions: ConversionContext.() -> Unit) { + ConversionContext(convertOrFail, convertOrNull, equality).assertions() +} + + +private fun compareConversionWithRadix(convertOrFail: String.(Int) -> T, + convertOrNull: String.(Int) -> T?, + assertions: ConversionWithRadixContext.() -> Unit) { + ConversionWithRadixContext(convertOrFail, convertOrNull).assertions() +} + + +private class ConversionContext(val convertOrFail: (String) -> T, + val convertOrNull: (String) -> T?, + val equality: (T, T?) -> Boolean) { + + private fun assertEquals(expected: T, actual: T?, input: String, operation: String) { + assertTrue(equality(expected, actual), "Expected $operation('$input') to produce $expected but was $actual") + } + + fun assertProduces(input: String, output: T) { + assertEquals(output, convertOrFail(input), input, "convertOrFail") + assertEquals(output, convertOrNull(input), input, "convertOrNull") + } + + fun assertFailsOrNull(input: String) { + assertFailsWith("Expected to fail on input \"$input\"") { convertOrFail(input) } + assertNull(convertOrNull(input), message = "On input \"$input\"") + } +} + +private class ConversionWithRadixContext(val convertOrFail: (String, Int) -> T, + val convertOrNull: (String, Int) -> T?) { + fun assertProduces(radix: Int, input: String, output: T) { + assertEquals(output, convertOrFail(input, radix)) + assertEquals(output, convertOrNull(input, radix)) + } + + fun assertFailsOrNull(radix: Int, input: String) { + assertFailsWith("Expected to fail on input \"$input\" with radix $radix", + { convertOrFail(input, radix) }) + + assertNull(convertOrNull(input, radix), message = "On input \"$input\" with radix $radix") + } +} + +private fun doubleTotalOrderEquals(a: Any?, b: Any?) = a == b + +fun box() { + compareConversion(String::toDouble, String::toDoubleOrNull, ::doubleTotalOrderEquals) { + assertProduces("-77", -77.0) + assertProduces("77.", 77.0) + assertProduces("77.0", 77.0) + assertProduces("-1.77", -1.77) + assertProduces("+.77", 0.77) + assertProduces("\t-77 \n", -77.0) + assertProduces("7.7e1", 77.0) + assertProduces("+770e-1", 77.0) + + assertProduces("-NaN", -Double.NaN) + assertProduces("+Infinity", Double.POSITIVE_INFINITY) + + assertFailsOrNull("7..7") + assertFailsOrNull("007 not a number") + assertFailsOrNull("") + assertFailsOrNull(" ") + } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toFloat.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toFloat.kt new file mode 100644 index 00000000000..8e89c95eaf0 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toFloat.kt @@ -0,0 +1,63 @@ +import kotlin.test.* + + + +private fun compareConversion(convertOrFail: (String) -> T, + convertOrNull: (String) -> T?, + equality: (T, T?) -> Boolean = { a, b -> a == b }, + assertions: ConversionContext.() -> Unit) { + ConversionContext(convertOrFail, convertOrNull, equality).assertions() +} + + +private fun compareConversionWithRadix(convertOrFail: String.(Int) -> T, + convertOrNull: String.(Int) -> T?, + assertions: ConversionWithRadixContext.() -> Unit) { + ConversionWithRadixContext(convertOrFail, convertOrNull).assertions() +} + + +private class ConversionContext(val convertOrFail: (String) -> T, + val convertOrNull: (String) -> T?, + val equality: (T, T?) -> Boolean) { + + private fun assertEquals(expected: T, actual: T?, input: String, operation: String) { + assertTrue(equality(expected, actual), "Expected $operation('$input') to produce $expected but was $actual") + } + + fun assertProduces(input: String, output: T) { + assertEquals(output, convertOrFail(input), input, "convertOrFail") + assertEquals(output, convertOrNull(input), input, "convertOrNull") + } + + fun assertFailsOrNull(input: String) { + assertFailsWith("Expected to fail on input \"$input\"") { convertOrFail(input) } + assertNull(convertOrNull(input), message = "On input \"$input\"") + } +} + +private class ConversionWithRadixContext(val convertOrFail: (String, Int) -> T, + val convertOrNull: (String, Int) -> T?) { + fun assertProduces(radix: Int, input: String, output: T) { + assertEquals(output, convertOrFail(input, radix)) + assertEquals(output, convertOrNull(input, radix)) + } + + fun assertFailsOrNull(radix: Int, input: String) { + assertFailsWith("Expected to fail on input \"$input\" with radix $radix", + { convertOrFail(input, radix) }) + + assertNull(convertOrNull(input, radix), message = "On input \"$input\" with radix $radix") + } +} + +fun box() { + compareConversion(String::toFloat, String::toFloatOrNull) { + assertProduces("77.0", 77.0f) + assertProduces("-1e39", Float.NEGATIVE_INFINITY) + assertProduces("1000000000000000000000000000000000000000", Float.POSITIVE_INFINITY) + assertFailsOrNull("dark side") + assertFailsOrNull("") + assertFailsOrNull(" ") + } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toHexDouble.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toHexDouble.kt new file mode 100644 index 00000000000..f0f0d45f672 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toHexDouble.kt @@ -0,0 +1,62 @@ +import kotlin.test.* + + +private fun compareConversion(convertOrFail: (String) -> T, + convertOrNull: (String) -> T?, + equality: (T, T?) -> Boolean = { a, b -> a == b }, + assertions: ConversionContext.() -> Unit) { + ConversionContext(convertOrFail, convertOrNull, equality).assertions() +} + + +private fun compareConversionWithRadix(convertOrFail: String.(Int) -> T, + convertOrNull: String.(Int) -> T?, + assertions: ConversionWithRadixContext.() -> Unit) { + ConversionWithRadixContext(convertOrFail, convertOrNull).assertions() +} + + +private class ConversionContext(val convertOrFail: (String) -> T, + val convertOrNull: (String) -> T?, + val equality: (T, T?) -> Boolean) { + + private fun assertEquals(expected: T, actual: T?, input: String, operation: String) { + assertTrue(equality(expected, actual), "Expected $operation('$input') to produce $expected but was $actual") + } + + fun assertProduces(input: String, output: T) { + assertEquals(output, convertOrFail(input), input, "convertOrFail") + assertEquals(output, convertOrNull(input), input, "convertOrNull") + } + + fun assertFailsOrNull(input: String) { + assertFailsWith("Expected to fail on input \"$input\"") { convertOrFail(input) } + assertNull(convertOrNull(input), message = "On input \"$input\"") + } +} + +private class ConversionWithRadixContext(val convertOrFail: (String, Int) -> T, + val convertOrNull: (String, Int) -> T?) { + fun assertProduces(radix: Int, input: String, output: T) { + assertEquals(output, convertOrFail(input, radix)) + assertEquals(output, convertOrNull(input, radix)) + } + + fun assertFailsOrNull(radix: Int, input: String) { + assertFailsWith("Expected to fail on input \"$input\" with radix $radix", + { convertOrFail(input, radix) }) + + assertNull(convertOrNull(input, radix), message = "On input \"$input\" with radix $radix") + } +} + +private fun doubleTotalOrderEquals(a: Any?, b: Any?) = a == b + +fun box() { + compareConversion(String::toDouble, String::toDoubleOrNull, ::doubleTotalOrderEquals) { + assertProduces("0x77p1", (0x77 shl 1).toDouble()) + assertProduces("0x.77P8", 0x77.toDouble()) + + assertFailsOrNull("0x77e1") + } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toInt.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toInt.kt new file mode 100644 index 00000000000..acbee45e0ba --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toInt.kt @@ -0,0 +1,88 @@ +import kotlin.test.* + + +private fun compareConversion(convertOrFail: (String) -> T, + convertOrNull: (String) -> T?, + equality: (T, T?) -> Boolean = { a, b -> a == b }, + assertions: ConversionContext.() -> Unit) { + ConversionContext(convertOrFail, convertOrNull, equality).assertions() +} + + +private fun compareConversionWithRadix(convertOrFail: String.(Int) -> T, + convertOrNull: String.(Int) -> T?, + assertions: ConversionWithRadixContext.() -> Unit) { + ConversionWithRadixContext(convertOrFail, convertOrNull).assertions() +} + + +private class ConversionContext(val convertOrFail: (String) -> T, + val convertOrNull: (String) -> T?, + val equality: (T, T?) -> Boolean) { + + private fun assertEquals(expected: T, actual: T?, input: String, operation: String) { + assertTrue(equality(expected, actual), "Expected $operation('$input') to produce $expected but was $actual") + } + + fun assertProduces(input: String, output: T) { + assertEquals(output, convertOrFail(input), input, "convertOrFail") + assertEquals(output, convertOrNull(input), input, "convertOrNull") + } + + fun assertFailsOrNull(input: String) { + assertFailsWith("Expected to fail on input \"$input\"") { convertOrFail(input) } + assertNull(convertOrNull(input), message = "On input \"$input\"") + } +} + +private class ConversionWithRadixContext(val convertOrFail: (String, Int) -> T, + val convertOrNull: (String, Int) -> T?) { + fun assertProduces(radix: Int, input: String, output: T) { + assertEquals(output, convertOrFail(input, radix)) + assertEquals(output, convertOrNull(input, radix)) + } + + fun assertFailsOrNull(radix: Int, input: String) { + assertFailsWith("Expected to fail on input \"$input\" with radix $radix", + { convertOrFail(input, radix) }) + + assertNull(convertOrNull(input, radix), message = "On input \"$input\" with radix $radix") + } +} + +fun box() { + compareConversion({it.toInt()}, {it.toIntOrNull()}) { + assertProduces("77", 77) + assertProduces("+2147483647", Int.MAX_VALUE) + assertProduces("-2147483648", Int.MIN_VALUE) + + assertFailsOrNull("2147483648") + assertFailsOrNull("-2147483649") + assertFailsOrNull("239239kotlin") + assertFailsOrNull("") + assertFailsOrNull(" ") + } + + compareConversionWithRadix(String::toInt, String::toIntOrNull) { + assertProduces(10, "0", 0) + assertProduces(10, "473", 473) + assertProduces(10, "+42", 42) + assertProduces(10, "-0", 0) + assertProduces(10, "2147483647", 2147483647) + assertProduces(10, "-2147483648", -2147483648) + + assertProduces(16, "-FF", -255) + assertProduces(16, "-ff", -255) + assertProduces(2, "1100110", 102) + assertProduces(27, "Kona", 411787) + + assertFailsOrNull(10, "2147483648") + assertFailsOrNull(8, "99") + assertFailsOrNull(10, "Kona") + assertFailsOrNull(16, "") + assertFailsOrNull(16, " ") + } + + assertFailsWith("Expected to fail with radix 1") { "1".toInt(radix = 1) } + assertFailsWith("Expected to fail with radix 37") { "37".toIntOrNull(radix = 37) } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toIntArabicDigits.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toIntArabicDigits.kt new file mode 100644 index 00000000000..93cfb99a5b4 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toIntArabicDigits.kt @@ -0,0 +1,57 @@ +import kotlin.test.* + + +private fun compareConversion(convertOrFail: (String) -> T, + convertOrNull: (String) -> T?, + equality: (T, T?) -> Boolean = { a, b -> a == b }, + assertions: ConversionContext.() -> Unit) { + ConversionContext(convertOrFail, convertOrNull, equality).assertions() +} + + +private fun compareConversionWithRadix(convertOrFail: String.(Int) -> T, + convertOrNull: String.(Int) -> T?, + assertions: ConversionWithRadixContext.() -> Unit) { + ConversionWithRadixContext(convertOrFail, convertOrNull).assertions() +} + + +private class ConversionContext(val convertOrFail: (String) -> T, + val convertOrNull: (String) -> T?, + val equality: (T, T?) -> Boolean) { + + private fun assertEquals(expected: T, actual: T?, input: String, operation: String) { + assertTrue(equality(expected, actual), "Expected $operation('$input') to produce $expected but was $actual") + } + + fun assertProduces(input: String, output: T) { + assertEquals(output, convertOrFail(input), input, "convertOrFail") + assertEquals(output, convertOrNull(input), input, "convertOrNull") + } + + fun assertFailsOrNull(input: String) { + assertFailsWith("Expected to fail on input \"$input\"") { convertOrFail(input) } + assertNull(convertOrNull(input), message = "On input \"$input\"") + } +} + +private class ConversionWithRadixContext(val convertOrFail: (String, Int) -> T, + val convertOrNull: (String, Int) -> T?) { + fun assertProduces(radix: Int, input: String, output: T) { + assertEquals(output, convertOrFail(input, radix)) + assertEquals(output, convertOrNull(input, radix)) + } + + fun assertFailsOrNull(radix: Int, input: String) { + assertFailsWith("Expected to fail on input \"$input\" with radix $radix", + { convertOrFail(input, radix) }) + + assertNull(convertOrNull(input, radix), message = "On input \"$input\" with radix $radix") + } +} + +fun box() { + compareConversion({ it.toInt() }, { it.toIntOrNull() }) { + assertProduces("٢٣١٩٦٠", 231960) + } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLong.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLong.kt new file mode 100644 index 00000000000..6f8879d7490 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLong.kt @@ -0,0 +1,89 @@ +import kotlin.test.* + + +private fun compareConversion(convertOrFail: (String) -> T, + convertOrNull: (String) -> T?, + equality: (T, T?) -> Boolean = { a, b -> a == b }, + assertions: ConversionContext.() -> Unit) { + ConversionContext(convertOrFail, convertOrNull, equality).assertions() +} + + +private fun compareConversionWithRadix(convertOrFail: String.(Int) -> T, + convertOrNull: String.(Int) -> T?, + assertions: ConversionWithRadixContext.() -> Unit) { + ConversionWithRadixContext(convertOrFail, convertOrNull).assertions() +} + + +private class ConversionContext(val convertOrFail: (String) -> T, + val convertOrNull: (String) -> T?, + val equality: (T, T?) -> Boolean) { + + private fun assertEquals(expected: T, actual: T?, input: String, operation: String) { + assertTrue(equality(expected, actual), "Expected $operation('$input') to produce $expected but was $actual") + } + + fun assertProduces(input: String, output: T) { + assertEquals(output, convertOrFail(input), input, "convertOrFail") + assertEquals(output, convertOrNull(input), input, "convertOrNull") + } + + fun assertFailsOrNull(input: String) { + assertFailsWith("Expected to fail on input \"$input\"") { convertOrFail(input) } + assertNull(convertOrNull(input), message = "On input \"$input\"") + } +} + +private class ConversionWithRadixContext(val convertOrFail: (String, Int) -> T, + val convertOrNull: (String, Int) -> T?) { + fun assertProduces(radix: Int, input: String, output: T) { + assertEquals(output, convertOrFail(input, radix)) + assertEquals(output, convertOrNull(input, radix)) + } + + fun assertFailsOrNull(radix: Int, input: String) { + assertFailsWith("Expected to fail on input \"$input\" with radix $radix", + { convertOrFail(input, radix) }) + + assertNull(convertOrNull(input, radix), message = "On input \"$input\" with radix $radix") + } +} + +fun box() { + compareConversion({it.toLong()}, {it.toLongOrNull()}) { + assertProduces("77", 77.toLong()) + assertProduces("+9223372036854775807", Long.MAX_VALUE) + assertProduces("-9223372036854775808", Long.MIN_VALUE) + + assertFailsOrNull("9223372036854775808") + assertFailsOrNull("-9223372036854775809") + assertFailsOrNull("922337 75809") + assertFailsOrNull("92233,75809") + assertFailsOrNull("92233`75809") + assertFailsOrNull("-922337KOTLIN775809") + assertFailsOrNull("") + assertFailsOrNull(" ") + } + + compareConversionWithRadix(String::toLong, String::toLongOrNull) { + assertProduces(10, "0", 0L) + assertProduces(10, "473", 473L) + assertProduces(10, "+42", 42L) + assertProduces(10, "-0", 0L) + + assertProduces(16, "7F11223344556677", 0x7F11223344556677) + assertProduces(16, "+7faabbccddeeff00", 0x7faabbccddeeff00) + assertProduces(16, "-8000000000000000", Long.MIN_VALUE) + assertProduces(2, "1100110", 102L) + assertProduces(36, "Hazelnut", 1356099454469L) + + assertFailsOrNull(8, "99") + assertFailsOrNull(10, "Hazelnut") + assertFailsOrNull(4, "") + assertFailsOrNull(4, " ") + } + + assertFailsWith("Expected to fail with radix 37") { "37".toLong(radix = 37) } + assertFailsWith("Expected to fail with radix 1") { "1".toLongOrNull(radix = 1) } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLongArabicDigits.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLongArabicDigits.kt new file mode 100644 index 00000000000..4bc6bbd69ce --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLongArabicDigits.kt @@ -0,0 +1,34 @@ +import kotlin.test.* + + +private fun compareConversion(convertOrFail: (String) -> T, + convertOrNull: (String) -> T?, + equality: (T, T?) -> Boolean = { a, b -> a == b }, + assertions: ConversionContext.() -> Unit) { + ConversionContext(convertOrFail, convertOrNull, equality).assertions() +} + +private class ConversionContext(val convertOrFail: (String) -> T, + val convertOrNull: (String) -> T?, + val equality: (T, T?) -> Boolean) { + + private fun assertEquals(expected: T, actual: T?, input: String, operation: String) { + assertTrue(equality(expected, actual), "Expected $operation('$input') to produce $expected but was $actual") + } + + fun assertProduces(input: String, output: T) { + assertEquals(output, convertOrFail(input), input, "convertOrFail") + assertEquals(output, convertOrNull(input), input, "convertOrNull") + } + + fun assertFailsOrNull(input: String) { + assertFailsWith("Expected to fail on input \"$input\"") { convertOrFail(input) } + assertNull(convertOrNull(input), message = "On input \"$input\"") + } +} + +fun box() { + compareConversion({ it.toLong() }, { it.toLongOrNull() }) { + assertProduces("٢٣١٩٦٠٧٧٨٤٥٩", 231960778459) + } +} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toShort.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toShort.kt new file mode 100644 index 00000000000..07ceb33c0f0 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toShort.kt @@ -0,0 +1,70 @@ +import kotlin.test.* + + +private fun compareConversion(convertOrFail: (String) -> T, + convertOrNull: (String) -> T?, + equality: (T, T?) -> Boolean = { a, b -> a == b }, + assertions: ConversionContext.() -> Unit) { + ConversionContext(convertOrFail, convertOrNull, equality).assertions() +} + + +private fun compareConversionWithRadix(convertOrFail: String.(Int) -> T, + convertOrNull: String.(Int) -> T?, + assertions: ConversionWithRadixContext.() -> Unit) { + ConversionWithRadixContext(convertOrFail, convertOrNull).assertions() +} + + +private class ConversionContext(val convertOrFail: (String) -> T, + val convertOrNull: (String) -> T?, + val equality: (T, T?) -> Boolean) { + + private fun assertEquals(expected: T, actual: T?, input: String, operation: String) { + assertTrue(equality(expected, actual), "Expected $operation('$input') to produce $expected but was $actual") + } + + fun assertProduces(input: String, output: T) { + assertEquals(output, convertOrFail(input), input, "convertOrFail") + assertEquals(output, convertOrNull(input), input, "convertOrNull") + } + + fun assertFailsOrNull(input: String) { + assertFailsWith("Expected to fail on input \"$input\"") { convertOrFail(input) } + assertNull(convertOrNull(input), message = "On input \"$input\"") + } +} + +private class ConversionWithRadixContext(val convertOrFail: (String, Int) -> T, + val convertOrNull: (String, Int) -> T?) { + fun assertProduces(radix: Int, input: String, output: T) { + assertEquals(output, convertOrFail(input, radix)) + assertEquals(output, convertOrNull(input, radix)) + } + + fun assertFailsOrNull(radix: Int, input: String) { + assertFailsWith("Expected to fail on input \"$input\" with radix $radix", + { convertOrFail(input, radix) }) + + assertNull(convertOrNull(input, radix), message = "On input \"$input\" with radix $radix") + } +} + +fun box() { + compareConversion({it.toShort()}, {it.toShortOrNull()}) { + assertProduces("+77", 77.toShort()) + assertProduces("32767", Short.MAX_VALUE) + assertProduces("-32768", Short.MIN_VALUE) + assertFailsOrNull("+32768") + assertFailsOrNull("") + assertFailsOrNull(" ") + } + + compareConversionWithRadix(String::toShort, String::toShortOrNull) { + assertProduces(16, "7FFF", 0x7FFF.toShort()) + assertProduces(16, "-8000", (-0x8000).toShort()) + assertFailsOrNull(5, "10000000") + assertFailsOrNull(2, "") + assertFailsOrNull(2, " ") + } +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/capitalize.kt b/backend.native/tests/external/stdlib/text/StringTest/capitalize.kt new file mode 100644 index 00000000000..4721db51203 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/capitalize.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + + + +fun box() { + assertEquals("A", "A".capitalize()) + assertEquals("A", "a".capitalize()) + assertEquals("Abcd", "abcd".capitalize()) + assertEquals("Abcd", "Abcd".capitalize()) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/decapitalize.kt b/backend.native/tests/external/stdlib/text/StringTest/decapitalize.kt new file mode 100644 index 00000000000..96e21b9b6f4 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/decapitalize.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + + + +fun box() { + assertEquals("a", "A".decapitalize()) + assertEquals("a", "a".decapitalize()) + assertEquals("abcd", "abcd".decapitalize()) + assertEquals("abcd", "Abcd".decapitalize()) + assertEquals("uRL", "URL".decapitalize()) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/drop.kt b/backend.native/tests/external/stdlib/text/StringTest/drop.kt new file mode 100644 index 00000000000..14ed3cee3ff --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/drop.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + + + +fun box() { + val data = "abcd1234" + assertEquals("d1234", data.drop(3)) + assertFails { + data.drop(-2) + } + assertEquals("", data.drop(data.length + 5)) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/dropWhile.kt b/backend.native/tests/external/stdlib/text/StringTest/dropWhile.kt new file mode 100644 index 00000000000..48687191a83 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/dropWhile.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +// helper predicates available on both platforms +fun Char.isAsciiDigit() = this in '0'..'9' +fun Char.isAsciiLetter() = this in 'A'..'Z' || this in 'a'..'z' +fun Char.isAsciiUpperCase() = this in 'A'..'Z' + +fun box() { + val data = "ab1cd2" + assertEquals("1cd2", data.dropWhile { it.isAsciiLetter() }) + assertEquals("", data.dropWhile { true }) + assertEquals("ab1cd2", data.dropWhile { false }) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/endsWithString.kt b/backend.native/tests/external/stdlib/text/StringTest/endsWithString.kt new file mode 100644 index 00000000000..540b6ad90e0 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/endsWithString.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + + + +fun box() { + assertTrue("abcd".endsWith("d")) + assertTrue("abcd".endsWith("abcd")) + assertFalse("abcd".endsWith("b")) + assertFalse("strö".endsWith("RÖ", ignoreCase = false)) + assertTrue("strö".endsWith("RÖ", ignoreCase = true)) + assertFalse("".endsWith("a")) + assertTrue("some".endsWith("")) + assertTrue("".endsWith("")) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/equalsIgnoreCase.kt b/backend.native/tests/external/stdlib/text/StringTest/equalsIgnoreCase.kt new file mode 100644 index 00000000000..1fa61bf356a --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/equalsIgnoreCase.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + + + +fun box() { + assertFalse("sample".equals("Sample", ignoreCase = false)) + assertTrue("sample".equals("Sample", ignoreCase = true)) + assertFalse("sample".equals(null, ignoreCase = false)) + assertFalse("sample".equals(null, ignoreCase = true)) + assertTrue(null.equals(null, ignoreCase = true)) + assertTrue(null.equals(null, ignoreCase = false)) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/filter.kt b/backend.native/tests/external/stdlib/text/StringTest/filter.kt new file mode 100644 index 00000000000..bbd9b318ba2 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/filter.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +// helper predicates available on both platforms +fun Char.isAsciiDigit() = this in '0'..'9' +fun Char.isAsciiLetter() = this in 'A'..'Z' || this in 'a'..'z' +fun Char.isAsciiUpperCase() = this in 'A'..'Z' + +fun box() { + assertEquals("acdca", ("abcdcba").filter { !it.equals('b') }) + assertEquals("1234", ("a1b2c3d4").filter { it.isAsciiDigit() }) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/filterIndexed.kt b/backend.native/tests/external/stdlib/text/StringTest/filterIndexed.kt new file mode 100644 index 00000000000..d9d16a218b9 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/filterIndexed.kt @@ -0,0 +1,8 @@ +import kotlin.test.* + + + +fun box() { + val data = "abedcf" + assertEquals("abdf", data.filterIndexed { index, c -> c == 'a' + index }) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/filterNot.kt b/backend.native/tests/external/stdlib/text/StringTest/filterNot.kt new file mode 100644 index 00000000000..5dde6637c23 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/filterNot.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + +// helper predicates available on both platforms +fun Char.isAsciiDigit() = this in '0'..'9' +fun Char.isAsciiLetter() = this in 'A'..'Z' || this in 'a'..'z' +fun Char.isAsciiUpperCase() = this in 'A'..'Z' + +fun box() { + assertEquals("acdca", ("abcdcba").filterNot { it.equals('b') }) + assertEquals("abcd", ("a1b2c3d4").filterNot { it.isAsciiDigit() }) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/joinTo.kt b/backend.native/tests/external/stdlib/text/StringTest/joinTo.kt new file mode 100644 index 00000000000..2b912037908 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/joinTo.kt @@ -0,0 +1,10 @@ +import kotlin.test.* + + + +fun box() { + val data = "kotlin".toList() + val sb = StringBuilder() + data.joinTo(sb, "^", "<", ">") + assertEquals("", sb.toString()) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/joinToString.kt b/backend.native/tests/external/stdlib/text/StringTest/joinToString.kt new file mode 100644 index 00000000000..452f67e0d95 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/joinToString.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + + + +fun box() { + val data = "abcd".toList() + val result = data.joinToString("_", "(", ")") + assertEquals("(a_b_c_d)", result) + + val data2 = "verylongstring".toList() + val result2 = data2.joinToString("-", "[", "]", 11, "oops") + assertEquals("[v-e-r-y-l-o-n-g-s-t-r-oops]", result2) + + val data3 = "a1/b".toList() + val result3 = data3.joinToString() { it.toUpperCase().toString() } + assertEquals("A, 1, /, B", result3) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/orEmpty.kt b/backend.native/tests/external/stdlib/text/StringTest/orEmpty.kt new file mode 100644 index 00000000000..7b030acdf6d --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/orEmpty.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + + + +fun box() { + val s: String? = "hey" + val ns: String? = null + + assertEquals("hey", s.orEmpty()) + assertEquals("", ns.orEmpty()) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/partition.kt b/backend.native/tests/external/stdlib/text/StringTest/partition.kt new file mode 100644 index 00000000000..5fcbec94b3f --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/partition.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +// helper predicates available on both platforms +fun Char.isAsciiDigit() = this in '0'..'9' +fun Char.isAsciiLetter() = this in 'A'..'Z' || this in 'a'..'z' +fun Char.isAsciiUpperCase() = this in 'A'..'Z' + +fun box() { + val data = "a1b2c3" + val pair = data.partition { it.isAsciiDigit() } + assertEquals("123", pair.first, "pair.first") + assertEquals("abc", pair.second, "pair.second") +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/replace.kt b/backend.native/tests/external/stdlib/text/StringTest/replace.kt new file mode 100644 index 00000000000..b4ce3417935 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/replace.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + + + +fun box() { + val input = "abbAb" + assertEquals("abb${'$'}b", input.replace('A', '$')) + assertEquals("/bb/b", input.replace('A', '/', ignoreCase = true)) + + assertEquals("${'$'}bAb", input.replace("ab", "$")) + assertEquals("/b/", input.replace("ab", "/", ignoreCase = true)) + + assertEquals("-a-b-b-A-b-", input.replace("", "-")) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/replaceDelimited.kt b/backend.native/tests/external/stdlib/text/StringTest/replaceDelimited.kt new file mode 100644 index 00000000000..c93d7df6e59 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/replaceDelimited.kt @@ -0,0 +1,26 @@ +import kotlin.test.* + + + +fun box() { + val s = "/user/folder/file.extension" + // chars + assertEquals("/user/folder/file.doc", s.replaceAfter('.', "doc")) + assertEquals("/user/folder/another.doc", s.replaceAfterLast('/', "another.doc")) + assertEquals("new name.extension", s.replaceBefore('.', "new name")) + assertEquals("/new/path/file.extension", s.replaceBeforeLast('/', "/new/path")) + + // strings + assertEquals("/user/folder/file.doc", s.replaceAfter(".", "doc")) + assertEquals("/user/folder/another.doc", s.replaceAfterLast("/", "another.doc")) + assertEquals("new name.extension", s.replaceBefore(".", "new name")) + assertEquals("/new/path/file.extension", s.replaceBeforeLast("/", "/new/path")) + + // non-existing delimiter + assertEquals("/user/folder/file.extension", s.replaceAfter("=", "doc")) + assertEquals("/user/folder/file.extension", s.replaceAfterLast("=", "another.doc")) + assertEquals("/user/folder/file.extension", s.replaceBefore("=", "new name")) + assertEquals("/user/folder/file.extension", s.replaceBeforeLast("=", "/new/path")) + assertEquals("xxx", s.replaceBefore("=", "new name", "xxx")) + assertEquals("xxx", s.replaceBeforeLast("=", "/new/path", "xxx")) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/replaceFirst.kt b/backend.native/tests/external/stdlib/text/StringTest/replaceFirst.kt new file mode 100644 index 00000000000..f6399332213 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/replaceFirst.kt @@ -0,0 +1,16 @@ +import kotlin.test.* + + + +fun box() { + val input = "AbbabA" + assertEquals("Abb${'$'}bA", input.replaceFirst('a','$')) + assertEquals("${'$'}bbabA", input.replaceFirst('a','$', ignoreCase = true)) + // doesn't pass in Rhino JS + // assertEquals("schrodinger", "schrÖdinger".replaceFirst('ö', 'o', ignoreCase = true)) + + assertEquals("Abba${'$'}", input.replaceFirst("bA", "$")) + assertEquals("Ab${'$'}bA", input.replaceFirst("bA", "$", ignoreCase = true)) + + assertEquals("-test", "test".replaceFirst("", "-")) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/reverse.kt b/backend.native/tests/external/stdlib/text/StringTest/reverse.kt new file mode 100644 index 00000000000..8e665f025f8 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/reverse.kt @@ -0,0 +1,9 @@ +import kotlin.test.* + + + +fun box() { + assertEquals("dcba", "abcd".reversed()) + assertEquals("4321", "1234".reversed()) + assertEquals("", "".reversed()) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/slice.kt b/backend.native/tests/external/stdlib/text/StringTest/slice.kt new file mode 100644 index 00000000000..d7966e09596 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/slice.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + + + +fun box() { + val iter = listOf(4, 3, 0, 1) + // abcde + // 01234 + assertEquals("bcd", "abcde".substring(1..3)) + assertEquals("dcb", "abcde".slice(3 downTo 1)) + assertEquals("edab", "abcde".slice(iter)) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/startsWithString.kt b/backend.native/tests/external/stdlib/text/StringTest/startsWithString.kt new file mode 100644 index 00000000000..1e2afd8f07f --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/startsWithString.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + + + +fun box() { + assertTrue("abcd".startsWith("ab")) + assertTrue("abcd".startsWith("abcd")) + assertTrue("abcd".startsWith("a")) + assertFalse("abcd".startsWith("abcde")) + assertFalse("abcd".startsWith("b")) + assertFalse("".startsWith("a")) + assertTrue("some".startsWith("")) + assertTrue("".startsWith("")) + + assertFalse("abcd".startsWith("aB", ignoreCase = false)) + assertTrue("abcd".startsWith("aB", ignoreCase = true)) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/substringDelimited.kt b/backend.native/tests/external/stdlib/text/StringTest/substringDelimited.kt new file mode 100644 index 00000000000..6bf30dba755 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/substringDelimited.kt @@ -0,0 +1,27 @@ +import kotlin.test.* + + + +fun box() { + val s = "-1,22,3+" + // chars + assertEquals("22,3+", s.substringAfter(',')) + assertEquals("3+", s.substringAfterLast(',')) + assertEquals("-1", s.substringBefore(',')) + assertEquals("-1,22", s.substringBeforeLast(',')) + + // strings + assertEquals("22,3+", s.substringAfter(",")) + assertEquals("3+", s.substringAfterLast(",")) + assertEquals("-1", s.substringBefore(",")) + assertEquals("-1,22", s.substringBeforeLast(",")) + + // non-existing delimiter + assertEquals("", s.substringAfter("+")) + assertEquals("", s.substringBefore("-")) + assertEquals(s, s.substringBefore("=")) + assertEquals(s, s.substringAfter("=")) + assertEquals("xxx", s.substringBefore("=", "xxx")) + assertEquals("xxx", s.substringAfter("=", "xxx")) + +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/take.kt b/backend.native/tests/external/stdlib/text/StringTest/take.kt new file mode 100644 index 00000000000..fcfaa1b0681 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/take.kt @@ -0,0 +1,12 @@ +import kotlin.test.* + + + +fun box() { + val data = "abcd1234" + assertEquals("abc", data.take(3)) + assertFails { + data.take(-7) + } + assertEquals(data, data.take(data.length + 42)) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/takeWhile.kt b/backend.native/tests/external/stdlib/text/StringTest/takeWhile.kt new file mode 100644 index 00000000000..365b215c55b --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/takeWhile.kt @@ -0,0 +1,13 @@ +import kotlin.test.* + +// helper predicates available on both platforms +fun Char.isAsciiDigit() = this in '0'..'9' +fun Char.isAsciiLetter() = this in 'A'..'Z' || this in 'a'..'z' +fun Char.isAsciiUpperCase() = this in 'A'..'Z' + +fun box() { + val data = "ab1cd2" + assertEquals("ab", data.takeWhile { it.isAsciiLetter() }) + assertEquals("", data.takeWhile { false }) + assertEquals("ab1cd2", data.takeWhile { true }) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/testIndent.kt b/backend.native/tests/external/stdlib/text/StringTest/testIndent.kt new file mode 100644 index 00000000000..c92408aa119 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/testIndent.kt @@ -0,0 +1,11 @@ +import kotlin.test.* + + + +fun box() { + assertEquals(" ABC\n 123", "ABC\n123".prependIndent(" ")) + assertEquals(" ABC\n \n 123", "ABC\n\n123".prependIndent(" ")) + assertEquals(" ABC\n \n 123", "ABC\n \n123".prependIndent(" ")) + assertEquals(" ABC\n \n 123", "ABC\n \n123".prependIndent(" ")) + assertEquals(" ", "".prependIndent(" ")) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/trimIndent.kt b/backend.native/tests/external/stdlib/text/StringTest/trimIndent.kt new file mode 100644 index 00000000000..240b38bcda8 --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/trimIndent.kt @@ -0,0 +1,67 @@ +import kotlin.test.* + + + +fun box() { + // WARNING + // DO NOT REFORMAT AS TESTS MAY FAIL DUE TO INDENTATION CHANGE + + assertEquals("123", """ + 123 + """.trimIndent()) + + assertEquals("123\n 456", """ + 123 + 456 + """.trimIndent()) + + assertEquals(" 123\n456", """ + 123 + 456 + """.trimIndent()) + + assertEquals(" 123\n 456", """ + 123 + 456 + """.replaceIndent(newIndent = " ")) + + assertEquals(" 123\n456", """ + 123 + 456""".trimIndent()) + + assertEquals(" ", """ +${" "} + """.trimIndent()) + + val deindented = """ + ,. + ,. _ oo. `88P + ]88b ,o. d88. ]88b ' + 888 _ Y888o888 d88P _ _ + 888 ,888 `Y88888o_ ,888 d88b d88._____ + 888,888P ,oooooo. ;888888b.]88P 888' d888888888p + 888888P d88888888. J88b'YPP ]88b ,888 d888P'''888. + 8888P' ]88P `888 d88[ d88P ]88b 888' Y88b + 8888p ]88b 888 888 d88[ 888 888. `888 + ,88888b 888[ 888 888. d88[ 888. Y88b Y88[ + d88PY88b `888L,d88P Y88b Y88b ]88b `888 888' + 888 Y88b Y88888P 888. 888. 888. Y88b `88P + d88P 888 `'P' Y888. `888. `88P `Y8P ' + Y8P' ' `YP Y8P' ' + + ____ dXp _ _ _________ + ddXXXXXp XXP ,XX dXb Yo.XXXXXX ,oooooo. + X'L_oXXP XX' XX[ dXb dXb YPPPPXXX' + XYXXXXX ]XX dXb dXb dX8Xooooo dXXP + XXb`YYXXo. YXXo_ dXP dXP YXb'''''' ,XXP' + `XX `YYXb `YXXXXP XX[ ]XX ,XX' + YXb YXb `'' XXXXooL `XX._____ `XXXXXXXXooooo. + `XP ' '''''' YPXXXXXX' ''''''`''YPPP + """.trimIndent() + + assertEquals(23, deindented.lines().size) + val indents = deindented.lines().map { "^\\s*".toRegex().find(it)!!.value.length } + assertEquals(0, indents.min()) + assertEquals(42, indents.max()) + assertEquals(1, deindented.lines().count { it.isEmpty() }) +} diff --git a/backend.native/tests/external/stdlib/text/StringTest/trimMargin.kt b/backend.native/tests/external/stdlib/text/StringTest/trimMargin.kt new file mode 100644 index 00000000000..68765b6711a --- /dev/null +++ b/backend.native/tests/external/stdlib/text/StringTest/trimMargin.kt @@ -0,0 +1,50 @@ +import kotlin.test.* + + + +fun box() { + // WARNING + // DO NOT REFORMAT AS TESTS MAY FAIL DUE TO INDENTATION CHANGE + + assertEquals("ABC\n123\n456", """ABC + |123 + |456""".trimMargin()) + + assertEquals("ABC\n 123\n 456", """ABC + |123 + |456""".replaceIndentByMargin(newIndent = " ")) + + assertEquals("ABC \n123\n456", """ABC${" "} + |123 + |456""".trimMargin()) + + assertEquals(" ABC\n123\n456", """ ABC + >>123 + ${"\t"}>>456""".trimMargin(">>")) + + assertEquals("", "".trimMargin()) + + assertEquals("", """ + """.trimMargin()) + + assertEquals("", """ + |""".trimMargin()) + + assertEquals("", """ + | + """.trimMargin()) + + assertEquals(" a", """ + | a + """.trimMargin()) + + assertEquals(" a", """ + | a""".trimMargin()) + + assertEquals(" a", """ | a + """.trimMargin()) + + assertEquals(" a", """ | a""".trimMargin()) + + assertEquals("\u0000|ABC", "${"\u0000"}|ABC".trimMargin()) +} diff --git a/backend.native/tests/external/stdlib/utils/KotlinVersionTest/componentValidation.kt b/backend.native/tests/external/stdlib/utils/KotlinVersionTest/componentValidation.kt new file mode 100644 index 00000000000..0885f9687ed --- /dev/null +++ b/backend.native/tests/external/stdlib/utils/KotlinVersionTest/componentValidation.kt @@ -0,0 +1,17 @@ +import kotlin.test.* + + +fun box() { + for (component in listOf(Int.MIN_VALUE, -1, 0, KotlinVersion.MAX_COMPONENT_VALUE, KotlinVersion.MAX_COMPONENT_VALUE + 1, Int.MAX_VALUE)) { + for (place in 0..2) { + val (major, minor, patch) = IntArray(3) { index -> if (index == place) component else 0 } + if (component in 0..KotlinVersion.MAX_COMPONENT_VALUE) { + KotlinVersion(major, minor, patch) + } else { + assertFailsWith("Expected $major.$minor.$patch to be invalid version") { + KotlinVersion(major, minor, patch) + } + } + } + } +} diff --git a/backend.native/tests/external/stdlib/utils/KotlinVersionTest/currentVersion.kt b/backend.native/tests/external/stdlib/utils/KotlinVersionTest/currentVersion.kt new file mode 100644 index 00000000000..eaf795ffa53 --- /dev/null +++ b/backend.native/tests/external/stdlib/utils/KotlinVersionTest/currentVersion.kt @@ -0,0 +1,14 @@ +import kotlin.test.* + + +fun box() { + assertTrue(KotlinVersion.CURRENT.isAtLeast(1, 1)) + assertTrue(KotlinVersion.CURRENT.isAtLeast(1, 1, 0)) + assertTrue(KotlinVersion.CURRENT >= KotlinVersion(1, 1)) + assertTrue(KotlinVersion(1, 1) <= KotlinVersion.CURRENT) + + val anotherCurrent = KotlinVersion.CURRENT.run { KotlinVersion(major, minor, patch) } + assertEquals(KotlinVersion.CURRENT, anotherCurrent) + assertEquals(KotlinVersion.CURRENT.hashCode(), anotherCurrent.hashCode()) + assertEquals(0, KotlinVersion.CURRENT.compareTo(anotherCurrent)) +} diff --git a/backend.native/tests/external/stdlib/utils/LazyTest/alreadyInitialized.kt b/backend.native/tests/external/stdlib/utils/LazyTest/alreadyInitialized.kt new file mode 100644 index 00000000000..d824e25d93b --- /dev/null +++ b/backend.native/tests/external/stdlib/utils/LazyTest/alreadyInitialized.kt @@ -0,0 +1,10 @@ +import kotlin.* +import kotlin.test.* + + +fun box() { + val lazyInt = lazyOf(1) + + assertTrue(lazyInt.isInitialized()) + assertEquals(1, lazyInt.value) +} diff --git a/backend.native/tests/external/stdlib/utils/LazyTest/initializationCalledOnce.kt b/backend.native/tests/external/stdlib/utils/LazyTest/initializationCalledOnce.kt new file mode 100644 index 00000000000..42db2090dfb --- /dev/null +++ b/backend.native/tests/external/stdlib/utils/LazyTest/initializationCalledOnce.kt @@ -0,0 +1,17 @@ +import kotlin.* +import kotlin.test.* + + +fun box() { + var callCount = 0 + val lazyInt = lazy { ++callCount } + + assertEquals(0, callCount) + assertFalse(lazyInt.isInitialized()) + assertEquals(1, lazyInt.value) + assertEquals(1, callCount) + assertTrue(lazyInt.isInitialized()) + + lazyInt.value + assertEquals(1, callCount) +} diff --git a/backend.native/tests/external/stdlib/utils/LazyTest/lazyToString.kt b/backend.native/tests/external/stdlib/utils/LazyTest/lazyToString.kt new file mode 100644 index 00000000000..16e6837dde9 --- /dev/null +++ b/backend.native/tests/external/stdlib/utils/LazyTest/lazyToString.kt @@ -0,0 +1,15 @@ +import kotlin.* +import kotlin.test.* + + +fun box() { + var callCount = 0 + val lazyInt = lazy { ++callCount } + + assertNotEquals("1", lazyInt.toString()) + assertEquals(0, callCount) + + assertEquals(1, lazyInt.value) + assertEquals("1", lazyInt.toString()) + assertEquals(1, callCount) +} diff --git a/backend.native/tests/external/stdlib/utils/TODOTest/usage.kt b/backend.native/tests/external/stdlib/utils/TODOTest/usage.kt new file mode 100644 index 00000000000..a7cfb9f4f7e --- /dev/null +++ b/backend.native/tests/external/stdlib/utils/TODOTest/usage.kt @@ -0,0 +1,45 @@ +import kotlin.* +import kotlin.test.* + +private class PartiallyImplementedClass { + public val prop: String get() = TODO() + fun method1() = TODO() as String + public fun method2(): Int = TODO() + + public fun method3(switch: Boolean, value: String): String { + if (!switch) + TODO("what if false") + else { + if (value.length < 3) + throw TODO("write message") + } + + return value + } + + public fun method4() { + TODO() + } +} + +private fun assertNotImplemented(block: () -> Unit) { + assertFailsWith(block = block) +} + +private fun assertNotImplementedWithMessage(message: String, block: () -> Unit) { + val e = assertFailsWith(block = block) + assertTrue(message in e.message!!) +} + + +fun box() { + val inst = PartiallyImplementedClass() + + assertNotImplemented { inst.prop } + assertNotImplemented { inst.method1() } + assertNotImplemented { inst.method2() } + assertNotImplemented { inst.method4() } + assertNotImplementedWithMessage("what if false") { inst.method3(false, "test") } + assertNotImplementedWithMessage("write message") { inst.method3(true, "t") } + assertEquals("test", inst.method3(true, "test")) +} diff --git a/backend.native/tests/testUtils.kt b/backend.native/tests/testUtils.kt index 0d726251ef6..60342ae43d7 100644 --- a/backend.native/tests/testUtils.kt +++ b/backend.native/tests/testUtils.kt @@ -1,8 +1,16 @@ package kotlin.test +annotation class Test() + class TestFailedException(val msg:String):RuntimeException(msg) -fun assertEquals(a:T, b:T, msg:String = "") { if (a != b) throw TestFailedException(msg) } +class Assert { + companion object { + fun assertEquals(a:T, b:T, msg:String? = null) { if (a != b) throw TestFailedException(msg ?: "") } + } +} + +fun assertEquals(a:T, b:T, msg:String? = null) = Assert.assertEquals(a, b, msg) /** Asserts that the expression is `true` with an optional [message]. */ fun assertTrue(actual: Boolean, message: String? = null) { @@ -17,6 +25,94 @@ fun assertFalse(actual: Boolean, message: String? = null) { } /** Fails the current test with the specified [message]. */ -fun fail(message: String? = null) { - throw TestFailedException(message ?: "Expected value to be true.") -} \ No newline at end of file +fun fail(message: String? = null): Nothing = throw TestFailedException(message ?: "Expected value to be true.") + + +/** Asserts that given function [block] returns the given [expected] value. */ +fun expect(expected: T, block: () -> T) { + assertEquals(expected, block()) +} + +/** Asserts that given function [block] returns the given [expected] value and use the given [message] if it fails. */ +fun expect(expected: T, message: String?, block: () -> T) { + assertEquals(expected, block(), message) +} + +/** Asserts that given function [block] fails by throwing an exception. */ +fun assertFails(block: () -> Unit): Throwable = assertFails(null, block) + +/** Asserts that given function [block] fails by throwing an exception. */ +fun assertFails(message: String?, block: () -> Unit): Throwable { + try { + block() + } catch (e: Throwable) { + return e + } + fail(message + ". Expected an exception to be thrown, but was completed successfully.") +} + +/** Asserts that a [block] fails with a specific exception of type [exceptionClass] being thrown. */ +inline fun assertFailsWith(message: String? = null, block: () -> Unit): T { + try { + block() + } catch (e: Throwable) { + if (e is T) { + @Suppress("UNCHECKED_CAST") + return e + } + + @Suppress("INVISIBLE_MEMBER") + fail(message + ". Expected an exception of type //TODO: add type!// to be thrown, but was $e") + } + + @Suppress("INVISIBLE_MEMBER") + fail(message + ". Expected an exception of type //TODO: add type!// to be thrown, but was completed successfully.") +} + +@Suppress("UNUSED_PARAMETER") +public fun assertTypeEquals(expected: Any?, actual: Any?) { + //TODO: find analogue + //assertEquals(expected?.javaClass, actual?.javaClass) +} + +/** Asserts that the given [block] returns `true`. */ +fun assertTrue(message: String? = null, block: () -> Boolean): Unit = assertTrue(block(), message) + +/** Asserts that the [actual] value is not equal to the illegal value, with an optional [message]. */ +fun assertNotEquals(illegal: T, actual: T, message: String? = null) { + assertFalse(illegal == actual, message) +} + +fun Iterable.assertSorted(isInOrder: (T, T) -> Boolean): Unit { this.iterator().assertSorted(isInOrder) } +fun Iterator.assertSorted(isInOrder: (T, T) -> Boolean) { + if (!hasNext()) return + var index = 0 + var prev = next() + while (hasNext()) { + index += 1 + val next = next() + assertTrue(isInOrder(prev, next), "Not in order at position $index, element[${index-1}]: $prev, element[$index]: $next") + prev = next + } + return +} + +/** Asserts that the [actual] value is not `null`, with an optional [message]. */ +fun assertNotNull(actual: T?, message: String? = null): T { + assertTrue(actual != null, message) + return actual!! +} + +/** Asserts that the [actual] value is not `null`, with an optional [message] and a function [block] to process the not-null value. */ +fun assertNotNull(actual: T?, message: String? = null, block: (T) -> R) { + assertTrue(actual != null, message) + if (actual != null) { + block(actual) + } +} + +/** Asserts that the [actual] value is `null`, with an optional [message]. */ +fun assertNull(actual: Any?, message: String? = null) { + assertTrue(actual == null, message) +} +