From 670d05a4f35cbb3613d694406af515a13b796fb3 Mon Sep 17 00:00:00 2001 From: Pavel Punegov Date: Tue, 9 Jan 2018 13:17:55 +0300 Subject: [PATCH] Update stdlib and tests (#1194) --- backend.native/tests/build.gradle | 57 +- .../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 | 13 - .../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/iterators.kt | 54 - .../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 | 39 - .../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 | 32 - .../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 | 41 - .../collections/CollectionTest/sortInPlace.kt | 14 - .../collections/CollectionTest/sorted.kt | 8 - .../collections/CollectionTest/sortedBy.kt | 8 - .../CollectionTest/sortedByNullable.kt | 11 - .../CollectionTest/sortedNullableBy.kt | 27 - .../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 - .../collections/SetOperationsTest/distinct.kt | 7 - .../SetOperationsTest/distinctBy.kt | 7 - .../SetOperationsTest/intersect.kt | 9 - .../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 | 17 - .../numbers/NaNPropagationTest/arrayTMin.kt | 17 - .../numbers/NaNPropagationTest/listMax.kt | 29 - .../numbers/NaNPropagationTest/listMin.kt | 29 - .../numbers/NaNPropagationTest/listTMax.kt | 17 - .../numbers/NaNPropagationTest/listTMin.kt | 17 - .../numbers/NaNPropagationTest/maxOf.kt | 47 - .../numbers/NaNPropagationTest/maxOfT.kt | 17 - .../numbers/NaNPropagationTest/minOf.kt | 47 - .../numbers/NaNPropagationTest/minOfT.kt | 17 - .../NaNPropagationTest/primitiveArrayMax.kt | 29 - .../NaNPropagationTest/primitiveArrayMin.kt | 29 - .../numbers/NaNPropagationTest/sequenceMax.kt | 29 - .../numbers/NaNPropagationTest/sequenceMin.kt | 29 - .../NaNPropagationTest/sequenceTMax.kt | 17 - .../NaNPropagationTest/sequenceTMin.kt | 17 - .../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 - .../VarByMapExtensionsTest$a2$2.class | Bin 1370 -> 0 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 - .../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 - .../RegexTest/harmony/AllCodePointsTest.kt | 60 - .../text/RegexTest/harmony/MatchResultTest.kt | 474 ------ .../RegexTest/harmony/MatchResultTest2.kt | 116 -- .../stdlib/text/RegexTest/harmony/ModeTest.kt | 116 -- .../text/RegexTest/harmony/PatternTest.kt | 1306 ----------------- .../text/RegexTest/harmony/PatternTest2.kt | 1212 --------------- .../text/RegexTest/harmony/ReplaceTest.kt | 85 -- .../text/RegexTest/harmony/SplitTest.kt | 156 -- .../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 | 79 - .../StringNumberConversionTest/toFloat.kt | 63 - .../StringNumberConversionTest/toHexDouble.kt | 68 - .../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 | 72 - .../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 - .../tests/stdlib_external/OrderingTest.kt | 184 +++ .../tests/stdlib_external/TuplesTest.kt | 101 ++ .../stdlib_external/collections/ArraysTest.kt | 1256 ++++++++++++++++ .../collections/CollectionBehaviors.kt | 119 ++ .../collections/CollectionTest.kt | 941 ++++++++++++ .../collections/ComparisonDSL.kt | 35 + .../collections/GroupingTest.kt | 112 ++ .../collections/IterableTests.kt | 517 +++++++ .../collections/IteratorsTest.kt | 14 + .../collections/ListBinarySearchTest.kt | 112 ++ .../collections/ListSpecificTest.kt | 80 + .../stdlib_external/collections/MapTest.kt | 485 ++++++ .../collections/MutableCollectionsTest.kt | 117 ++ .../collections/ReversedViewsTest.kt | 222 +++ .../collections/SequenceTest.kt | 562 +++++++ .../collections/SetOperationsTest.kt | 77 + .../coroutines/CoroutineContextTest.kt | 174 +++ .../CoroutinesReferenceValuesTest.kt | 70 + .../coroutines/SequenceBuilderTest.kt | 304 ++++ .../language/EscapedTestNamesTest.kt | 16 + .../numbers/BitwiseOperationsTest.kt | 34 + .../numbers/HarmonyMathTests.kt | 824 +++++++++++ .../tests/stdlib_external/numbers/MathTest.kt | 820 +++++++++++ .../numbers/NaNPropagationTest.kt | 155 ++ .../stdlib_external/numbers/NumbersTest.kt | 172 +++ .../properties/delegation/DelegationTest.kt | 61 + .../properties/delegation/MapAccessorsTest.kt | 60 + .../delegation/lazy/LazyValuesTest.kt | 92 ++ .../stdlib_external/ranges/CoercionTest.kt | 118 ++ .../ranges/ProgressionLastElementTest.kt | 84 ++ .../ranges/RangeIterationTest.kt | 233 +++ .../tests/stdlib_external/ranges/RangeTest.kt | 378 +++++ .../tests/stdlib_external/testUtils.kt | 4 + .../tests/stdlib_external/text/RegexTest.kt | 191 +++ .../stdlib_external/text/StringBuilderTest.kt | 64 + .../text/StringNumberConversionTest.kt | 278 ++++ .../tests/stdlib_external/text/StringTest.kt | 1282 ++++++++++++++++ .../text/harmony_regex/AllCodePointsTest.kt | 65 + .../text/harmony_regex/MatchResultTest.kt | 449 ++++++ .../text/harmony_regex/MatchResultTest2.kt | 117 ++ .../text/harmony_regex/ModeTest.kt | 117 ++ .../text/harmony_regex}/PatternErrorTest.kt | 41 +- .../PatternSyntaxExceptionTest.kt | 41 +- .../text/harmony_regex/PatternTest.kt | 1256 ++++++++++++++++ .../text/harmony_regex/PatternTest2.kt | 1195 +++++++++++++++ .../text/harmony_regex/ReplaceTest.kt | 84 ++ .../text/harmony_regex/SplitTest.kt | 155 ++ .../utils/KotlinVersionTest.kt | 58 + .../tests/stdlib_external/utils/LazyTest.kt | 41 + .../utils/PreconditionsTest.kt | 127 ++ .../tests/stdlib_external/utils/TODOTest.kt | 66 + .../org/jetbrains/kotlin/KonanTest.groovy | 43 +- .../src/main/kotlin/kotlin/KotlinVersion.kt | 4 +- .../kotlin/kotlin/collections/Collections.kt | 146 +- .../main/kotlin/kotlin/collections/Maps.kt | 75 + .../kotlin/collections/SlidingWindow.kt | 210 +++ .../main/kotlin/kotlin/sequences/Sequences.kt | 118 ++ .../src/main/kotlin/kotlin/text/Strings.kt | 193 +++ 582 files changed, 14933 insertions(+), 14639 deletions(-) delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/combineComparators.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/compareByCompareTo.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/compareByNameFirst.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/compareByRatingFirst.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/compareNullables.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/compareSameObjectsByRatingFirst.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/maxOf.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/maxOfWith.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/minOf.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/minOfWith.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/naturalOrderComparator.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/reversedComparator.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/sortByThenBy.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/sortByThenByDescending.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/sortComparatorThenComparator.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/sortUsingCustomComparator.kt delete mode 100644 backend.native/tests/external/stdlib/OrderingTest/sortUsingFunctionalComparator.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairEquals.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairFirstAndSecond.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairHashCode.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairHashSet.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairMultiAssignment.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairToList.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/pairToString.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleEquals.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleFirstAndSecond.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleHashCode.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleHashSet.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleMultiAssignment.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleToList.kt delete mode 100644 backend.native/tests/external/stdlib/TuplesTest/tripleToString.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/arrayLastIndex.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/asIterable.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/asList.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/asListObjects.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/asListPrimitives.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/average.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/booleanArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/booleanArrayInit.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/byteArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/byteArrayInit.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/charArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/charArrayInit.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contains.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepEquals.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepHashCode.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToString.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToStringNoRecursion.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentEquals.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentHashCode.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/contentToString.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/copyAndResize.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/copyOf.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/copyOfRange.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/doubleArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/doubleArrayInit.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/drop.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/dropLast.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/dropLastWhile.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/dropWhile.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/emptyArrayLastIndex.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/filter.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/filterIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/filterNot.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/filterNotNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/first.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/flattenArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/floatArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/floatArrayInit.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/indexOf.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/indexOfInPrimitiveArrays.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/intArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/intArrayInit.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/isEmpty.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/isNotEmpty.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/iterators.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/joinToString.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/last.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/lastIndexOf.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/longArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/longArrayInit.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/map.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexedNotNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/mapNotNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/max.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxByEvaluateOnce.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxByInPrimitiveArrays.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxInPrimitiveArrays.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxIndex.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxWith.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/maxWithInPrimitiveArrays.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/min.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minByEvaluateOnce.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minByInPrimitiveArrays.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minInPrimitiveArrays.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minIndex.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minWith.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/minWithInPrimitiveArrays.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNotNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/plus.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/plusAssign.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/plusInference.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/plusVararg.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reduce.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reduceIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reduceRight.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reduceRightIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reverseInPlace.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reversed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/reversedArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/shortArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/shortArrayInit.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/slice.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sliceArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sort.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sortByInPlace.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sortedBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sortedNullableBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sortedTests.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sortedWith.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sum.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/sumInPrimitiveArrays.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/take.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/takeLast.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/takeLastWhile.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/takeWhile.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/toPrimitiveArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ArraysTest/toTypedArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/abstractCollectionToArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/average.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/contains.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/copyToArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/count.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/createListWithInit.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/decomposeArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/decomposeFirst.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/decomposeIntArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/decomposeList.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/decomposeSplit.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/drop.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/dropLast.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/dropLastWhile.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/dropWhile.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/filterIntoSet.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceList.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/filterNotNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/first.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/fold.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithDifferentTypes.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithNonCommutativeOperation.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRight.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithDifferentTypes.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithNonCommutativeOperation.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithDifferentTypes.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithNonCommutativeOperation.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldWithDifferentTypes.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/foldWithNonCommutativeOperation.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/groupBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/groupByKeysAndValues.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/indices.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/joinTo.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/joinToString.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/last.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/listOfNotNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/mapRanges.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/max.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/maxBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/maxByEvaluateOnce.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/maxWith.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/min.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/minBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/minByEvaluateOnce.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/minWith.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/minusAssign.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/minusIsEager.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/partition.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/plusAssign.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionBug.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionInference.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/plusRanges.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/randomAccess.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reduce.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reduceIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reduceRight.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reduceRightIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/requireNoNulls.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reverseInPlace.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/reversed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortByInPlace.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortInPlace.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sorted.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortedBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortedByNullable.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortedNullableBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sortedWith.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/specialLists.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/specialMaps.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/specialSets.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/subscript.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/sum.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/take.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/takeLast.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/takeLastWhile.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/takeReturnsFirstNElements.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/takeWhile.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/toStringTest.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/unzipArray.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/unzipList.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/zip.kt delete mode 100644 backend.native/tests/external/stdlib/collections/CollectionTest/zipTransform.kt delete mode 100644 backend.native/tests/external/stdlib/collections/GroupingTest/countEach.kt delete mode 100644 backend.native/tests/external/stdlib/collections/GroupingTest/foldWithComputedInitialValue.kt delete mode 100644 backend.native/tests/external/stdlib/collections/GroupingTest/foldWithConstantInitialValue.kt delete mode 100644 backend.native/tests/external/stdlib/collections/GroupingTest/groupingProducers.kt delete mode 100644 backend.native/tests/external/stdlib/collections/GroupingTest/reduce.kt delete mode 100644 backend.native/tests/external/stdlib/collections/IteratorsTest/iterationOverIterator.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElement.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElementNullable.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKey.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKeyWithComparator.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByMultipleKeys.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchWithComparator.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/_toString.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/getOr.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/indexOfLast.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/lastIndex.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/mutableList.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/slice.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/tail.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ListSpecificTest/testNullToString.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/all.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/any.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/contains.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/countBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createFrom.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createLinkedMap.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createMutableMap.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createUsingTo.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createWithPairSelector.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createWithSelector.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorAndOverwrite.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorForKeyAndValue.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/filter.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/filterNot.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/filterOutProjectedTo.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/getOrElse.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/getOrPut.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/getValue.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/iterate.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/iterateWithExtraction.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/iterateWithProperties.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/map.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/mapKeys.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/mapNotNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/mapValues.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/onEach.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/plusAny.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/populateTo.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/setViaIndexOperators.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/sizeAndEmpty.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MapTest/stream.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MutableCollectionsTest/addAll.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MutableCollectionsTest/removeAll.kt delete mode 100644 backend.native/tests/external/stdlib/collections/MutableCollectionsTest/retainAll.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testAddIOOB.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBehavior.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBidirectionalModifications.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testContains.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testDoubleReverse.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testEmpty.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testGetIOOB.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testIndexOf.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableAdd.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableClear.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableDoubleReverse.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableEmpty.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemove.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemoveByObj.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableReversedSubList.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSet.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSimple.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSubList.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testNullToString.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRandomAccess.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRemoveIOOB.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testReversedSubList.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSetIOOB.kt delete mode 100644 backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSimple.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceJVMTest/filterIsInstance.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/distinct.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/distinctBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/drop.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/dropWhile.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterAndTakeWhileExtractTheElementsWithinRange.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterEmptySequence.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterNot.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterNotNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/filterNullable.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/flatMap.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/flatMapAndTakeExtractTheTransformedElements.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/flatMapOnEmpty.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/flatMapWithEmptyItems.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/flatten.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/foldReducesTheFirstNElements.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/iterationOverSequence.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/joinConcatenatesTheFirstNElementsAboveAThreshold.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/makeSequenceOneTimeConstrained.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapAndJoinToString.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapAndTakeWhileExtractTheTransformedElements.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapEmptySequence.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexedNotNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/mapNotNull.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/minusAssign.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/minusIsLazyIterated.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/onEach.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/plusAssign.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/requireNoNulls.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sequenceExtensions.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunction.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithInitialValue.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithLazyInitialValue.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromIterator.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sorted.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sortedBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/sortedWith.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/subSequence.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/take.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/takeExtractsTheFirstNElements.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/toStringJoinsNoMoreThanTheFirstTenElements.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/unzip.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/withIndex.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/zip.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SequenceTest/zipPairs.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/distinct.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/distinctBy.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/intersect.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/plusAssign.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/subtract.kt delete mode 100644 backend.native/tests/external/stdlib/collections/SetOperationsTest/union.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testEquals.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testGetPlusFold.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testLastDispatcher.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testMinusKey.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testPlusCombined.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/CoroutinesReferenceValuesTest/testBadClass.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testCallHasNextSeveralTimes.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testEmptySequence.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testExceptionInCoroutine.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testInfiniteYieldAll.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testLaziness.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testManualIteration.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testParallelIteration.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testSimple.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollection.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionManyEmpty.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedBoth.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedFirst.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLast.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLong.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionOneEmpty.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllIterator.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSequence.kt delete mode 100644 backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSideEffects.kt delete mode 100644 backend.native/tests/external/stdlib/language/EscapedTestNamesTest/numbersEqual.kt delete mode 100644 backend.native/tests/external/stdlib/language/EscapedTestNamesTest/stringsEqual.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/andForInt.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/invForInt.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/orForInt.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shlForInt.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shrForInt.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/ushrForInt.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/xorForInt.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMax.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMin.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMax.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMin.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMax.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMin.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMax.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMin.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOf.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOfT.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOf.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOfT.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMax.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMin.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMax.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMin.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMax.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMin.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/byteMinMaxValues.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/doubleMinMaxValues.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/doubleProperties.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/floatMinMaxValues.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/floatProperties.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/intMinMaxValues.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/longMinMaxValues.kt delete mode 100644 backend.native/tests/external/stdlib/numbers/NumbersTest/shortMinMaxValues.kt delete mode 100644 backend.native/tests/external/stdlib/properties/VarByMapExtensionsTest$a2$2.class delete mode 100644 backend.native/tests/external/stdlib/properties/delegation/DelegationTest/NotNullVarTest.kt delete mode 100644 backend.native/tests/external/stdlib/properties/delegation/DelegationTest/ObservablePropertyTest.kt delete mode 100644 backend.native/tests/external/stdlib/properties/delegation/DelegationTest/VetoablePropertyTest.kt delete mode 100644 backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/ValByMapExtensionsTest.kt delete mode 100644 backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/VarByMapExtensionsTest.kt delete mode 100644 backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/IdentityEqualsIsUsedToUnescapeLazyValTest.kt delete mode 100644 backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/LazyValTest.kt delete mode 100644 backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/NullableLazyValTest.kt delete mode 100644 backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeLazyValTest.kt delete mode 100644 backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeNullableLazyValTest.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsComparable.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsDouble.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsInt.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsLong.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/calculateFinalElement.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/iterateToFinalElement.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyConstant.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyDownto.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedDownTo.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementDownTo.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/openRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedBackSequence.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyBackSequence.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedInexactSteppedDownTo.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleDownTo.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedDownTo.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/byteRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/charRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/comparableRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/doubleRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/emptyEquals.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/emptyHashCode.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/floatRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/intRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/isEmpty.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/longRange.kt delete mode 100644 backend.native/tests/external/stdlib/ranges/RangeTest/shortRange.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/escapeLiteral.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/harmony/AllCodePointsTest.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/harmony/MatchResultTest.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/harmony/MatchResultTest2.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/harmony/ModeTest.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternTest.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternTest2.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/harmony/ReplaceTest.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/harmony/SplitTest.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchAllSequence.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchEntire.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchEntireLazyQuantor.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchGroups.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchIgnoreCase.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchMultiline.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchOptionalGroup.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchResult.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/matchSequence.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/replace.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/replaceEvaluator.kt delete mode 100644 backend.native/tests/external/stdlib/text/RegexTest/split.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringBuilderTest/append.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringBuilderTest/appendMany.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringBuilderTest/asCharSequence.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringBuilderTest/constructors.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringBuilderTest/stringBuild.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/byteToStringWithRadix.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/intToStringWithRadix.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/longToStringWithRadix.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/shortToStringWithRadix.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toBoolean.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toByte.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toDouble.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toFloat.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toHexDouble.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toInt.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toIntArabicDigits.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLong.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLongArabicDigits.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringNumberConversionTest/toShort.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/capitalize.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/decapitalize.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/drop.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/dropWhile.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/endsWithString.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/equalsIgnoreCase.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/filter.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/filterIndexed.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/filterNot.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/joinTo.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/joinToString.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/orEmpty.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/partition.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/replace.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/replaceDelimited.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/replaceFirst.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/reverse.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/slice.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/startsWithString.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/substringDelimited.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/take.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/takeWhile.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/testIndent.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/trimIndent.kt delete mode 100644 backend.native/tests/external/stdlib/text/StringTest/trimMargin.kt delete mode 100644 backend.native/tests/external/stdlib/utils/KotlinVersionTest/componentValidation.kt delete mode 100644 backend.native/tests/external/stdlib/utils/KotlinVersionTest/currentVersion.kt delete mode 100644 backend.native/tests/external/stdlib/utils/LazyTest/alreadyInitialized.kt delete mode 100644 backend.native/tests/external/stdlib/utils/LazyTest/initializationCalledOnce.kt delete mode 100644 backend.native/tests/external/stdlib/utils/LazyTest/lazyToString.kt delete mode 100644 backend.native/tests/external/stdlib/utils/TODOTest/usage.kt create mode 100644 backend.native/tests/stdlib_external/OrderingTest.kt create mode 100644 backend.native/tests/stdlib_external/TuplesTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/ArraysTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/CollectionBehaviors.kt create mode 100644 backend.native/tests/stdlib_external/collections/CollectionTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/ComparisonDSL.kt create mode 100644 backend.native/tests/stdlib_external/collections/GroupingTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/IterableTests.kt create mode 100644 backend.native/tests/stdlib_external/collections/IteratorsTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/ListBinarySearchTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/ListSpecificTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/MapTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/MutableCollectionsTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/ReversedViewsTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/SequenceTest.kt create mode 100644 backend.native/tests/stdlib_external/collections/SetOperationsTest.kt create mode 100644 backend.native/tests/stdlib_external/coroutines/CoroutineContextTest.kt create mode 100644 backend.native/tests/stdlib_external/coroutines/CoroutinesReferenceValuesTest.kt create mode 100644 backend.native/tests/stdlib_external/coroutines/SequenceBuilderTest.kt create mode 100644 backend.native/tests/stdlib_external/language/EscapedTestNamesTest.kt create mode 100644 backend.native/tests/stdlib_external/numbers/BitwiseOperationsTest.kt create mode 100644 backend.native/tests/stdlib_external/numbers/HarmonyMathTests.kt create mode 100644 backend.native/tests/stdlib_external/numbers/MathTest.kt create mode 100644 backend.native/tests/stdlib_external/numbers/NaNPropagationTest.kt create mode 100644 backend.native/tests/stdlib_external/numbers/NumbersTest.kt create mode 100644 backend.native/tests/stdlib_external/properties/delegation/DelegationTest.kt create mode 100644 backend.native/tests/stdlib_external/properties/delegation/MapAccessorsTest.kt create mode 100644 backend.native/tests/stdlib_external/properties/delegation/lazy/LazyValuesTest.kt create mode 100644 backend.native/tests/stdlib_external/ranges/CoercionTest.kt create mode 100644 backend.native/tests/stdlib_external/ranges/ProgressionLastElementTest.kt create mode 100644 backend.native/tests/stdlib_external/ranges/RangeIterationTest.kt create mode 100644 backend.native/tests/stdlib_external/ranges/RangeTest.kt create mode 100644 backend.native/tests/stdlib_external/testUtils.kt create mode 100644 backend.native/tests/stdlib_external/text/RegexTest.kt create mode 100644 backend.native/tests/stdlib_external/text/StringBuilderTest.kt create mode 100644 backend.native/tests/stdlib_external/text/StringNumberConversionTest.kt create mode 100644 backend.native/tests/stdlib_external/text/StringTest.kt create mode 100644 backend.native/tests/stdlib_external/text/harmony_regex/AllCodePointsTest.kt create mode 100644 backend.native/tests/stdlib_external/text/harmony_regex/MatchResultTest.kt create mode 100644 backend.native/tests/stdlib_external/text/harmony_regex/MatchResultTest2.kt create mode 100644 backend.native/tests/stdlib_external/text/harmony_regex/ModeTest.kt rename backend.native/tests/{external/stdlib/text/RegexTest/harmony => stdlib_external/text/harmony_regex}/PatternErrorTest.kt (54%) rename backend.native/tests/{external/stdlib/text/RegexTest/harmony => stdlib_external/text/harmony_regex}/PatternSyntaxExceptionTest.kt (62%) create mode 100644 backend.native/tests/stdlib_external/text/harmony_regex/PatternTest.kt create mode 100644 backend.native/tests/stdlib_external/text/harmony_regex/PatternTest2.kt create mode 100644 backend.native/tests/stdlib_external/text/harmony_regex/ReplaceTest.kt create mode 100644 backend.native/tests/stdlib_external/text/harmony_regex/SplitTest.kt create mode 100644 backend.native/tests/stdlib_external/utils/KotlinVersionTest.kt create mode 100644 backend.native/tests/stdlib_external/utils/LazyTest.kt create mode 100644 backend.native/tests/stdlib_external/utils/PreconditionsTest.kt create mode 100644 backend.native/tests/stdlib_external/utils/TODOTest.kt create mode 100644 runtime/src/main/kotlin/kotlin/collections/SlidingWindow.kt diff --git a/backend.native/tests/build.gradle b/backend.native/tests/build.gradle index ff087d86b22..abd144b230d 100644 --- a/backend.native/tests/build.gradle +++ b/backend.native/tests/build.gradle @@ -43,6 +43,7 @@ dependencies { ext.testOutputRoot = rootProject.file("test.output").absolutePath ext.externalTestsDir = project.file("external") +ext.externalStdlibTestsDir = project.file("stdlib_external") externalTestsDir.mkdirs() project.convention.plugins.remoteExec = new org.jetbrains.kotlin.ExecRemote(project) @@ -59,6 +60,11 @@ allprojects { testOutputExternal { output.dir(rootProject.file("$testOutputRoot/external")) } + + // backend.native/tests/stdlib_external + testOutputStdlib { + output.dir(rootProject.file("$testOutputRoot/stdlib")) + } } } @@ -130,12 +136,15 @@ task clean { } } -task run() { +def tasksOf(Closure filter) { String prefix = project.findProperty("prefix") - if (prefix != null) - dependsOn(tasks.withType(KonanTest).matching { !(it instanceof RunExternalTestGroup) && it.enabled && it.name.startsWith(prefix) }) - else - dependsOn(tasks.withType(KonanTest).matching { !(it instanceof RunExternalTestGroup) && it.enabled }) + project.tasks.withType(KonanTest) + .matching { filter(it) && it.enabled && (prefix != null ? it.name.startsWith(prefix) : true) } +} + +task run() { + def tasks = tasksOf { it instanceof RunKonanTest && !(it instanceof RunStdlibTest) } + dependsOn(tasks) } // Collect results in one json. @@ -161,8 +170,7 @@ task resultsTask() { } } -Set createExternalTests(File testRoot, Closure taskConfiguration) { - def result = new HashSet() +def createTestTasks(File testRoot, Class taskType, Closure taskConfiguration) { testRoot.eachDirRecurse { // Skip build directory and directories without *.kt files. if (it.name == "build" || it.listFiles().count { it.name.endsWith(".kt") && it.isFile() } == 0) { @@ -172,35 +180,25 @@ Set createExternalTests(File testRoot, Closure taskConfigu def taskDirectory = project.relativePath(it) def taskName = taskDirectory.replaceAll("[-/\\\\]", '_') - def task = (RunExternalTestGroup) project.task("$taskName", type: RunExternalTestGroup) { - groupDirectory = "$taskDirectory" + def task = project.task(taskName, type: taskType) { + groupDirectory = taskDirectory finalizedBy resultsTask } taskConfiguration(task) - result.add(task) } - return result } task run_external () { - // TODO Consider test output directory cleaning before execution. - // TODO Consider using some logger instead of println // Create tasks for external tests. - for (testDir in ["codegen", "compileKotlinAgainstKotlin"]) { - createExternalTests(new File(externalTestsDir, testDir)) { + createTestTasks(new File(externalTestsDir, testDir), RunExternalTestGroup) { it.goldValue = "OK" } } - createExternalTests(new File(externalTestsDir, "stdlib")) {} // Set up dependencies. - def testTasks = tasks.withType(RunExternalTestGroup).matching { it.enabled } - String prefix = project.findProperty("prefix") - if (prefix != null) { - testTasks = testTasks.matching { it.name.startsWith(prefix) } - } - dependsOn(testTasks) + dependsOn(clean) + dependsOn(tasksOf { it instanceof RunExternalTestGroup || it instanceof RunStdlibTest }) } task daily() { @@ -500,7 +498,7 @@ task entry0(type: RunStandaloneKonanTest) { task entry1(type: RunStandaloneKonanTest) { goldValue = "Hello.\n" source = "runtime/basic/entry1.kt" - flags = ["-entry", "foo"] + flags = ["-entry", "foo"] } task entry2(type: LinkKonanTest) { @@ -2357,6 +2355,19 @@ task produce_dynamic(type: DynamicKonanTest) { "RW property is 239\n" } +task buildKonanStdlibTests(type: BuildKonanTest) { + outputSourceSetName = "testOutputStdlib" + compileList = [ "stdlib_external", "testUtils.kt" ] +} + +task runStdlibTests(type: RunStdlibTest) { + outputSourceSetName = "testOutputStdlib" + // runs all tests and hence source name should be not null + source = "stdlib_external/testUtils.kt" + useFilter = false + runnerLogger = RunKonanTest.Logger.GTEST +} + task buildKonanTests(type: BuildKonanTest) { compileList = [ "codegen", "datagen", "lower", "runtime", "serialization"] diff --git a/backend.native/tests/external/stdlib/OrderingTest/combineComparators.kt b/backend.native/tests/external/stdlib/OrderingTest/combineComparators.kt deleted file mode 100644 index 0b670c4e4ed..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/combineComparators.kt +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index e163826c641..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/compareByCompareTo.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index c9a351e7cca..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/compareByNameFirst.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 907abcca324..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/compareByRatingFirst.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 13fff370946..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/compareNullables.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index a10475539f4..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/compareSameObjectsByRatingFirst.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 65e7d74afa3..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/maxOf.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index b5d3a510c03..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/maxOfWith.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index b4fbbcfa8aa..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/minOf.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 076c82903ca..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/minOfWith.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index e17f48a84de..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/naturalOrderComparator.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index a1643541294..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/reversedComparator.kt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 33d8d4c2aeb..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/sortByThenBy.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index ee28f05de6f..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/sortByThenByDescending.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 81e2a514ed1..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/sortComparatorThenComparator.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 8971c8b40a6..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/sortUsingCustomComparator.kt +++ /dev/null @@ -1,28 +0,0 @@ -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 deleted file mode 100644 index c2aeef396e2..00000000000 --- a/backend.native/tests/external/stdlib/OrderingTest/sortUsingFunctionalComparator.kt +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index fa777005f0d..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/pairEquals.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index bc1eea18123..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/pairFirstAndSecond.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 0285585e92f..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/pairHashCode.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 91ff3479e67..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/pairHashSet.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 13fd1843d17..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/pairMultiAssignment.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 76b67071520..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/pairToList.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 2d15e02384e..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/pairToString.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index a2b29923061..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/tripleEquals.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 534dbea12a8..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/tripleFirstAndSecond.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 801839f454e..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/tripleHashCode.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 14e097d075f..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/tripleHashSet.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index bd8ea5f9647..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/tripleMultiAssignment.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 8402b5849de..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/tripleToList.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 6c3677160b5..00000000000 --- a/backend.native/tests/external/stdlib/TuplesTest/tripleToString.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 415fe460b4c..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/arrayLastIndex.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index a6d16ae3729..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/asIterable.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 69e99f726dc..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/asList.kt +++ /dev/null @@ -1,109 +0,0 @@ -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 deleted file mode 100644 index 26e8bf65240..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/asListObjects.kt +++ /dev/null @@ -1,34 +0,0 @@ -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 deleted file mode 100644 index 1e46b20314d..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/asListPrimitives.kt +++ /dev/null @@ -1,33 +0,0 @@ -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 deleted file mode 100644 index a8687dd2117..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/average.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 042a7ef214a..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/booleanArray.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 01c141aca05..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/booleanArrayInit.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index cb9c54f557f..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/byteArray.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 9a81221294c..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/byteArrayInit.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 71b899a7c23..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/charArray.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 38526d92749..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/charArrayInit.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 90bc34adc79..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/contains.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 61142a7fc28..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepEquals.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 979642810c6..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepHashCode.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 8011121ac30..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToString.kt +++ /dev/null @@ -1,13 +0,0 @@ -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(null, "aa", 1, null, charArrayOf('d'), arrayOf()) - arr[0] = arr - 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 deleted file mode 100644 index b08e26488ad..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/contentDeepToStringNoRecursion.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 0ebfb961a67..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/contentEquals.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index f21040484bc..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/contentHashCode.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index ac01548b5b3..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/contentToString.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index ea389b15e12..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/copyAndResize.kt +++ /dev/null @@ -1,51 +0,0 @@ -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 deleted file mode 100644 index ef9a642b786..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/copyOf.kt +++ /dev/null @@ -1,48 +0,0 @@ -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 deleted file mode 100644 index 9a7540b9f83..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/copyOfRange.kt +++ /dev/null @@ -1,48 +0,0 @@ -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 deleted file mode 100644 index 495a28c7598..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/doubleArray.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 926141d056e..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/doubleArrayInit.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index da34b59199b..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/drop.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index a3967312623..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/dropLast.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 0a4aee2bd96..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/dropLastWhile.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 81055582fd0..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/dropWhile.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 9b7386a959e..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/emptyArrayLastIndex.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index bf7db78f5d7..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/filter.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 7ea6fc7c7a6..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/filterIndexed.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 585b0a380ae..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/filterNot.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index b306e890884..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/filterNotNull.kt +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index f32b6a53438..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/first.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 12bf608b736..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/flattenArray.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 822bfcc6ff8..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/floatArray.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 9c456126823..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/floatArrayInit.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index fbedc5fd94a..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/indexOf.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index c91a1f4b6aa..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/indexOfInPrimitiveArrays.kt +++ /dev/null @@ -1,42 +0,0 @@ -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 deleted file mode 100644 index 3cfb40a3dab..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/intArray.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 8fc44dffa33..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/intArrayInit.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 29f9cd6731b..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/isEmpty.kt +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 4a9c9b3759b..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/isNotEmpty.kt +++ /dev/null @@ -1,6 +0,0 @@ -import kotlin.test.* - -fun box() { - assertFalse(intArrayOf().isNotEmpty()) - assertTrue(intArrayOf(1).isNotEmpty()) -} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/iterators.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/iterators.kt deleted file mode 100644 index 4c2260cbef1..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/iterators.kt +++ /dev/null @@ -1,54 +0,0 @@ -import kotlin.test.* - -public fun compare(expected: T, actual: T, block:CompareContext.() -> Unit) { - CompareContext(expected, actual).block() -} - -public 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) - } -} - -public fun CompareContext>.iteratorBehavior() { - propertyEquals { hasNext() } - - while (expected.hasNext()) { - propertyEquals { next() } - propertyEquals { hasNext() } - } - propertyFails { next() } -} - -fun box() { - fun checkContract(array: T, toList: T.() -> List, iterator: T.() -> Iterator) = - compare(array.toList().iterator(), array.iterator()) { - iteratorBehavior() - } - - checkContract(arrayOf("a", "b", "c"), { toList() }, { iterator() }) - checkContract(intArrayOf(), { toList() }, { iterator() }) - checkContract(intArrayOf(1, 2, 3), { toList() }, { iterator() }) - checkContract(shortArrayOf(1, 2, 3), { toList() }, { iterator() }) - checkContract(byteArrayOf(1, 2, 3), { toList() }, { iterator() }) - checkContract(longArrayOf(1L, 2L, 3L), { toList() }, { iterator() }) - checkContract(doubleArrayOf(2.0, 3.0, 9.0), { toList() }, { iterator() }) - checkContract(floatArrayOf(2f, 3f, 9f), { toList() }, { iterator() }) - checkContract(charArrayOf('a', 'b', 'c'), { toList() }, { iterator() }) - checkContract(booleanArrayOf(true, false), { toList() }, { iterator() }) -} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/joinToString.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/joinToString.kt deleted file mode 100644 index 8ef019bf180..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/joinToString.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 1491662a40f..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/last.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index c8b3f11d28d..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/lastIndexOf.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 93999ec47b4..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/longArray.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 93d5febf5d6..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/longArrayInit.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index a173bcd5bf5..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/map.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 311f9903189..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexed.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 8222603b60c..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/mapIndexedNotNull.kt +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 89300fba1af..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/mapNotNull.kt +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 9ea8818caae..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/max.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 7184725db9b..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/maxBy.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index f147262d2a6..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/maxByEvaluateOnce.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 1c3358d3da4..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/maxByInPrimitiveArrays.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 2a27afc0144..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/maxInPrimitiveArrays.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 2eeaa6e7e2d..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/maxIndex.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 82f02845cb2..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/maxWith.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index e28798ffca9..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/maxWithInPrimitiveArrays.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 95e53a40dfb..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/min.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 034c43c6b29..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/minBy.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 2c511c248cc..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/minByEvaluateOnce.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 8e7ed026699..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/minByInPrimitiveArrays.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index addaac4769a..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/minInPrimitiveArrays.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index f977da3b6cf..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/minIndex.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 96eba9a1a9b..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/minWith.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 22da478ac3f..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/minWithInPrimitiveArrays.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 5aa86dbbd8e..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNotNull.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 93e5fd65cb7..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/orEmptyNull.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 0ae56e98dae..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/plus.kt +++ /dev/null @@ -1,47 +0,0 @@ -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 deleted file mode 100644 index 66e82d2407f..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/plusAssign.kt +++ /dev/null @@ -1,46 +0,0 @@ -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 deleted file mode 100644 index 9be2f32e222..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/plusInference.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 64f08888595..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/plusVararg.kt +++ /dev/null @@ -1,47 +0,0 @@ -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 deleted file mode 100644 index 5888b534211..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/reduce.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index f142524ed02..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/reduceIndexed.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 92b7ddd1934..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/reduceRight.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index aca212570cb..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/reduceRightIndexed.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 48ef9813513..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/reverseInPlace.kt +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index 962bf2ed7bd..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/reversed.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 78a8aa08a63..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/reversedArray.kt +++ /dev/null @@ -1,50 +0,0 @@ -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 deleted file mode 100644 index 3338750bf47..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/shortArray.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 3e5f27d3275..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/shortArrayInit.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 399fc1db13d..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/slice.kt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index d7e51fb56d5..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/sliceArray.kt +++ /dev/null @@ -1,56 +0,0 @@ -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 deleted file mode 100644 index 72b40c760cd..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/sort.kt +++ /dev/null @@ -1,64 +0,0 @@ -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 deleted file mode 100644 index 6a35c3a217f..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/sortByInPlace.kt +++ /dev/null @@ -1,39 +0,0 @@ -import kotlin.test.* - -fun > assertSorted(array: Array, message: String = "") = assertSorted(array, message, { it }) - -inline fun > assertSorted(array: Array, message: String = "", crossinline selector: (T) -> R) { - if (array.isEmpty() || array.size == 1) { - return - } - var prev = selector(array[0]) - for (i in 1..array.lastIndex) { - val cur = selector(array[i]) - assertTrue(prev.compareTo(cur) <= 0, message) - prev = cur - } -} - -inline fun > assertSortedDescending(array: Array, message: String = "", crossinline selector: (T) -> R) { - if (array.isEmpty() || array.size == 1) { - return - } - var prev = selector(array[0]) - for (i in 1..array.lastIndex) { - val cur = selector(array[i]) - assertTrue(prev.compareTo(cur) >= 0, message) - prev = cur - } -} - -fun box() { - val data = arrayOf("aa" to 20, "ab" to 3, "aa" to 3) - data.sortBy { it.second } - assertSorted(data) { it.second } - - data.sortBy { it.first } - assertSorted(data) { it.first } - - data.sortByDescending { (it.first + it.second).length } - assertSortedDescending(data) { (it.first + it.second).length } -} diff --git a/backend.native/tests/external/stdlib/collections/ArraysTest/sortedBy.kt b/backend.native/tests/external/stdlib/collections/ArraysTest/sortedBy.kt deleted file mode 100644 index c98b5849740..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/sortedBy.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 25d163bdf75..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/sortedNullableBy.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 8bac9065cb6..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/sortedTests.kt +++ /dev/null @@ -1,51 +0,0 @@ -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 deleted file mode 100644 index 567c85977f2..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/sortedWith.kt +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index c3d317814ff..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/sum.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 0ae9c98a778..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/sumInPrimitiveArrays.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 53e32ac5dc0..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/take.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 21db77d8652..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/takeLast.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 4486bd24547..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/takeLastWhile.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index a7276fc1882..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/takeWhile.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 03eb8fcd60b..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/toPrimitiveArray.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index aac6212c5d3..00000000000 --- a/backend.native/tests/external/stdlib/collections/ArraysTest/toTypedArray.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 1070df762e3..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/abstractCollectionToArray.kt +++ /dev/null @@ -1,32 +0,0 @@ -import kotlin.test.* -import kotlin.comparisons.* - -fun box() { - class TestCollection(val data: Collection) : AbstractCollection() { - override val size get() = data.size - override fun iterator() = data.iterator() - - public override fun toArray(): Array = super.toArray() - public override fun toArray(array: Array): Array = super.toArray(array) - } - - val data = listOf(1, 2, 3) - assertEquals(TestCollection(data).toArray().asList(), data) - assertEquals(TestCollection(listOf()).toArray().size, 0) - - var arr1 = Array(3) { -1 } - var arr2 = TestCollection(data).toArray(arr1) - assertTrue(arr1 === arr2) - assertEquals(arr2.asList(), data) - - arr1 = Array(4) { -1 } - arr2 = TestCollection(data).toArray(arr1) - assertTrue(arr1 === arr2) - assertEquals(arr2.asList(), data + listOf(-1)) - - arr1 = Array(2) { -1 } - arr2 = TestCollection(data).toArray(arr1) - assertFalse(arr1 === arr2) - assertEquals(arr2.asList(), data) - -} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/average.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/average.kt deleted file mode 100644 index 9c0ec28848a..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/average.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index d8f4c9d56cc..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/contains.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index a39385e1b7d..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/copyToArray.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 9fb7e4a0a51..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/count.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 21884c2cfe9..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/createListWithInit.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index a4852c1aafd..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeArray.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 076ee5e3544..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeFirst.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index f5841dc2fab..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeIntArray.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 9ecb0580ee7..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeList.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 07f89c74ea9..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/decomposeSplit.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index b30d0a9c675..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/drop.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 61182be85f5..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/dropLast.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 32840d28eec..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/dropLastWhile.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 76a5861ebcb..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/dropWhile.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index ce2562b51cd..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/filterIntoSet.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 5fe722539d5..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceArray.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index d95f94c17dd..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/filterIsInstanceList.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index be8996860d2..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/filterNotNull.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 9efc924f2a5..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/first.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index c61c1c6baf3..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/fold.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 8d9d6810ee3..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexed.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 2fd6abdff75..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithDifferentTypes.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 4a6d1ae7f40..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldIndexedWithNonCommutativeOperation.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index e4669923e41..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRight.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 03b0c632dde..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexed.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 8dafc2c2876..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithDifferentTypes.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 3ec4fff3ca0..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightIndexedWithNonCommutativeOperation.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index fd714ee3ec8..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithDifferentTypes.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 36fa9ffc44e..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldRightWithNonCommutativeOperation.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index be81abea615..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldWithDifferentTypes.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index ca084d1c335..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/foldWithNonCommutativeOperation.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 6234615c420..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/groupBy.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 33243e731e4..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/groupByKeysAndValues.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index c95f8e8b790..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/indices.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 370d002854f..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/joinTo.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index c46b59ba7c4..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/joinToString.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 295640098e4..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/last.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 063db3566e3..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/listOfNotNull.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 7413f41d85e..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/mapRanges.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index b61edf48208..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/max.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 2072d229881..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/maxBy.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index a72b195a7ec..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/maxByEvaluateOnce.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 27ebf7155cf..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/maxWith.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index da20bf435f9..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/min.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 2288f3bf776..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/minBy.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 6aed50211b8..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/minByEvaluateOnce.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 3d25619c652..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/minWith.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index ea1fe870d5d..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/minusAssign.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 4a7a8856be4..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/minusIsEager.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 3abecfc1a9d..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/partition.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 10a62642b0f..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/plusAssign.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index a0310a32fe3..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionBug.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 49501ad06ab..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/plusCollectionInference.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index b6eea0a04d2..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/plusRanges.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index dd70bf77a9f..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/randomAccess.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index cd90175ad85..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/reduce.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 8ede5abbdbf..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/reduceIndexed.kt +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index dbadeee9858..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/reduceRight.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index ca334c0cd2b..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/reduceRightIndexed.kt +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 6bf95627b86..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/requireNoNulls.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 10bc7fbbccd..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/reverseInPlace.kt +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index 139db62f66f..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/reversed.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index b07d759a29f..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/sortByInPlace.kt +++ /dev/null @@ -1,41 +0,0 @@ -import kotlin.test.* - -fun > assertSorted(list: List, message: String = "") = assertSorted(list, message, { it }) - -inline fun > assertSorted(list: List, message: String = "", crossinline selector: (T) -> R) { - if (list.isEmpty() || list.size == 1) { - return - } - val it = list.iterator() - var prev = selector(it.next()) - while (it.hasNext()) { - val cur = selector(it.next()) - assertTrue(prev.compareTo(cur) <= 0, message) - prev = cur - } -} - -inline fun > assertSortedDescending(list: List, message: String = "", crossinline selector: (T) -> R) { - if (list.isEmpty() || list.size == 1) { - return - } - val it = list.iterator() - var prev = selector(it.next()) - while (it.hasNext()) { - val cur = selector(it.next()) - assertTrue(prev.compareTo(cur) >= 0, message) - prev = cur - } -} - -fun box() { - val data = arrayListOf("aa" to 20, "ab" to 3, "aa" to 3) - data.sortBy { it.second } - assertSorted(data) { it.second } - - data.sortBy { it.first } - assertSorted(data) { it.first } - - data.sortByDescending { (it.first + it.second).length } - assertSortedDescending(data) { (it.first + it.second).length } -} diff --git a/backend.native/tests/external/stdlib/collections/CollectionTest/sortInPlace.kt b/backend.native/tests/external/stdlib/collections/CollectionTest/sortInPlace.kt deleted file mode 100644 index 7c0da8770a3..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/sortInPlace.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 472734896b4..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/sorted.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 76bd0495489..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/sortedBy.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 4717f8b23ed..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/sortedByNullable.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index ecdd17499da..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/sortedNullableBy.kt +++ /dev/null @@ -1,27 +0,0 @@ -import kotlin.test.* -import kotlin.comparisons.* - -fun assertSorted(list: List, cmp: Comparator, message: String = "") { - if (list.isEmpty() || list.size == 1) { - return - } - val it = list.iterator() - var prev = it.next() - while(it.hasNext()) { - val cur = it.next() - assert(cmp.compare(prev, cur) <= 0) - prev = cur - } -} - -fun box() { - fun String.nullIfEmpty() = if (isEmpty()) null else this - listOf(null, "", "a").let { - assertSorted(it.sortedWith(nullsFirst(compareBy { it })), nullsFirst(compareBy { it })) - assertSorted(it.sortedWith(nullsLast(compareByDescending { it })), compareByDescending { it }) - assertSorted( - it.sortedWith(nullsFirst(compareByDescending { it.nullIfEmpty() })), - 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 deleted file mode 100644 index 8a958f2fc23..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/sortedWith.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index a552348dcfe..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/specialLists.kt +++ /dev/null @@ -1,101 +0,0 @@ -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 deleted file mode 100644 index b67e588037f..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/specialMaps.kt +++ /dev/null @@ -1,135 +0,0 @@ -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 deleted file mode 100644 index 025014977d0..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/specialSets.kt +++ /dev/null @@ -1,116 +0,0 @@ -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 deleted file mode 100644 index 134f36c1f59..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/subscript.kt +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index e6ddda9e7c2..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/sum.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index f040d718845..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/take.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 0e297cddba5..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/takeLast.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 21367cfc915..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/takeLastWhile.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 8cbc72dd2d3..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/takeReturnsFirstNElements.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index ffb95611e17..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/takeWhile.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index ba108d0296f..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/toStringTest.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 6251d798b8e..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/unzipArray.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 3f355096bd7..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/unzipList.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index c59760d0146..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/zip.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 905c0b39c71..00000000000 --- a/backend.native/tests/external/stdlib/collections/CollectionTest/zipTransform.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index bbd74e97386..00000000000 --- a/backend.native/tests/external/stdlib/collections/GroupingTest/countEach.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 31420b6705b..00000000000 --- a/backend.native/tests/external/stdlib/collections/GroupingTest/foldWithComputedInitialValue.kt +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index 8db6034c0a7..00000000000 --- a/backend.native/tests/external/stdlib/collections/GroupingTest/foldWithConstantInitialValue.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index d8d0a64c771..00000000000 --- a/backend.native/tests/external/stdlib/collections/GroupingTest/groupingProducers.kt +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index acd88de57cf..00000000000 --- a/backend.native/tests/external/stdlib/collections/GroupingTest/reduce.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 01428365ffb..00000000000 --- a/backend.native/tests/external/stdlib/collections/IteratorsTest/iterationOverIterator.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 742ba2b3ea7..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElement.kt +++ /dev/null @@ -1,30 +0,0 @@ -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 deleted file mode 100644 index 7682e03463c..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByElementNullable.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index d9690e52323..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKey.kt +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index c0db07ac499..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByKeyWithComparator.kt +++ /dev/null @@ -1,34 +0,0 @@ -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 deleted file mode 100644 index 93e46e0a3fc..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchByMultipleKeys.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index e0191eb656e..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListBinarySearchTest/binarySearchWithComparator.kt +++ /dev/null @@ -1,30 +0,0 @@ -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 deleted file mode 100644 index 7016b530220..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListSpecificTest/_toString.kt +++ /dev/null @@ -1,41 +0,0 @@ -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 deleted file mode 100644 index 4b64843c1c5..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListSpecificTest/getOr.kt +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index 828fb364c07..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListSpecificTest/indexOfLast.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 329657fa1a6..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListSpecificTest/lastIndex.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 997ec4ab342..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListSpecificTest/mutableList.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 4e5438b457e..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListSpecificTest/slice.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 041f8256464..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListSpecificTest/tail.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 7927567acc2..00000000000 --- a/backend.native/tests/external/stdlib/collections/ListSpecificTest/testNullToString.kt +++ /dev/null @@ -1,5 +0,0 @@ -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 deleted file mode 100644 index 53bed2a1fc3..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/all.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 0422fcd51e4..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/any.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 3c41c9c48c4..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/contains.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index d80b749e71b..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/countBy.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 2801e8092ee..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/createFrom.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 7d222467795..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/createLinkedMap.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 8ac9df0e653..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/createMutableMap.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 16769fba3f3..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/createUsingTo.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index cef9d5cd15b..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/createWithPairSelector.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index b25e4e2866d..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/createWithSelector.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 90932bf5ad8..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorAndOverwrite.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 963a1c37bdc..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/createWithSelectorForKeyAndValue.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 9ebc707445b..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/filter.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 943f573a945..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/filterNot.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 694a65d8eef..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/filterOutProjectedTo.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 95747a65013..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/getOrElse.kt +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 04fdb6d60d7..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/getOrPut.kt +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index c869bc81c9e..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/getValue.kt +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index bc1cb9c3bbf..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/iterate.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index ad3bd7a4a3b..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/iterateWithExtraction.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index bc1cb9c3bbf..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/iterateWithProperties.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 1324faea415..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/map.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 69476b7e8c1..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/mapKeys.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 0201636e292..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/mapNotNull.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 934efa2785a..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/mapValues.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 98425833983..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/onEach.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index ca49946590b..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/plusAny.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 1b16792941d..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/populateTo.kt +++ /dev/null @@ -1,22 +0,0 @@ -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 deleted file mode 100644 index 013d120f6fd..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/setViaIndexOperators.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 876fd6d0d4b..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/sizeAndEmpty.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 7a07996f926..00000000000 --- a/backend.native/tests/external/stdlib/collections/MapTest/stream.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index ab70a139499..00000000000 --- a/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/addAll.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 3e21bb400b4..00000000000 --- a/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/removeAll.kt +++ /dev/null @@ -1,36 +0,0 @@ -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 deleted file mode 100644 index 20eec783fe7..00000000000 --- a/backend.native/tests/external/stdlib/collections/MutableCollectionsTest/retainAll.kt +++ /dev/null @@ -1,47 +0,0 @@ -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 deleted file mode 100644 index f2a460e3278..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testAddIOOB.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 18cf862b5f4..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBehavior.kt +++ /dev/null @@ -1,105 +0,0 @@ -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 deleted file mode 100644 index 217cf9fe861..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testBidirectionalModifications.kt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 7fc03534986..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testContains.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 00718994f43..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testDoubleReverse.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index dab00d8c34c..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testEmpty.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 05c2382d367..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testGetIOOB.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index f29674d2835..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testIndexOf.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 14b903d31fe..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableAdd.kt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 7743d6d7a20..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableClear.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index cfb0d29808e..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableDoubleReverse.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index f3b4767ab4f..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableEmpty.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index f862384acf4..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemove.kt +++ /dev/null @@ -1,20 +0,0 @@ -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 deleted file mode 100644 index 32c59bc3d69..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableRemoveByObj.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index faf4257dee3..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableReversedSubList.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 0623f75dfec..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSet.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 975e95efdde..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSimple.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index e4c4207502d..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testMutableSubList.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 03516c776f1..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testNullToString.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index fbd0ca111c2..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRandomAccess.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index c391ea91cfc..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testRemoveIOOB.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 7ff2f67f07c..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testReversedSubList.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index e1d17160b1f..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSetIOOB.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index b04de95d064..00000000000 --- a/backend.native/tests/external/stdlib/collections/ReversedViewsTest/testSimple.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 90dcba9a9c4..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceJVMTest/filterIsInstance.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 3fc2772eeff..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/distinct.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 0c30c748e88..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/distinctBy.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 398709def71..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/drop.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index c9449ef04f8..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/dropWhile.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 40796b2e832..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/filterAndTakeWhileExtractTheElementsWithinRange.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index ebea48b4085..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/filterEmptySequence.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index f67a00a86b9..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/filterIndexed.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 02313a891a2..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/filterNot.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 4c355fe4900..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/filterNotNull.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 3751a50c95a..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/filterNullable.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index e265c16cf60..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/flatMap.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index b5292d129f5..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapAndTakeExtractTheTransformedElements.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 459ccc7bb53..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapOnEmpty.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 79466f22779..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/flatMapWithEmptyItems.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 877380dff89..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/flatten.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index 40b23c16a99..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/foldReducesTheFirstNElements.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index b89c59a7d67..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/iterationOverSequence.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index cd526af8ee3..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/joinConcatenatesTheFirstNElementsAboveAThreshold.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 6e09049bd07..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/makeSequenceOneTimeConstrained.kt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 1a920467204..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/mapAndJoinToString.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 7d96a2946d8..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/mapAndTakeWhileExtractTheTransformedElements.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index f2a708c4958..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/mapEmptySequence.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 42ecd81c38a..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexed.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 773e06f90ac..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/mapIndexedNotNull.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index a7db52f17ca..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/mapNotNull.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index b42f7d4f58b..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/minusAssign.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 0b37421e2a6..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/minusIsLazyIterated.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index d7b266ea340..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/onEach.kt +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index 2241fbe1e1d..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/plusAssign.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index e6b4f7302cf..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/requireNoNulls.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index e26da0c533d..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceExtensions.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 49f2bc9ccae..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunction.kt +++ /dev/null @@ -1,19 +0,0 @@ -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 deleted file mode 100644 index f3e12c2812e..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithInitialValue.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index faaaf6d8693..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromFunctionWithLazyInitialValue.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 02f8d1da637..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/sequenceFromIterator.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 92a9850f58d..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/sorted.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 9dc1164f6c0..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/sortedBy.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 775fcee8378..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/sortedWith.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index c3ca9f2566c..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/subSequence.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 076fdce1314..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/take.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 8d448587a5d..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/takeExtractsTheFirstNElements.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 906f977f091..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/toStringJoinsNoMoreThanTheFirstTenElements.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 944539bc55b..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/unzip.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 13ae651147f..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/withIndex.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index fe289eb8f34..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/zip.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index f957c360657..00000000000 --- a/backend.native/tests/external/stdlib/collections/SequenceTest/zipPairs.kt +++ /dev/null @@ -1,14 +0,0 @@ -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/distinct.kt b/backend.native/tests/external/stdlib/collections/SetOperationsTest/distinct.kt deleted file mode 100644 index 9658b0a25f4..00000000000 --- a/backend.native/tests/external/stdlib/collections/SetOperationsTest/distinct.kt +++ /dev/null @@ -1,7 +0,0 @@ -import kotlin.test.* - - -fun box() { - assertEquals(listOf(1, 3, 5), listOf(1, 3, 3, 1, 5, 1, 3).distinct()) - assertTrue(listOf().distinct().isEmpty()) -} diff --git a/backend.native/tests/external/stdlib/collections/SetOperationsTest/distinctBy.kt b/backend.native/tests/external/stdlib/collections/SetOperationsTest/distinctBy.kt deleted file mode 100644 index 1915eefdaa0..00000000000 --- a/backend.native/tests/external/stdlib/collections/SetOperationsTest/distinctBy.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index f88c6ee2e1b..00000000000 --- a/backend.native/tests/external/stdlib/collections/SetOperationsTest/intersect.kt +++ /dev/null @@ -1,9 +0,0 @@ -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/plusAssign.kt b/backend.native/tests/external/stdlib/collections/SetOperationsTest/plusAssign.kt deleted file mode 100644 index 3000005ec4d..00000000000 --- a/backend.native/tests/external/stdlib/collections/SetOperationsTest/plusAssign.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index 1dc7312d101..00000000000 --- a/backend.native/tests/external/stdlib/collections/SetOperationsTest/subtract.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 4da8f95b830..00000000000 --- a/backend.native/tests/external/stdlib/collections/SetOperationsTest/union.kt +++ /dev/null @@ -1,7 +0,0 @@ -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 deleted file mode 100644 index 4b8bf4489e7..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testEquals.kt +++ /dev/null @@ -1,28 +0,0 @@ -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 deleted file mode 100644 index 5bbfd4e101f..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testGetPlusFold.kt +++ /dev/null @@ -1,63 +0,0 @@ -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 deleted file mode 100644 index 5be6f1a5d56..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testLastDispatcher.kt +++ /dev/null @@ -1,49 +0,0 @@ -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 deleted file mode 100644 index bfb77512d83..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testMinusKey.kt +++ /dev/null @@ -1,58 +0,0 @@ -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 deleted file mode 100644 index 3fa8b1b7438..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/CoroutineContextTest/testPlusCombined.kt +++ /dev/null @@ -1,33 +0,0 @@ -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 deleted file mode 100644 index 0698bd40b65..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/CoroutinesReferenceValuesTest/testBadClass.kt +++ /dev/null @@ -1,47 +0,0 @@ -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 deleted file mode 100644 index 081e6dcef6b..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testCallHasNextSeveralTimes.kt +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index a45ecea9ee0..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testEmptySequence.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 3c14bcced71..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testExceptionInCoroutine.kt +++ /dev/null @@ -1,27 +0,0 @@ -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 deleted file mode 100644 index acb58d4d562..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testInfiniteYieldAll.kt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index cb2b2fe45d5..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testLaziness.kt +++ /dev/null @@ -1,35 +0,0 @@ -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 deleted file mode 100644 index 91ae9984ef4..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testManualIteration.kt +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index 2712c971c93..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testParallelIteration.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 6961604fb92..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testSimple.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index fc8d7c62977..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollection.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index d3541b68331..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionManyEmpty.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 7bb3587ba3b..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedBoth.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index ea8da0b5eb4..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedFirst.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index a6137ee93b8..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLast.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 73535e6e966..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionMixedLong.kt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 72e87e97b93..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllCollectionOneEmpty.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 57468ad7189..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllIterator.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 72ed0092537..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSequence.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 7e05e113cdf..00000000000 --- a/backend.native/tests/external/stdlib/coroutines/SequenceBuilderTest/testYieldAllSideEffects.kt +++ /dev/null @@ -1,42 +0,0 @@ -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 deleted file mode 100644 index 1fab750288f..00000000000 --- a/backend.native/tests/external/stdlib/language/EscapedTestNamesTest/numbersEqual.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 47c7ae5e3f6..00000000000 --- a/backend.native/tests/external/stdlib/language/EscapedTestNamesTest/stringsEqual.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index c773cb4278d..00000000000 --- a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/andForInt.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index bb8bb343f77..00000000000 --- a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/invForInt.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index c214ec2f947..00000000000 --- a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/orForInt.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index f8ab44787a7..00000000000 --- a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shlForInt.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index c96d856a6d7..00000000000 --- a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/shrForInt.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 0772d5bea8b..00000000000 --- a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/ushrForInt.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index f5719ca07d9..00000000000 --- a/backend.native/tests/external/stdlib/numbers/BitwiseOperationsTest/xorForInt.kt +++ /dev/null @@ -1,6 +0,0 @@ -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 deleted file mode 100644 index 42fa813912d..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMax.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 39b89b32cf9..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayMin.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 89a82081fe5..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMax.kt +++ /dev/null @@ -1,17 +0,0 @@ -// IGNORE_BACKEND: NATIVE -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 deleted file mode 100644 index e639f5dc1c7..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/arrayTMin.kt +++ /dev/null @@ -1,17 +0,0 @@ -// IGNORE_BACKEND: NATIVE -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 deleted file mode 100644 index 5776efd7060..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMax.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 994e8aa1923..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listMin.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 0528b5fd734..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMax.kt +++ /dev/null @@ -1,17 +0,0 @@ -// IGNORE_BACKEND: NATIVE -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 deleted file mode 100644 index 71c077d49ac..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/listTMin.kt +++ /dev/null @@ -1,17 +0,0 @@ -// IGNORE_BACKEND: NATIVE -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 deleted file mode 100644 index b1e1d6b401b..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOf.kt +++ /dev/null @@ -1,47 +0,0 @@ -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 deleted file mode 100644 index 2216a0bdd91..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/maxOfT.kt +++ /dev/null @@ -1,17 +0,0 @@ -// IGNORE_BACKEND: NATIVE -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 deleted file mode 100644 index 03a448a0897..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOf.kt +++ /dev/null @@ -1,47 +0,0 @@ -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 deleted file mode 100644 index 841ebf82224..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/minOfT.kt +++ /dev/null @@ -1,17 +0,0 @@ -// IGNORE_BACKEND: NATIVE -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 deleted file mode 100644 index a15da1f6a0d..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMax.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index d8eca65586c..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/primitiveArrayMin.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 65b17913052..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMax.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index e30f7f7ec4c..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceMin.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 52acf6a66a3..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMax.kt +++ /dev/null @@ -1,17 +0,0 @@ -// IGNORE_BACKEND: NATIVE -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 deleted file mode 100644 index 7857d05deca..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NaNPropagationTest/sequenceTMin.kt +++ /dev/null @@ -1,17 +0,0 @@ -// IGNORE_BACKEND: NATIVE -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 deleted file mode 100644 index 7b2b56e3dbf..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NumbersTest/byteMinMaxValues.kt +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index 1c0bc7545e1..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NumbersTest/doubleMinMaxValues.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 3e5109ac6bc..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NumbersTest/doubleProperties.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 22c2b009a83..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NumbersTest/floatMinMaxValues.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index c8f1edf41ab..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NumbersTest/floatProperties.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 781e8a88352..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NumbersTest/intMinMaxValues.kt +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index 4f9429f1da3..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NumbersTest/longMinMaxValues.kt +++ /dev/null @@ -1,31 +0,0 @@ -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 deleted file mode 100644 index 938437e80d3..00000000000 --- a/backend.native/tests/external/stdlib/numbers/NumbersTest/shortMinMaxValues.kt +++ /dev/null @@ -1,31 +0,0 @@ -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/VarByMapExtensionsTest$a2$2.class b/backend.native/tests/external/stdlib/properties/VarByMapExtensionsTest$a2$2.class deleted file mode 100644 index 351c437c39991a3b2e8403443c67830358b6e6a4..0000000000000000000000000000000000000000 GIT binary patch literal 0 HcmV?d00001 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(JXh6J4(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 deleted file mode 100644 index cfbf2325011..00000000000 --- a/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/ObservablePropertyTest.kt +++ /dev/null @@ -1,23 +0,0 @@ -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 deleted file mode 100644 index 02338e89fb1..00000000000 --- a/backend.native/tests/external/stdlib/properties/delegation/DelegationTest/VetoablePropertyTest.kt +++ /dev/null @@ -1,33 +0,0 @@ -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 deleted file mode 100644 index 179622791e1..00000000000 --- a/backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/ValByMapExtensionsTest.kt +++ /dev/null @@ -1,32 +0,0 @@ -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 deleted file mode 100644 index dc4f105c9a9..00000000000 --- a/backend.native/tests/external/stdlib/properties/delegation/MapAccessorsTest/VarByMapExtensionsTest.kt +++ /dev/null @@ -1,40 +0,0 @@ -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" - assertFailsWith { c } - - map["a"] = null - assertFailsWith { a } - - 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 deleted file mode 100644 index c089eff478c..00000000000 --- a/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/IdentityEqualsIsUsedToUnescapeLazyValTest.kt +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index f314fa49974..00000000000 --- a/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/LazyValTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 16809d9ee64..00000000000 --- a/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/NullableLazyValTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index f75816a98f9..00000000000 --- a/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeLazyValTest.kt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index 35afbcbcd2b..00000000000 --- a/backend.native/tests/external/stdlib/properties/delegation/lazy/LazyValuesTest/UnsafeNullableLazyValTest.kt +++ /dev/null @@ -1,29 +0,0 @@ -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/ranges/CoercionTest/coercionsComparable.kt b/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsComparable.kt deleted file mode 100644 index b14ad3f8880..00000000000 --- a/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsComparable.kt +++ /dev/null @@ -1,34 +0,0 @@ -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 deleted file mode 100644 index 4bf6b52f9f3..00000000000 --- a/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsDouble.kt +++ /dev/null @@ -1,33 +0,0 @@ -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 deleted file mode 100644 index 666700d10f0..00000000000 --- a/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsInt.kt +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index 60c2231e8d3..00000000000 --- a/backend.native/tests/external/stdlib/ranges/CoercionTest/coercionsLong.kt +++ /dev/null @@ -1,25 +0,0 @@ -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 deleted file mode 100644 index dae7ff454de..00000000000 --- a/backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/calculateFinalElement.kt +++ /dev/null @@ -1,55 +0,0 @@ -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 deleted file mode 100644 index fe735460ae3..00000000000 --- a/backend.native/tests/external/stdlib/ranges/ProgressionLastElementTest/iterateToFinalElement.kt +++ /dev/null @@ -1,41 +0,0 @@ -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 deleted file mode 100644 index 964fc692503..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyConstant.kt +++ /dev/null @@ -1,91 +0,0 @@ -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 deleted file mode 100644 index e9272132279..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyDownto.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 3b8059c7400..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/emptyRange.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 683543c95b0..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedDownTo.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 96f941f39f0..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/inexactSteppedRange.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 12b5e1d944e..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementDownTo.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 992c112948b..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/oneElementRange.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index bc01d09f2a7..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/openRange.kt +++ /dev/null @@ -1,92 +0,0 @@ -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 deleted file mode 100644 index d68e8190f81..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedBackSequence.kt +++ /dev/null @@ -1,103 +0,0 @@ -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 deleted file mode 100644 index 5e52dcf3af9..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyBackSequence.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index f5cbe91e8c9..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedEmptyRange.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 7ba92565ddd..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedInexactSteppedDownTo.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 097fbdbdd4b..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/reversedRange.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 8970d51f2c7..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleDownTo.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 79348c9f871..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleRange.kt +++ /dev/null @@ -1,103 +0,0 @@ -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 deleted file mode 100644 index cae5d83366c..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedDownTo.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 958c1ac268d..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeIterationTest/simpleSteppedRange.kt +++ /dev/null @@ -1,93 +0,0 @@ -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 deleted file mode 100644 index 41de87a0def..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/byteRange.kt +++ /dev/null @@ -1,37 +0,0 @@ -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 deleted file mode 100644 index c83788d641d..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/charRange.kt +++ /dev/null @@ -1,29 +0,0 @@ -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 deleted file mode 100644 index 0b235a8a407..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/comparableRange.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index fb90643568f..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/doubleRange.kt +++ /dev/null @@ -1,48 +0,0 @@ -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 deleted file mode 100644 index 7807b033ccd..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/emptyEquals.kt +++ /dev/null @@ -1,27 +0,0 @@ -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 deleted file mode 100644 index 07a4f40ead3..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/emptyHashCode.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index dc98c1fab69..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/floatRange.kt +++ /dev/null @@ -1,49 +0,0 @@ -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 deleted file mode 100644 index b7ec53be94b..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/intRange.kt +++ /dev/null @@ -1,37 +0,0 @@ -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 deleted file mode 100644 index 043490e81f2..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/isEmpty.kt +++ /dev/null @@ -1,21 +0,0 @@ -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 deleted file mode 100644 index b90455475a7..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/longRange.kt +++ /dev/null @@ -1,39 +0,0 @@ -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 deleted file mode 100644 index b6106b813ff..00000000000 --- a/backend.native/tests/external/stdlib/ranges/RangeTest/shortRange.kt +++ /dev/null @@ -1,35 +0,0 @@ -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 deleted file mode 100644 index 61763313388..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/escapeLiteral.kt +++ /dev/null @@ -1,10 +0,0 @@ -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/harmony/AllCodePointsTest.kt b/backend.native/tests/external/stdlib/text/RegexTest/harmony/AllCodePointsTest.kt deleted file mode 100644 index c30df1c5f45..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/harmony/AllCodePointsTest.kt +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import kotlin.text.* -import kotlin.test.* - -fun assertTrue(msg: String, value: Boolean) = assertTrue(value, msg) -fun assertFalse(msg: String, value: Boolean) = assertFalse(value, msg) - -fun codePointToString(codePoint: Int): String { - val charArray = Char.toChars(codePoint) - return fromCharArray(charArray, 0, charArray.size) -} - -// TODO: Here is a performance problem: an execution of this test requires much more time than it in Kotlin/JVM. -fun box() { - // Regression for HARMONY-3145 - var p = Regex("(\\p{all})+") - var res = true - var cnt = 0 - var s: String - for (i in 0..1114111) { - s = codePointToString(i) - if (!s.matches(p)) { - cnt++ - res = false - } - } - assertTrue(res) - assertEquals(0, cnt) - - p = Regex("(\\P{all})+") - res = true - cnt = 0 - - for (i in 0..1114111) { - s = codePointToString(i) - if (!s.matches(p)) { - cnt++ - res = false - } - } - - assertFalse(res) - assertEquals(0x110000, cnt) -} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/text/RegexTest/harmony/MatchResultTest.kt b/backend.native/tests/external/stdlib/text/RegexTest/harmony/MatchResultTest.kt deleted file mode 100644 index fffe31e64e6..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/harmony/MatchResultTest.kt +++ /dev/null @@ -1,474 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import kotlin.text.* -import kotlin.test.* - -fun assertTrue(msg: String, value: Boolean) = assertTrue(value, msg) -fun assertFalse(msg: String, value: Boolean) = assertFalse(value, msg) - -internal var testPatterns = arrayOf("(a|b)*abb", "(1*2*3*4*)*567", "(a|b|c|d)*aab", "(1|2|3|4|5|6|7|8|9|0)(1|2|3|4|5|6|7|8|9|0)*", "(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)*", "(a|b)*(a|b)*A(a|b)*lice.*", "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)(a|b|c|d|e|f|g|h|" + "i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)*(1|2|3|4|5|6|7|8|9|0)*|while|for|struct|if|do") - -internal var groupPatterns = arrayOf("(a|b)*aabb", "((a)|b)*aabb", "((a|b)*)a(abb)", "(((a)|(b))*)aabb", "(((a)|(b))*)aa(b)b", "(((a)|(b))*)a(a(b)b)") - -fun testReplaceAll() { - val input = "aabfooaabfooabfoob" - val pattern = "a*b" - val regex = Regex(pattern) - - assertEquals("-foo-foo-foo-", regex.replace(input, "-")) -} - -fun testReplaceFirst() { - val input = "zzzdogzzzdogzzz" - val pattern = "dog" - val regex = Regex(pattern) - - assertEquals("zzzcatzzzdogzzz", regex.replaceFirst(input, "cat")) -} - -/* - * Class under test for String group(int) - */ -fun testGroupint() { - val positiveTestString = "ababababbaaabb" - - // test IndexOutOfBoundsException - // // - for (i in groupPatterns.indices) { - val regex = Regex(groupPatterns[i]) - val result = regex.matchEntire(positiveTestString)!! - try { - // groupPattern equals to number of groups - // of the specified pattern - // // - result.groups[i + 2] - fail("IndexOutBoundsException expected") - result.groups[i + 100] - fail("IndexOutBoundsException expected") - result.groups[-1] - fail("IndexOutBoundsException expected") - result.groups[-100] - fail("IndexOutBoundsException expected") - } catch (e: IndexOutOfBoundsException) { - } - } - - val groupResults = arrayOf( - arrayOf("a"), - arrayOf("a", "a"), - arrayOf("ababababba", "a", "abb"), - arrayOf("ababababba", "a", "a", "b"), - arrayOf("ababababba", "a", "a", "b", "b"), - arrayOf("ababababba", "a", "a", "b", "abb", "b") - ) - - for (i in groupPatterns.indices) { - val regex = Regex(groupPatterns[i]) - val result = regex.matchEntire(positiveTestString)!! - for (j in 0..groupResults[i].size - 1) { - assertEquals(groupResults[i][j], result.groupValues[j + 1], "i: $i j: $j") - } - } - -} - -fun testGroup() { - val positiveTestString = "ababababbaaabb" - val negativeTestString = "gjhfgdsjfhgcbv" - for (element in groupPatterns) { - val regex = Regex(element) - val result = regex.matchEntire(positiveTestString)!! - assertEquals(positiveTestString, result.groupValues[0]) - assertEquals(positiveTestString, result.groups[0]!!.value) - assertEquals(0 until positiveTestString.length, result.groups[0]!!.range) - } - - for (element in groupPatterns) { - val regex = Regex(element) - val result = regex.matchEntire(negativeTestString) - assertEquals(result, null) - } -} - -fun testGroupPossessive() { - val regex = Regex("((a)|(b))++c") - assertEquals("a", regex.matchEntire("aac")!!.groupValues[1]) -} - -fun testMatchesMisc() { - val posSeq = arrayOf( - arrayOf("abb", "ababb", "abababbababb", "abababbababbabababbbbbabb"), - arrayOf("213567", "12324567", "1234567", "213213567", "21312312312567", "444444567"), - arrayOf("abcdaab", "aab", "abaab", "cdaab", "acbdadcbaab"), - arrayOf("213234567", "3458", "0987654", "7689546432", "0398576", "98432", "5"), - arrayOf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", - "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), - arrayOf("ababbaAabababblice", "ababbaAliceababab", "ababbAabliceaaa", "abbbAbbbliceaaa", "Alice"), - arrayOf("a123", "bnxnvgds156", "for", "while", "if", "struct")) - - for (i in testPatterns.indices) { - val regex = Regex(testPatterns[i]) - for (j in 0..posSeq[i].size - 1) { - assertTrue("Incorrect match: " + testPatterns[i] + " vs " + posSeq[i][j], regex.matches(posSeq[i][j])) - } - } -} - -fun testMatchesQuantifiers() { - val testPatternsSingles = arrayOf("a{5}", "a{2,4}", "a{3,}") - val testPatternsMultiple = arrayOf("((a)|(b)){1,2}abb", "((a)|(b)){2,4}", "((a)|(b)){3,}") - - val stringSingles = arrayOf( - arrayOf("aaaaa", "aaa"), - arrayOf("aa", "a", "aaa", "aaaaaa", "aaaa", "aaaaa"), - arrayOf("aaa", "a", "aaaa", "aa") - ) - - val stringMultiples = arrayOf( - arrayOf("ababb", "aba"), - arrayOf("ab", "b", "bab", "ababa", "abba", "abababbb"), - arrayOf("aba", "b", "abaa", "ba") - ) - - for (i in testPatternsSingles.indices) { - val regex = Regex(testPatternsSingles[i]) - for (j in 0..stringSingles.size / 2 - 1) { - assertTrue("Match expected, but failed: " + regex.pattern + " : " + stringSingles[i][j], - regex.matches(stringSingles[i][j * 2]) - ) - assertFalse("Match failure expected, but match succeed: " + regex.pattern + " : " + stringSingles[i][j * 2 + 1], - regex.matches(stringSingles[i][j * 2 + 1]) - ) - } - } - - for (i in testPatternsMultiple.indices) { - val regex = Regex(testPatternsMultiple[i]) - for (j in 0..stringMultiples.size / 2 - 1) { - assertTrue("Match expected, but failed: " + regex.pattern + " : " + stringMultiples[i][j], - regex.matches(stringMultiples[i][j * 2]) - ) - assertFalse("Match failure expected, but match succeed: " + regex.pattern + " : " + stringMultiples[i][j * 2 + 1], - regex.matches(stringMultiples[i][j * 2 + 1]) - ) - } - } - - // Test for the optimized '.+' quantifier node. - assertFalse(Regex(".+abc").matches("abc")) - assertFalse(Regex(".+\nabc", RegexOption.DOT_MATCHES_ALL).matches("\nabc")) - assertFalse(Regex(".+").matches("")) - assertFalse(Regex(".+\n", RegexOption.DOT_MATCHES_ALL).matches("\n")) - assertFalse(Regex(".+abc").containsMatchIn("abc")) - assertFalse(Regex(".+\nabc", RegexOption.DOT_MATCHES_ALL).containsMatchIn("\nabc")) - assertFalse(Regex(".+").containsMatchIn("")) - assertFalse(Regex(".+\n", RegexOption.DOT_MATCHES_ALL).containsMatchIn("\n")) - - assertTrue(Regex(".+abc").matches("aabc")) - assertTrue(Regex(".+\nabc", RegexOption.DOT_MATCHES_ALL).matches("a\nabc")) - assertTrue(Regex(".+").matches("a")) - assertTrue(Regex(".+\n", RegexOption.DOT_MATCHES_ALL).matches("a\n")) - assertTrue(Regex(".+abc").containsMatchIn("aabc")) - assertTrue(Regex(".+\nabc", RegexOption.DOT_MATCHES_ALL).containsMatchIn("a\nabc")) - assertTrue(Regex(".+").containsMatchIn("a")) - assertTrue(Regex(".+\n", RegexOption.DOT_MATCHES_ALL).containsMatchIn("a\n")) -} - -fun testQuantVsGroup() { - val patternString = "(d{1,3})((a|c)*)(d{1,3})((a|c)*)(d{1,3})" - val testString = "dacaacaacaaddaaacaacaaddd" - - val regex = Regex(patternString) - - val result = regex.matchEntire(testString)!! - assertEquals("dacaacaacaaddaaacaacaaddd", result.groupValues[0]) - assertEquals("d", result.groupValues[1]) - assertEquals("acaacaacaa", result.groupValues[2]) - assertEquals("dd", result.groupValues[4]) - assertEquals("aaacaacaa", result.groupValues[5]) - assertEquals("ddd", result.groupValues[7]) -} - -/* - * Class under test for boolean find() - */ -fun testFind() { - var testPattern = "(abb)" - var testString = "cccabbabbabbabbabb" - val regex = Regex(testPattern) - var result = regex.find(testString) - var start = 3 - var end = 6 - while (result != null) { - assertEquals(start, result.groups[1]!!.range.start) - assertEquals(end, result.groups[1]!!.range.endInclusive + 1) - - start = end - end += 3 - result = result.next() - } - - testPattern = "(\\d{1,3})" - testString = "aaaa123456789045" - - val regex2 = Regex(testPattern) - var result2 = regex2.find(testString) - start = 4 - val length = 3 - while (result2 != null) { - assertEquals(testString.substring(start, start + length), result2.groupValues[1]) - start += length - result2 = result2.next() - } -} - -fun testSEOLsymbols() { - val regex = Regex("^a\\(bb\\[$") - assertTrue(regex.matches("a(bb[")) -} - -fun testGroupCount() { - for (i in groupPatterns.indices) { - val regex = Regex(groupPatterns[i]) - val result = regex.matchEntire("ababababbaaabb")!! - assertEquals(i + 1, result.groups.size - 1) - } -} - -fun testReluctantQuantifiers() { - val regex = Regex("(ab*)*b") - val result = regex.matchEntire("abbbb") - if (result != null) { - assertEquals("abbb", result.groupValues[1]) - } else { - fail("Match expected: (ab*)*b vs abbbb") - } -} - -fun testEnhancedFind() { - val input = "foob" - val pattern = "a*b" - val regex = Regex(pattern) - val result = regex.find(input)!! - assertEquals("b", result.groupValues[0]) -} - -fun testPosCompositeGroup() { - val posExamples = arrayOf("aabbcc", "aacc", "bbaabbcc") - val negExamples = arrayOf("aabb", "bb", "bbaabb") - val posPat = Regex("(aa|bb){1,3}+cc") - val negPat = Regex("(aa|bb){1,3}+bb") - - for (element in posExamples) { - assertTrue(posPat.matches(element)) - } - - for (element in negExamples) { - assertFalse(negPat.matches(element)) - } - - assertTrue(Regex("(aa|bb){1,3}+bb").matches("aabbaabb")) -} - -fun testPosAltGroup() { - val posExamples = arrayOf("aacc", "bbcc", "cc") - val negExamples = arrayOf("bb", "aa") - val posPat = Regex("(aa|bb)?+cc") - val negPat = Regex("(aa|bb)?+bb") - - for (element in posExamples) { - assertTrue(posPat.toString() + " vs: " + element, posPat.matches(element)) - } - - for (element in negExamples) { - assertFalse(negPat.matches(element)) - } - - assertTrue(Regex("(aa|bb)?+bb").matches("aabb")) -} - -fun testRelCompGroup() { - var res = "" - for (i in 0..3) { - val regex = Regex("((aa|bb){$i,3}?).*cc") - val result = regex.matchEntire("aaaaaacc") - assertTrue(regex.toString() + " vs: " + "aaaaaacc", result != null) - assertEquals(res, result!!.groupValues[1]) - res += "aa" - } -} - -fun testRelAltGroup() { - var regex = Regex("((aa|bb)??).*cc") - var result = regex.matchEntire("aacc") - assertTrue(regex.toString() + " vs: " + "aacc", result != null) - assertEquals("", result!!.groupValues[1]) - - regex = Regex("((aa|bb)??)cc") - result = regex.matchEntire("aacc") - assertTrue(regex.toString() + " vs: " + "aacc", result != null) - assertEquals("aa", result!!.groupValues[1]) -} - -fun testIgnoreCase() { - var regex = Regex("(aa|bb)*", RegexOption.IGNORE_CASE) - assertTrue(regex.matches("aAbb")) - - regex = Regex("(a|b|c|d|e)*", RegexOption.IGNORE_CASE) - assertTrue(regex.matches("aAebbAEaEdebbedEccEdebbedEaedaebEbdCCdbBDcdcdADa")) - - regex = Regex("[a-e]*", RegexOption.IGNORE_CASE) - assertTrue(regex.matches("aAebbAEaEdebbedEccEdebbedEaedaebEbdCCdbBDcdcdADa")) -} - -fun testQuoteReplacement() { - assertEquals("\\\\aaCC\\$1", Regex.escapeReplacement("\\aaCC$1")) -} - -fun testOverFlow() { - var regex = Regex("(a*)*") - var result = regex.matchEntire("aaa") - assertTrue(result != null) - assertEquals("", result!!.groupValues[1]) - - assertTrue(Regex("(1+)\\1+").matches("11")) - assertTrue(Regex("(1+)(2*)\\2+").matches("11")) - - regex = Regex("(1+)\\1*") - result = regex.matchEntire("11") - - assertTrue(result != null) - assertEquals("11", result!!.groupValues[1]) - - regex = Regex("((1+)|(2+))(\\2+)") - result = regex.matchEntire("11") - - assertTrue(result != null) - assertEquals("1", result!!.groupValues[2]) - assertEquals("1", result.groupValues[1]) - assertEquals("1", result.groupValues[4]) - assertEquals("", result.groupValues[3]) -} - -fun testUnicode() { - assertTrue(Regex("\\x61a").matches("aa")) - assertTrue(Regex("\\u0061a").matches("aa")) - assertTrue(Regex("\\0141a").matches("aa")) - assertTrue(Regex("\\0777").matches("?7")) -} - -fun testUnicodeCategory() { - assertTrue(Regex("\\p{Ll}").matches("k")) // Unicode lower case - assertTrue(Regex("\\P{Ll}").matches("K")) // Unicode non-lower - // case - assertTrue(Regex("\\p{Lu}").matches("K")) // Unicode upper case - assertTrue(Regex("\\P{Lu}").matches("k")) // Unicode non-upper - // case combinations - assertTrue(Regex("[\\p{L}&&[^\\p{Lu}]]").matches("k")) - assertTrue(Regex("[\\p{L}&&[^\\p{Ll}]]").matches("K")) - assertFalse(Regex("[\\p{L}&&[^\\p{Lu}]]").matches("K")) - assertFalse(Regex("[\\p{L}&&[^\\p{Ll}]]").matches("k")) - - // category/character combinations - assertFalse(Regex("[\\p{L}&&[^a-z]]").matches("k")) - assertTrue(Regex("[\\p{L}&&[^a-z]]").matches("K")) - - assertTrue(Regex("[\\p{Lu}a-z]").matches("k")) - assertTrue(Regex("[a-z\\p{Lu}]").matches("k")) - - assertFalse(Regex("[\\p{Lu}a-d]").matches("k")) - assertTrue(Regex("[a-d\\p{Lu}]").matches("K")) - - assertFalse(Regex("[\\p{L}&&[^\\p{Lu}&&[^G]]]").matches("K")) - -} - -fun testSplitEmpty() { - - val regex = Regex("") - val s = regex.split("", 0) - - assertEquals(1, s.size) - assertEquals("", s[0]) -} - -fun testFindDollar() { - val regex = Regex("a$") - val result = regex.find("a\n") - assertTrue(result != null) - assertEquals("a", result!!.groupValues[0]) -} - -/* - * Regression test for HARMONY-674 - */ -fun testPatternMatcher() { - assertTrue(Regex("(?:\\d+)(?:pt)").matches("14pt")) -} - -/** - * Inspired by HARMONY-3360 - */ -fun test3360() { - val str = "!\"#%&'(),-./" - val regex = Regex("\\s") - assertFalse(regex.containsMatchIn(str)) -} - -/** - * Regression test for HARMONY-3360 - */ -fun testGeneralPunctuationCategory() { - val s = arrayOf(",", "!", "\"", "#", "%", "&", "'", "(", ")", "-", ".", "/") - val regexp = "\\p{P}" - - for (i in s.indices) { - val regex = Regex(regexp) - assertTrue(regex.containsMatchIn(s[i])) - } -} - -fun box() { - testReplaceAll() - testReplaceFirst() - testGroupint() - testGroup() - testGroupPossessive() - testMatchesMisc() - testMatchesQuantifiers() - testQuantVsGroup() - testFind() - testSEOLsymbols() - testGroupCount() - testReluctantQuantifiers() - testEnhancedFind() - testPosCompositeGroup() - testPosAltGroup() - testRelCompGroup() - testRelAltGroup() - testIgnoreCase() - testQuoteReplacement() - testOverFlow() - testUnicode() - testUnicodeCategory() - testSplitEmpty() - testFindDollar() - testPatternMatcher() - test3360() - testGeneralPunctuationCategory() -} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/text/RegexTest/harmony/MatchResultTest2.kt b/backend.native/tests/external/stdlib/text/RegexTest/harmony/MatchResultTest2.kt deleted file mode 100644 index d39f25e2a7d..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/harmony/MatchResultTest2.kt +++ /dev/null @@ -1,116 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import kotlin.text.* -import kotlin.test.* - -fun testErrorConditions2() { - // Test match cursors in absence of a match - val regex = Regex("(foo[0-9])(bar[a-z])") - var result = regex.find("foo1barzfoo2baryfoozbar5") - - assertTrue(result != null) - assertEquals(0, result!!.range.start) - assertEquals(7, result.range.endInclusive) - assertEquals(0, result.groups[0]!!.range.start) - assertEquals(7, result.groups[0]!!.range.endInclusive) - assertEquals(0, result.groups[1]!!.range.start) - assertEquals(3, result.groups[1]!!.range.endInclusive) - assertEquals(4, result.groups[2]!!.range.start) - assertEquals(7, result.groups[2]!!.range.endInclusive) - - try { - result.groups[3] - fail("IndexOutOfBoundsException expected") - } catch (e: IndexOutOfBoundsException) { - } - - try { - result.groupValues[3] - fail("IndexOutOfBoundsException expected") - } catch (e: IndexOutOfBoundsException) { - } - - try { - result.groups[-1] - fail("IndexOutOfBoundsException expected") - } catch (e: IndexOutOfBoundsException) { - } - - try { - result.groupValues[-1] - fail("IndexOutOfBoundsException expected") - } catch (e: IndexOutOfBoundsException) { - } - - result = result.next() - assertTrue(result != null) - assertEquals(8, result!!.range.start) - assertEquals(15, result.range.endInclusive) - assertEquals(8, result.groups[0]!!.range.start) - assertEquals(15, result.groups[0]!!.range.endInclusive) - assertEquals(8, result.groups[1]!!.range.start) - assertEquals(11, result.groups[1]!!.range.endInclusive) - assertEquals(12, result.groups[2]!!.range.start) - assertEquals(15, result.groups[2]!!.range.endInclusive) - - try { - result.groups[3] - fail("IndexOutOfBoundsException expected") - } catch (e: IndexOutOfBoundsException) { - } - - try { - result.groupValues[3] - fail("IndexOutOfBoundsException expected") - } catch (e: IndexOutOfBoundsException) { - } - - try { - result.groups[-1] - fail("IndexOutOfBoundsException expected") - } catch (e: IndexOutOfBoundsException) { - } - - try { - result.groupValues[-1] - fail("IndexOutOfBoundsException expected") - } catch (e: IndexOutOfBoundsException) { - } - - result = result.next() - assertFalse(result != null) -} - -/* - * Regression test for HARMONY-997 - */ -fun testReplacementBackSlash() { - val str = "replace me" - val replacedString = "me" - val substitutionString = "\\" - val regex = Regex(replacedString) - try { - regex.replace(str, substitutionString) - fail("IllegalArgumentException should be thrown") - } catch (e: IllegalArgumentException) { - } -} - -fun box() { - testErrorConditions2() - testReplacementBackSlash() -} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/harmony/ModeTest.kt b/backend.native/tests/external/stdlib/text/RegexTest/harmony/ModeTest.kt deleted file mode 100644 index 8e7f46db163..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/harmony/ModeTest.kt +++ /dev/null @@ -1,116 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import kotlin.text.* -import kotlin.test.* - -/** - * Tests Pattern compilation modes and modes triggered in pattern strings - */ -fun testCase() { - var regex: Regex - var result: MatchResult? - - regex = Regex("([a-z]+)[0-9]+") - result = regex.find("cAT123#dog345") - assertNotNull(result) - assertEquals("dog", result!!.groupValues[1]) - assertNull(result.next()) - - regex = Regex("([a-z]+)[0-9]+", RegexOption.IGNORE_CASE) - result = regex.find("cAt123#doG345") - assertNotNull(result) - assertEquals("cAt", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("doG", result!!.groupValues[1]) - assertNull(result.next()) - - regex = Regex("(?i)([a-z]+)[0-9]+") - result = regex.find("cAt123#doG345") - assertNotNull(result) - assertEquals("cAt", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("doG", result!!.groupValues[1]) - assertNull(result.next()) -} - -fun testMultiline() { - var regex: Regex - var result: MatchResult? - - regex = Regex("^foo") - result = regex.find("foobar") - assertNotNull(result) - assertTrue(result!!.range.start == 0 && result.range.endInclusive == 2) - assertTrue(result.groups[0]!!.range.start == 0 && result.groups[0]!!.range.endInclusive == 2) - assertNull(result.next()) - - result = regex.find("barfoo") - assertNull(result) - - regex = Regex("foo$") - result = regex.find("foobar") - assertNull(result) - - result = regex.find("barfoo") - assertNotNull(result) - assertTrue(result!!.range.start == 3 && result.range.endInclusive == 5) - assertTrue(result.groups[0]!!.range.start == 3 && result.groups[0]!!.range.endInclusive == 5) - assertNull(result.next()) - - regex = Regex("^foo([0-9]*)", RegexOption.MULTILINE) - result = regex.find("foo1bar\nfoo2foo3\nbarfoo4") - assertNotNull(result) - assertEquals("1", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("2", result!!.groupValues[1]) - assertNull(result.next()) - - regex = Regex("foo([0-9]*)$", RegexOption.MULTILINE) - result = regex.find("foo1bar\nfoo2foo3\nbarfoo4") - assertNotNull(result) - assertEquals("3", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("4", result!!.groupValues[1]) - assertNull(result.next()) - - regex = Regex("(?m)^foo([0-9]*)") - result = regex.find("foo1bar\nfoo2foo3\nbarfoo4") - assertNotNull(result) - assertEquals("1", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("2", result!!.groupValues[1]) - assertNull(result.next()) - - regex = Regex("(?m)foo([0-9]*)$") - result = regex.find("foo1bar\nfoo2foo3\nbarfoo4") - assertNotNull(result) - assertEquals("3", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("4", result!!.groupValues[1]) - assertNull(result.next()) -} - -fun box() { - testCase() - testMultiline() -} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternTest.kt b/backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternTest.kt deleted file mode 100644 index 8622887011b..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternTest.kt +++ /dev/null @@ -1,1306 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import kotlin.text.* -import kotlin.test.* - -fun assertTrue(msg: String, value: Boolean) = assertTrue(value, msg) -fun assertFalse(msg: String, value: Boolean) = assertFalse(value, msg) - -internal var testPatterns = arrayOf("(a|b)*abb", "(1*2*3*4*)*567", "(a|b|c|d)*aab", "(1|2|3|4|5|6|7|8|9|0)(1|2|3|4|5|6|7|8|9|0)*", "(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)*", "(a|b)*(a|b)*A(a|b)*lice.*", "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)(a|b|c|d|e|f|g|h|" + "i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)*(1|2|3|4|5|6|7|8|9|0)*|while|for|struct|if|do", "x(?c)y", "x(?cc)y", "x(?:c)y") - -fun testCommentsInPattern() { - val p = Regex("ab# this is a comment\ncd", RegexOption.COMMENTS) - assertTrue(p.matches("abcd")) -} - -fun testSplitCharSequenceint() { - // Splitting CharSequence which ends with pattern. - // Harmony regress tests. - assertEquals(",,".split(",".toRegex(), 3).toTypedArray().size, 3) - assertEquals(",,".split(",".toRegex(), 4).toTypedArray().size, 3) - assertEquals(Regex("o").split("boo:and:foo", 5).size, 5) - assertEquals(Regex("b").split("ab", 0).size, 2) - var s: List - var regex = Regex("x") - s = regex.split("zxx:zzz:zxx", 10) - assertEquals(s.size, 5) - s = regex.split("zxx:zzz:zxx", 3) - assertEquals(s.size, 3) - s = regex.split("zxx:zzz:zxx", 0) - assertEquals(s.size, 5) - - // Other splitting. - // Negative limit - regex = Regex("b") - s = regex.split("abccbadfebb", 0) - assertEquals(s.size, 5) - s = regex.split("", 0) - assertEquals(s.size, 1) - regex = Regex("") - s = regex.split("", 0) - assertEquals(s.size, 1) - s = regex.split("abccbadfe", 0) - assertEquals(s.size, 11) - - // positive limit - regex = Regex("b") - s = regex.split("abccbadfebb", 12) - assertEquals(s.size, 5) - s = regex.split("", 6) - assertEquals(s.size, 1) - regex = Regex("") - s = regex.split("", 11) - assertEquals(s.size, 1) - s = regex.split("abccbadfe", 15) - assertEquals(s.size, 11) - - regex = Regex("b") - s = regex.split("abccbadfebb", 5) - assertEquals(s.size, 5) - s = regex.split("", 1) - assertEquals(s.size, 1) - regex = Regex("") - s = regex.split("", 1) - assertEquals(s.size, 1) - s = regex.split("abccbadfe", 11) - assertEquals(s.size, 11) - - regex = Regex("b") - s = regex.split("abccbadfebb", 3) - assertEquals(s.size, 3) - regex = Regex("") - s = regex.split("abccbadfe", 5) - assertEquals(s.size, 5) -} - -fun testFlags() { - var baseString: String - var testString: String - var regex: Regex - - baseString = "((?i)|b)a" - testString = "A" - regex = Regex(baseString) - assertFalse(regex.matches(testString)) - - baseString = "(?i)a|b" - testString = "A" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "(?i)a|b" - testString = "B" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "c|(?i)a|b" - testString = "B" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "(?i)a|(?s)b" - testString = "B" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "(?i)a|(?-i)b" - testString = "B" - regex = Regex(baseString) - assertFalse(regex.matches(testString)) - - baseString = "(?i)a|(?-i)c|b" - testString = "B" - regex = Regex(baseString) - assertFalse(regex.matches(testString)) - - baseString = "(?i)a|(?-i)c|(?i)b" - testString = "B" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "(?i)a|(?-i)b" - testString = "A" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "((?i))a" - testString = "A" - regex = Regex(baseString) - assertFalse(regex.matches(testString)) - - baseString = "|(?i)|a" - testString = "A" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "(?i)((?s)a.)" - testString = "A\n" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "(?i)((?-i)a)" - testString = "A" - regex = Regex(baseString) - assertFalse(regex.matches(testString)) - - baseString = "(?i)(?s:a.)" - testString = "A\n" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "(?i)fgh(?s:aa)" - testString = "fghAA" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "(?i)((?-i))a" - testString = "A" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "abc(?i)d" - testString = "ABCD" - regex = Regex(baseString) - assertFalse(regex.matches(testString)) - - testString = "abcD" - assertTrue(regex.matches(testString)) - - baseString = "a(?i)a(?-i)a(?i)a(?-i)a" - testString = "aAaAa" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - testString = "aAAAa" - assertFalse(regex.matches(testString)) -} - -fun Set.containsOnly(vararg options: RegexOption): Boolean { - val toCheck = options.toSet() - return size == toCheck.size && containsAll(toCheck) -} - -fun testFlagsMethod() { - val a = kotlin.text.Regex("sdf") - var baseString: String - var regex: Regex - - baseString = "(?-i)" - regex = Regex(baseString) - - baseString = "(?idmsux)abc(?-i)vg(?-dmu)" - regex = Regex(baseString) - assertTrue(regex.options.containsOnly(RegexOption.DOT_MATCHES_ALL, RegexOption.COMMENTS)) - - baseString = "(?idmsux)abc|(?-i)vg|(?-dmu)" - regex = Regex(baseString) - assertTrue(regex.options.containsOnly(RegexOption.DOT_MATCHES_ALL, RegexOption.COMMENTS)) - - baseString = "(?is)a((?x)b.)" - regex = Regex(baseString) - assertTrue(regex.options.containsOnly(RegexOption.DOT_MATCHES_ALL, RegexOption.IGNORE_CASE)) - - baseString = "(?i)a((?-i))" - regex = Regex(baseString) - assertTrue(regex.options.containsOnly(RegexOption.IGNORE_CASE)) - - baseString = "((?i)a)" - regex = Regex(baseString) - assertTrue(regex.options.isEmpty()) - - regex = Regex("(?is)abc") - assertTrue(regex.options.containsOnly(RegexOption.IGNORE_CASE, RegexOption.DOT_MATCHES_ALL)) -} - -fun testCompileStringint() { - /* - * this tests are needed to verify that appropriate exceptions are hrown - */ - var pattern = "b)a" - try { - Regex(pattern) - fail("Expected a PatternSyntaxException when compiling pattern: " + pattern) - } catch (e: PatternSyntaxException) { - // pass - } - - pattern = "bcde)a" - try { - Regex(pattern) - fail("Expected a PatternSyntaxException when compiling pattern: " + pattern) - } catch (e: PatternSyntaxException) { - // pass - } - - pattern = "bbg())a" - try { - Regex(pattern) - fail("Expected a PatternSyntaxException when compiling pattern: " + pattern) - } catch (e: PatternSyntaxException) { - // pass - } - - pattern = "cdb(?i))a" - try { - Regex(pattern) - fail("Expected a PatternSyntaxException when compiling pattern: " + pattern) - } catch (e: PatternSyntaxException) { - // pass - } - - /* - * This pattern should compile (Originally it is a regression test for HARMONY-2127) - */ - pattern = "x(?c)y" - Regex(pattern) - - /* - * This pattern doesn't match any string, but should be compiled anyway - */ - pattern = "(b\\u0001)a" - Regex(pattern) -} - - -fun testQuantCompileNeg() { - val patterns = arrayOf("5{,2}", "{5asd", "{hgdhg", "{5,hjkh", "{,5hdsh", "{5,3shdfkjh}") - for (element in patterns) { - try { - Regex(element) - fail("PatternSyntaxException was expected, but compilation succeeds") - } catch (pse: PatternSyntaxException) { - continue - } - - } -} - -fun testQuantCompilePos() { - val patterns = arrayOf("abc{2,}", "abc{5}") - for (element in patterns) { - Regex(element) - } -} - -fun testQuantComposition() { - val pattern = "(a{1,3})aab" - val regex = Regex(pattern) - val result = regex.matchEntire("aaab") - assertNotNull(result) - assertEquals(result!!.groups[1]!!.range.start, 0) - assertEquals(result.groupValues[1], "a") -} - -fun testTimeZoneIssue() { - val regex = Regex("GMT(\\+|\\-)(\\d+)(:(\\d+))?") - val result = regex.matchEntire("GMT-9:45") - assertNotNull(result) - assertEquals("-", result!!.groupValues[1]) - assertEquals("9", result.groupValues[2]) - assertEquals(":45", result.groupValues[3]) - assertEquals("45", result.groupValues[4]) -} - -fun testCompileRanges() { - val correctTestPatterns = arrayOf("[^]*abb]*", "[^a-d[^m-p]]*abb", "[a-d\\d]*abb", "[abc]*abb", - "[a-e&&[de]]*abb", "[^abc]*abb", "[a-e&&[^de]]*abb", "[a-z&&[^m-p]]*abb", "[a-d[m-p]]*abb", - "[a-zA-Z]*abb", "[+*?]*abb", "[^+*?]*abb") - - val inputSecuence = arrayOf("kkkk", "admpabb", "abcabcd124654abb", "abcabccbacababb", - "dededededededeedabb", "gfdhfghgdfghabb", "accabacbcbaabb", "acbvfgtyabb", "adbcacdbmopabcoabb", - "jhfkjhaSDFGHJkdfhHNJMjkhfabb", "+*??+*abb", "sdfghjkabb") - - for (i in correctTestPatterns.indices) { - assertTrue("pattern: " + correctTestPatterns[i] + " input: " + inputSecuence[i], - Regex(correctTestPatterns[i]).matches(inputSecuence[i])) - } - - val wrongInputSecuence = arrayOf("]", "admpkk", "abcabcd124k654abb", "abwcabccbacababb", - "abababdeababdeabb", "abcabcacbacbabb", "acdcbecbaabb", "acbotyabb", "adbcaecdbmopabcoabb", - "jhfkjhaSDFGHJk;dfhHNJMjkhfabb", "+*?a?+*abb", "sdf+ghjkabb") - - for (i in correctTestPatterns.indices) { - assertFalse("pattern: " + correctTestPatterns[i] + " input: " + wrongInputSecuence[i], - Regex(correctTestPatterns[i]).matches(wrongInputSecuence[i])) - } -} - -fun testRangesSpecialCases() { - val neg_patterns = arrayOf("[a-&&[b-c]]", "[a-\\w]", "[b-a]", "[]") - - for (element in neg_patterns) { - try { - Regex(element) - fail("PatternSyntaxException was expected: " + element) - } catch (pse: PatternSyntaxException) { - } - - } - - val pos_patterns = arrayOf("[-]+", "----", "[a-]+", "a-a-a-a-aa--", "[\\w-a]+", "123-2312--aaa-213", "[a-]]+", "-]]]]]]]]]]]]]]]") - - var i = 0 - while (i < pos_patterns.size) { - val pat = pos_patterns[i++] - val inp = pos_patterns[i] - assertTrue("pattern: $pat input: $inp", Regex(pat).matches(inp)) - i++ - } -} - -fun testZeroSymbols() { - assertTrue(Regex("[\u0000]*abb").matches("\u0000\u0000\u0000\u0000\u0000\u0000abb")) -} - -fun testEscapes() { - val regex = Regex("\\Q{]()*?") - assertTrue(regex.matches("{]()*?")) -} - -fun testRegressions() { - // Bug 181 - Regex("[\\t-\\r]") - - // HARMONY-4472 - Regex("a*.+") - - // Bug187 - Regex("|(?idmsux-idmsux)|(?idmsux-idmsux)|[^|\\[-\\0274|\\,-\\\\[^|W\\}\\nq\\x65\\002\\xFE\\05\\06\\00\\x66\\x47i\\,\\xF2\\=\\06\\u0EA4\\x9B\\x3C\\f\\|\\{\\xE5\\05\\r\\u944A\\xCA\\e|\\x19\\04\\x07\\04\\u607B\\023\\0073\\x91Tr\\0150\\x83]]?(?idmsux-idmsux:\\p{Alpha}{7}?)||(?<=[^\\uEC47\\01\\02\\u3421\\a\\f\\a\\013q\\035w\\e])(?<=\\p{Punct}{0,}?)(?=^\\p{Lower})(?!\\b{8,14})(?[\\x3E-\\]])|(?idmsux-idmsux:\\p{Punct})|(?[|\\n\\042\\uB09F\\06\\u0F2B\\uC96D\\x89\\uC166\\xAA|\\04-\\][^|\\a\\|\\rx\\04\\uA770\\n\\02\\t\\052\\056\\0274\\|\\=\\07\\e|\\00-\\x1D&&[^\\005\\uB15B\\uCDAC\\n\\x74\\0103\\0147\\uD91B\\n\\062G\\u9B4B\\077\\}\\0324&&[^\\0302\\,\\0221\\04\\u6D16\\04xy\\uD193\\[\\061\\06\\045\\x0F|\\e\\xBB\\f\\u1B52\\023\\u3AD2\\033\\007\\022\\}\\x66\\uA63FJ-\\0304]]]]{0,0})||(?^+)|(?![^|\\|\\nJ\\t\\<\\04E\\\\\\t\\01\\\\\\02\\|\\=\\}\\xF3\\uBEC2\\032K\\014\\uCC5F\\072q\\|\\0153\\xD9\\0322\\uC6C8[^\\t\\0342\\x34\\x91\\06\\{\\xF1\\a\\u1710\\?\\xE7\\uC106\\02pF\\<&&[^|\\]\\064\\u381D\\u50CF\\eO&&[^|\\06\\x2F\\04\\045\\032\\u8536W\\0377\\0017|\\x06\\uE5FA\\05\\xD4\\020\\04c\\xFC\\02H\\x0A\\r]]]]+?)(?idmsux-idmsux)|(?[\\{-\\0207|\\06-\\0276\\p{XDigit}])(?idmsux-idmsux:[^|\\x52\\0012\\]u\\xAD\\0051f\\0142\\\\l\\|\\050\\05\\f\\t\\u7B91\\r\\u7763\\{|h\\0104\\a\\f\\0234\\u2D4F&&^\\P{InGreek}]))") - - // HARMONY-5858 - Regex("\\u6211", RegexOption.LITERAL) -} - -fun testOrphanQuantifiers() { - try { - Regex("+++++") - fail("PatternSyntaxException expected") - } catch (pse: PatternSyntaxException) { - } - -} - -fun testOrphanQuantifiers2() { - try { - Regex("\\d+*") - fail("PatternSyntaxException expected") - } catch (pse: PatternSyntaxException) { - } - -} - -fun testBug197() { - val vals = arrayOf(":", 2, arrayOf("boo", "and:foo"), - ":", 5, arrayOf("boo", "and", "foo"), - ":", 0, arrayOf("boo", "and", "foo"), - ":", 3, arrayOf("boo", "and", "foo"), - ":", 1, arrayOf("boo:and:foo"), - "o", 5, arrayOf("b", "", ":and:f", "", ""), - "o", 4, arrayOf("b", "", ":and:f", "o"), - "o", 0, arrayOf("b", "", ":and:f", "", "") - ) - - var i = 0 - while (i < vals.size / 3) { - val res = Regex(vals[i++].toString()).split("boo:and:foo", (vals[i++] as Int)) - val expectedRes = vals[i++] as Array - - assertEquals(expectedRes.size, res.size) - - for (j in expectedRes.indices) { - assertEquals(expectedRes[j], res[j]) - } - } -} - -fun testURIPatterns() { - val URI_REGEXP_STR = "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"; - val SCHEME_REGEXP_STR = "^[a-zA-Z]{1}[\\w+-.]+$"; - val REL_URI_REGEXP_STR = "^(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"; - val IPV6_REGEXP_STR = "^[0-9a-fA-F\\:\\.]+(\\%\\w+)?$"; - val IPV6_REGEXP_STR2 = "^\\[[0-9a-fA-F\\:\\.]+(\\%\\w+)?\\]$"; - val IPV4_REGEXP_STR = "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$"; - val HOSTNAME_REGEXP_STR = "\\w+[\\w\\-\\.]*"; - - Regex(URI_REGEXP_STR) - Regex(REL_URI_REGEXP_STR) - Regex(SCHEME_REGEXP_STR) - Regex(IPV4_REGEXP_STR) - Regex(IPV6_REGEXP_STR) - Regex(IPV6_REGEXP_STR2) - Regex(HOSTNAME_REGEXP_STR) -} - -fun testFindBoundaryCases1() { - val regex = Regex(".*\n") - val result = regex.find("a\n") - - assertNotNull(result) - assertEquals("a\n", result!!.value) -} - -fun testFindBoundaryCases2() { - val regex = Regex(".*A") - val result = regex.find("aAa") - - assertNotNull(result) - assertEquals("aA", result!!.value) - -} - -fun testFindBoundaryCases3() { - val regex = Regex(".*A") - val result = regex.find("a\naA\n") - - assertNotNull(result) - assertEquals("aA", result!!.value) - -} - -fun testFindBoundaryCases4() { - val regex = Regex("A.*") - val result = regex.find("A\n") - - assertNotNull(result) - assertEquals("A", result!!.value) - -} - -fun testFindBoundaryCases5() { - val regex = Regex(".*A.*") - var result = regex.find("\nA\naaa\nA\naaAaa\naaaA\n") - val expected = arrayOf("A", "A", "aaAaa", "aaaA") - - var k = 0 - while (result != null) { - assertEquals(expected[k], result.value) - result = result.next() - k++ - } -} - -fun testFindBoundaryCases6() { - val regex = Regex(".*") - var result = regex.find("\na\n") - val expected = arrayOf("", "a", "", "") - - var k = 0 - while (result != null) { - assertEquals(expected[k], result.value) - k++ - result = result.next() - } -} - -fun testBackReferences() { - var regex = Regex("(\\((\\w*):(.*):(\\2)\\))") - var result = regex.find("(start1: word :start1)(start2: word :start2)") - - var k = 1 - while (result != null) { - assertEquals("start" + k, result.groupValues[2]) - assertEquals(" word ", result.groupValues[3]) - assertEquals("start" + k, result.groupValues[4]) - k++ - result = result.next() - } - - assertEquals(3, k) - regex = Regex(".*(.)\\1") - assertTrue(regex.matches("saa")) -} - -fun testNewLine() { - val regex = Regex("(^$)*\n", RegexOption.MULTILINE) - var result = regex.find("\r\n\n") - var counter = 0 - while (result != null) { - counter++ - result = result.next() - } - assertEquals(2, counter) -} - -fun testFindGreedy() { - val regex = Regex(".*aaa", RegexOption.DOT_MATCHES_ALL) - val result = regex.matchEntire("aaaa\naaa\naaaaaa") - assertNotNull(result) - assertEquals(14, result!!.range.endInclusive) -} - -fun testSOLQuant() { - val regex = Regex("$*", RegexOption.MULTILINE) - var result = regex.find("\n\n") - var counter = 0 - while (result != null) { - counter++ - result = result.next() - } - assertEquals(3, counter) -} - -fun testIllegalEscape() { - try { - Regex("\\y") - fail("PatternSyntaxException expected") - } catch (pse: PatternSyntaxException) { - } -} - -fun testEmptyFamily() { - Regex("\\p{Lower}") -} - -fun testNonCaptConstr() { - // Flags - var regex = Regex("(?i)b*(?-i)a*") - assertTrue(regex.matches("bBbBaaaa")) - assertFalse(regex.matches("bBbBAaAa")) - - // Non-capturing groups - regex = Regex("(?i:b*)a*") - assertTrue(regex.matches("bBbBaaaa")) - assertFalse(regex.matches("bBbBAaAa")) - - // 1 2 3 4 5 6 7 8 9 10 11 - regex = Regex("(?:-|(-?\\d+\\d\\d\\d))?(?:-|-(\\d\\d))?(?:-|-(\\d\\d))?(T)?(?:(\\d\\d):(\\d\\d):(\\d\\d)(\\.\\d+)?)?(?:(?:((?:\\+|\\-)\\d\\d):(\\d\\d))|(Z))?") - val result = regex.matchEntire("-1234-21-31T41:51:61.789+71:81") - assertNotNull(result) - assertEquals("-1234", result!!.groupValues[1]) - assertEquals("21", result.groupValues[2]) - assertEquals("31", result.groupValues[3]) - assertEquals("T", result.groupValues[4]) - assertEquals("41", result.groupValues[5]) - assertEquals("51", result.groupValues[6]) - assertEquals("61", result.groupValues[7]) - assertEquals(".789", result.groupValues[8]) - assertEquals("+71", result.groupValues[9]) - assertEquals("81", result.groupValues[10]) - - // positive lookahead - regex = Regex(".*\\.(?=log$).*$") - assertTrue(regex.matches("a.b.c.log")) - assertFalse(regex.matches("a.b.c.log.")) - - // negative lookahead - regex = Regex(".*\\.(?!log$).*$") - assertFalse(regex.matches("abc.log")) - assertTrue(regex.matches("abc.logg")) - - // positive lookbehind - regex = Regex(".*(?<=abc)\\.log$") - assertFalse(regex.matches("cde.log")) - assertTrue(regex.matches("abc.log")) - - // negative lookbehind - regex = Regex(".*(?a*)abb") - assertFalse(regex.matches("aaabb")) - regex = Regex("(?>a*)bb") - assertTrue(regex.matches("aaabb")) - - regex = Regex("(?>a|aa)aabb") - assertTrue(regex.matches("aaabb")) - regex = Regex("(?>aa|a)aabb") - assertFalse(regex.matches("aaabb")) - - // quantifiers over look ahead - regex = Regex(".*(?<=abc)*\\.log$") - assertTrue(regex.matches("cde.log")) - regex = Regex(".*(?<=abc)+\\.log$") - assertFalse(regex.matches("cde.log")) -} - -fun testCompilePatternWithTerminatorMark() { - val regex = Regex("a\u0000\u0000cd") - assertTrue(regex.matches("a\u0000\u0000cd")) -} - -fun testAlternations() { - var baseString = "|a|bc" - var regex = Regex(baseString) - assertTrue(regex.matches("")) - - baseString = "a||bc" - regex = Regex(baseString) - assertTrue(regex.matches("")) - - baseString = "a|bc|" - regex = Regex(baseString) - assertTrue(regex.matches("")) - - baseString = "a|b|" - regex = Regex(baseString) - assertTrue(regex.matches("")) - - baseString = "a(|b|cd)e" - regex = Regex(baseString) - assertTrue(regex.matches("ae")) - - baseString = "a(b||cd)e" - regex = Regex(baseString) - assertTrue(regex.matches("ae")) - - baseString = "a(b|cd|)e" - regex = Regex(baseString) - assertTrue(regex.matches("ae")) - - baseString = "a(b|c|)e" - regex = Regex(baseString) - assertTrue(regex.matches("ae")) - - baseString = "a(|)e" - regex = Regex(baseString) - assertTrue(regex.matches("ae")) - - baseString = "|" - regex = Regex(baseString) - assertTrue(regex.matches("")) - - baseString = "a(?:|)e" - regex = Regex(baseString) - assertTrue(regex.matches("ae")) - - baseString = "a||||bc" - regex = Regex(baseString) - assertTrue(regex.matches("")) - - baseString = "(?i-is)|a" - regex = Regex(baseString) - assertTrue(regex.matches("a")) -} - -fun testMatchWithGroups() { - var baseString = "jwkerhjwehrkwjehrkwjhrwkjehrjwkehrjkwhrkwehrkwhrkwrhwkhrwkjehr" - var pattern = ".*(..).*\\1.*" - assertTrue(Regex(pattern).matches(baseString)) - - baseString = "saa" - pattern = ".*(.)\\1" - assertTrue(Regex(pattern).matches(baseString)) - assertTrue(Regex(pattern).containsMatchIn(baseString)) -} - -fun testSplitEmptyCharSequence() { - val s1 = "" - val arr = s1.split(":".toRegex()) - assertEquals(arr.size, 1) -} - -fun testSplitEndsWithPattern() { - assertEquals(",,".split(",".toRegex(), 3).toTypedArray().size, 3) - assertEquals(",,".split(",".toRegex(), 4).toTypedArray().size, 3) - - assertEquals(Regex("o").split("boo:and:foo", 5).size, 5) - assertEquals(Regex("b").split("ab", 0).size, 2) -} - -fun testCaseInsensitiveFlag() { - assertTrue(Regex("(?i-:AbC)").matches("ABC")) -} - -fun testEmptyGroups() { - var regex = Regex("ab(?>)cda") - assertTrue(regex.matches("abcda")) - - regex = Regex("ab()") - assertTrue(regex.matches("ab")) - - regex = Regex("abc(?:)(..)") - assertTrue(regex.matches("abcgf")) -} - -fun testCompileNonCaptGroup() { - var isCompiled = false - - try { - Regex("(?:)", RegexOption.CANON_EQ) - Regex("(?:)", setOf(RegexOption.CANON_EQ, RegexOption.DOT_MATCHES_ALL)) - Regex("(?:)", setOf(RegexOption.CANON_EQ, RegexOption.IGNORE_CASE)) - Regex("(?:)", setOf(RegexOption.CANON_EQ, RegexOption.COMMENTS, RegexOption.UNIX_LINES)) - isCompiled = true - } catch (e: PatternSyntaxException) { - println(e) - } - assertTrue(isCompiled) -} - -fun testEmbeddedFlags() { - var baseString = "(?i)((?s)a)" - var testString = "A" - var regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "(?x)(?i)(?s)(?d)a" - testString = "A" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "(?x)(?i)(?s)(?d)a." - testString = "a\n" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "abc(?x:(?i)(?s)(?d)a.)" - testString = "abcA\n" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) - - baseString = "abc((?x)d)(?i)(?s)a" - testString = "abcdA" - regex = Regex(baseString) - assertTrue(regex.matches(testString)) -} - -fun testAltWithFlags() { - Regex("|(?i-xi)|()") -} - -fun testRestoreFlagsAfterGroup() { - val baseString = "abc((?x)d) a" - val testString = "abcd a" - val regex = Regex(baseString) - assertTrue(regex.matches(testString)) -} - -fun testCanonEqFlag() { - - /* - * for decompositions see - * http://www.unicode.org/Public/4.0-Update/UnicodeData-4.0.0.txt - * http://www.unicode.org/reports/tr15/#Decomposition - */ - var baseString: String - var testString: String - var regex: Regex - - baseString = "ab(a*)\\u0001" - regex = Regex(baseString, RegexOption.CANON_EQ) - - baseString = "a(abcdf)d" - regex = Regex(baseString, RegexOption.CANON_EQ) - - baseString = "aabcdfd" - regex = Regex(baseString, RegexOption.CANON_EQ) - - // \u01E0 -> \u0226\u0304 ->\u0041\u0307\u0304 - // \u00CC -> \u0049\u0300 - - baseString = "\u01E0\u00CCcdb(ac)" - testString = "\u0226\u0304\u0049\u0300cdbac" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\u01E0cdb(a\u00CCc)" - testString = "\u0041\u0307\u0304cdba\u0049\u0300c" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "a\u00CC" - testString = "a\u0049\u0300" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\u0226\u0304cdb(ac\u0049\u0300)" - testString = "\u01E0cdbac\u00CC" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "cdb(?:\u0041\u0307\u0304\u00CC)" - testString = "cdb\u0226\u0304\u0049\u0300" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\u01E0[a-c]\u0049\u0300cdb(ac)" - testString = "\u01E0b\u00CCcdbac" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\u01E0|\u00CCcdb(ac)" - testString = "\u0041\u0307\u0304" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\u00CC?cdb(ac)*(\u01E0)*[a-c]" - testString = "cdb\u0041\u0307\u0304b" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "a\u0300" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.containsMatchIn("a\u00E0a")) - - baseString = "\u7B20\uF9F8abc" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches("\uF9F8\uF9F8abc")) - - // \u01F9 -> \u006E\u0300 - // \u00C3 -> \u0041\u0303 - - baseString = "cdb(?:\u00C3\u006E\u0300)" - testString = "cdb\u0041\u0303\u01F9" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - // \u014C -> \u004F\u0304 - // \u0163 -> \u0074\u0327 - - baseString = "cdb(?:\u0163\u004F\u0304)" - testString = "cdb\u0074\u0327\u014C" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - // \u00E1->a\u0301 - // canonical ordering takes place \u0301\u0327 -> \u0327\u0301 - - baseString = "c\u0327\u0301" - testString = "c\u0301\u0327" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - /* - * Hangul decompositions - */ - // \uD4DB->\u1111\u1171\u11B6 - // \uD21E->\u1110\u116D\u11B5 - // \uD264->\u1110\u1170 - // not Hangul:\u0453->\u0433\u0301 - baseString = "a\uD4DB\u1111\u1171\u11B6\uD264" - regex = Regex(baseString, RegexOption.CANON_EQ) - - baseString = "\u0453c\uD4DB" - regex = Regex(baseString, RegexOption.CANON_EQ) - - baseString = "a\u1110\u116D\u11B5b\uD21Ebc" - regex = Regex(baseString, RegexOption.CANON_EQ) - - baseString = "\uD4DB\uD21E\u1110\u1170cdb(ac)" - testString = "\u1111\u1171\u11B6\u1110\u116D\u11B5\uD264cdbac" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\uD4DB\uD264cdb(a\uD21Ec)" - testString = "\u1111\u1171\u11B6\u1110\u1170cdba\u1110\u116D\u11B5c" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "a\uD4DB" - testString = "a\u1111\u1171\u11B6" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "a\uD21E" - testString = "a\u1110\u116D\u11B5" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\u1111\u1171\u11B6cdb(ac\u1110\u116D\u11B5)" - testString = "\uD4DBcdbac\uD21E" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "cdb(?:\u1111\u1171\u11B6\uD21E)" - testString = "cdb\uD4DB\u1110\u116D\u11B5" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\uD4DB[a-c]\u1110\u116D\u11B5cdb(ac)" - testString = "\uD4DBb\uD21Ecdbac" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\uD4DB|\u00CCcdb(ac)" - testString = "\u1111\u1171\u11B6" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\uD4DB|\u00CCcdb(ac)" - testString = "\u1111\u1171" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertFalse(regex.matches(testString)) - - baseString = "\u00CC?cdb(ac)*(\uD4DB)*[a-c]" - testString = "cdb\u1111\u1171\u11B6b" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - baseString = "\uD4DB" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertTrue(regex.containsMatchIn("a\u1111\u1171\u11B6a")) - - baseString = "\u1111" - regex = Regex(baseString, RegexOption.CANON_EQ) - assertFalse(regex.containsMatchIn("bcda\uD4DBr")) -} - -fun testIndexesCanonicalEq() { - var baseString: String - var testString: String - var regex: Regex - var result: MatchResult? - - baseString = "\uD4DB" - testString = "bcda\u1111\u1171\u11B6awr" - regex = Regex(baseString, RegexOption.CANON_EQ) - result = regex.find(testString) - assertNotNull(result) - assertEquals(result!!.range.start, 4) - assertEquals(result.range.endInclusive, 6) - - baseString = "\uD4DB\u1111\u1171\u11B6" - testString = "bcda\u1111\u1171\u11B6\uD4DBawr" - regex = Regex(baseString, RegexOption.CANON_EQ) - result = regex.find(testString) // Use the same testString - assertNotNull(result) - assertEquals(result!!.range.start, 4) - assertEquals(result.range.endInclusive, 7) - - baseString = "\uD4DB\uD21E\u1110\u1170" - testString = "abcabc\u1111\u1171\u11B6\u1110\u116D\u11B5\uD264cdbac" - regex = Regex(baseString, RegexOption.CANON_EQ) - result = regex.find(testString) - assertNotNull(result) - assertEquals(result!!.range.start, 6) - assertEquals(result.range.endInclusive, 12) -} - -fun testCanonEqFlagWithSupplementaryCharacters() { - - /* - * \u1D1BF->\u1D1BB\u1D16F->\u1D1B9\u1D165\u1D16F in UTF32 - * \uD834\uDDBF->\uD834\uDDBB\uD834\uDD6F - * ->\uD834\uDDB9\uD834\uDD65\uD834\uDD6F in UTF16 - */ - var patString = "abc\uD834\uDDBFef" - var testString = "abc\uD834\uDDB9\uD834\uDD65\uD834\uDD6Fef" - var regex = Regex(patString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - testString = "abc\uD834\uDDBB\uD834\uDD6Fef" - assertTrue(regex.matches(testString)) - - patString = "abc\uD834\uDDBB\uD834\uDD6Fef" - testString = "abc\uD834\uDDBFef" - regex = Regex(patString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - testString = "abc\uD834\uDDB9\uD834\uDD65\uD834\uDD6Fef" - assertTrue(regex.matches(testString)) - - patString = "abc\uD834\uDDB9\uD834\uDD65\uD834\uDD6Fef" - testString = "abc\uD834\uDDBFef" - regex = Regex(patString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) - - testString = "abc\uD834\uDDBB\uD834\uDD6Fef" - assertTrue(regex.matches(testString)) - - /* - * testSupplementary characters with no decomposition - */ - patString = "a\uD9A0\uDE8Ebc\uD834\uDDBB\uD834\uDD6Fe\uDE8Ef" - testString = "a\uD9A0\uDE8Ebc\uD834\uDDBFe\uDE8Ef" - regex = Regex(patString, RegexOption.CANON_EQ) - assertTrue(regex.matches(testString)) -} - -fun testRangesWithSurrogatesSupplementary() { - var patString = "[abc\uD8D2]" - var testString = "\uD8D2" - var regex = Regex(patString) - assertTrue(regex.matches(testString)) - - testString = "a" - assertTrue(regex.matches(testString)) - - testString = "ef\uD8D2\uDD71gh" - assertFalse(regex.containsMatchIn(testString)) - - testString = "ef\uD8D2gh" - assertTrue(regex.containsMatchIn(testString)) - - patString = "[abc\uD8D3&&[c\uD8D3]]" - testString = "c" - regex = Regex(patString) - assertTrue(regex.matches(testString)) - - testString = "a" - assertFalse(regex.matches(testString)) - - testString = "ef\uD8D3\uDD71gh" - assertFalse(regex.containsMatchIn(testString)) - - testString = "ef\uD8D3gh" - assertTrue(regex.containsMatchIn(testString)) - - patString = "[abc\uD8D3\uDBEE\uDF0C&&[c\uD8D3\uDBEE\uDF0C]]" - testString = "c" - regex = Regex(patString) - assertTrue(regex.matches(testString)) - - testString = "\uDBEE\uDF0C" - assertTrue(regex.matches(testString)) - - testString = "ef\uD8D3\uDD71gh" - assertFalse(regex.containsMatchIn(testString)) - - testString = "ef\uD8D3gh" - assertTrue(regex.containsMatchIn(testString)) - - patString = "[abc\uDBFC]\uDDC2cd" - testString = "\uDBFC\uDDC2cd" - regex = Regex(patString) - assertFalse(regex.matches(testString)) - - testString = "a\uDDC2cd" - assertTrue(regex.matches(testString)) -} - -fun testSequencesWithSurrogatesSupplementary() { - var patString = "abcd\uD8D3" - var testString = "abcd\uD8D3\uDFFC" - var regex = Regex(patString) - assertFalse(regex.containsMatchIn(testString)) - - testString = "abcd\uD8D3abc" - assertTrue(regex.containsMatchIn(testString)) - - patString = "ab\uDBEFcd" - testString = "ab\uDBEFcd" - regex = Regex(patString) - assertTrue(regex.matches(testString)) - - patString = "\uDFFCabcd" - testString = "\uD8D3\uDFFCabcd" - regex = Regex(patString) - assertFalse(regex.containsMatchIn(testString)) - - testString = "abc\uDFFCabcdecd" - assertTrue(regex.containsMatchIn(testString)) - - patString = "\uD8D3\uDFFCabcd" - testString = "abc\uD8D3\uD8D3\uDFFCabcd" - regex = Regex(patString) - assertTrue(regex.containsMatchIn(testString)) -} - -fun testPredefinedClassesWithSurrogatesSupplementary() { - var patString = "[123\\D]" - var testString = "a" - var regex = Regex(patString) - assertTrue(regex.containsMatchIn(testString)) - - testString = "5" - assertFalse(regex.containsMatchIn(testString)) - - testString = "3" - assertTrue(regex.containsMatchIn(testString)) - - // low surrogate - testString = "\uDFC4" - assertTrue(regex.containsMatchIn(testString)) - - // high surrogate - testString = "\uDADA" - assertTrue(regex.containsMatchIn(testString)) - - testString = "\uDADA\uDFC4" - assertTrue(regex.containsMatchIn(testString)) - - testString = "5" - assertFalse(regex.containsMatchIn(testString)) - - testString = "3" - assertTrue(regex.containsMatchIn(testString)) - - // low surrogate - testString = "\uDFC4" - assertTrue(regex.containsMatchIn(testString)) - - // high surrogate - testString = "\uDADA" - assertTrue(regex.containsMatchIn(testString)) - - testString = "\uDADA\uDFC4" - assertTrue(regex.containsMatchIn(testString)) - - // surrogate characters - patString = "\\p{Cs}" - testString = "\uD916\uDE27" - regex = Regex(patString) - /* - * see http://www.unicode.org/reports/tr18/#Supplementary_Characters we - * have to treat text as code points not code units. \\p{Cs} matches any - * surrogate character but here testString is a one code point - * consisting of two code units (two surrogate characters) so we find - * nothing - */ - assertFalse(regex.containsMatchIn(testString)) - - // swap low and high surrogates - testString = "\uDE27\uD916" - assertTrue(regex.containsMatchIn(testString)) - - patString = "[\uD916\uDE271\uD91623&&[^\\p{Cs}]]" - testString = "1" - regex = Regex(patString) - assertTrue(regex.containsMatchIn(testString)) - - testString = "\uD916" - regex = Regex(patString) - assertFalse(regex.containsMatchIn(testString)) - - testString = "\uD916\uDE27" - regex = Regex(patString) - assertTrue(regex.containsMatchIn(testString)) - - // \uD9A0\uDE8E=\u7828E - // \u78281=\uD9A0\uDE81 - patString = "[a-\uD9A0\uDE8E]" - testString = "\uD9A0\uDE81" - regex = Regex(patString) - assertTrue(regex.matches(testString)) -} - -fun testDotConstructionWithSurrogatesSupplementary() { - var patString = "." - var testString = "\uD9A0\uDE81" - var regex = Regex(patString) - assertTrue(regex.matches(testString)) - - testString = "\uDE81" - assertTrue(regex.matches(testString)) - - testString = "\uD9A0" - assertTrue(regex.matches(testString)) - - testString = "\n" - assertFalse(regex.matches(testString)) - - patString = ".*\uDE81" - testString = "\uD9A0\uDE81\uD9A0\uDE81\uD9A0\uDE81" - regex = Regex(patString) - assertFalse(regex.matches(testString)) - - testString = "\uD9A0\uDE81\uD9A0\uDE81\uDE81" - assertTrue(regex.matches(testString)) - - patString = ".*" - testString = "\uD9A0\uDE81\n\uD9A0\uDE81\uD9A0\n\uDE81" - regex = Regex(patString, RegexOption.DOT_MATCHES_ALL) - assertTrue(regex.matches(testString)) -} - -fun testQuantifiersWithSurrogatesSupplementary() { - val patString = "\uD9A0\uDE81*abc" - var testString = "\uD9A0\uDE81\uD9A0\uDE81abc" - val regex = Regex(patString) - assertTrue(regex.matches(testString)) - - testString = "abc" - assertTrue(regex.matches(testString)) -} - -fun testAlternationsWithSurrogatesSupplementary() { - val patString = "\uDE81|\uD9A0\uDE81|\uD9A0" - var testString = "\uD9A0" - val regex = Regex(patString) - assertTrue(regex.matches(testString)) - - testString = "\uDE81" - assertTrue(regex.matches(testString)) - - testString = "\uD9A0\uDE81" - assertTrue(regex.matches(testString)) - - testString = "\uDE81\uD9A0" - assertFalse(regex.matches(testString)) -} - -fun testGroupsWithSurrogatesSupplementary() { - - // this pattern matches nothing - var patString = "(\uD9A0)\uDE81" - var testString = "\uD9A0\uDE81" - var regex = Regex(patString) - assertFalse(regex.matches(testString)) - - patString = "(\uD9A0)" - testString = "\uD9A0\uDE81" - regex = Regex(patString, RegexOption.DOT_MATCHES_ALL) - assertFalse(regex.containsMatchIn(testString)) -} - -fun box() { - testCommentsInPattern() - testSplitCharSequenceint() - testFlags() - testFlagsMethod() - testCompileStringint() - testQuantCompileNeg() - testQuantCompilePos() - testQuantComposition() - testTimeZoneIssue() - testCompileRanges() - testRangesSpecialCases() - testZeroSymbols() - testEscapes() - testRegressions() - testOrphanQuantifiers() - testOrphanQuantifiers2() - testBug197() - testURIPatterns() - testFindBoundaryCases1() - testFindBoundaryCases2() - testFindBoundaryCases3() - testFindBoundaryCases4() - testFindBoundaryCases5() - testFindBoundaryCases6() - testBackReferences() - testNewLine() - testFindGreedy() - testSOLQuant() - testIllegalEscape() - testEmptyFamily() - testNonCaptConstr() - testCompilePatternWithTerminatorMark() - testAlternations() - testMatchWithGroups() - testSplitEmptyCharSequence() - testSplitEndsWithPattern() - testCaseInsensitiveFlag() - testEmptyGroups() - testCompileNonCaptGroup() - testEmbeddedFlags() - testAltWithFlags() - testRestoreFlagsAfterGroup() - testCanonEqFlag() - testIndexesCanonicalEq() - testCanonEqFlagWithSupplementaryCharacters() - testRangesWithSurrogatesSupplementary() - testSequencesWithSurrogatesSupplementary() - testPredefinedClassesWithSurrogatesSupplementary() - testDotConstructionWithSurrogatesSupplementary() - testQuantifiersWithSurrogatesSupplementary() - testAlternationsWithSurrogatesSupplementary() - testGroupsWithSurrogatesSupplementary() -} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternTest2.kt b/backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternTest2.kt deleted file mode 100644 index 903a21bbe44..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternTest2.kt +++ /dev/null @@ -1,1212 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import kotlin.text.* -import kotlin.test.* - -fun assertTrue(msg: String, value: Boolean) = assertTrue(value, msg) -fun assertFalse(msg: String, value: Boolean) = assertFalse(value, msg) - -/** - * Tests simple pattern compilation and matching methods - */ -fun testSimpleMatch() { - val regex = Regex("foo.*") - - var testString = "foo123" - assertTrue(regex.matches(testString)) - assertTrue(regex.containsMatchIn(testString, 0)) - assertTrue(regex.lookingAt(testString)) - - testString = "fox" - assertFalse(regex.matches(testString)) - assertFalse(regex.containsMatchIn(testString, 0)) - assertFalse(regex.lookingAt(testString)) - - assertTrue(Regex("foo.*").matches("foo123")) - assertFalse(Regex("foo.*").matches("fox")) - assertFalse(Regex("bar").matches("foobar")) - assertTrue(Regex("").matches("")) -} - -fun testCursors() { - val regex: Regex - var result: MatchResult? - - try { - regex = Regex("foo") - - result = regex.find("foobar") - assertNotNull(result) - assertEquals(0, result!!.range.start) - assertEquals(3, result.range.endInclusive + 1) - assertNull(result.next()) - - - result = regex.find("barfoobar") - assertNotNull(result) - assertEquals(3, result!!.range.start) - assertEquals(6, result.range.endInclusive + 1) - assertNull(result.next()) - - result = regex.find("barfoo") - assertNotNull(result) - assertEquals(3, result!!.range.start) - assertEquals(6, result.range.endInclusive + 1) - assertNull(result.next()) - - result = regex.find("foobarfoobarfoo") - assertNotNull(result) - assertEquals(0, result!!.range.start) - assertEquals(3, result.range.endInclusive + 1) - result = result.next() - assertNotNull(result) - assertEquals(6, result!!.range.start) - assertEquals(9, result.range.endInclusive + 1) - result = result.next() - assertNotNull(result) - assertEquals(12, result!!.range.start) - assertEquals(15, result.range.endInclusive + 1) - assertNull(result.next()) - - result = regex.find("foobarfoobarfoo", 0) - assertNotNull(result) - assertEquals(0, result!!.range.start) - assertEquals(3, result.range.endInclusive + 1) - - result = regex.find("foobarfoobarfoo", 4) - assertNotNull(result) - assertEquals(6, result!!.range.start) - assertEquals(9, result.range.endInclusive + 1) - } catch (e: PatternSyntaxException) { - println(e.message) - fail() - } - -} - -fun testGroups() { - val regex: Regex - var result: MatchResult? - - regex = Regex("(p[0-9]*)#?(q[0-9]*)") - - result = regex.find("p1#q3p2q42p5p71p63#q888") - assertNotNull(result) - assertEquals(0, result!!.range.start) - assertEquals(5, result.range.endInclusive + 1) - assertEquals(3, result.groups.size) - assertEquals(0, result.groups[0]!!.range.start) - assertEquals(5, result.groups[0]!!.range.endInclusive + 1) - assertEquals(0, result.groups[1]!!.range.start) - assertEquals(2, result.groups[1]!!.range.endInclusive + 1) - assertEquals(3, result.groups[2]!!.range.start) - assertEquals(5, result.groups[2]!!.range.endInclusive + 1) - assertEquals("p1#q3", result.value) - assertEquals("p1#q3", result.groupValues[0]) - assertEquals("p1", result.groupValues[1]) - assertEquals("q3", result.groupValues[2]) - - result = result.next() - assertNotNull(result) - assertEquals(5, result!!.range.start) - assertEquals(10, result.range.endInclusive + 1) - assertEquals(3, result.groups.size) - assertEquals(10, result.groups[0]!!.range.endInclusive + 1) - assertEquals(5, result.groups[1]!!.range.start) - assertEquals(7, result.groups[1]!!.range.endInclusive + 1) - assertEquals(7, result.groups[2]!!.range.start) - assertEquals(10, result.groups[2]!!.range.endInclusive + 1) - assertEquals("p2q42", result.value) - assertEquals("p2q42", result.groupValues[0]) - assertEquals("p2", result.groupValues[1]) - assertEquals("q42", result.groupValues[2]) - - result = result.next() - assertNotNull(result) - assertEquals(15, result!!.range.start) - assertEquals(23, result.range.endInclusive + 1) - assertEquals(3, result.groups.size) - assertEquals(15, result.groups[0]!!.range.start) - assertEquals(23, result.groups[0]!!.range.endInclusive + 1) - assertEquals(15, result.groups[1]!!.range.start) - assertEquals(18, result.groups[1]!!.range.endInclusive + 1) - assertEquals(19, result.groups[2]!!.range.start) - assertEquals(23, result.groups[2]!!.range.endInclusive + 1) - assertEquals("p63#q888", result.value) - assertEquals("p63#q888", result.groupValues[0]) - assertEquals("p63", result.groupValues[1]) - assertEquals("q888", result.groupValues[2]) - assertNull(result.next()) -} - -fun testReplace() { - var regex: Regex - - // Note: examples from book, - // Hitchens, Ron, 2002, "Java NIO", O'Reilly, page 171 - regex = Regex("a*b") - - var testString = "aabfooaabfooabfoob" - assertTrue(regex.replace(testString, "-") == "-foo-foo-foo-") - assertTrue(regex.replaceFirst(testString, "-") == "-fooaabfooabfoob") - - regex = Regex("([bB])yte") - - testString = "Byte for byte" - assertTrue(regex.replaceFirst(testString, "$1ite") == "Bite for byte") - assertTrue(regex.replace(testString, "$1ite") == "Bite for bite") - - regex = Regex("\\d\\d\\d\\d([- ])") - - testString = "card #1234-5678-1234" - assertTrue(regex.replaceFirst(testString, "xxxx$1") == "card #xxxx-5678-1234") - assertTrue(regex.replace(testString, "xxxx$1") == "card #xxxx-xxxx-1234") - - regex = Regex("(up|left)( *)(right|down)") - - testString = "left right, up down" - assertTrue(regex.replaceFirst(testString, "$3$2$1") == "right left, up down") - assertTrue(regex.replace(testString, "$3$2$1") == "right left, down up") - - regex = Regex("([CcPp][hl]e[ea]se)") - - testString = "I want cheese. Please." - assertTrue(regex.replaceFirst(testString, " $1 ") == "I want cheese . Please.") - assertTrue(regex.replace(testString, " $1 ") == "I want cheese . Please .") -} - -fun testEscapes() { - var regex: Regex - var result: MatchResult? - - // Test \\ sequence - regex = Regex("([a-z]+)\\\\([a-z]+);") - result = regex.find("fred\\ginger;abbott\\costello;jekell\\hyde;") - assertNotNull(result) - assertEquals("fred", result!!.groupValues[1]) - assertEquals("ginger", result.groupValues[2]) - result = result.next() - assertNotNull(result) - assertEquals("abbott", result!!.groupValues[1]) - assertEquals("costello", result.groupValues[2]) - result = result.next() - assertNotNull(result) - assertEquals("jekell", result!!.groupValues[1]) - assertEquals("hyde", result.groupValues[2]) - assertNull(result.next()) - - // Test \n, \t, \r, \f, \e, \a sequences - regex = Regex("([a-z]+)[\\n\\t\\r\\f\\e\\a]+([a-z]+)") - result = regex.find("aa\nbb;cc\u0009\rdd;ee\u000C\u001Bff;gg\n\u0007hh") - assertNotNull(result) - assertEquals("aa", result!!.groupValues[1]) - assertEquals("bb", result.groupValues[2]) - result = result.next() - assertNotNull(result) - assertEquals("cc", result!!.groupValues[1]) - assertEquals("dd", result.groupValues[2]) - result = result.next() - assertNotNull(result) - assertEquals("ee", result!!.groupValues[1]) - assertEquals("ff", result.groupValues[2]) - result = result.next() - assertNotNull(result) - assertEquals("gg", result!!.groupValues[1]) - assertEquals("hh", result.groupValues[2]) - assertNull(result.next()) - - // Test \\u and \\x sequences - regex = Regex("([0-9]+)[\\u0020:\\x21];") - result = regex.find("11:;22 ;33-;44!;") - assertNotNull(result) - assertEquals("11", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("22", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("44", result!!.groupValues[1]) - assertNull(result.next()) - - // Test invalid unicode sequences // TODO: Double check it. - try { - regex = Regex("\\u") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\u;") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\u002") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\u002;") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - // Test invalid hex sequences - try { - regex = Regex("\\x") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\x;") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\xa") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\xa;") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - // Test \0 (octal) sequences (1, 2 and 3 digit) - regex = Regex("([0-9]+)[\\07\\040\\0160];") - result = regex.find("11\u0007;22:;33 ;44p;") - assertNotNull(result) - assertEquals("11", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("33", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("44", result!!.groupValues[1]) - assertNull(result.next()) - - // Test invalid octal sequences - try { - regex = Regex("\\08") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\0") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\0;") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - // Test \c (control character) sequence - regex = Regex("([0-9]+)[\\cA\\cB\\cC\\cD];") - result = regex.find("11\u0001;22:;33\u0002;44p;55\u0003;66\u0004;") - assertNotNull(result) - assertEquals("11", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("33", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("55", result!!.groupValues[1]) - result = result.next() - assertNotNull(result) - assertEquals("66", result!!.groupValues[1]) - assertNull(result.next()) - - // More thorough control escape test - // Ensure that each escape matches exactly the corresponding - // character - // code and no others (well, from 0-255 at least) - for (i in 0..25) { - regex = Regex("\\c${'A' + i}") - var match_char = -1 - for (j in 0..255) { - if (regex.matches("${j.toChar()}")) { - assertEquals(-1, match_char) - match_char = j - } - } - assertTrue(match_char == i + 1) - } - - - // Test invalid control escapes - try { - regex = Regex("\\c") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } -} - -fun testCharacterClasses() { - var regex: Regex - - // Test one character range - regex = Regex("[p].*[l]") - assertTrue(regex.matches("paul")) - assertTrue(regex.matches("pool")) - assertFalse(regex.matches("pong")) - assertTrue(regex.matches("pl")) - - // Test two character range - regex = Regex("[pm].*[lp]") - assertTrue(regex.matches("prop")) - assertTrue(regex.matches("mall")) - assertFalse(regex.matches("pong")) - assertTrue(regex.matches("pill")) - - // Test range including [ and ] - regex = Regex("[<\\[].*[\\]>]") - assertTrue(regex.matches("")) - assertTrue(regex.matches("[bar]")) - assertFalse(regex.matches("{foobar]")) - assertTrue(regex.matches("") - assertTrue(regex.matches("")) - assertFalse(regex.matches("")) - val result = regex.find("xyz zzz") - assertNotNull(result) - assertNotNull(result!!.next()) - assertNull(result.next()!!.next()) - - // Test \S (not whitespace) // TODO: We've removed \f from string since kotlin doesn't recognize this escape in a string. - regex = Regex("<[a-z] \\S[0-9][\\S\n]+[^\\S]221>") - assertTrue(regex.matches("")) - assertTrue(regex.matches("")) - assertFalse(regex.matches("")) - assertTrue(regex.matches("")) - regex = Regex("<[a-z] \\S[0-9][\\S\n]+[^\\S]221[\\S&&[^abc]]>") - assertTrue(regex.matches("")) - assertTrue(regex.matches("")) - assertFalse(regex.matches("")) - assertFalse(regex.matches("")) - assertFalse(regex.matches("")) - assertTrue(regex.matches("")) - - // Test \w (ascii word) - regex = Regex("<\\w+\\s[0-9]+;[^\\w]\\w+/[\\w$]+;") - assertTrue(regex.matches(""); - * m = p.matcher(""); assertTrue(m.matches()); m = p.matcher(""); - * assertTrue(m.matches()); m = p.matcher(""); - * assertFalse(m.matches()); - */ - regex = Regex("\\p{Lower}+") - assertTrue(regex.matches("abcdefghijklmnopqrstuvwxyz")) - - // Invalid uses of \p{Lower} - try { - regex = Regex("\\p") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\p;") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\p{") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\p{;") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\p{Lower") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\p{Lower;") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - // Test \p{Upper} - /* - * FIXME: Requires complex range processing p = Regex("<\\p{Upper}\\d\\P{Upper}:[\\p{Upper}z]\\s[^\\P{Upper}]>"); - * m = p.matcher(""); assertTrue(m.matches()); m = p.matcher(""); - * assertTrue(m.matches()); m = p.matcher(""); - * assertFalse(m.matches()); - */ - regex = Regex("\\p{Upper}+") - assertTrue(regex.matches("ABCDEFGHIJKLMNOPQRSTUVWXYZ")) - - // Invalid uses of \p{Upper} - try { - regex = Regex("\\p{Upper") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\p{Upper;") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - // Test \p{ASCII} - /* - * FIXME: Requires complex range processing p = Regex("<\\p{ASCII}\\d\\P{ASCII}:[\\p{ASCII}\u1234]\\s[^\\P{ASCII}]>"); - * m = p.matcher(""); assertTrue(m.matches()); m = - * p.matcher(""); assertTrue(m.matches()); m = - * p.matcher("<\u00846#:E E>"); assertFalse(m.matches()) - */ - regex = Regex("\\p{ASCII}") - for (i in 0 until 0x80) { - assertTrue(regex.matches("${i.toChar()}")) - } - for (i in 0x80..0xff) { - assertFalse(regex.matches("${i.toChar()}")) - } - - // Invalid uses of \p{ASCII} - try { - regex = Regex("\\p{ASCII") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - try { - regex = Regex("\\p{ASCII;") - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - } - - // Test \p{Alpha} - // TODO - - // Test \p{Digit} - // TODO - - // Test \p{XDigit} - // TODO - - // Test \p{Alnum} - // TODO - - // Test \p{Punct} - // TODO - - // Test \p{Graph} - // TODO - - // Test \p{Print} - // TODO - - // Test \p{Blank} - // TODO - - // Test \p{Space} - // TODO - - // Test \p{Cntrl} - // TODO -} - -fun testUnicodeCategories() { - // Test Unicode categories using \p and \P - // One letter codes: L, M, N, P, S, Z, C - // Two letter codes: Lu, Nd, Sc, Sm, ... - // See java.lang.Character and Unicode standard for complete list - // TODO - // Test \p{L} - // TODO - - // Test \p{N} - // TODO - - // ... etc - - // Test two letter codes: - // From unicode.org: - // Lu - // Ll - // Lt - // Lm - // Lo - // Mn - // Mc - // Me - // Nd - // Nl - // No - // Pc - // Pd - // Ps - // Pe - // Pi - // Pf - // Po - // Sm - // Sc - // Sk - // So - // Zs - // Zl - // Zp - // Cc - // Cf - // Cs - // Co - // Cn -} - -fun testUnicodeBlocks() { - var regex: Regex - - // Test Unicode blocks using \p and \P - for (block in UBlocks) { - regex = Regex("\\p{In" + block.name + "}") - if (block.low > 0) { - assertFalse(regex.matches((block.low - 1).toChar().toString())) - } - for (i in block.low..block.high) { - assertTrue(regex.matches(i.toChar().toString())) - } - if (block.high < 0xFFFF) { - assertFalse(regex.matches((block.high + 1).toChar().toString())) - } - - regex = Regex("\\P{In" + block.name + "}") - if (block.low > 0) { - assertTrue(regex.matches((block.low - 1).toChar().toString())) - } - for (i in block.low..block.high) { - assertFalse("assert: Regex: $regex, match to: ${i.toChar()} ($i)", regex.matches(i.toChar().toString())) - } - if (block.high < 0xFFFF) { - assertTrue(regex.matches((block.high + 1).toChar().toString())) - } - - } -} - -fun testCapturingGroups() { - // Test simple capturing groups - // TODO - - // Test grouping without capture (?:...) - // TODO - - // Test combination of grouping and capture - // TODO - - // Test \ sequence with capturing and non-capturing groups - // TODO - - // Test \ with out of range - // TODO -} - -fun testRepeats() { - // Test ? - // TODO - - // Test * - // TODO - - // Test + - // TODO - - // Test {}, including 0, 1 and more - // TODO - - // Test {,}, including 0, 1 and more - // TODO - - // Test {,}, with n1 < n2, n1 = n2 and n1 > n2 (illegal?) - // TODO -} - -fun testAnchors() { - // Test ^, default and MULTILINE - // TODO - - // Test $, default and MULTILINE - // TODO - - // Test \b (word boundary) - // TODO - - // Test \B (not a word boundary) - // TODO - - // Test \A (beginning of string) - // TODO - - // Test \Z (end of string) - // TODO - - // Test \z (end of string) - // TODO - - // Test \G - // TODO - - // Test positive lookahead using (?=...) - // TODO - - // Test negative lookahead using (?!...) - // TODO - - // Test positive lookbehind using (?<=...) - // TODO - - // Test negative lookbehind using (?...) - // TODO - - // Test (?onflags-offflags) - // Valid flags are i,m,d,s,u,x - // TODO - - // Test (?onflags-offflags:...) - // TODO - - // Test \Q, \E - regex = Regex("[a-z]+;\\Q[a-z]+;\\Q(foo.*);\\E[0-9]+") - assertTrue(regex.matches("abc;[a-z]+;\\Q(foo.*);411")) - assertFalse(regex.matches("abc;def;foo42;555")) - assertFalse(regex.matches("abc;\\Qdef;\\Qfoo99;\\E123")) - - regex = Regex("[a-z]+;(foo[0-9]-\\Q(...)\\E);[0-9]+") - val result = regex.matchEntire("abc;foo5-(...);123") - assertNotNull(result) - assertEquals("foo5-(...)", result!!.groupValues[1]) - assertFalse(regex.matches("abc;foo9-(xxx);789")) - - regex = Regex("[a-z]+;(bar[0-9]-[a-z\\Q$-\\E]+);[0-9]+") - assertTrue(regex.matches("abc;bar0-def$-;123")) - - regex = Regex("[a-z]+;(bar[0-9]-[a-z\\Q-$\\E]+);[0-9]+") - assertTrue(regex.matches("abc;bar0-def$-;123")) - - regex = Regex("[a-z]+;(bar[0-9]-[a-z\\Q[0-9]\\E]+);[0-9]+") - assertTrue(regex.matches("abc;bar0-def[99]-]0x[;123")); - - regex = Regex("[a-z]+;(bar[0-9]-[a-z\\[0\\-9\\]]+);[0-9]+") - assertTrue(regex.matches("abc;bar0-def[99]-]0x[;123")) - - // Test # - // TODO -} - -fun testCompile1() { - val regex = Regex("[0-9A-Za-z][0-9A-Za-z\\x2e\\x3a\\x2d\\x5f]*") - val name = "iso-8859-1" - assertTrue(regex.matches(name)) -} - -fun testCompile2() { - val findString = "\\Qimport\\E" - val regex = Regex(findString) - regex.containsMatchIn("import a.A;\n\n import b.B;\nclass C {}", 0) -} - -fun testCompile3() { - var regex: Regex - var result: MatchResult? - - regex = Regex("a$") - result = regex.find("a\n") - assertNotNull(result) - assertEquals("a", result!!.value) - assertNull(result.next()) - - regex = Regex("(a$)") - result = regex.find("a\n") - assertNotNull(result) - assertEquals("a", result!!.value) - assertEquals("a", result.groupValues[1]) - assertNull(result.next()) - - regex = Regex("^.*$", RegexOption.MULTILINE) - - result = regex.find("a\n") - assertNotNull(result) - assertEquals("a", result!!.value) - assertNull(result.next()) - - result = regex.find("a\nb\n") - assertNotNull(result) - assertEquals("a", result!!.value) - result = result.next() - assertNotNull(result) - assertEquals("b", result!!.value) - assertNull(result.next()) - - result = regex.find("a\nb") - assertNotNull(result) - assertEquals("a", result!!.value) - result = result.next() - assertNotNull(result) - assertEquals("b", result!!.value) - assertNull(result.next()) - - result = regex.find("\naa\r\nbb\rcc\n\n") - assertNotNull(result) - assertTrue(result!!.value == "") - result = result.next() - assertNotNull(result) - assertEquals("aa", result!!.value) - result = result.next() - assertNotNull(result) - assertEquals("bb", result!!.value) - result = result.next() - assertNotNull(result) - assertEquals("cc", result!!.value) - result = result.next() - assertNotNull(result) - assertTrue(result!!.value == "") - assertNull(result.next()) - - result = regex.find("a") - assertNotNull(result) - assertEquals("a", result!!.value) - assertNull(result.next()) - - result = regex.find("") - assertNull(result) - - regex = Regex("^.*$") - result = regex.find("") - assertNotNull(result) - assertTrue(result!!.value == "") - assertNull(result.next()) -} - -fun testCompile4() { - val findString = "\\Qpublic\\E" - val text = StringBuilder(" public class Class {\n" + " public class Class {") - val regex = Regex(findString) - - val result = regex.find(text) - assertNotNull(result) - assertEquals(4, result!!.range.start) - - // modify text - text.length = 0 - text.append("Text have been changed.") - - assertNull(regex.find(text)) -} - -fun testCompile5() { - val p = Regex("^[0-9]") - val s = p.split("12", 0) - assertEquals("", s[0]) - assertEquals("2", s[1]) - assertEquals(2, s.size) -} - -private class UBInfo(var low: Int, var high: Int, var name: String) - -// A table representing the unicode categories -// private static UBInfo[] UCategories = { -// Lu -// Ll -// Lt -// Lm -// Lo -// Mn -// Mc -// Me -// Nd -// Nl -// No -// Pc -// Pd -// Ps -// Pe -// Pi -// Pf -// Po -// Sm -// Sc -// Sk -// So -// Zs -// Zl -// Zp -// Cc -// Cf -// Cs -// Co -// Cn -// }; - -// A table representing the unicode character blocks -private val UBlocks = arrayOf( - /* 0000; 007F; Basic Latin */ - UBInfo(0x0000, 0x007F, "BasicLatin"), // Character.UnicodeBlock.BASIC_LATIN - /* 0080; 00FF; Latin-1 Supplement */ - UBInfo(0x0080, 0x00FF, "Latin-1Supplement"), // Character.UnicodeBlock.LATIN_1_SUPPLEMENT - /* 0100; 017F; Latin Extended-A */ - UBInfo(0x0100, 0x017F, "LatinExtended-A"), // Character.UnicodeBlock.LATIN_EXTENDED_A - /* 0180; 024F; Latin Extended-B */ - // new UBInfo (0x0180,0x024F,"InLatinExtended-B"), // - // Character.UnicodeBlock.LATIN_EXTENDED_B - /* 0250; 02AF; IPA Extensions */ - UBInfo(0x0250, 0x02AF, "IPAExtensions"), // Character.UnicodeBlock.IPA_EXTENSIONS - /* 02B0; 02FF; Spacing Modifier Letters */ - UBInfo(0x02B0, 0x02FF, "SpacingModifierLetters"), // Character.UnicodeBlock.SPACING_MODIFIER_LETTERS - /* 0300; 036F; Combining Diacritical Marks */ - UBInfo(0x0300, 0x036F, "CombiningDiacriticalMarks"), // Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS - /* 0370; 03FF; Greek */ - UBInfo(0x0370, 0x03FF, "Greek"), // Character.UnicodeBlock.GREEK - /* 0400; 04FF; Cyrillic */ - UBInfo(0x0400, 0x04FF, "Cyrillic"), // Character.UnicodeBlock.CYRILLIC - /* 0530; 058F; Armenian */ - UBInfo(0x0530, 0x058F, "Armenian"), // Character.UnicodeBlock.ARMENIAN - /* 0590; 05FF; Hebrew */ - UBInfo(0x0590, 0x05FF, "Hebrew"), // Character.UnicodeBlock.HEBREW - /* 0600; 06FF; Arabic */ - UBInfo(0x0600, 0x06FF, "Arabic"), // Character.UnicodeBlock.ARABIC - /* 0700; 074F; Syriac */ - UBInfo(0x0700, 0x074F, "Syriac"), // Character.UnicodeBlock.SYRIAC - /* 0780; 07BF; Thaana */ - UBInfo(0x0780, 0x07BF, "Thaana"), // Character.UnicodeBlock.THAANA - /* 0900; 097F; Devanagari */ - UBInfo(0x0900, 0x097F, "Devanagari"), // Character.UnicodeBlock.DEVANAGARI - /* 0980; 09FF; Bengali */ - UBInfo(0x0980, 0x09FF, "Bengali"), // Character.UnicodeBlock.BENGALI - /* 0A00; 0A7F; Gurmukhi */ - UBInfo(0x0A00, 0x0A7F, "Gurmukhi"), // Character.UnicodeBlock.GURMUKHI - /* 0A80; 0AFF; Gujarati */ - UBInfo(0x0A80, 0x0AFF, "Gujarati"), // Character.UnicodeBlock.GUJARATI - /* 0B00; 0B7F; Oriya */ - UBInfo(0x0B00, 0x0B7F, "Oriya"), // Character.UnicodeBlock.ORIYA - /* 0B80; 0BFF; Tamil */ - UBInfo(0x0B80, 0x0BFF, "Tamil"), // Character.UnicodeBlock.TAMIL - /* 0C00; 0C7F; Telugu */ - UBInfo(0x0C00, 0x0C7F, "Telugu"), // Character.UnicodeBlock.TELUGU - /* 0C80; 0CFF; Kannada */ - UBInfo(0x0C80, 0x0CFF, "Kannada"), // Character.UnicodeBlock.KANNADA - /* 0D00; 0D7F; Malayalam */ - UBInfo(0x0D00, 0x0D7F, "Malayalam"), // Character.UnicodeBlock.MALAYALAM - /* 0D80; 0DFF; Sinhala */ - UBInfo(0x0D80, 0x0DFF, "Sinhala"), // Character.UnicodeBlock.SINHALA - /* 0E00; 0E7F; Thai */ - UBInfo(0x0E00, 0x0E7F, "Thai"), // Character.UnicodeBlock.THAI - /* 0E80; 0EFF; Lao */ - UBInfo(0x0E80, 0x0EFF, "Lao"), // Character.UnicodeBlock.LAO - /* 0F00; 0FFF; Tibetan */ - UBInfo(0x0F00, 0x0FFF, "Tibetan"), // Character.UnicodeBlock.TIBETAN - /* 1000; 109F; Myanmar */ - UBInfo(0x1000, 0x109F, "Myanmar"), // Character.UnicodeBlock.MYANMAR - /* 10A0; 10FF; Georgian */ - UBInfo(0x10A0, 0x10FF, "Georgian"), // Character.UnicodeBlock.GEORGIAN - /* 1100; 11FF; Hangul Jamo */ - UBInfo(0x1100, 0x11FF, "HangulJamo"), // Character.UnicodeBlock.HANGUL_JAMO - /* 1200; 137F; Ethiopic */ - UBInfo(0x1200, 0x137F, "Ethiopic"), // Character.UnicodeBlock.ETHIOPIC - /* 13A0; 13FF; Cherokee */ - UBInfo(0x13A0, 0x13FF, "Cherokee"), // Character.UnicodeBlock.CHEROKEE - /* 1400; 167F; Unified Canadian Aboriginal Syllabics */ - UBInfo(0x1400, 0x167F, "UnifiedCanadianAboriginalSyllabics"), // Character.UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS - /* 1680; 169F; Ogham */ - UBInfo(0x1680, 0x169F, "Ogham"), // Character.UnicodeBlock.OGHAM - /* 16A0; 16FF; Runic */ - UBInfo(0x16A0, 0x16FF, "Runic"), // Character.UnicodeBlock.RUNIC - /* 1780; 17FF; Khmer */ - UBInfo(0x1780, 0x17FF, "Khmer"), // Character.UnicodeBlock.KHMER - /* 1800; 18AF; Mongolian */ - UBInfo(0x1800, 0x18AF, "Mongolian"), // Character.UnicodeBlock.MONGOLIAN - /* 1E00; 1EFF; Latin Extended Additional */ - UBInfo(0x1E00, 0x1EFF, "LatinExtendedAdditional"), // Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL - /* 1F00; 1FFF; Greek Extended */ - UBInfo(0x1F00, 0x1FFF, "GreekExtended"), // Character.UnicodeBlock.GREEK_EXTENDED - /* 2000; 206F; General Punctuation */ - UBInfo(0x2000, 0x206F, "GeneralPunctuation"), // Character.UnicodeBlock.GENERAL_PUNCTUATION - /* 2070; 209F; Superscripts and Subscripts */ - UBInfo(0x2070, 0x209F, "SuperscriptsandSubscripts"), // Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS - /* 20A0; 20CF; Currency Symbols */ - UBInfo(0x20A0, 0x20CF, "CurrencySymbols"), // Character.UnicodeBlock.CURRENCY_SYMBOLS - /* 20D0; 20FF; Combining Marks for Symbols */ - UBInfo(0x20D0, 0x20FF, "CombiningMarksforSymbols"), // Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS - /* 2100; 214F; Letterlike Symbols */ - UBInfo(0x2100, 0x214F, "LetterlikeSymbols"), // Character.UnicodeBlock.LETTERLIKE_SYMBOLS - /* 2150; 218F; Number Forms */ - UBInfo(0x2150, 0x218F, "NumberForms"), // Character.UnicodeBlock.NUMBER_FORMS - /* 2190; 21FF; Arrows */ - UBInfo(0x2190, 0x21FF, "Arrows"), // Character.UnicodeBlock.ARROWS - /* 2200; 22FF; Mathematical Operators */ - UBInfo(0x2200, 0x22FF, "MathematicalOperators"), // Character.UnicodeBlock.MATHEMATICAL_OPERATORS - /* 2300; 23FF; Miscellaneous Technical */ - UBInfo(0x2300, 0x23FF, "MiscellaneousTechnical"), // Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL - /* 2400; 243F; Control Pictures */ - UBInfo(0x2400, 0x243F, "ControlPictures"), // Character.UnicodeBlock.CONTROL_PICTURES - /* 2440; 245F; Optical Character Recognition */ - UBInfo(0x2440, 0x245F, "OpticalCharacterRecognition"), // Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION - /* 2460; 24FF; Enclosed Alphanumerics */ - UBInfo(0x2460, 0x24FF, "EnclosedAlphanumerics"), // Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS - /* 2500; 257F; Box Drawing */ - UBInfo(0x2500, 0x257F, "BoxDrawing"), // Character.UnicodeBlock.BOX_DRAWING - /* 2580; 259F; Block Elements */ - UBInfo(0x2580, 0x259F, "BlockElements"), // Character.UnicodeBlock.BLOCK_ELEMENTS - /* 25A0; 25FF; Geometric Shapes */ - UBInfo(0x25A0, 0x25FF, "GeometricShapes"), // Character.UnicodeBlock.GEOMETRIC_SHAPES - /* 2600; 26FF; Miscellaneous Symbols */ - UBInfo(0x2600, 0x26FF, "MiscellaneousSymbols"), // Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS - /* 2700; 27BF; Dingbats */ - UBInfo(0x2700, 0x27BF, "Dingbats"), // Character.UnicodeBlock.DINGBATS - /* 2800; 28FF; Braille Patterns */ - UBInfo(0x2800, 0x28FF, "BraillePatterns"), // Character.UnicodeBlock.BRAILLE_PATTERNS - /* 2E80; 2EFF; CJK Radicals Supplement */ - UBInfo(0x2E80, 0x2EFF, "CJKRadicalsSupplement"), // Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT - /* 2F00; 2FDF; Kangxi Radicals */ - UBInfo(0x2F00, 0x2FDF, "KangxiRadicals"), // Character.UnicodeBlock.KANGXI_RADICALS - /* 2FF0; 2FFF; Ideographic Description Characters */ - UBInfo(0x2FF0, 0x2FFF, "IdeographicDescriptionCharacters"), // Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS - /* 3000; 303F; CJK Symbols and Punctuation */ - UBInfo(0x3000, 0x303F, "CJKSymbolsandPunctuation"), // Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION - /* 3040; 309F; Hiragana */ - UBInfo(0x3040, 0x309F, "Hiragana"), // Character.UnicodeBlock.HIRAGANA - /* 30A0; 30FF; Katakana */ - UBInfo(0x30A0, 0x30FF, "Katakana"), // Character.UnicodeBlock.KATAKANA - /* 3100; 312F; Bopomofo */ - UBInfo(0x3100, 0x312F, "Bopomofo"), // Character.UnicodeBlock.BOPOMOFO - /* 3130; 318F; Hangul Compatibility Jamo */ - UBInfo(0x3130, 0x318F, "HangulCompatibilityJamo"), // Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO - /* 3190; 319F; Kanbun */ - UBInfo(0x3190, 0x319F, "Kanbun"), // Character.UnicodeBlock.KANBUN - /* 31A0; 31BF; Bopomofo Extended */ - UBInfo(0x31A0, 0x31BF, "BopomofoExtended"), // Character.UnicodeBlock.BOPOMOFO_EXTENDED - /* 3200; 32FF; Enclosed CJK Letters and Months */ - UBInfo(0x3200, 0x32FF, "EnclosedCJKLettersandMonths"), // Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS - /* 3300; 33FF; CJK Compatibility */ - UBInfo(0x3300, 0x33FF, "CJKCompatibility"), // Character.UnicodeBlock.CJK_COMPATIBILITY - /* 3400; 4DB5; CJK Unified Ideographs Extension A */ - UBInfo(0x3400, 0x4DB5, "CJKUnifiedIdeographsExtensionA"), // Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A - /* 4E00; 9FFF; CJK Unified Ideographs */ - UBInfo(0x4E00, 0x9FFF, "CJKUnifiedIdeographs"), // Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS - /* A000; A48F; Yi Syllables */ - UBInfo(0xA000, 0xA48F, "YiSyllables"), // Character.UnicodeBlock.YI_SYLLABLES - /* A490; A4CF; Yi Radicals */ - UBInfo(0xA490, 0xA4CF, "YiRadicals"), // Character.UnicodeBlock.YI_RADICALS - /* AC00; D7A3; Hangul Syllables */ - UBInfo(0xAC00, 0xD7A3, "HangulSyllables"), // Character.UnicodeBlock.HANGUL_SYLLABLES - /* D800; DB7F; High Surrogates */ - /* DB80; DBFF; High Private Use Surrogates */ - /* DC00; DFFF; Low Surrogates */ - /* E000; F8FF; Private Use */ - /* F900; FAFF; CJK Compatibility Ideographs */ - UBInfo(0xF900, 0xFAFF, "CJKCompatibilityIdeographs"), // Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS - /* FB00; FB4F; Alphabetic Presentation Forms */ - UBInfo(0xFB00, 0xFB4F, "AlphabeticPresentationForms"), // Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS - /* FB50; FDFF; Arabic Presentation Forms-A */ - UBInfo(0xFB50, 0xFDFF, "ArabicPresentationForms-A"), // Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A - /* FE20; FE2F; Combining Half Marks */ - UBInfo(0xFE20, 0xFE2F, "CombiningHalfMarks"), // Character.UnicodeBlock.COMBINING_HALF_MARKS - /* FE30; FE4F; CJK Compatibility Forms */ - UBInfo(0xFE30, 0xFE4F, "CJKCompatibilityForms"), // Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS - /* FE50; FE6F; Small Form Variants */ - UBInfo(0xFE50, 0xFE6F, "SmallFormVariants"), // Character.UnicodeBlock.SMALL_FORM_VARIANTS - /* FE70; FEFE; Arabic Presentation Forms-B */ - // new UBInfo (0xFE70,0xFEFE,"InArabicPresentationForms-B"), // - // Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B - /* FEFF; FEFF; Specials */ - UBInfo(0xFEFF, 0xFEFF, "Specials"), // Character.UnicodeBlock.SPECIALS - /* FF00; FFEF; Halfwidth and Fullwidth Forms */ - UBInfo(0xFF00, 0xFFEF, "HalfwidthandFullwidthForms"), // Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS - /* FFF0; FFFD; Specials */ - UBInfo(0xFFF0, 0xFFFD, "Specials") // Character.UnicodeBlock.SPECIALS -) - - -fun box() { - testSimpleMatch() - testCursors() - testGroups() - testReplace() - testEscapes() - testCharacterClasses() - testPOSIXGroups() - testUnicodeCategories() - testUnicodeBlocks() - testCapturingGroups() - testRepeats() - testAnchors() - testMisc() - testCompile1() - testCompile2() - testCompile3() - testCompile4() - testCompile5() -} \ No newline at end of file diff --git a/backend.native/tests/external/stdlib/text/RegexTest/harmony/ReplaceTest.kt b/backend.native/tests/external/stdlib/text/RegexTest/harmony/ReplaceTest.kt deleted file mode 100644 index 02dd59872cd..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/harmony/ReplaceTest.kt +++ /dev/null @@ -1,85 +0,0 @@ -/* Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import kotlin.text.* -import kotlin.test.* - -fun testSimpleReplace() { - val target: String - val pattern: String - val repl: String - - target = "foobarfobarfoofo1" - pattern = "fo[^o]" - repl = "xxx" - - val regex = Regex(pattern) - - assertEquals("foobarxxxarfoofo1", regex.replaceFirst(target, repl)) - assertEquals("foobarxxxarfooxxx", regex.replace(target, repl)) -} - -fun testCaptureReplace() { - var target: String - var pattern: String - var repl: String - var s: String - var regex: Regex - - target = "[31]foo;bar[42];[99]xyz" - pattern = "\\[([0-9]+)\\]([a-z]+)" - repl = "$2[$1]" - - regex = Regex(pattern) - s = regex.replaceFirst(target, repl) - assertEquals("foo[31];bar[42];[99]xyz", s) - s = regex.replace(target, repl) - assertEquals("foo[31];bar[42];xyz[99]", s) - - target = "[31]foo(42)bar{63}zoo;[12]abc(34)def{56}ghi;{99}xyz[88]xyz(77)xyz;" - pattern = "\\[([0-9]+)\\]([a-z]+)\\(([0-9]+)\\)([a-z]+)\\{([0-9]+)\\}([a-z]+)" - repl = "[$5]$6($3)$4{$1}$2" - regex = Regex(pattern) - s = regex.replaceFirst(target, repl) - assertEquals("[63]zoo(42)bar{31}foo;[12]abc(34)def{56}ghi;{99}xyz[88]xyz(77)xyz;", s) - s = regex.replace(target, repl) - assertEquals("[63]zoo(42)bar{31}foo;[56]ghi(34)def{12}abc;{99}xyz[88]xyz(77)xyz;", s) -} - -fun testEscapeReplace() { - val target: String - val pattern: String - var repl: String - var s: String - - target = "foo'bar''foo" - pattern = "'" - repl = "\\'" - s = target.replace(pattern.toRegex(), repl) - assertEquals("foo'bar''foo", s) - repl = "\\\\'" - s = target.replace(pattern.toRegex(), repl) - assertEquals("foo\\'bar\\'\\'foo", s) - repl = "\\$3" - s = target.replace(pattern.toRegex(), repl) - assertEquals("foo$3bar$3$3foo", s) -} - -fun box() { - testSimpleReplace() - testCaptureReplace() - testEscapeReplace() -} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/harmony/SplitTest.kt b/backend.native/tests/external/stdlib/text/RegexTest/harmony/SplitTest.kt deleted file mode 100644 index c977407bf56..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/harmony/SplitTest.kt +++ /dev/null @@ -1,156 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -import kotlin.text.* -import kotlin.test.* - -fun testSimple() { - val p = Regex("/") - val results = p.split("have/you/done/it/right") - val expected = arrayOf("have", "you", "done", "it", "right") - assertEquals(expected.size, results.size) - for (i in expected.indices) { - assertEquals(results[i], expected[i]) - } -} - -fun testSplit1() { - var p = Regex(" ") - - val input = "poodle zoo" - var tokens: List - - tokens = p.split(input, 1) - assertEquals(1, tokens.size) - assertTrue(tokens[0] == input) - tokens = p.split(input, 2) - assertEquals(2, tokens.size) - assertEquals("poodle", tokens[0]) - assertEquals("zoo", tokens[1]) - tokens = p.split(input, 5) - assertEquals(2, tokens.size) - assertEquals("poodle", tokens[0]) - assertEquals("zoo", tokens[1]) - tokens = p.split(input, 0) - assertEquals(2, tokens.size) - assertEquals("poodle", tokens[0]) - assertEquals("zoo", tokens[1]) - tokens = p.split(input) - assertEquals(2, tokens.size) - assertEquals("poodle", tokens[0]) - assertEquals("zoo", tokens[1]) - - p = Regex("d") - - tokens = p.split(input, 1) - assertEquals(1, tokens.size) - assertTrue(tokens[0] == input) - tokens = p.split(input, 2) - assertEquals(2, tokens.size) - assertEquals("poo", tokens[0]) - assertEquals("le zoo", tokens[1]) - tokens = p.split(input, 5) - assertEquals(2, tokens.size) - assertEquals("poo", tokens[0]) - assertEquals("le zoo", tokens[1]) - tokens = p.split(input, 0) - assertEquals(2, tokens.size) - assertEquals("poo", tokens[0]) - assertEquals("le zoo", tokens[1]) - tokens = p.split(input) - assertEquals(2, tokens.size) - assertEquals("poo", tokens[0]) - assertEquals("le zoo", tokens[1]) - - p = Regex("o") - - tokens = p.split(input, 1) - assertEquals(1, tokens.size) - assertTrue(tokens[0] == input) - tokens = p.split(input, 2) - assertEquals(2, tokens.size) - assertEquals("p", tokens[0]) - assertEquals("odle zoo", tokens[1]) - tokens = p.split(input, 5) - assertEquals(5, tokens.size) - assertEquals("p", tokens[0]) - assertTrue(tokens[1] == "") - assertEquals("dle z", tokens[2]) - assertTrue(tokens[3] == "") - assertTrue(tokens[4] == "") - tokens = p.split(input, 0) - assertEquals(5, tokens.size) - assertEquals("p", tokens[0]) - assertTrue(tokens[1] == "") - assertEquals("dle z", tokens[2]) - assertTrue(tokens[3] == "") - assertTrue(tokens[4] == "") - tokens = p.split(input) - assertEquals(5, tokens.size) - assertEquals("p", tokens[0]) - assertTrue(tokens[1] == "") - assertEquals("dle z", tokens[2]) - assertTrue(tokens[3] == "") - assertTrue(tokens[4] == "") -} - -fun testSplit2() { - val p = Regex("") - var s: List - s = p.split("a", 0) - assertEquals(3, s.size) - assertEquals("", s[0]) - assertEquals("a", s[1]) - assertEquals("", s[2]) - - s = p.split("", 0) - assertEquals(1, s.size) - assertEquals("", s[0]) - - s = p.split("abcd", 0) - assertEquals(6, s.size) - assertEquals("", s[0]) - assertEquals("a", s[1]) - assertEquals("b", s[2]) - assertEquals("c", s[3]) - assertEquals("d", s[4]) - assertEquals("", s[5]) -} - -fun testSplitSupplementaryWithEmptyString() { - - /* - * See http://www.unicode.org/reports/tr18/#Supplementary_Characters We - * have to treat text as code points not code units. - */ - val p = Regex("") - val s: List - s = p.split("a\ud869\uded6b", 0) - assertEquals(5, s.size) - assertEquals("", s[0]) - assertEquals("a", s[1]) - assertEquals("\ud869\uded6", s[2]) - assertEquals("b", s[3]) - assertEquals("", s[4]) -} - -fun box() { - testSimple() - testSplit1() - testSplit2() - testSplitSupplementaryWithEmptyString() -} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/matchAllSequence.kt b/backend.native/tests/external/stdlib/text/RegexTest/matchAllSequence.kt deleted file mode 100644 index bde9c623951..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/matchAllSequence.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index b02771a0a7a..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/matchEntire.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index 938aba7d5ed..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/matchEntireLazyQuantor.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 272670c522c..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/matchGroups.kt +++ /dev/null @@ -1,38 +0,0 @@ -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 deleted file mode 100644 index cc0cdca2371..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/matchIgnoreCase.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index 7d88671d148..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/matchMultiline.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index f6c7f76d02c..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/matchOptionalGroup.kt +++ /dev/null @@ -1,34 +0,0 @@ -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 deleted file mode 100644 index e677ff806c7..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/matchResult.kt +++ /dev/null @@ -1,32 +0,0 @@ -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 deleted file mode 100644 index e13ce0e36e6..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/matchSequence.kt +++ /dev/null @@ -1,18 +0,0 @@ -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 deleted file mode 100644 index a7ca638bd35..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/replace.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 514e65c851c..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/replaceEvaluator.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 2b13b629d4d..00000000000 --- a/backend.native/tests/external/stdlib/text/RegexTest/split.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 0c2adc46acf..00000000000 --- a/backend.native/tests/external/stdlib/text/StringBuilderTest/append.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index b5f91142f1a..00000000000 --- a/backend.native/tests/external/stdlib/text/StringBuilderTest/appendMany.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index ef758c22c6d..00000000000 --- a/backend.native/tests/external/stdlib/text/StringBuilderTest/asCharSequence.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 0742a19718c..00000000000 --- a/backend.native/tests/external/stdlib/text/StringBuilderTest/constructors.kt +++ /dev/null @@ -1,24 +0,0 @@ -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 deleted file mode 100644 index 4bb0ce865d9..00000000000 --- a/backend.native/tests/external/stdlib/text/StringBuilderTest/stringBuild.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 83266e98013..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/byteToStringWithRadix.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index ef453768ea8..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/intToStringWithRadix.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 4653ae8fa5b..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/longToStringWithRadix.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 49626ad5eae..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/shortToStringWithRadix.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index d5791e3d085..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toBoolean.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 637245e053d..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toByte.kt +++ /dev/null @@ -1,69 +0,0 @@ -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 deleted file mode 100644 index 17fedf06098..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toDouble.kt +++ /dev/null @@ -1,79 +0,0 @@ -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: Double?, b: Double?): Boolean { - if (a != null && b != null && a.isNaN() && b.isNaN()) { - return true - } - return 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 deleted file mode 100644 index 8e89c95eaf0..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toFloat.kt +++ /dev/null @@ -1,63 +0,0 @@ -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 deleted file mode 100644 index 7b96d0d209b..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toHexDouble.kt +++ /dev/null @@ -1,68 +0,0 @@ -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()) - - // TODO: Java Double.valueOf specification requires mandatory binary exponent character (p) in the string parsed if the string is a hex one. - // See: http://docs.oracle.com/javase/8/docs/api/java/lang/Double.html#valueOf-java.lang.String- - // E.g. - // "0x77p0".toDouble() // OK for both Kotlin/JVM and Kotlin/Native. - // "0x77".toDouble() // throws NumberFormatException in Kotlin/JVM and OK in Kotlin/Native. - // Do we need to handle such case? Or it is OK to consume such strings? - //assertFailsOrNull("0x77e1") - } -} diff --git a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toInt.kt b/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toInt.kt deleted file mode 100644 index acbee45e0ba..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toInt.kt +++ /dev/null @@ -1,88 +0,0 @@ -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 deleted file mode 100644 index 93cfb99a5b4..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toIntArabicDigits.kt +++ /dev/null @@ -1,57 +0,0 @@ -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 deleted file mode 100644 index 6f8879d7490..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLong.kt +++ /dev/null @@ -1,89 +0,0 @@ -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 deleted file mode 100644 index 4bc6bbd69ce..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toLongArabicDigits.kt +++ /dev/null @@ -1,34 +0,0 @@ -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 deleted file mode 100644 index 07ceb33c0f0..00000000000 --- a/backend.native/tests/external/stdlib/text/StringNumberConversionTest/toShort.kt +++ /dev/null @@ -1,70 +0,0 @@ -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 deleted file mode 100644 index 4721db51203..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/capitalize.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 96e21b9b6f4..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/decapitalize.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 14ed3cee3ff..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/drop.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 48687191a83..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/dropWhile.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index 540b6ad90e0..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/endsWithString.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index 1fa61bf356a..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/equalsIgnoreCase.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index bbd9b318ba2..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/filter.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index d9d16a218b9..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/filterIndexed.kt +++ /dev/null @@ -1,8 +0,0 @@ -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 deleted file mode 100644 index 5dde6637c23..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/filterNot.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 2b912037908..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/joinTo.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 452f67e0d95..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/joinToString.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 7b030acdf6d..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/orEmpty.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index 5fcbec94b3f..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/partition.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index b4ce3417935..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/replace.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index c93d7df6e59..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/replaceDelimited.kt +++ /dev/null @@ -1,26 +0,0 @@ -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 deleted file mode 100644 index f6399332213..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/replaceFirst.kt +++ /dev/null @@ -1,16 +0,0 @@ -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 deleted file mode 100644 index 8e665f025f8..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/reverse.kt +++ /dev/null @@ -1,9 +0,0 @@ -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 deleted file mode 100644 index d7966e09596..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/slice.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 1e2afd8f07f..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/startsWithString.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 6bf30dba755..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/substringDelimited.kt +++ /dev/null @@ -1,27 +0,0 @@ -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 deleted file mode 100644 index fcfaa1b0681..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/take.kt +++ /dev/null @@ -1,12 +0,0 @@ -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 deleted file mode 100644 index 365b215c55b..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/takeWhile.kt +++ /dev/null @@ -1,13 +0,0 @@ -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 deleted file mode 100644 index c92408aa119..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/testIndent.kt +++ /dev/null @@ -1,11 +0,0 @@ -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 deleted file mode 100644 index fd09f9f799b..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/trimIndent.kt +++ /dev/null @@ -1,72 +0,0 @@ -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 { - var i = 0 - while (i < it.length && it[i].isWhitespace()) - i++ - return@map i - } - 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 deleted file mode 100644 index 68765b6711a..00000000000 --- a/backend.native/tests/external/stdlib/text/StringTest/trimMargin.kt +++ /dev/null @@ -1,50 +0,0 @@ -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 deleted file mode 100644 index 0885f9687ed..00000000000 --- a/backend.native/tests/external/stdlib/utils/KotlinVersionTest/componentValidation.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index eaf795ffa53..00000000000 --- a/backend.native/tests/external/stdlib/utils/KotlinVersionTest/currentVersion.kt +++ /dev/null @@ -1,14 +0,0 @@ -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 deleted file mode 100644 index d824e25d93b..00000000000 --- a/backend.native/tests/external/stdlib/utils/LazyTest/alreadyInitialized.kt +++ /dev/null @@ -1,10 +0,0 @@ -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 deleted file mode 100644 index 42db2090dfb..00000000000 --- a/backend.native/tests/external/stdlib/utils/LazyTest/initializationCalledOnce.kt +++ /dev/null @@ -1,17 +0,0 @@ -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 deleted file mode 100644 index 16e6837dde9..00000000000 --- a/backend.native/tests/external/stdlib/utils/LazyTest/lazyToString.kt +++ /dev/null @@ -1,15 +0,0 @@ -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 deleted file mode 100644 index a7cfb9f4f7e..00000000000 --- a/backend.native/tests/external/stdlib/utils/TODOTest/usage.kt +++ /dev/null @@ -1,45 +0,0 @@ -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/stdlib_external/OrderingTest.kt b/backend.native/tests/stdlib_external/OrderingTest.kt new file mode 100644 index 00000000000..407442c9e36 --- /dev/null +++ b/backend.native/tests/stdlib_external/OrderingTest.kt @@ -0,0 +1,184 @@ +package test.comparisons + +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 STRING_CASE_INSENSITIVE_ORDER: Comparator = compareBy { it: String -> it.toUpperCase() }.thenBy { it.toLowerCase() }.thenBy { it } + +class OrderingTest { + val v1 = Item("wine", 9) + val v2 = Item("beer", 10) + val v3 = Item("apple", 20) + + @Test + fun compareByCompareTo() { + val diff = v1.compareTo(v2) + assertTrue(diff < 0) + } + + @Test + fun compareByNameFirst() { + val diff = compareValuesBy(v1, v2, { it.name }, { it.rating }) + assertTrue(diff > 0) + } + + @Test + fun compareByRatingFirst() { + val diff = compareValuesBy(v1, v2, { it.rating }, { it.name }) + assertTrue(diff < 0) + } + + @Test + fun compareSameObjectsByRatingFirst() { + val diff = compareValuesBy(v1, v1, { it.rating }, { it.name }) + assertTrue(diff == 0) + } + + @Test + fun compareNullables() { + val v1: Item? = this.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) + } + + @Test + fun sortComparatorThenComparator() { + 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]) + } + + @Test + fun combineComparators() { + 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 ) + } + + @Test + fun reversedComparator() { + val comparator = compareBy { it.name } + val reversed = comparator.reversed() + assertEquals(comparator.compare(v2, v1), reversed.compare(v1, v2)) + assertEquals(comparator, reversed.reversed()) + } + + @Test + fun naturalOrderComparator() { + 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()) + } + + @Test + fun sortByThenBy() { + 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]) + } + + @Test + fun sortByThenByDescending() { + 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]) + } + + @Test + fun sortUsingFunctionalComparator() { + 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]) + } + + @Test + fun sortUsingCustomComparator() { + 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]) + } + + @Test fun maxOf() { + 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)) + } + + @Test fun maxOfWith() { + 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 })) + } + + @Test fun minOf() { + 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)) + } + + @Test fun minOfWith() { + 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/stdlib_external/TuplesTest.kt b/backend.native/tests/stdlib_external/TuplesTest.kt new file mode 100644 index 00000000000..89d40d47ac0 --- /dev/null +++ b/backend.native/tests/stdlib_external/TuplesTest.kt @@ -0,0 +1,101 @@ +package test.tuples + +import kotlin.test.* + +class PairTest { + val p = Pair(1, "a") + + @Test fun pairFirstAndSecond() { + assertEquals(1, p.first) + assertEquals("a", p.second) + } + + @Test fun pairMultiAssignment() { + val (a, b) = p + assertEquals(1, a) + assertEquals("a", b) + } + + @Test fun pairToString() { + assertEquals("(1, a)", p.toString()) + } + + @Test fun pairEquals() { + assertEquals(Pair(1, "a"), p) + assertNotEquals(Pair(2, "a"), p) + assertNotEquals(Pair(1, "b"), p) + assertTrue(!p.equals(null)) + assertNotEquals("", (p as Any)) + } + + @Test fun pairHashCode() { + 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()) + } + + @Test fun pairHashSet() { + val s = hashSetOf(Pair(1, "a"), Pair(1, "b"), Pair(1, "a")) + assertEquals(2, s.size) + assertTrue(s.contains(p)) + } + + @Test fun pairToList() { + assertEquals(listOf(1, 2), (1 to 2).toList()) + assertEquals(listOf(1, null), (1 to null).toList()) + assertEquals(listOf(1, "2"), (1 to "2").toList()) + } +} + +class TripleTest { + val t = Triple(1, "a", 0.07) + + @Test fun tripleFirstAndSecond() { + assertEquals(1, t.first) + assertEquals("a", t.second) + assertEquals(0.07, t.third) + } + + @Test fun tripleMultiAssignment() { + val (a, b, c) = t + assertEquals(1, a) + assertEquals("a", b) + assertEquals(0.07, c) + } + + @Test fun tripleToString() { + assertEquals("(1, a, 0.07)", t.toString()) + } + + @Test fun tripleEquals() { + 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)) + } + + @Test fun tripleHashCode() { + 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()) + } + + @Test fun tripleHashSet() { + 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)) + } + + @Test fun tripleToList() { + 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/stdlib_external/collections/ArraysTest.kt b/backend.native/tests/stdlib_external/collections/ArraysTest.kt new file mode 100644 index 00000000000..71d687a44ff --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/ArraysTest.kt @@ -0,0 +1,1256 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.collections + +import test.collections.behaviors.* +import test.comparisons.STRING_CASE_INSENSITIVE_ORDER +import kotlin.test.* +import kotlin.comparisons.* + +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) } + + +class ArraysTest { + + data class Value(val value: Int) { + override fun hashCode(): Int = value + } + + @Test fun orEmptyNull() { + val x: Array? = null + val y: Array? = null + val xArray = x.orEmpty() + val yArray = y.orEmpty() + expect(0) { xArray.size } + expect(0) { yArray.size } + } + + @Test fun orEmptyNotNull() { + val x: Array? = arrayOf("1", "2") + val xArray = x.orEmpty() + expect(2) { xArray.size } + expect("1") { xArray[0] } + expect("2") { xArray[1] } + } + + @Test fun emptyArrayLastIndex() { + val arr1 = IntArray(0) + assertEquals(-1, arr1.lastIndex) + + val arr2 = emptyArray() + assertEquals(-1, arr2.lastIndex) + } + + @Test fun arrayLastIndex() { + 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]) + } + + @Test fun byteArray() { + val arr = ByteArray(2) + + val expected: Byte = 0 + assertEquals(arr.size, 2) + assertEquals(expected, arr[0]) + assertEquals(expected, arr[1]) + } + + @Test fun byteArrayInit() { + val arr = ByteArray(2) { it.toByte() } + + assertEquals(2, arr.size) + assertEquals(0.toByte(), arr[0]) + assertEquals(1.toByte(), arr[1]) + } + + @Test fun shortArray() { + val arr = ShortArray(2) + + val expected: Short = 0 + assertEquals(arr.size, 2) + assertEquals(expected, arr[0]) + assertEquals(expected, arr[1]) + } + + @Test fun shortArrayInit() { + val arr = ShortArray(2) { it.toShort() } + + assertEquals(2, arr.size) + assertEquals(0.toShort(), arr[0]) + assertEquals(1.toShort(), arr[1]) + } + + @Test fun intArray() { + val arr = IntArray(2) + + assertEquals(arr.size, 2) + assertEquals(0, arr[0]) + assertEquals(0, arr[1]) + } + + @Test fun intArrayInit() { + val arr = IntArray(2) { it.toInt() } + + assertEquals(2, arr.size) + assertEquals(0.toInt(), arr[0]) + assertEquals(1.toInt(), arr[1]) + } + + @Test fun longArray() { + val arr = LongArray(2) + + val expected: Long = 0 + assertEquals(arr.size, 2) + assertEquals(expected, arr[0]) + assertEquals(expected, arr[1]) + } + + @Test fun longArrayInit() { + val arr = LongArray(2) { it.toLong() } + + assertEquals(2, arr.size) + assertEquals(0.toLong(), arr[0]) + assertEquals(1.toLong(), arr[1]) + } + + @Test fun floatArray() { + val arr = FloatArray(2) + + val expected: Float = 0.0F + assertEquals(arr.size, 2) + assertEquals(expected, arr[0]) + assertEquals(expected, arr[1]) + } + + @Test fun floatArrayInit() { + val arr = FloatArray(2) { it.toFloat() } + + assertEquals(2, arr.size) + assertEquals(0.toFloat(), arr[0]) + assertEquals(1.toFloat(), arr[1]) + } + + @Test fun doubleArray() { + val arr = DoubleArray(2) + + assertEquals(arr.size, 2) + assertEquals(0.0, arr[0]) + assertEquals(0.0, arr[1]) + } + + @Test fun doubleArrayInit() { + val arr = DoubleArray(2) { it.toDouble() } + + assertEquals(2, arr.size) + assertEquals(0.toDouble(), arr[0]) + assertEquals(1.toDouble(), arr[1]) + } + + @Test fun charArray() { + val arr = CharArray(2) + + val expected: Char = '\u0000' + assertEquals(arr.size, 2) + assertEquals(expected, arr[0]) + assertEquals(expected, arr[1]) + } + + @Test fun charArrayInit() { + val arr = CharArray(2) { 'a' + it } + + assertEquals(2, arr.size) + assertEquals('a', arr[0]) + assertEquals('b', arr[1]) + } + + @Test fun booleanArray() { + val arr = BooleanArray(2) + assertEquals(arr.size, 2) + assertEquals(false, arr[0]) + assertEquals(false, arr[1]) + } + + @Test fun booleanArrayInit() { + val arr = BooleanArray(2) { it % 2 == 0 } + + assertEquals(2, arr.size) + assertEquals(true, arr[0]) + assertEquals(false, arr[1]) + } + + @Test fun contentEquals() { + val arr1 = arrayOf("a", 1, null) + val arr2 = arrayOf(*arr1) + assertTrue(arr1 contentEquals arr2) + val arr3 = arr2.reversedArray() + assertFalse(arr1 contentEquals arr3) + } + + @Test fun contentDeepEquals() { + 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) + } + + @Test fun contentToString() { + arrayOf("a", 1, null).let { arr -> assertEquals(arr.asList().toString(), arr.contentToString()) } + charArrayOf('a', 'b', 'd').let { arr -> assertEquals(arr.asList().toString(), arr.contentToString()) } + intArrayOf(1, 10, 42).let { arr -> assertEquals(arr.asList().toString(), arr.contentToString()) } + longArrayOf(1L, 5L, Long.MAX_VALUE).let { arr -> assertEquals(arr.asList().toString(), arr.contentToString()) } + doubleArrayOf(0.0, Double.MAX_VALUE, Double.POSITIVE_INFINITY, Double.NaN).let { arr -> assertEquals(arr.asList().toString(), arr.contentToString()) } + } + + @Test fun contentDeepToString() { + // 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()) + } + + @Test fun contentDeepToStringNoRecursion() { + // 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) + } + + @Test fun contentHashCode() { + 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()) + } + + @Test fun contentDeepHashCode() { + val arr = arrayOf(null, Value(2), arrayOf(Value(3))) + assertEquals(((1*31 + 0)*31 + 2) * 31 + (1 * 31 + 3), arr.contentDeepHashCode()) + } + + + @Test fun joinToString() { + 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) + } + + + + @Test fun min() { + 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() }) + } + + @Test fun minInPrimitiveArrays() { + 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() }) + } + + @Test fun max() { + 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() }) + } + + @Test fun maxInPrimitiveArrays() { + 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() }) + } + + @Test fun minWith() { + assertEquals(null, arrayOf().minWith(naturalOrder()) ) + assertEquals("a", arrayOf("a", "B").minWith(STRING_CASE_INSENSITIVE_ORDER)) + } + + @Test fun minWithInPrimitiveArrays() { + expect(null, { intArrayOf().minWith(naturalOrder()) }) + expect(1, { intArrayOf(1).minWith(naturalOrder()) }) + expect(4, { intArrayOf(2, 3, 4).minWith(compareBy { it % 4 }) }) + } + + @Test fun maxWith() { + assertEquals(null, arrayOf().maxWith(naturalOrder()) ) + assertEquals("B", arrayOf("a", "B").maxWith(STRING_CASE_INSENSITIVE_ORDER)) + } + + @Test fun maxWithInPrimitiveArrays() { + expect(null, { intArrayOf().maxWith(naturalOrder()) }) + expect(1, { intArrayOf(1).maxWith(naturalOrder()) }) + expect(-4, { intArrayOf(2, 3, -4).maxWith(compareBy { it*it }) }) + } + + @Test fun minBy() { + 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 } }) + } + + @Test fun minByInPrimitiveArrays() { + 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 } }) + } + + @Test fun maxBy() { + 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 } }) + } + + @Test fun maxByInPrimitiveArrays() { + 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 } }) + } + + @Test fun minIndex() { + val a = intArrayOf(1, 7, 9, -42, 54, 93) + expect(3, { a.indices.minBy { a[it] } }) + } + + @Test fun maxIndex() { + val a = intArrayOf(1, 7, 9, 239, 54, 93) + expect(3, { a.indices.maxBy { a[it] } }) + } + + @Test fun minByEvaluateOnce() { + var c = 0 + expect(1, { arrayOf(5, 4, 3, 2, 1).minBy { c++; it * it } }) + assertEquals(5, c) + } + + @Test fun maxByEvaluateOnce() { + var c = 0 + expect(5, { arrayOf(5, 4, 3, 2, 1).maxBy { c++; it * it } }) + assertEquals(5, c) + } + + @Test fun sum() { + 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() } + } + + @Test fun sumInPrimitiveArrays() { + 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() } + } + + @Test fun average() { + 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() + } + + @Test fun indexOfInPrimitiveArrays() { + 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) } + } + + @Test fun indexOf() { + 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') } } + } + + @Test fun lastIndexOf() { + 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') } } + } + + @Test fun isEmpty() { + 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()) + } + + @Test fun isNotEmpty() { + assertFalse(intArrayOf().isNotEmpty()) + assertTrue(intArrayOf(1).isNotEmpty()) + } + + @Test fun plusInference() { + 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]) + } + + + @Test fun plus() { + 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)) + } + + @Test fun plusVararg() { + 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") + } + + @Test fun plusAssign() { + // 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) + } + + @Test fun first() { + expect(1) { arrayOf(1, 2, 3).first() } + expect(2) { arrayOf(1, 2, 3).first { it % 2 == 0 } } + } + + @Test fun last() { + expect(3) { arrayOf(1, 2, 3).last() } + expect(2) { arrayOf(1, 2, 3).last { it % 2 == 0 } } + } + + @Test fun contains() { + assertTrue(arrayOf("1", "2", "3", "4").contains("2")) + assertTrue("3" in arrayOf("1", "2", "3", "4")) + assertTrue("0" !in arrayOf("1", "2", "3", "4")) + } + + @Test fun slice() { + 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)) + } + + @Test fun sliceArray() { + 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)) + } + + @Test fun iterators() { + fun checkContract(array: T, toList: T.() -> List, iterator: T.() -> Iterator) = + compare(array.toList().iterator(), array.iterator()) { + iteratorBehavior() + } + + checkContract(arrayOf("a", "b", "c"), { toList() }, { iterator() }) + checkContract(intArrayOf(), { toList() }, { iterator() }) + checkContract(intArrayOf(1, 2, 3), { toList() }, { iterator() }) + checkContract(shortArrayOf(1, 2, 3), { toList() }, { iterator() }) + checkContract(byteArrayOf(1, 2, 3), { toList() }, { iterator() }) + checkContract(longArrayOf(1L, 2L, 3L), { toList() }, { iterator() }) + checkContract(doubleArrayOf(2.0, 3.0, 9.0), { toList() }, { iterator() }) + checkContract(floatArrayOf(2f, 3f, 9f), { toList() }, { iterator() }) + checkContract(charArrayOf('a', 'b', 'c'), { toList() }, { iterator() }) + checkContract(booleanArrayOf(true, false), { toList() }, { iterator() }) + } + + @Test fun asIterable() { + 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()) + } + + @Test fun asList() { + 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") + } + + @Test fun toPrimitiveArray() { + 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()) + } + + @Test fun toTypedArray() { + val primitiveArray: LongArray = longArrayOf(1, 2, Long.MAX_VALUE) + val genericArray: Array = primitiveArray.toTypedArray() + expect(3) { genericArray.size } + assertEquals(primitiveArray.asList(), genericArray.asList()) + } + + @Test fun copyOf() { + 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()) } + } + + @Test fun copyAndResize() { + 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)) + } + + @Test fun copyOfRange() { + 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)) + } + + + + @Test fun reduceIndexed() { + 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 -> index + a + b } + } + } + + @Test fun reduceRightIndexed() { + 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 -> index + a + b } + } + } + + @Test fun reduce() { + 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 } + } + } + + @Test fun reduceRight() { + 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 } + } + } + + @Test fun reverseInPlace() { + + 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() }) + } + + + @Test fun reversed() { + 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() } + } + + @Test fun reversedArray() { + 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()) + } + + @Test fun drop() { + 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) + } + } + + @Test fun dropLast() { + 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) + } + } + + @Test fun dropWhile() { + 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" } }) + } + + @Test fun dropLastWhile() { + 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" } }) + } + + @Test fun take() { + 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) + } + } + + @Test fun takeLast() { + 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) + } + } + + @Test fun takeWhile() { + 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" } }) + } + + @Test fun takeLastWhile() { + 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" } }) + } + + @Test fun filter() { + 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" } }) + } + + @Test fun filterIndexed() { + 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 } }) + } + + @Test fun filterNot() { + 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" } }) + } + + @Test fun filterNotNull() { + expect(listOf("a"), { arrayOf("a", null).filterNotNull() }) + } + + @Test fun map() { + 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 }) + } + + @Test fun mapIndexed() { + 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" }) + } + + @Test fun mapNotNull() { + assertEquals(listOf(2, 3), arrayOf("", "bc", "def").mapNotNull { if (it.isEmpty()) null else it.length }) + } + + @Test fun mapIndexedNotNull() { + assertEquals(listOf(2), arrayOf("a", null, "test").mapIndexedNotNull { index, it -> it?.run { if (index != 0) length / index else null } }) + } + + @Test fun flattenArray() { + val arr1: Array> = arrayOf(arrayOf(1, 2, 3), arrayOf(4, 5, 6)) + val arr2: Array> = arr1 + val arr3: Array> = arr1 + @Suppress("UNCHECKED_CAST") + 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()) + } + + @Test fun asListPrimitives() { + // 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()) + } + + @Test fun asListObjects() { + 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()) + } + + @Test fun sort() { + 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) + } + + @Test fun sortedTests() { + 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() }) + } + } + + @Test fun sortByInPlace() { + 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) + } + + @Test fun sortedBy() { + val values = arrayOf("ac", "aD", "aba") + val indices = values.indices.toList().toIntArray() + + assertEquals(listOf(1, 2, 0), indices.sortedBy { values[it] }) + } + + @Test fun sortedNullableBy() { + 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() })) } + } + } + + @Test fun sortedWith() { + 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 } + } +} + +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 } + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/collections/CollectionBehaviors.kt b/backend.native/tests/stdlib_external/collections/CollectionBehaviors.kt new file mode 100644 index 00000000000..ec0368d2196 --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/CollectionBehaviors.kt @@ -0,0 +1,119 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.collections.behaviors + +import test.collections.CompareContext + +public 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>.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() } +} + +public fun CompareContext>.iteratorBehavior() { + propertyEquals { hasNext() } + + while (expected.hasNext()) { + propertyEquals { next() } + propertyEquals { hasNext() } + } + propertyFails { next() } +} + +public fun CompareContext>.setBehavior(objectName: String = "") { + equalityBehavior(objectName) + collectionBehavior(objectName) + compareProperty({ iterator() }, { iteratorBehavior() }) +} + +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") }) +} + +public 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>.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) } +} + + diff --git a/backend.native/tests/stdlib_external/collections/CollectionTest.kt b/backend.native/tests/stdlib_external/collections/CollectionTest.kt new file mode 100644 index 00000000000..a90027155b6 --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/CollectionTest.kt @@ -0,0 +1,941 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.collections + +import kotlin.test.* +import test.collections.behaviors.* +import test.comparisons.STRING_CASE_INSENSITIVE_ORDER +import kotlin.comparisons.* + +class CollectionTest { + + @Test fun createListWithInit() { + val list = List(3) { index -> "x".repeat(index + 1) } + assertEquals(3, list.size) + assertEquals(listOf("x", "xx", "xxx"), list) + } + + @Test fun joinTo() { + val data = listOf("foo", "bar") + val buffer = StringBuilder() + data.joinTo(buffer, "-", "{", "}") + assertEquals("{foo-bar}", buffer.toString()) + } + + @Test fun joinToString() { + 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) + } + + @Test fun filterNotNull() { + val data = listOf(null, "foo", null, "bar") + val foo = data.filterNotNull() + + assertEquals(2, foo.size) + assertEquals(listOf("foo", "bar"), foo) + + assertTrue { + foo is List + } + } + + /* + @Test fun mapNotNull() { + val data = listOf(null, "foo", null, "bar") + val foo = data.mapNotNull { it.length() } + assertEquals(2, foo.size()) + assertEquals(listOf(3, 3), foo) + + assertTrue { + foo is List + } + } + */ + + @Test fun listOfNotNull() { + 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) + } + + @Test fun filterIntoSet() { + 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 + } + } + + @Test fun filterIsInstanceList() { + 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) + } + + @Test fun filterIsInstanceArray() { + 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) + } + + @Test fun foldIndexed() { + 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 } + } + } + + @Test fun foldIndexedWithDifferentTypes() { + 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) } + } + } + + @Test fun foldIndexedWithNonCommutativeOperation() { + expect(4) { + val numbers = listOf(1, 2, 3) + numbers.foldIndexed(7) { index, a, b -> index + a - b } + } + } + + @Test fun foldRightIndexed() { + expect("12343210") { + val numbers = listOf(1, 2, 3, 4) + numbers.map { it.toString() }.foldRightIndexed("") { index, a, b -> a + b + index } + } + } + + @Test fun foldRightIndexedWithDifferentTypes() { + expect("12343210") { + val numbers = listOf(1, 2, 3, 4) + numbers.foldRightIndexed("") { index, a, b -> "" + a + b + index } + } + } + + @Test fun foldRightIndexedWithNonCommutativeOperation() { + expect(-4) { + val numbers = listOf(1, 2, 3) + numbers.foldRightIndexed(7) { index, a, b -> index + a - b } + } + } + + @Test fun fold() { + // 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 } + } + } + + @Test fun foldWithDifferentTypes() { + 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 } + } + } + + @Test fun foldWithNonCommutativeOperation() { + expect(1) { + val numbers = listOf(1, 2, 3) + numbers.fold(7) { a, b -> a - b } + } + } + + @Test fun foldRight() { + expect("1234") { + val numbers = listOf(1, 2, 3, 4) + numbers.map { it.toString() }.foldRight("") { a, b -> a + b } + } + } + + @Test fun foldRightWithDifferentTypes() { + expect("1234") { + val numbers = listOf(1, 2, 3, 4) + numbers.foldRight("") { a, b -> "" + a + b } + } + } + + @Test fun foldRightWithNonCommutativeOperation() { + expect(-5) { + val numbers = listOf(1, 2, 3) + numbers.foldRight(7) { a, b -> a - b } + } + } + + @Test + fun zipTransform() { + expect(listOf("ab", "bc", "cd")) { + listOf("a", "b", "c").zip(listOf("b", "c", "d")) { a, b -> a + b } + } + } + + @Test + fun zip() { + expect(listOf("a" to "b", "b" to "c", "c" to "d")) { + listOf("a", "b", "c").zip(listOf("b", "c", "d")) + } + } + + @Test fun partition() { + 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") + } + + @Test fun reduceIndexed() { + 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 -> index + a + b } + } + } + + @Test fun reduceRightIndexed() { + 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 -> index + a + b } + } + } + + @Test fun reduce() { + expect("1234") { + val list = listOf("1", "2", "3", "4") + list.reduce { a, b -> a + b } + } + + assertFailsWith { + arrayListOf().reduce { a, b -> a + b } + } + } + + @Test fun reduceRight() { + expect("1234") { + val list = listOf("1", "2", "3", "4") + list.reduceRight { a, b -> a + b } + } + + assertFailsWith { + arrayListOf().reduceRight { a, b -> a + b } + } + } + + @Test fun groupBy() { + 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) + } + + @Test fun groupByKeysAndValues() { + 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) + } + + @Test fun plusRanges() { + val range1 = 1..3 + val range2 = 4..7 + val combined = range1 + range2 + assertEquals((1..7).toList(), combined) + } + + @Test fun mapRanges() { + val range = (1..3).map { it * 2 } + assertEquals(listOf(2, 4, 6), range) + } + + fun testPlus(doPlus: (List) -> List) { + val list = listOf("foo", "bar") + val list2: List = doPlus(list) + assertEquals(listOf("foo", "bar"), list) + assertEquals(listOf("foo", "bar", "cheese", "wine"), list2) + } + + @Test fun plusElement() = testPlus { it + "cheese" + "wine" } + @Test fun plusCollection() = testPlus { it + listOf("cheese", "wine") } + @Test fun plusArray() = testPlus { it + arrayOf("cheese", "wine") } + @Test fun plusSequence() = testPlus { it + sequenceOf("cheese", "wine") } + + @Test fun plusCollectionBug() { + val list = listOf("foo", "bar") + listOf("cheese", "wine") + assertEquals(listOf("foo", "bar", "cheese", "wine"), list) + } + + @Test fun plusCollectionInference() { + 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") + } + + @Test fun plusAssign() { + // 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) + } + + + private fun testMinus(expected: List? = null, doMinus: (List) -> List) { + val a = listOf("foo", "bar", "bar") + val b: List = doMinus(a) + val expected_ = expected ?: listOf("foo") + assertEquals(expected_, b.toList()) + } + + @Test fun minusElement() = testMinus(expected = listOf("foo", "bar")) { it - "bar" - "zoo" } + @Test fun minusCollection() = testMinus { it - listOf("bar", "zoo") } + @Test fun minusArray() = testMinus { it - arrayOf("bar", "zoo") } + @Test fun minusSequence() = testMinus { it - sequenceOf("bar", "zoo") } + + @Test fun minusIsEager() { + val source = listOf("foo", "bar") + val list = arrayListOf() + val result = source - list + + list += "foo" + assertEquals(source, result) + list += "bar" + assertEquals(source, result) + } + + @Test fun minusAssign() { + // 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) + } + + + + @Test fun requireNoNulls() { + 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() + } + } + + @Test fun reverseInPlace() { + 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) + } + + @Test fun reversed() { + val data = listOf("foo", "bar") + val rev = data.reversed() + assertEquals(listOf("bar", "foo"), rev) + assertNotEquals(data, rev) + } + + + @Test fun drop() { + val coll = listOf("foo", "bar", "abc") + assertEquals(listOf("bar", "abc"), coll.drop(1)) + assertEquals(listOf("abc"), coll.drop(2)) + } + + @Test fun dropWhile() { + val coll = listOf("foo", "bar", "abc") + assertEquals(listOf("bar", "abc"), coll.dropWhile { it.startsWith("f") }) + } + + @Test fun dropLast() { + 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) } + } + + @Test fun dropLastWhile() { + 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' } }) + } + + @Test fun take() { + 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) } + } + + @Test fun takeWhile() { + 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 }) + } + + @Test fun takeLast() { + 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) } + + val collWithoutRandomAccess = object : List by coll {} + assertEquals(listOf("abc"), collWithoutRandomAccess.takeLast(1)) + assertEquals(listOf("bar", "abc"), collWithoutRandomAccess.takeLast(2)) + } + + @Test fun takeLastWhile() { + 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' }) + } + + @Test fun copyToArray() { + val data = listOf("foo", "bar") + val arr = data.toTypedArray() + println("Got array ${arr}") + assertEquals(2, arr.size) + } + + @Test fun count() { + val data = listOf("foo", "bar") + assertEquals(2, data.count()) + assertEquals(3, hashSetOf(12, 14, 15).count()) + assertEquals(0, ArrayList().count()) + } + + @Test fun first() { + 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() } + } + + @Test fun last() { + 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() } + } + + @Test fun subscript() { + val list = arrayListOf("foo", "bar") + assertEquals("foo", list[0]) + assertEquals("bar", list[1]) + + // lists throw an exception if out of range + assertFails { + @Suppress("UNUSED_VARIABLE") + 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) + } + + @Test fun indices() { + val data = listOf("foo", "bar") + val indices = data.indices + assertEquals(0, indices.start) + assertEquals(1, indices.endInclusive) + assertEquals(0..data.size - 1, indices) + } + + @Test fun contains() { + assertFalse(hashSetOf().contains(12)) + assertTrue(listOf(15, 19, 20).contains(15)) + + assertTrue(hashSetOf(45, 14, 13).toIterable().contains(14)) + } + + @Test fun min() { + 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() }) + } + + @Test fun max() { + 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() }) + } + + @Test fun minWith() { + 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) }) + } + + @Test fun maxWith() { + 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) }) + } + + @Test fun minBy() { + 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 } }) + } + + @Test fun maxBy() { + 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 } }) + } + + @Test fun minByEvaluateOnce() { + 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) + } + + @Test fun maxByEvaluateOnce() { + 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) + } + + @Test fun sum() { + 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() } + } + + @Test fun average() { + 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() } + } + + @Test fun takeReturnsFirstNElements() { + 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) } + } + + @Test fun sortInPlace() { + 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) + } + + @Test fun sorted() { + val data = listOf(11, 3, 7) + assertEquals(listOf(3, 7, 11), data.sorted()) + assertEquals(listOf(11, 7, 3), data.sortedDescending()) + } + + @Test fun sortByInPlace() { + 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) + } + + @Test fun sortedBy() { + 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 }) + } + + @Test fun sortedNullableBy() { + 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() })) } + } + } + + @Test fun sortedByNullable() { + 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()})) + } + } + + @Test fun sortedWith() { + 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()) } + } + + @Test fun decomposeFirst() { + val (first) = listOf(1, 2) + assertEquals(first, 1) + } + + @Test fun decomposeSplit() { + val (key, value) = "key = value".split("=").map { it.trim() } + assertEquals(key, "key") + assertEquals(value, "value") + } + + @Test fun decomposeList() { + 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) + } + + @Test fun decomposeArray() { + 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) + } + + @Test fun decomposeIntArray() { + 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) + } + + @Test fun unzipList() { + 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) + } + + @Test fun unzipArray() { + 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) + } + + @Test fun specialLists() { + compare(arrayListOf(), listOf()) { listBehavior() } + compare(arrayListOf(), emptyList()) { listBehavior() } + compare(arrayListOf("value"), listOf("value")) { listBehavior() } + } + + @Test fun specialSets() { + compare(linkedSetOf(), setOf()) { setBehavior() } + compare(hashSetOf(), emptySet()) { setBehavior() } + compare(listOf("value").toMutableSet(), setOf("value")) { setBehavior() } + } + + @Test fun specialMaps() { + compare(hashMapOf(), mapOf()) { mapBehavior() } + compare(linkedMapOf(), emptyMap()) { mapBehavior() } + compare(linkedMapOf(2 to 3), mapOf(2 to 3)) { mapBehavior() } + } + + @Test fun toStringTest() { + // 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()) + } + + @Test fun randomAccess() { + 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") + } + + /* + Test relies on Kotlin/JVM toTypedArray() implementation that invokes toArray() after the cast to JDK class + @Test fun abstractCollectionToArray() { + 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/stdlib_external/collections/ComparisonDSL.kt b/backend.native/tests/stdlib_external/collections/ComparisonDSL.kt new file mode 100644 index 00000000000..9900d3abce6 --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/ComparisonDSL.kt @@ -0,0 +1,35 @@ +package test.collections + +import test.* +import kotlin.reflect.KProperty1 +import kotlin.test.* + +public fun compare(expected: T, actual: T, block:CompareContext.() -> Unit) { + CompareContext(expected, actual).block() +} + +public class CompareContext(public val expected: T, public val actual: T) { + + public fun equals(message: String = "") { + assertEquals(expected, actual, message) + } + + public fun

propertyEquals(property: KProperty1) { + propertyEquals(property.name, property) + } + + 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) + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/collections/GroupingTest.kt b/backend.native/tests/stdlib_external/collections/GroupingTest.kt new file mode 100644 index 00000000000..4654f7b1796 --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/GroupingTest.kt @@ -0,0 +1,112 @@ +package test.collections + +import kotlin.test.* + +class GroupingTest { + + @Test fun groupingProducers() { + + 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() }) + } + + // aggregate and aggregateTo operations are not tested, but they're used in every other operation + + + @Test fun foldWithConstantInitialValue() { + 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) + } + + data class Collector(val key: K, val values: MutableList = mutableListOf()) + + @Test fun foldWithComputedInitialValue() { + + 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, _ -> Collector(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, _ -> error("should not be called for $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) + } + + inline fun > maxOfBy(a: T, b: T, keySelector: (T) -> K) = if (keySelector(a) >= keySelector(b)) a else b + + @Test fun reduce() { + 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 { _, 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)) { _, acc, e -> acc + e } + + assertEquals(mapOf('f' to "foofork", 'b' to "biscuitbar", 'z' to "zooz"), concats) + } + + @Test fun countEach() { + 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) + } + +/** + @Test fun sumEach() { + val values = listOf("k" to 50, "b" to 20, "k" to 1000 ) + val summary = values.groupingBy { it.first }.eachSumOf { it.second } + + assertEquals(mapOf("k" to 1050, "b" to 20), summary) + + val values2 = listOf("key", "ball", "builder", "alpha") + val summary2 = values2.groupingBy { it.first().toString() }.eachSumOfTo(HashMap(summary)) { it.length } + + assertEquals(mapOf("k" to 1053, "b" to 31, "a" to 5), summary2) + } +*/ +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/collections/IterableTests.kt b/backend.native/tests/stdlib_external/collections/IterableTests.kt new file mode 100644 index 00000000000..adc730e847a --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/IterableTests.kt @@ -0,0 +1,517 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.collections + +import test.* +import kotlin.test.* + +fun iterableOf(vararg items: T): Iterable = Iterable { items.iterator() } +fun Iterable.toIterable(): Iterable = Iterable { this.iterator() } + +class IterableTest : OrderedIterableTests>({ iterableOf(*it) }, iterableOf()) +class SetTest : IterableTests>({ setOf(*it) }, setOf()) +class LinkedSetTest : OrderedIterableTests>({ linkedSetOf(*it) }, linkedSetOf()) +class ListTest : OrderedIterableTests>( { listOf(*it) }, listOf()) +class ArrayListTest : OrderedIterableTests>({ arrayListOf(*it) }, arrayListOf()) + +abstract class OrderedIterableTests>(createFrom: (Array) -> T, empty: T) : IterableTests(createFrom, empty) { + @Test + fun indexOf() { + expect(0) { data.indexOf("foo") } + expect(-1) { empty.indexOf("foo") } + expect(1) { data.indexOf("bar") } + expect(-1) { data.indexOf("zap") } + } + + @Test + fun lastIndexOf() { + expect(0) { data.lastIndexOf("foo") } + expect(-1) { empty.lastIndexOf("foo") } + expect(1) { data.lastIndexOf("bar") } + expect(-1) { data.lastIndexOf("zap") } + } + + @Test + fun indexOfFirst() { + expect(-1) { data.indexOfFirst { it.contains("p") } } + expect(0) { data.indexOfFirst { it.startsWith('f') } } + expect(-1) { empty.indexOfFirst { it.startsWith('f') } } + } + + @Test + fun indexOfLast() { + expect(-1) { data.indexOfLast { it.contains("p") } } + expect(1) { data.indexOfLast { it.length == 3 } } + expect(-1) { empty.indexOfLast { it.startsWith('f') } } + } + + @Test + fun elementAt() { + expect("foo") { data.elementAt(0) } + expect("bar") { data.elementAt(1) } + assertFails { data.elementAt(2) } + assertFails { data.elementAt(-1) } + assertFails { empty.elementAt(0) } + + expect("foo") { data.elementAtOrElse(0, {""} )} + expect("zoo") { data.elementAtOrElse(-1, { "zoo" })} + expect("zoo") { data.elementAtOrElse(2, { "zoo" })} + expect("zoo") { empty.elementAtOrElse(0) { "zoo" }} + + expect(null) { empty.elementAtOrNull(0) } + + } + + @Test + fun first() { + expect("foo") { data.first() } + assertFails { + data.first { it.startsWith("x") } + } + assertFails { + empty.first() + } + expect("foo") { data.first { it.startsWith("f") } } + } + + @Test + fun firstOrNull() { + expect(null) { data.firstOrNull { it.startsWith("x") } } + expect(null) { empty.firstOrNull() } + + val f = data.firstOrNull { it.startsWith("f") } + assertEquals("foo", f) + } + + @Test + fun last() { + assertEquals("bar", data.last()) + assertFails { + data.last { it.startsWith("x") } + } + assertFails { + empty.last() + } + expect("foo") { data.last { it.startsWith("f") } } + } + + @Test + fun lastOrNull() { + expect(null) { data.lastOrNull { it.startsWith("x") } } + expect(null) { empty.lastOrNull() } + expect("foo") { data.lastOrNull { it.startsWith("f") } } + } + + + @Test + fun zipWithNext() { + val data = createFrom("", "a", "xyz") + val lengthDeltas = data.zipWithNext { a: String, b: String -> b.length - a.length } + assertEquals(listOf(1, 2), lengthDeltas) + + assertTrue(empty.zipWithNext { a: String, b: String -> a + b }.isEmpty()) + assertTrue(createFrom("foo").zipWithNext { a: String, b: String -> a + b }.isEmpty()) + } + + @Test + fun zipWithNextPairs() { + assertTrue(empty.zipWithNext().isEmpty()) + assertTrue(createFrom("foo").zipWithNext().isEmpty()) + assertEquals(listOf("a" to "b"), createFrom("a", "b").zipWithNext()) + assertEquals(listOf("a" to "b", "b" to "c"), createFrom("a", "b", "c").zipWithNext()) + } + + @Test + fun chunked() { + val size = 7 + val data = createFrom(Array(size) { "$it" }) + val result = data.chunked(4) + assertEquals(listOf( + listOf("0", "1", "2", "3"), + listOf("4", "5", "6") + ), result) + + val result2 = data.chunked(3) { it.joinToString("") } + assertEquals(listOf("012", "345", "6"), result2) + + data.toList().let { expectedSingleChunk -> + assertEquals(expectedSingleChunk, data.chunked(size).single()) + assertEquals(expectedSingleChunk, data.chunked(size + 3).single()) + } + + assertTrue(empty.chunked(3).isEmpty()) + + for (illegalValue in listOf(Int.MIN_VALUE, -1, 0)) { + assertFailsWith("size $illegalValue") { data.chunked(illegalValue) } + } + } + + + @Test + fun windowed() { + val size = 7 + val data = createFrom(Array(size) { "$it" }) + val result = data.windowed(4, 2) + assertEquals(listOf( + listOf("0", "1", "2", "3"), + listOf("2", "3", "4", "5") + ), result) + + val resultPartial = data.windowed(4, 2, partialWindows = true) + assertEquals(listOf( + listOf("0", "1", "2", "3"), + listOf("2", "3", "4", "5"), + listOf("4", "5", "6"), + listOf("6") + ), resultPartial) + + + val result2 = data.windowed(2, 3) { it.joinToString("") } + assertEquals(listOf("01", "34"), result2) + + val result2partial = data.windowed(2, 3, partialWindows = true) { it.joinToString("") } + assertEquals(listOf("01", "34", "6"), result2partial) + + assertEquals(data.chunked(2), data.windowed(2, 2, partialWindows = true)) + + assertEquals(data.take(2), data.windowed(2, size).single()) + assertEquals(data.take(3), data.windowed(3, size + 3).single()) + + assertEquals(data.toList(), data.windowed(size, 1).single()) + assertTrue(data.windowed(size + 1, 1).isEmpty()) + + val result3partial = data.windowed(size, 1, partialWindows = true) + result3partial.forEachIndexed { index, window -> + assertEquals(size - index, window.size, "size of window#$index") + } + + assertTrue(empty.windowed(3, 2).isEmpty()) + + for (illegalValue in listOf(Int.MIN_VALUE, -1, 0)) { + assertFailsWith("size $illegalValue") { data.windowed(illegalValue, 1) } + assertFailsWith("step $illegalValue") { data.windowed(1, illegalValue) } + } + } + + +} + +abstract class IterableTests>(val createFrom: (Array) -> T, val empty: T) { + fun createFrom(vararg items: String): T = createFrom(items) + + val data = createFrom("foo", "bar") + + @Test + fun any() { + expect(true) { data.any() } + expect(false) { empty.any() } + expect(true) { data.any { it.startsWith("f") } } + expect(false) { data.any { it.startsWith("x") } } + expect(false) { empty.any { it.startsWith("x") } } + } + + @Test + fun all() { + expect(true) { data.all { it.length == 3 } } + expect(false) { data.all { it.startsWith("b") } } + expect(true) { empty.all { it.startsWith("b") } } + } + + @Test + fun none() { + expect(false) { data.none() } + expect(true) { empty.none() } + expect(false) { data.none { it.length == 3 } } + expect(false) { data.none { it.startsWith("b") } } + expect(true) { data.none { it.startsWith("x") } } + expect(true) { empty.none { it.startsWith("b") } } + } + + @Test + fun filter() { + val foo = data.filter { it.startsWith("f") } + expect(true) { foo is List } + expect(true) { foo.all { it.startsWith("f") } } + expect(1) { foo.size } + assertEquals(listOf("foo"), foo) + } + + @Test fun filterIndexed() { + val result = data.filterIndexed { index, value -> value.first() == ('a' + index) } + assertEquals(listOf("bar"), result) + } + + @Test + fun drop() { + val foo = data.drop(1) + expect(true) { foo is List } + expect(true) { foo.all { it.startsWith("b") } } + expect(1) { foo.size } + assertEquals(listOf("bar"), foo) + } + + @Test + fun dropWhile() { + val foo = data.dropWhile { it[0] == 'f' } + expect(true) { foo is List } + expect(true) { foo.all { it.startsWith("b") } } + expect(1) { foo.size } + assertEquals(listOf("bar"), foo) + } + + @Test + fun filterNot() { + val notFoo = data.filterNot { it.startsWith("f") } + expect(true) { notFoo is List } + expect(true) { notFoo.none { it.startsWith("f") } } + expect(1) { notFoo.size } + assertEquals(listOf("bar"), notFoo) + } + + @Test + fun forEach() { + var count = 0 + data.forEach { count += it.length } + assertEquals(6, count) + } + + @Test + fun onEach() { + var count = 0 + val newData = data.onEach { count += it.length } + assertEquals(6, count) + assertTrue(data === newData) + + // static types test + assertStaticTypeIs>(arrayListOf(1, 2, 3).onEach { }) + } + + @Test + fun contains() { + assertTrue(data.contains("foo")) + assertTrue("bar" in data) + assertTrue("baz" !in data) + assertFalse("baz" in empty) + } + + @Test + fun single() { + assertFails { data.single() } + assertFails { empty.single() } + expect("foo") { data.single { it.startsWith("f") } } + expect("bar") { data.single { it.startsWith("b") } } + assertFails { + data.single { it.length == 3 } + } + } + + @Test + fun singleOrNull() { + expect(null) { data.singleOrNull() } + expect(null) { empty.singleOrNull() } + expect("foo") { data.singleOrNull { it.startsWith("f") } } + expect("bar") { data.singleOrNull { it.startsWith("b") } } + expect(null) { + data.singleOrNull { it.length == 3 } + } + } + + @Test + fun map() { + val lengths = data.map { it.length } + assertTrue { + lengths.all { it == 3 } + } + assertEquals(2, lengths.size) + assertEquals(listOf(3, 3), lengths) + } + + @Test + fun flatten() { + assertEquals(listOf(0, 1, 2, 3, 0, 1, 2, 3), data.map { 0..it.length }.flatten()) + } + + @Test + fun mapIndexed() { + val shortened = data.mapIndexed { index, value -> value.substring(0..index) } + assertEquals(2, shortened.size) + assertEquals(listOf("f", "ba"), shortened) + } + + @Test + fun withIndex() { + val indexed = data.withIndex().map { it.value.substring(0..it.index) } + assertEquals(2, indexed.size) + assertEquals(listOf("f", "ba"), indexed) + } + + @Test + fun mapNotNull() { + assertEquals(listOf('o'), data.mapNotNull { it.firstOrNull { c -> c in "oui" } }) + } + + @Test + fun mapIndexedNotNull() { + assertEquals(listOf('b'), data.mapIndexedNotNull { index, s -> s.getOrNull(index - 1) }) + } + + @Test + fun max() { + expect("foo") { data.max() } + expect("bar") { data.maxBy { it.last() } } + } + + @Test + fun min() { + expect("bar") { data.min() } + expect("foo") { data.minBy { it.last() } } + } + + @Test + fun count() { + expect(2) { data.count() } + expect(0) { empty.count() } + + expect(1) { data.count { it.startsWith("f") } } + expect(0) { empty.count { it.startsWith("f") } } + + expect(0) { data.count { it.startsWith("x") } } + expect(0) { empty.count { it.startsWith("x") } } + } + + @Test + fun sumBy() { + expect(6) { data.sumBy { it.length } } + expect(0) { empty.sumBy { it.length } } + + expect(3.0) { data.sumByDouble { it.length.toDouble() / 2 } } + expect(0.0) { empty.sumByDouble { it.length.toDouble() / 2 } } + } + + @Test + fun withIndices() { + var index = 0 + for ((i, d) in data.withIndex()) { + assertEquals(i, index) + assertEquals(d, data.elementAt(index)) + index++ + } + assertEquals(data.count(), index) + } + + @Test + fun fold() { + expect(231) { data.fold(1, { a, b -> a + if (b == "foo") 200 else 30 }) } + } + + @Test + fun reduce() { + val reduced = data.reduce { a, b -> a + b } + assertEquals(6, reduced.length) + assertTrue(reduced == "foobar" || reduced == "barfoo") + } + + @Test + fun mapAndJoinToString() { + val result = data.joinToString(separator = "-") { it.toUpperCase() } + assertEquals("FOO-BAR", result) + } + + fun testPlus(doPlus: (Iterable) -> List) { + val result: List = doPlus(data) + assertEquals(listOf("foo", "bar", "zoo", "g"), result) + assertFalse(result === data) + } + + @Test + fun plusElement() = testPlus { it + "zoo" + "g" } + @Test + fun plusCollection() = testPlus { it + listOf("zoo", "g") } + @Test + fun plusArray() = testPlus { it + arrayOf("zoo", "g") } + @Test + fun plusSequence() = testPlus { it + sequenceOf("zoo", "g") } + + @Test + fun plusAssign() { + // lets use a mutable variable + var result: Iterable = data + result += "foo" + result += listOf("beer") + result += arrayOf("cheese", "wine") + result += sequenceOf("zoo", "g") + assertEquals(listOf("foo", "bar", "foo", "beer", "cheese", "wine", "zoo", "g"), result) + } + + @Test + fun minusElement() { + val result = data - "foo" - "g" + assertEquals(listOf("bar"), result) + } + + @Test + fun minusCollection() { + val result = data - listOf("foo", "g") + assertEquals(listOf("bar"), result) + } + + @Test + fun minusArray() { + val result = data - arrayOf("foo", "g") + assertEquals(listOf("bar"), result) + } + + @Test + fun minusSequence() { + val result = data - sequenceOf("foo", "g") + assertEquals(listOf("bar"), result) + } + + @Test + fun minusAssign() { + // lets use a mutable variable + var result: Iterable = data + result -= "foo" + assertEquals(listOf("bar"), result as? List) + result = data + result -= listOf("beer", "bar") + assertEquals(listOf("foo"), result as? List) + result = data + result -= arrayOf("bar", "foo") + assertEquals(emptyList(), result as? List) + result = data + result -= sequenceOf("foo", "g") + assertEquals(listOf("bar"), result as? List) + } + +} + + +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 +} + diff --git a/backend.native/tests/stdlib_external/collections/IteratorsTest.kt b/backend.native/tests/stdlib_external/collections/IteratorsTest.kt new file mode 100644 index 00000000000..40fb41cc189 --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/IteratorsTest.kt @@ -0,0 +1,14 @@ +package test.collections + +import kotlin.test.* + +class IteratorsTest { + @Test fun iterationOverIterator() { + 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/stdlib_external/collections/ListBinarySearchTest.kt b/backend.native/tests/stdlib_external/collections/ListBinarySearchTest.kt new file mode 100644 index 00000000000..e87fac4d643 --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/ListBinarySearchTest.kt @@ -0,0 +1,112 @@ +package test.collections.binarySearch + +import kotlin.test.* +import kotlin.comparisons.* + +class ListBinarySearchTest { + + val values = listOf(1, 3, 7, 10, 12, 15, 22, 45) + + fun notFound(index: Int) = -(index + 1) + + private val comparator = compareBy?> { it?.value } + + @Test + fun binarySearchByElement() { + 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)) } + } + } + } + + @Test + fun binarySearchByElementNullable() { + 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)) } + } + } + } + + @Test + fun binarySearchWithComparator() { + 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)) } + } + } + } + + @Test + fun binarySearchByKey() { + 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 }) } + } + } + } + + + @Test + fun binarySearchByKeyWithComparator() { + 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) }) + } + } + } + } + + @Test + fun binarySearchByMultipleKeys() { + 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 }) }) + } + } +} + + +private data class IncomparableDataItem(public val value: T) +private fun IncomparableDataItem.pred(): IncomparableDataItem = IncomparableDataItem(value - 1) +private fun IncomparableDataItem.succ(): IncomparableDataItem = IncomparableDataItem(value + 1) +private fun Int.pred() = dec() +private fun Int.succ() = inc() + + diff --git a/backend.native/tests/stdlib_external/collections/ListSpecificTest.kt b/backend.native/tests/stdlib_external/collections/ListSpecificTest.kt new file mode 100644 index 00000000000..ea1491762df --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/ListSpecificTest.kt @@ -0,0 +1,80 @@ +package test.collections + +import kotlin.test.* + +class ListSpecificTest { + val data = listOf("foo", "bar") + val empty = listOf() + + @Test + fun _toString() { + assertEquals("[foo, bar]", data.toString()) + } + + @Test + fun tail() { + val data = listOf("foo", "bar", "whatnot") + val actual = data.drop(1) + assertEquals(listOf("bar", "whatnot"), actual) + } + + @Test + 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)) + } + + @Test + 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) } + + } + + @Test + fun lastIndex() { + assertEquals(-1, empty.lastIndex) + assertEquals(1, data.lastIndex) + } + + @Test + fun indexOfLast() { + expect(-1) { data.indexOfLast { it.contains("p") } } + expect(1) { data.indexOfLast { it.length == 3 } } + expect(-1) { empty.indexOfLast { it.startsWith('f') } } + } + + @Test + fun mutableList() { + 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(",")) + } + + @Test + fun testNullToString() { + assertEquals("[null]", listOf(null).toString()) + } +} diff --git a/backend.native/tests/stdlib_external/collections/MapTest.kt b/backend.native/tests/stdlib_external/collections/MapTest.kt new file mode 100644 index 00000000000..7c25ad3c948 --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/MapTest.kt @@ -0,0 +1,485 @@ +package test.collections + +import kotlin.test.* +import test.* + +class MapTest { + + @Test fun getOrElse() { + 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) + } + + @Test fun getValue() { + 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")) + } + + @Test fun getOrPut() { + 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) + } + + @Test fun sizeAndEmpty() { + val data = hashMapOf() + assertTrue { data.none() } + assertEquals(data.size, 0) + } + + @Test fun setViaIndexOperators() { + val map = hashMapOf() + assertTrue { map.none() } + assertEquals(map.size, 0) + + map["name"] = "James" + + assertTrue { map.any() } + assertEquals(map.size, 1) + assertEquals("James", map["name"]) + } + + @Test fun iterate() { + 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(",")) + } + + @Test fun iterateAndMutate() { + val map = mutableMapOf("beverage" to "beer", "location" to "Mells", "name" to "James") + val it = map.iterator() + for (e in it) { + when (e.key) { + "beverage" -> e.setValue("juice") + "location" -> it.remove() + } + } + assertEquals(mapOf("beverage" to "juice", "name" to "James"), map) + } + + + @Test + fun onEach() { + 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 + assertStaticTypeIs>( + hashMapOf("a" to "b").onEach { } + ) + } + + @Test fun stream() { + 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) + } + + @Test fun iterateWithProperties() { + 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(",")) + } + + @Test fun iterateWithExtraction() { + 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(",")) + } + + @Test fun contains() { + val map = mapOf("a" to 1, "b" to 2) + assertTrue("a" in map) + assertTrue("c" !in map) + } + + @Test fun map() { + val m1 = mapOf("beverage" to "beer", "location" to "Mells") + val list = m1.map { it.value + " rocks" } + + assertEquals(listOf("beer rocks", "Mells rocks"), list) + } + + + @Test fun mapNotNull() { + val m1 = mapOf("a" to 1, "b" to null) + val list = m1.mapNotNull { it.value?.let { v -> "${it.key}$v" } } + assertEquals(listOf("a1"), list) + } + + @Test fun mapValues() { + 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) + } + + @Test fun mapKeys() { + 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) + } + + @Test fun createFrom() { + 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) + } + + @Test fun populateTo() { + 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) + } + + @Test fun createWithSelector() { + 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)) + } + + @Test fun createWithSelectorAndOverwrite() { + val map = listOf("aa", "bb", "ccc").associateBy { it.length } + assertEquals(2, map.size) + assertEquals("bb", map.get(2)) + assertEquals("ccc", map.get(3)) + } + + @Test fun createWithSelectorForKeyAndValue() { + 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]) + } + + @Test fun createWithPairSelector() { + 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]) + } + + @Test fun createUsingTo() { + val map = mapOf("a" to 1, "b" to 2) + assertEquals(2, map.size) + assertEquals(1, map["a"]) + assertEquals(2, map["b"]) + } + + @Test fun createMutableMap() { + 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()) + } + + @Test fun createLinkedMap() { + 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()) + } + + @Test fun filter() { + 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) + } + + @Test fun filterOutProjectedTo() { + 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) + } + + @Test fun any() { + 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 }) + } + + @Test fun all() { + 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 }) + } + + @Test fun countBy() { + 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) + } + + @Test fun filterNot() { + 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"]) + } + + fun testPlusAssign(doPlusAssign: (MutableMap) -> Unit) { + val map = hashMapOf("a" to 1, "b" to 2) + doPlusAssign(map) + assertEquals(3, map.size) + assertEquals(1, map["a"]) + assertEquals(4, map["b"]) + assertEquals(3, map["c"]) + } + + @Test fun plusAssign() = testPlusAssign { + it += "b" to 4 + it += "c" to 3 + } + + @Test fun plusAssignList() = testPlusAssign { it += listOf("c" to 3, "b" to 4) } + + @Test fun plusAssignArray() = testPlusAssign { it += arrayOf("c" to 3, "b" to 4) } + + @Test fun plusAssignSequence() = testPlusAssign { it += sequenceOf("c" to 3, "b" to 4) } + + @Test fun plusAssignMap() = testPlusAssign { it += mapOf("c" to 3, "b" to 4) } + + fun testPlus(doPlus: (Map) -> Map) { + val original = mapOf("A" to 1, "B" to 2) + val extended = doPlus(original) + assertEquals(3, extended.size) + assertEquals(1, extended["A"]) + assertEquals(4, extended["B"]) + assertEquals(3, extended["C"]) + } + + @Test fun plus() = testPlus { it + ("C" to 3) + ("B" to 4) } + + @Test fun plusList() = testPlus { it + listOf("C" to 3, "B" to 4) } + + @Test fun plusArray() = testPlus { it + arrayOf("C" to 3, "B" to 4) } + + @Test fun plusSequence() = testPlus { it + sequenceOf("C" to 3, "B" to 4) } + + @Test fun plusMap() = testPlus { it + mapOf("C" to 3, "B" to 4) } + + @Test fun plusAny() { + testPlusAny(emptyMap(), 1 to "A") + testPlusAny(mapOf("A" to null), "A" as CharSequence to 2) + } + + 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 testMinus(doMinus: (Map) -> Map) { + val original = mapOf("A" to 1, "B" to 2) + val shortened = doMinus(original) + assertEquals("A" to 1, shortened.entries.single().toPair()) + } + + @Test fun minus() = testMinus { it - "B" - "C" } + + @Test fun minusList() = testMinus { it - listOf("B", "C") } + + @Test fun minusArray() = testMinus { it - arrayOf("B", "C") } + + @Test fun minusSequence() = testMinus { it - sequenceOf("B", "C") } + + @Test fun minusSet() = testMinus { it - setOf("B", "C") } + + + + fun testMinusAssign(doMinusAssign: (MutableMap) -> Unit) { + val original = hashMapOf("A" to 1, "B" to 2) + doMinusAssign(original) + assertEquals("A" to 1, original.entries.single().toPair()) + } + + @Test fun minusAssign() = testMinusAssign { + it -= "B" + it -= "C" + } + + @Test fun minusAssignList() = testMinusAssign { it -= listOf("B", "C") } + + @Test fun minusAssignArray() = testMinusAssign { it -= arrayOf("B", "C") } + + @Test fun minusAssignSequence() = testMinusAssign { it -= sequenceOf("B", "C") } + + + fun testIdempotent(operation: (Map) -> Map) { + val original = mapOf("A" to 1, "B" to 2) + assertEquals(original, operation(original)) + } + + fun testIdempotentAssign(operation: (MutableMap) -> Unit) { + val original = hashMapOf("A" to 1, "B" to 2) + val result = HashMap(original) + operation(result) + assertEquals(original, result) + } + + + @Test fun plusEmptyList() = testIdempotent { it + listOf() } + + @Test fun plusEmptySet() = testIdempotent { it + setOf() } + + @Test fun plusAssignEmptyList() = testIdempotentAssign { it += listOf() } + + @Test fun plusAssignEmptySet() = testIdempotentAssign { it += setOf() } + + +} diff --git a/backend.native/tests/stdlib_external/collections/MutableCollectionsTest.kt b/backend.native/tests/stdlib_external/collections/MutableCollectionsTest.kt new file mode 100644 index 00000000000..068b4a7a6af --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/MutableCollectionsTest.kt @@ -0,0 +1,117 @@ +package test.collections + +import kotlin.test.* + + +class MutableCollectionTest { + 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() }) + + + @Test fun addAll() { + 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()) } + } + } + + @Test fun removeAll() { + 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 } } + } + } + + @Test fun retainAll() { + 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 } } + } + } + +/* + // Kotlin/JVM only: java.util.Collections.fill(this, value) + @Test fun listFill() { + val list = MutableList(3) { it } + list.fill(42) + assertEquals(listOf(42, 42, 42), list) + } +*/ + +/* + // shuffle is Kotlin/JVM only method + @Test fun shuffled() { + val list = MutableList(100) { it } + val shuffled = list.shuffled() + + assertNotEquals(list, shuffled) + assertEquals(list.toSet(), shuffled.toSet()) + assertEquals(list.size, shuffled.distinct().size) + } +*/ +} diff --git a/backend.native/tests/stdlib_external/collections/ReversedViewsTest.kt b/backend.native/tests/stdlib_external/collections/ReversedViewsTest.kt new file mode 100644 index 00000000000..f97e5cbfc30 --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/ReversedViewsTest.kt @@ -0,0 +1,222 @@ +/* + * Copyright 2010-2015 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.collections + +import test.collections.behaviors.listBehavior +import test.collections.compare +import kotlin.test.* + +class ReversedViewsTest { + + @Test fun testNullToString() { + assertEquals("[null]", listOf(null).asReversed().toString()) + } + + @Test fun testBehavior() { + val original = listOf(2L, 3L, Long.MAX_VALUE) + val reversed = original.reversed() + compare(reversed, original.asReversed()) { + listBehavior() + } + } + + @Test fun testSimple() { + assertEquals(listOf(3, 2, 1), listOf(1, 2, 3).asReversed()) + assertEquals(listOf(3, 2, 1), listOf(1, 2, 3).asReversed().toList()) + } + + @Test fun testRandomAccess() { + val reversed = listOf(1, 2, 3).asReversed() + + assertEquals(3, reversed[0]) + assertEquals(2, reversed[1]) + assertEquals(1, reversed[2]) + } + + @Test fun testDoubleReverse() { + 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()) + } + + @Test fun testEmpty() { + assertEquals(emptyList(), emptyList().asReversed()) + } + + @Test fun testReversedSubList() { + val reversed = (1..10).toList().asReversed() + assertEquals(listOf(9, 8, 7), reversed.subList(1, 4)) + } + + @Test fun testMutableSubList() { + 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) + } + + @Test fun testMutableSimple() { + assertEquals(listOf(3, 2, 1), mutableListOf(1, 2, 3).asReversed()) + assertEquals(listOf(3, 2, 1), mutableListOf(1, 2, 3).asReversed().toList()) + } + + @Test fun testMutableDoubleReverse() { + 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()) + } + + @Test fun testMutableEmpty() { + assertEquals(emptyList(), mutableListOf().asReversed()) + } + + @Test fun testMutableReversedSubList() { + val reversed = (1..10).toMutableList().asReversed() + assertEquals(listOf(9, 8, 7), reversed.subList(1, 4)) + } + + @Test fun testMutableAdd() { + 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) + } + + @Test fun testMutableSet() { + 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) + } + + @Test fun testMutableRemove() { + 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) + } + + @Test fun testMutableRemoveByObj() { + val original = mutableListOf("a", "b", "c") + val reversed = original.asReversed() + + reversed.remove("c") + assertEquals(listOf("a", "b"), original) + assertEquals(listOf("b", "a"), reversed) + } + + @Test fun testMutableClear() { + val original = mutableListOf(1, 2, 3) + val reversed = original.asReversed() + + reversed.clear() + + assertEquals(emptyList(), reversed) + assertEquals(emptyList(), original) + } + + @Test fun testContains() { + assertTrue { 1 in listOf(1, 2, 3).asReversed() } + assertTrue { 1 in mutableListOf(1, 2, 3).asReversed() } + } + + @Test fun testIndexOf() { + assertEquals(2, listOf(1, 2, 3).asReversed().indexOf(1)) + assertEquals(2, mutableListOf(1, 2, 3).asReversed().indexOf(1)) + } + + @Test fun testBidirectionalModifications() { + 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) + } + + @Test fun testGetIOOB() { + val success = try { + listOf(1, 2, 3).asReversed().get(3) + true + } catch (expected: IndexOutOfBoundsException) { + false + } + + assertFalse(success) + } + + @Test fun testSetIOOB() { + val success = try { + mutableListOf(1, 2, 3).asReversed().set(3, 0) + true + } catch(expected: IndexOutOfBoundsException) { + false + } + + assertFalse(success) + } + + @Test fun testAddIOOB() { + val success = try { + mutableListOf(1, 2, 3).asReversed().add(4, 0) + true + } catch(expected: IndexOutOfBoundsException) { + false + } + + assertFalse(success) + } + + @Test fun testRemoveIOOB() { + val success = try { + mutableListOf(1, 2, 3).asReversed().removeAt(3) + true + } catch(expected: IndexOutOfBoundsException) { + false + } + + assertFalse(success) + } +} diff --git a/backend.native/tests/stdlib_external/collections/SequenceTest.kt b/backend.native/tests/stdlib_external/collections/SequenceTest.kt new file mode 100644 index 00000000000..520e45c79e3 --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/SequenceTest.kt @@ -0,0 +1,562 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.collections + +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 * 1 } +} + +public class SequenceTest { + + private class TriggerSequence(val source: Sequence) : Sequence { + var iterated: Boolean = false + private set + + override fun iterator(): Iterator = source.iterator().also { iterated = true } + } + + fun ensureIsIntermediate(source: Sequence, operation: (Sequence) -> Sequence<*>) { + TriggerSequence(source).let { s -> + val result = operation(s) + assertFalse(s.iterated, "Source should not be iterated before the result is") + result.iterator().hasNext() + assertTrue(s.iterated, "Source should be iterated after the result is iterated") + } + } + + @Test fun filterEmptySequence() { + for (sequence in listOf(emptySequence(), sequenceOf())) { + assertEquals(0, sequence.filter { false }.count()) + assertEquals(0, sequence.filter { true }.count()) + } + } + + @Test fun mapEmptySequence() { + for (sequence in listOf(emptySequence(), sequenceOf())) { + assertEquals(0, sequence.map { true }.count()) + } + } + + @Test fun requireNoNulls() { + 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() + } + } + + @Test fun filterIndexed() { + assertEquals(listOf(1, 2, 5, 13, 34), fibonacci().filterIndexed { index, _ -> index % 2 == 1 }.take(5).toList()) + } + + @Test fun filterNullable() { + val data = sequenceOf(null, "foo", null, "bar") + val filtered = data.filter { it == null || it == "foo" } + assertEquals(listOf(null, "foo", null), filtered.toList()) + } + + @Test fun filterNot() { + val data = sequenceOf(null, "foo", null, "bar") + val filtered = data.filterNot { it == null } + assertEquals(listOf("foo", "bar"), filtered.toList()) + } + + @Test fun filterNotNull() { + val data = sequenceOf(null, "foo", null, "bar") + val filtered = data.filterNotNull() + assertEquals(listOf("foo", "bar"), filtered.toList()) + } + + @Test fun mapIndexed() { + assertEquals(listOf(0, 1, 2, 6, 12), fibonacci().mapIndexed { index, value -> index * value }.takeWhile { i: Int -> i < 20 }.toList()) + } + + @Test fun mapNotNull() { + assertEquals(listOf(0, 10, 110, 1220), fibonacci().mapNotNull { if (it % 5 == 0) it * 2 else null }.take(4).toList()) + } + + @Test fun mapIndexedNotNull() { + // 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()) + } + + + @Test fun mapAndJoinToString() { + assertEquals("3, 5, 8", fibonacci().withIndex().filter { it.index > 3 }.take(3).joinToString { it.value.toString() }) + } + + @Test fun withIndex() { + val data = sequenceOf("foo", "bar") + val indexed = data.withIndex().map { it.value.substring(0..it.index) }.toList() + assertEquals(listOf("f", "ba"), indexed) + } + + @Test + 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) + } + + + @Test fun filterAndTakeWhileExtractTheElementsWithinRange() { + assertEquals(listOf(144, 233, 377, 610, 987), fibonacci().filter { it > 100 }.takeWhile { it < 1000 }.toList()) + } + + @Test fun foldReducesTheFirstNElements() { + 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)) + } + + @Test fun takeExtractsTheFirstNElements() { + assertEquals(listOf(0, 1, 1, 2, 3, 5, 8, 13, 21, 34), fibonacci().take(10).toList()) + } + + @Test fun mapAndTakeWhileExtractTheTransformedElements() { + assertEquals(listOf(0, 3, 3, 6, 9, 15), fibonacci().map { it * 3 }.takeWhile { i: Int -> i < 20 }.toList()) + } + + @Test fun joinConcatenatesTheFirstNElementsAboveAThreshold() { + assertEquals("13, 21, 34, 55, 89, ...", fibonacci().filter { it > 10 }.joinToString(separator = ", ", limit = 5)) + } + + @Test fun drop() { + 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) } + } + + @Test fun take() { + 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) } + } + + @Test fun subSequence() { + 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()) + + } + + @Test fun dropWhile() { + assertEquals("233, 377, 610", fibonacci().dropWhile { it < 200 }.take(3).joinToString(limit = 10)) + assertEquals("", sequenceOf(1).dropWhile { it < 200 }.joinToString(limit = 10)) + } + + @Test fun zipWithNext() { + val deltas = fibonacci().zipWithNext { a: Int, b: Int -> b - a } + // deltas of 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, ... + // is the same sequence prepended by 1 + assertEquals(listOf(1) + fibonacci().take(9), deltas.take(10).toList()) + + ensureIsIntermediate(source = sequenceOf(1, 2)) { it.zipWithNext { a: Int, b: Int -> b - a } } + } + + @Test fun zipWithNextPairs() { + val pairs: Sequence> = sequenceOf("a", "b", "c", "d").zipWithNext() + assertEquals(listOf("a" to "b", "b" to "c", "c" to "d"), pairs.toList()) + + assertTrue(emptySequence().zipWithNext().toList().isEmpty()) + assertTrue(sequenceOf(1).zipWithNext().toList().isEmpty()) + + ensureIsIntermediate(source = sequenceOf(1, 2)) { it.zipWithNext() } + } + + @Test + fun chunked() { + val infiniteSeq = generateSequence(0) { it + 1 } + val result = infiniteSeq.chunked(4) + assertEquals(listOf( + listOf(0, 1, 2, 3), + listOf(4, 5, 6, 7) + ), result.take(2).toList()) + + val size = 7 + val seq = infiniteSeq.take(7) + + val result2 = seq.chunked(3) { it.joinToString("") } + assertEquals(listOf("012", "345", "6"), result2.toList()) + + seq.toList().let { expectedSingleChunk -> + assertEquals(expectedSingleChunk, seq.chunked(size).single()) + assertEquals(expectedSingleChunk, seq.chunked(size + 3).single()) + } + + assertTrue(emptySequence().chunked(3).none()) + + for (illegalValue in listOf(Int.MIN_VALUE, -1, 0)) { + assertFailsWith("size $illegalValue") { infiniteSeq.chunked(illegalValue) } + } + + ensureIsIntermediate(source = sequenceOf(1, 2, 3)) { it.chunked(2) } + } + + + @Test + fun windowed() { + val infiniteSeq = generateSequence(0) { it + 1 } + val result = infiniteSeq.windowed(5, 3) + result.take(10).forEachIndexed { windowIndex, window -> + val startElement = windowIndex * 3 + assertEquals((startElement until startElement + 5).toList(), window) + } + + val size = 7 + val seq = infiniteSeq.take(7) + + val result1 = seq.windowed(4, 2) + assertEquals(listOf( + listOf(0, 1, 2, 3), + listOf(2, 3, 4, 5) + ), result1.toList()) + + val result1partial = seq.windowed(4, 2, partialWindows = true) + assertEquals(listOf( + listOf(0, 1, 2, 3), + listOf(2, 3, 4, 5), + listOf(4, 5, 6), + listOf(6) + ), result1partial.toList()) + + val result2 = seq.windowed(2, 3) { it.joinToString("") } + assertEquals(listOf("01", "34"), result2.toList()) + + val result2partial = seq.windowed(2, 3, partialWindows = true) { it.joinToString("") } + assertEquals(listOf("01", "34", "6"), result2partial.toList()) + + assertEquals(seq.chunked(2).toList(), seq.windowed(2, 2, partialWindows = true).toList()) + + assertEquals(seq.take(2).toList(), seq.windowed(2, size).single()) + assertEquals(seq.take(3).toList(), seq.windowed(3, size + 3).single()) + + + assertEquals(seq.toList(), seq.windowed(size, 1).single()) + assertTrue(seq.windowed(size + 1, 1).none()) + + val result3partial = seq.windowed(size, 1, partialWindows = true) + result3partial.forEachIndexed { index, window -> + assertEquals(size - index, window.size, "size of window#$index") + } + + assertTrue(emptySequence().windowed(3, 2).none()) + + for (illegalValue in listOf(Int.MIN_VALUE, -1, 0)) { + assertFailsWith("size $illegalValue") { seq.windowed(illegalValue, 1) } + assertFailsWith("step $illegalValue") { seq.windowed(1, illegalValue) } + } + + ensureIsIntermediate(source = sequenceOf(1, 2, 3)) { it.windowed(2, 1) } + } + + @Test fun zip() { + expect(listOf("ab", "bc", "cd")) { + sequenceOf("a", "b", "c").zip(sequenceOf("b", "c", "d")) { a, b -> a + b }.toList() + } + } + +// @Test fun zipPairs() { +// 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) +// } + + @Test fun toStringJoinsNoMoreThanTheFirstTenElements() { + 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()) + } + + + fun testPlus(doPlus: (Sequence) -> Sequence) { + val seq = sequenceOf("foo", "bar") + val seq2: Sequence = doPlus(seq) + assertEquals(listOf("foo", "bar"), seq.toList()) + assertEquals(listOf("foo", "bar", "cheese", "wine"), seq2.toList()) + } + + + @Test fun plusElement() = testPlus { it + "cheese" + "wine" } + @Test fun plusCollection() = testPlus { it + listOf("cheese", "wine") } + @Test fun plusArray() = testPlus { it + arrayOf("cheese", "wine") } + @Test fun plusSequence() = testPlus { it + sequenceOf("cheese", "wine") } + + @Test fun plusAssign() { + // 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()) + } + + private fun testMinus(expected: List? = null, doMinus: (Sequence) -> Sequence) { + val a = sequenceOf("foo", "bar", "bar") + val b: Sequence = doMinus(a) + val expected_ = expected ?: listOf("foo") + assertEquals(expected_, b.toList()) + } + + @Test fun minusElement() = testMinus(expected = listOf("foo", "bar")) { it - "bar" - "zoo" } + @Test fun minusCollection() = testMinus { it - listOf("bar", "zoo") } + @Test fun minusArray() = testMinus { it - arrayOf("bar", "zoo") } + @Test fun minusSequence() = testMinus { it - sequenceOf("bar", "zoo") } + + @Test fun minusIsLazyIterated() { + 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()) + } + + @Test fun minusAssign() { + // 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()) + } + + + + @Test fun iterationOverSequence() { + var s = "" + for (i in sequenceOf(0, 1, 2, 3, 4, 5)) { + s += i.toString() + } + assertEquals("012345", s) + } + + @Test fun sequenceFromFunction() { + 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() + } + } + + @Test fun sequenceFromFunctionWithInitialValue() { + 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") + } + + @Test fun sequenceFromFunctionWithLazyInitialValue() { + 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() } + } + + + @Test fun sequenceFromIterator() { + val list = listOf(3, 2, 1, 0) + val iterator = list.iterator() + val sequence = iterator.asSequence() + assertEquals(list, sequence.toList()) + assertFails { + sequence.toList() + } + } + + @Test fun makeSequenceOneTimeConstrained() { + 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 + } + + } + + private fun > Sequence.takeWhileTo(result: C, predicate: (T) -> Boolean): C { + for (element in this) if (predicate(element)) result.add(element) else break + return result + } + + @Test fun sequenceExtensions() { + val d = ArrayList() + sequenceOf(0, 1, 2, 3, 4, 5).takeWhileTo(d, { i -> i < 4 }) + assertEquals(4, d.size) + } + + @Test fun flatMapAndTakeExtractTheTransformedElements() { + 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()) + } + + @Test fun flatMap() { + val result = sequenceOf(1, 2).flatMap { (0..it).asSequence() } + assertEquals(listOf(0, 1, 0, 1, 2), result.toList()) + } + + @Test fun flatMapOnEmpty() { + val result = sequenceOf().flatMap { (0..it).asSequence() } + assertTrue(result.none()) + } + + @Test fun flatMapWithEmptyItems() { + val result = sequenceOf(1, 2, 4).flatMap { if (it == 2) sequenceOf() else (it - 1..it).asSequence() } + assertEquals(listOf(0, 1, 3, 4), result.toList()) + } + + @Test fun flatten() { + 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()) + } + + @Test fun distinct() { + val sequence = fibonacci().dropWhile { it < 10 }.take(20) + assertEquals(listOf(1, 2, 3, 0), sequence.map { it % 4 }.distinct().toList()) + } + + @Test fun distinctBy() { + val sequence = fibonacci().dropWhile { it < 10 }.take(20) + assertEquals(listOf(13, 34, 55, 144), sequence.distinctBy { it % 4 }.toList()) + } + + @Test fun unzip() { + 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) + } + + @Test fun sorted() { + sequenceOf(3, 7, 5).let { + it.sorted().iterator().assertSorted { a, b -> a <= b } + it.sortedDescending().iterator().assertSorted { a, b -> a >= b } + } + } + + @Test fun sortedBy() { + 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 } + } + } + + @Test fun sortedWith() { + val comparator = compareBy { s: String -> s.reversed() } + assertEquals(listOf("act", "wast", "test"), sequenceOf("act", "test", "wast").sortedWith(comparator).toList()) + } + + /* + test fun pairIterator() { + 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) + } +*/ + +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/collections/SetOperationsTest.kt b/backend.native/tests/stdlib_external/collections/SetOperationsTest.kt new file mode 100644 index 00000000000..2b3be13eb84 --- /dev/null +++ b/backend.native/tests/stdlib_external/collections/SetOperationsTest.kt @@ -0,0 +1,77 @@ +package test.collections + +import kotlin.test.* + +class SetOperationsTest { + @Test fun distinct() { + assertEquals(listOf(1, 3, 5), listOf(1, 3, 3, 1, 5, 1, 3).distinct()) + assertTrue(listOf().distinct().isEmpty()) + } + + @Test fun distinctBy() { + assertEquals(listOf("some", "cat", "do"), arrayOf("some", "case", "cat", "do", "dog", "it").distinctBy { it.length }) + assertTrue(charArrayOf().distinctBy { it }.isEmpty()) + } + + @Test fun union() { + assertEquals(listOf(1, 3, 5), listOf(1, 3).union(listOf(5)).toList()) + assertEquals(listOf(1), listOf().union(listOf(1)).toList()) + } + + @Test fun subtract() { + 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()) + } + + @Test fun intersect() { + 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()) + } + + fun testPlus(doPlus: (Set) -> Set) { + val set = setOf("foo", "bar") + val set2: Set = doPlus(set) + assertEquals(setOf("foo", "bar"), set) + assertEquals(setOf("foo", "bar", "cheese", "wine"), set2) + } + + @Test fun plusElement() = testPlus { it + "bar" + "cheese" + "wine" } + @Test fun plusCollection() = testPlus { it + listOf("bar", "cheese", "wine") } + @Test fun plusArray() = testPlus { it + arrayOf("bar", "cheese", "wine") } + @Test fun plusSequence() = testPlus { it + sequenceOf("bar", "cheese", "wine") } + + @Test fun plusAssign() { + // 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) + } + + private fun testMinus(doMinus: (Set) -> Set) { + val a = setOf("foo", "bar") + val b: Set = doMinus(a) + assertEquals(setOf("foo"), b) + } + + @Test fun minusElement() = testMinus { it - "bar" - "zoo" } + @Test fun minusCollection() = testMinus { it - listOf("bar", "zoo") } + @Test fun minusArray() = testMinus { it - arrayOf("bar", "zoo") } + @Test fun minusSequence() = testMinus { it - sequenceOf("bar", "zoo") } + +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/coroutines/CoroutineContextTest.kt b/backend.native/tests/stdlib_external/coroutines/CoroutineContextTest.kt new file mode 100644 index 00000000000..6b25261eeff --- /dev/null +++ b/backend.native/tests/stdlib_external/coroutines/CoroutineContextTest.kt @@ -0,0 +1,174 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.coroutines + +import kotlin.test.* +import kotlin.coroutines.experimental.* + +class CoroutineContextTest { + 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" + } + + @Test + fun testGetPlusFold() { + 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]) + } + + @Test + fun testMinusKey() { + 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) + } + + @Test + fun testPlusCombined() { + 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]) + } + + @Test + fun testLastDispatcher() { + 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) + } + + @Test + fun testEquals() { + 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) + } + + 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) + } +} diff --git a/backend.native/tests/stdlib_external/coroutines/CoroutinesReferenceValuesTest.kt b/backend.native/tests/stdlib_external/coroutines/CoroutinesReferenceValuesTest.kt new file mode 100644 index 00000000000..f391606c130 --- /dev/null +++ b/backend.native/tests/stdlib_external/coroutines/CoroutinesReferenceValuesTest.kt @@ -0,0 +1,70 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.coroutines + +import kotlin.test.* +import kotlin.coroutines.experimental.* + +/** + * Test to ensure that coroutine machinery does not call equals/hashCode/toString anywhere. + */ +class CoroutinesReferenceValuesTest { + 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 + + @Test + fun testBadClass() { + 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) + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/coroutines/SequenceBuilderTest.kt b/backend.native/tests/stdlib_external/coroutines/SequenceBuilderTest.kt new file mode 100644 index 00000000000..27fd572eba8 --- /dev/null +++ b/backend.native/tests/stdlib_external/coroutines/SequenceBuilderTest.kt @@ -0,0 +1,304 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.coroutines + +import kotlin.test.* +import kotlin.coroutines.experimental.buildSequence +import kotlin.coroutines.experimental.buildIterator + +class SequenceBuilderTest { + @Test + fun testSimple() { + 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()) + } + + @Test + fun testCallHasNextSeveralTimes() { + 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() } + } + + @Test + fun testManualIteration() { + 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()) + } + + @Test + fun testEmptySequence() { + val result = buildSequence {} + val iterator = result.iterator() + + assertFalse(iterator.hasNext()) + assertFalse(iterator.hasNext()) + + assertFailsWith { iterator.next() } + } + + @Test + fun testLaziness() { + 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() } + } + + @Test + fun testExceptionInCoroutine() { + 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() } + } + + @Test + fun testParallelIteration() { + 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()) + } + + @Test + fun testYieldAllIterator() { + val result = buildSequence { + yieldAll(listOf(1, 2, 3).iterator()) + } + assertEquals(listOf(1, 2, 3), result.toList()) + } + + @Test + fun testYieldAllSequence() { + val result = buildSequence { + yieldAll(sequenceOf(1, 2, 3)) + } + assertEquals(listOf(1, 2, 3), result.toList()) + } + + @Test + fun testYieldAllCollection() { + val result = buildSequence { + yieldAll(listOf(1, 2, 3)) + } + assertEquals(listOf(1, 2, 3), result.toList()) + } + + @Test + fun testYieldAllCollectionMixedFirst() { + val result = buildSequence { + yield(0) + yieldAll(listOf(1, 2, 3)) + } + assertEquals(listOf(0, 1, 2, 3), result.toList()) + } + + @Test + fun testYieldAllCollectionMixedLast() { + val result = buildSequence { + yieldAll(listOf(1, 2, 3)) + yield(4) + } + assertEquals(listOf(1, 2, 3, 4), result.toList()) + } + + @Test + fun testYieldAllCollectionMixedBoth() { + val result = buildSequence { + yield(0) + yieldAll(listOf(1, 2, 3)) + yield(4) + } + assertEquals(listOf(0, 1, 2, 3, 4), result.toList()) + } + + @Test + fun testYieldAllCollectionMixedLong() { + 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()) + } + + @Test + fun testYieldAllCollectionOneEmpty() { + val result = buildSequence { + yieldAll(listOf()) + } + assertEquals(listOf(), result.toList()) + } + + @Test + fun testYieldAllCollectionManyEmpty() { + val result = buildSequence { + yieldAll(listOf()) + yieldAll(listOf()) + yieldAll(listOf()) + } + assertEquals(listOf(), result.toList()) + } + + @Test + fun testYieldAllSideEffects() { + 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() + ) + } + + @Test + fun testInfiniteYieldAll() { + 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/stdlib_external/language/EscapedTestNamesTest.kt b/backend.native/tests/stdlib_external/language/EscapedTestNamesTest.kt new file mode 100644 index 00000000000..c1d64bc5e79 --- /dev/null +++ b/backend.native/tests/stdlib_external/language/EscapedTestNamesTest.kt @@ -0,0 +1,16 @@ +package test.language + +import kotlin.test.* + +class EscapedTestNamesTest { + + @Test fun `strings equal`() { + val actual = "abc" + assertEquals("abc", actual) + } + + @Test fun `numbers equal`() { + val actual = 5 + assertEquals(5, actual) + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/numbers/BitwiseOperationsTest.kt b/backend.native/tests/stdlib_external/numbers/BitwiseOperationsTest.kt new file mode 100644 index 00000000000..6ed7a0c5b6d --- /dev/null +++ b/backend.native/tests/stdlib_external/numbers/BitwiseOperationsTest.kt @@ -0,0 +1,34 @@ +package test.numbers + +import kotlin.test.* + +// TODO: Run these tests during compiler test only (JVM & JS) +class BitwiseOperationsTest { + @Test fun orForInt() { + assertEquals(3, 2 or 1) + } + + @Test fun andForInt() { + assertEquals(0, 1 and 0) + } + + @Test fun xorForInt() { + assertEquals(1, 2 xor 3) + } + + @Test fun shlForInt() { + assertEquals(4, 1 shl 2) + } + + @Test fun shrForInt() { + assertEquals(1, 2 shr 1) + } + + @Test fun ushrForInt() { + assertEquals(2147483647, -1 ushr 1) + } + + @Test fun invForInt() { + assertEquals(0, (-1).inv()) + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/numbers/HarmonyMathTests.kt b/backend.native/tests/stdlib_external/numbers/HarmonyMathTests.kt new file mode 100644 index 00000000000..7715c7764ff --- /dev/null +++ b/backend.native/tests/stdlib_external/numbers/HarmonyMathTests.kt @@ -0,0 +1,824 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.numbers.harmony_math + +import kotlin.math.* +import kotlin.test.* + +class HarmonyMath { + + fun assertEquals(expected: Double, actual: Double, tolerance: Double? = null) = + assertEquals(null, expected, actual, tolerance) + + fun assertEquals(expected: Float, actual: Float, tolerance: Float? = null) = + assertEquals(null, expected, actual, tolerance) + + fun Double.Companion.isNaN(v: Double) = v.isNaN() + fun Float.Companion.isNaN(v: Float) = v.isNaN() + + fun pow(a: Double, b: Double) = a.pow(b) + fun pow(a: Float, b: Float) = a.pow(b) + + fun ulp(v: Double) = v.ulp + fun ulp(v: Float) = v.ulp + + fun assertEquals(message: String?, expected: Int, actual: Int) = assertEquals(expected, actual, message) + fun assertEquals(message: String?, expected: Long, actual: Long) = assertEquals(expected, actual, message) + + fun assertEquals(message: String?, expected: Double, actual: Double, tolerance: Double? = null) { + val tolerance_ = tolerance?.let { abs(it) } ?: 0.000000000001 + if (abs(expected - actual) > tolerance_) { + assertEquals(expected, actual, message) + } + } + + fun assertEquals(message: String?, expected: Float, actual: Float, tolerance: Float? = null) { + val tolerance_ = tolerance?.let { abs(it) } ?: 0.0000001f + if (abs(expected - actual) > tolerance_) { + assertEquals(expected, actual, message) + } + } + + fun assertTrue(message: String? = null, condition: Boolean) = assertTrue(condition, message) + + internal var HYP = sqrt(2.0) + + internal var OPP = 1.0 + + internal var ADJ = 1.0 + + /* Required to make previous preprocessor flags work - do not remove */ + internal var unused = 0 + + /** + * Tests kotlin.math.abs(Double) + */ + @Test fun absD() { + // Test for abs(Double): Double + + assertTrue("Incorrect Double abs value", + abs(-1908.8976) == 1908.8976) + assertTrue("Incorrect Double abs value", + abs(1908.8976) == 1908.8976) + } + + /** + * Tests kotlin.math.abs(float) + */ + @Test fun absF() { + // Test for abs(float): float + assertTrue("Incorrect float abs value", + abs(-1908.8976f) == 1908.8976f) + assertTrue("Incorrect float abs value", + abs(1908.8976f) == 1908.8976f) + } + + /** + * Tests kotlin.math.abs(int) + */ + @Test fun absI() { + // Test for abs(int): int + assertTrue("Incorrect int abs value", abs(-1908897) == 1908897) + assertTrue("Incorrect int abs value", abs(1908897) == 1908897) + } + + /** + * Tests kotlin.math.abs(long) + */ + @Test fun absJ() { + // Test for abs(long): long + assertTrue("Incorrect long abs value", + abs(-19088976000089L) == 19088976000089L) + assertTrue("Incorrect long abs value", + abs(19088976000089L) == 19088976000089L) + } + + /** + * Tests kotlin.math.acos(Double) + */ + @Test fun acosD() { + // Test for acos(Double): Double + val r = cos(acos(ADJ / HYP)) + val lr = r.toBits() + val t = (ADJ / HYP).toBits() + assertTrue("Returned incorrect arc cosine", lr == t || lr + 1 == t || lr - 1 == t) + } + + /** + * Tests kotlin.math.asin(Double) + */ + @Test fun asinD() { + // Test for asin(Double): Double + val r = sin(asin(OPP / HYP)) + val lr = r.toBits() + val t = (OPP / HYP).toBits() + assertTrue("Returned incorrect arc sine", lr == t || lr + 1 == t || lr - 1 == t) + } + + /** + * Tests kotlin.math.atan(Double) + */ + @Test fun atanD() { + // Test for atan(Double): Double + val answer = tan(atan(1.0)) + assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0 && answer >= 9.9999999999999983E-1) + } + + /** + * Tests kotlin.math.atan2(Double, Double) + */ + @Test fun atan2DD() { + // Test for atan2(Double, Double): Double + val answer = atan(tan(1.0)) + assertTrue("Returned incorrect arc tangent: " + answer, answer <= 1.0 && answer >= 9.9999999999999983E-1) + } + + /** + * Tests kotlin.math.ceil(Double) + */ + @Test fun ceilD() { + // Test for ceil(Double): Double + assertEquals("Incorrect ceiling for Double", + 79.0, ceil(78.89), 0.0) + assertEquals("Incorrect ceiling for Double", + -78.0, ceil(-78.89), 0.0) + } + + /** + * Tests kotlin.math.withSign(Double) + */ + @Test fun withSign_D() { + for (i in COPYSIGN_DD_CASES.indices) { + val magnitude = COPYSIGN_DD_CASES[i] + val absMagnitudeBits = abs(magnitude).toBits() + val negMagnitudeBits = (-abs(magnitude)).toBits() + + assertTrue("The result should be NaN.", Double.isNaN(Double.NaN.withSign(magnitude))) + + for (j in COPYSIGN_DD_CASES.indices) { + val sign = COPYSIGN_DD_CASES[j] + val resultBits = magnitude.withSign(sign).toBits() + + if (sign > 0 || (+0.0).toBits() == sign.toBits() || 0.0.toBits() == sign.toBits()) { + assertEquals( + "If the sign is positive, the result should be positive.", + absMagnitudeBits, resultBits) + } + if (sign < 0 || (-0.0).toBits() == sign.toBits()) { + assertEquals( + "If the sign is negative, the result should be negative.", + negMagnitudeBits, resultBits) + } + } + } + + assertTrue("The result should be NaN.", Double.isNaN(Double.NaN.withSign(Double.NaN))) + } + + /** + * Tests kotlin.math.withSign(Float) + */ + @Test fun withSign_F() { + for (i in COPYSIGN_FF_CASES.indices) { + val magnitude = COPYSIGN_FF_CASES[i] + val absMagnitudeBits = abs(magnitude).toBits() + val negMagnitudeBits = (-abs(magnitude)).toBits() + + assertTrue("The result should be NaN.", Float.isNaN(Float.NaN.withSign(magnitude))) + + for (j in COPYSIGN_FF_CASES.indices) { + val sign = COPYSIGN_FF_CASES[j] + val resultBits = magnitude.withSign(sign).toBits() + if (sign > 0 || (+0.0f).toBits() == sign.toBits() || 0.0f.toBits() == sign.toBits()) { + assertEquals( + "If the sign is positive, the result should be positive.", + absMagnitudeBits, resultBits) + } + if (sign < 0 || (-0.0f).toBits() == sign.toBits()) { + assertEquals( + "If the sign is negative, the result should be negative.", + negMagnitudeBits, resultBits) + } + } + } + + assertTrue("The result should be NaN.", Float.isNaN(Float.NaN.withSign(Float.NaN))) + } + + /** + * Tests kotlin.math.cos(Double) + */ + @Test fun cosD() { + // Test for cos(Double): Double + assertEquals("Incorrect answer", 1.0, cos(0.0), 0.0) + assertEquals("Incorrect answer", 0.5403023058681398, cos(1.0), 0.0) + } + + /** + * Tests kotlin.math.cosh(Double) + */ + @Test fun cosh_D() { + // Test for special situations + assertTrue(Double.isNaN(cosh(Double.NaN))) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, cosh(Double.POSITIVE_INFINITY), 0.0) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, cosh(Double.NEGATIVE_INFINITY), 0.0) + assertEquals("Should return 1.0", 1.0, cosh(+0.0), 0.0) + assertEquals("Should return 1.0", 1.0, cosh(-0.0), 0.0) + + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, cosh(1234.56), 0.0) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, cosh(-1234.56), 0.0) + assertEquals("Should return 1.0000000000005", 1.0000000000005, cosh(0.000001), 0.0) + assertEquals("Should return 1.0000000000005", 1.0000000000005, cosh(-0.000001), 0.0) + assertEquals("Should return 5.212214351945598", 5.212214351945598, cosh(2.33482), 0.0) + + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, cosh(Double.MAX_VALUE), 0.0) + assertEquals("Should return 1.0", 1.0, cosh(Double.MIN_VALUE), 0.0) + } + + /** + * Tests kotlin.math.exp(Double) + */ + @Test fun expD() { + // Test for exp(Double): Double + assertTrue("Incorrect answer returned for simple power", abs(exp(4.0) - E * E * E * E) < 0.1) + assertTrue("Incorrect answer returned for larger power", ln(abs(exp(5.5)) - 5.5) < 10.0) + } + + /** + * Tests kotlin.math.expm1(Double) + */ + @Test fun expm1_D() { + // Test for special cases + assertTrue("Should return NaN", Double.isNaN(expm1(Double.NaN))) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, expm1(Double.POSITIVE_INFINITY), 0.0) + assertEquals("Should return -1.0", -1.0, expm1(Double.NEGATIVE_INFINITY), 0.0) + + assertEquals(0.0.toBits(), expm1(0.0).toBits()) + assertEquals(+0.0.toBits(), expm1(+0.0).toBits()) + assertEquals((-0.0).toBits(), expm1(-0.0).toBits()) + + assertEquals("Should return -9.999950000166666E-6", + -9.999950000166666E-6, expm1(-0.00001), 0.0) + assertEquals("Should return 1.0145103074469635E60", + 1.0145103074469635E60, expm1(138.16951162), 0.0) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, expm1(123456789123456789123456789.4521584223), 0.0) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, expm1(Double.MAX_VALUE), 0.0) + assertEquals("Should return MIN_VALUE", Double.MIN_VALUE, expm1(Double.MIN_VALUE), 0.0) + } + + /** + * Tests kotlin.math.floor(Double) + */ + @Test fun floorD() { + assertEquals("Incorrect floor for int", 42.0, floor(42.0), 0.0) + assertEquals("Incorrect floor for -int", -2.0, floor(-2.0), 0.0) + assertEquals("Incorrect floor for zero", 0.0, floor(0.0), 0.0) + + assertEquals("Incorrect floor for +Double", 78.0, floor(78.89), 0.0) + assertEquals("Incorrect floor for -Double", -79.0, floor(-78.89), 0.0) + assertEquals("floor large +Double", 3.7314645675925406E19, floor(3.7314645675925406E19), 0.0) + assertEquals("floor large -Double", -8.173521839218E12, floor(-8.173521839218E12), 0.0) + assertEquals("floor small Double", 0.0, floor(1.11895241315E-102), 0.0) + + // Compare toString representations here since -0.0 = +0.0, and + // NaN != NaN and we need to distinguish + + assertEquals(Double.NaN.toString(), floor(Double.NaN).toString(), "Floor failed for NaN") + assertEquals((+0.0).toString(), floor(+0.0).toString(), "Floor failed for +0.0") + assertEquals((-0.0).toString(), floor(-0.0).toString(), "Floor failed for -0.0") + assertEquals(Double.POSITIVE_INFINITY.toString(), floor(Double.POSITIVE_INFINITY).toString(), + "Floor failed for +infinity") + assertEquals(Double.NEGATIVE_INFINITY.toString(), floor(Double.NEGATIVE_INFINITY).toString(), + "Floor failed for -infinity") + } + + /** + * Tests kotlin.math.hypot(Double, Double) + */ + @Test fun hypot_DD() { + // Test for special cases + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, hypot(Double.POSITIVE_INFINITY, + 1.0), 0.0) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, hypot(Double.NEGATIVE_INFINITY, + 123.324), 0.0) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, hypot(-758.2587, + Double.POSITIVE_INFINITY), 0.0) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, hypot(5687.21, + Double.NEGATIVE_INFINITY), 0.0) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, hypot(Double.POSITIVE_INFINITY, + Double.NEGATIVE_INFINITY), 0.0) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, hypot(Double.NEGATIVE_INFINITY, + Double.POSITIVE_INFINITY), 0.0) + assertTrue("Should be NaN", Double.isNaN(hypot(Double.NaN, + 2342301.89843))) + assertTrue("Should be NaN", Double.isNaN(hypot(-345.2680, + Double.NaN))) + + assertEquals("Should return 2396424.905416697", 2396424.905416697, hypot(12322.12, -2396393.2258), 0.0) + assertEquals("Should return 138.16958070558556", 138.16958070558556, + hypot(-138.16951162, 0.13817035864), 0.0) + assertEquals("Should return 1.7976931348623157E308", + 1.7976931348623157E308, hypot(Double.MAX_VALUE, 211370.35), 0.0) + assertEquals("Should return 5413.7185", 5413.7185, hypot( + -5413.7185, Double.MIN_VALUE), 0.0) + } + + /** + * Tests kotlin.math.IEEEremainder(Double, Double) + */ + @Test fun IEEEremainderDD() { + // Test for IEEEremainder(Double, Double): Double + assertEquals("Incorrect remainder returned", + 0.0, 1.0.IEEErem(1.0), 0.0) + assertTrue("Incorrect remainder returned", + 1.32.IEEErem(89.765) >= 1.4705063220631647E-2 || 1.32.IEEErem(89.765) >= 1.4705063220631649E-2) + } + + /** + * Tests kotlin.math.ln(Double) + */ + @Test fun lnD() { + // Test for log(Double): Double + var d = 10.0 + while (d >= -10) { + val answer = ln(exp(d)) + assertTrue("Answer does not equal expected answer for d = " + d + + " answer = " + answer, abs(answer - d) <= abs(d * 0.00000001)) + d -= 0.5 + } + } + + /** + * Tests kotlin.math.log10(Double) + */ + @Test fun log10_D() { + // Test for special cases + assertTrue(Double.isNaN(log10(Double.NaN))) + assertTrue(Double.isNaN(log10(-2541.05745687234187532))) + assertTrue(Double.isNaN(log10(-0.1))) + assertEquals(Double.POSITIVE_INFINITY, log10(Double.POSITIVE_INFINITY)) + assertEquals(Double.NEGATIVE_INFINITY, log10(0.0)) + assertEquals(Double.NEGATIVE_INFINITY, log10(+0.0)) + assertEquals(Double.NEGATIVE_INFINITY, log10(-0.0)) + + assertEquals(3.0, log10(1000.0)) + assertEquals(14.0, log10(10.0.pow(14.0))) + assertEquals(3.7389561269540406, log10(5482.2158)) + assertEquals(14.661551142893833, log10(458723662312872.125782332587)) + assertEquals(-0.9083828622192334, log10(0.12348583358871)) + assertEquals(308.25471555991675, log10(Double.MAX_VALUE)) + assertEquals(-323.3062153431158, log10(Double.MIN_VALUE)) + } + + /** + * Tests kotlin.math.ln1p(Double) + */ + @Test fun ln1p_D() { + // Test for special cases + assertTrue("Should return NaN", Double.isNaN(ln1p(Double.NaN))) + assertTrue("Should return NaN", Double.isNaN(ln1p(-32.0482175))) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, ln1p(Double.POSITIVE_INFINITY), 0.0) + assertEquals(0.0.toBits(), ln1p(0.0).toBits()) + assertEquals(+0.0.toBits(), ln1p(+0.0).toBits()) + assertEquals((-0.0).toBits(), ln1p(-0.0).toBits()) + + assertEquals("Should return -0.2941782295312541", -0.2941782295312541, + ln1p(-0.254856327), 0.0) + assertEquals("Should return 7.368050685564151", 7.368050685564151, ln1p(1583.542), 0.0) + assertEquals("Should return 0.4633708685409921", 0.4633708685409921, + ln1p(0.5894227), 0.0) + assertEquals("Should return 709.782712893384", 709.782712893384, ln1p(Double.MAX_VALUE), 0.0) + assertEquals("Should return Double.MIN_VALUE", Double.MIN_VALUE, ln1p(Double.MIN_VALUE), 0.0) + } + + /** + * Tests kotlin.math.max(Double, Double) + */ + @Test fun maxDD() { + // Test for max(Double, Double): Double + assertEquals("Incorrect Double max value", 1908897.6000089, max(-1908897.6000089, + 1908897.6000089), 0.0) + assertEquals("Incorrect Double max value", + 1908897.6000089, max(2.0, 1908897.6000089), 0.0) + assertEquals("Incorrect Double max value", -2.0, max(-2.0, + -1908897.6000089), 0.0) + + // Compare toString representations here since -0.0 = +0.0, and + // NaN != NaN and we need to distinguish + assertEquals((Double.NaN).toString(), max(Double.NaN, 42.0).toString(), "Max failed for NaN") + assertEquals((Double.NaN).toString(), max(42.0, Double.NaN).toString(), "Max failed for NaN") + assertEquals((+0.0).toString(), max(+0.0, -0.0).toString(), "Max failed for 0.0") + assertEquals((+0.0).toString(), max(-0.0, +0.0).toString(), "Max failed for 0.0") + assertEquals((-0.0).toString(), max(-0.0, -0.0).toString(), "Max failed for -0.0d") + assertEquals((+0.0).toString(), max(+0.0, +0.0).toString(), "Max failed for 0.0") + } + + /** + * Tests kotlin.math.max(float, float) + */ + @Test fun maxFF() { + // Test for max(float, float): float + assertTrue("Incorrect float max value", max(-1908897.600f, + 1908897.600f) == 1908897.600f) + assertTrue("Incorrect float max value", + max(2.0f, 1908897.600f) == 1908897.600f) + assertTrue("Incorrect float max value", + max(-2.0f, -1908897.600f) == -2.0f) + + // Compare toString representations here since -0.0 = +0.0, and + // NaN != NaN and we need to distinguish + assertEquals(Float.NaN.toString(), max(Float.NaN, 42.0f).toString(), "Max failed for NaN") + assertEquals(Float.NaN.toString(), max(42.0f, Float.NaN).toString(), "Max failed for NaN") + assertEquals((+0.0f).toString(), max(+0.0f, -0.0f).toString(), "Max failed for 0.0") + assertEquals((+0.0f).toString(), max(-0.0f, +0.0f).toString(), "Max failed for 0.0") + assertEquals((-0.0f).toString(), max(-0.0f, -0.0f).toString(), "Max failed for -0.0f") + assertEquals((+0.0f).toString(), max(+0.0f, +0.0f).toString(), "Max failed for 0.0") + } + + /** + * Tests kotlin.math.max(int, int) + */ + @Test fun maxII() { + // Test for max(int, int): int + assertEquals("Incorrect int max value", + 19088976, max(-19088976, 19088976)) + assertEquals("Incorrect int max value", + 19088976, max(20, 19088976)) + assertEquals("Incorrect int max value", -20, max(-20, -19088976)) + } + + /** + * Tests kotlin.math.max(long, long) + */ + @Test fun maxJJ() { + // Test for max(long, long): long + assertEquals("Incorrect long max value", 19088976000089L, max(-19088976000089L, + 19088976000089L)) + assertEquals("Incorrect long max value", + 19088976000089L, max(20, 19088976000089L)) + assertEquals("Incorrect long max value", + -20, max(-20, -19088976000089L)) + } + + /** + * Tests kotlin.math.min(Double, Double) + */ + @Test fun minDD() { + // Test for min(Double, Double): Double + assertEquals("Incorrect Double min value", -1908897.6000089, min(-1908897.6000089, + 1908897.6000089), 0.0) + assertEquals("Incorrect Double min value", + 2.0, min(2.0, 1908897.6000089), 0.0) + assertEquals("Incorrect Double min value", -1908897.6000089, min(-2.0, + -1908897.6000089), 0.0) + assertEquals("Incorrect Double min value", 1.0, min(1.0, 1.0)) + + // Compare toString representations here since -0.0 = +0.0, and + // NaN != NaN and we need to distinguish + assertEquals(Double.NaN.toString(), min(Double.NaN, 42.0).toString(), "Min failed for NaN") + assertEquals(Double.NaN.toString(), min(42.0, Double.NaN).toString(), "Min failed for NaN") + assertEquals((-0.0).toString(), min(+0.0, -0.0).toString(), "Min failed for -0.0") + assertEquals((-0.0).toString(), min(-0.0, +0.0).toString(), "Min failed for -0.0") + assertEquals((-0.0).toString(), min(-0.0, -0.0).toString(), "Min failed for -0.0d") + assertEquals((+0.0).toString(), min(+0.0, +0.0).toString(), "Min failed for 0.0") + } + + /** + * Tests kotlin.math.min(float, float) + */ + @Test fun minFF() { + // Test for min(float, float): float + assertTrue("Incorrect float min value", min(-1908897.600f, + 1908897.600f) == -1908897.600f) + assertTrue("Incorrect float min value", + min(2.0f, 1908897.600f) == 2.0f) + assertTrue("Incorrect float min value", + min(-2.0f, -1908897.600f) == -1908897.600f) + assertEquals("Incorrect float min value", 1.0f, min(1.0f, 1.0f)) + + // Compare toString representations here since -0.0 = +0.0, and + // NaN != NaN and we need to distinguish + assertEquals(Float.NaN.toString(), min(Float.NaN, 42.0f).toString(), "Min failed for NaN") + assertEquals(Float.NaN.toString(), min(42.0f, Float.NaN).toString(), "Min failed for NaN") + assertEquals((-0.0f).toString(), min(+0.0f, -0.0f).toString(), "Min failed for -0.0") + assertEquals((-0.0f).toString(), min(-0.0f, +0.0f).toString(), "Min failed for -0.0") + assertEquals((-0.0f).toString(), min(-0.0f, -0.0f).toString(), "Min failed for -0.0f") + assertEquals((+0.0f).toString(), min(+0.0f, +0.0f).toString(), "Min failed for 0.0") + } + + /** + * Tests kotlin.math.min(int, int) + */ + @Test fun minII() { + // Test for min(int, int): int + assertEquals("Incorrect int min value", + -19088976, min(-19088976, 19088976)) + assertEquals("Incorrect int min value", 20, min(20, 19088976)) + assertEquals("Incorrect int min value", + -19088976, min(-20, -19088976)) + + } + + /** + * @tests java.lang.Math#pow(double, double) + */ + fun test_powDD() { + // Test for method double java.lang.Math.pow(double, double) + assertTrue("pow returned incorrect value", + 2.0.pow(8.0).toLong() == 256L) + assertTrue("pow returned incorrect value", + 2.0.pow(-8.0) == 0.00390625) + assertEquals("Incorrect root returned1", + 2.0, sqrt(sqrt(2.0).pow(4.0)), 0.0) + } + + /** + * Tests kotlin.math.round(Double) + */ + @Test fun roundD() { + // Test for round(Double): Double + assertEquals("Failed to round properly - up to odd", + 3.0, round(2.9), 0.0) + assertTrue("Failed to round properly - NaN", Double.isNaN(round(Double.NaN))) + assertEquals("Failed to round properly down to even", + 2.0, round(2.1), 0.0) + assertTrue("Failed to round properly " + 2.5 + " to even", round(2.5) == 2.0) + assertTrue("Failed to round properly " + +0.0, + round(+0.0) == +0.0) + assertTrue("Failed to round properly " + -0.0, + round(-0.0) == -0.0) + } + + /** + * Tests kotlin.math.sign(Double) + */ + @Test fun sign_D() { + assertTrue(Double.isNaN(sign(Double.NaN))) + assertTrue(Double.isNaN(sign(Double.NaN))) + assertEquals(0.0.toBits(), sign(0.0).toBits()) + assertEquals(+0.0.toBits(), sign(+0.0).toBits()) + assertEquals((-0.0).toBits(), sign(-0.0).toBits()) + + assertEquals(1.0, sign(253681.2187962), 0.0) + assertEquals(-1.0, sign(-125874693.56), 0.0) + assertEquals(1.0, sign(1.2587E-308), 0.0) + assertEquals(-1.0, sign(-1.2587E-308), 0.0) + + assertEquals(1.0, sign(Double.MAX_VALUE), 0.0) + assertEquals(1.0, sign(Double.MIN_VALUE), 0.0) + assertEquals(-1.0, sign(-Double.MAX_VALUE), 0.0) + assertEquals(-1.0, sign(-Double.MIN_VALUE), 0.0) + assertEquals(1.0, sign(Double.POSITIVE_INFINITY), 0.0) + assertEquals(-1.0, sign(Double.NEGATIVE_INFINITY), 0.0) + } + + /** + * Tests kotlin.math.sign(float) + */ + @Test fun sign_F() { + assertTrue(Float.isNaN(sign(Float.NaN))) + assertEquals(0.0f.toBits(), sign(0.0f).toBits()) + assertEquals(+0.0f.toBits(), sign(+0.0f).toBits()) + assertEquals((-0.0f).toBits(), sign(-0.0f).toBits()) + + assertEquals(1.0f, sign(253681.2187962f), 0f) + assertEquals(-1.0f, sign(-125874693.56f), 0f) + assertEquals(1.0f, sign(1.2587E-11f), 0f) + assertEquals(-1.0f, sign(-1.2587E-11f), 0f) + + assertEquals(1.0f, sign(Float.MAX_VALUE), 0f) + assertEquals(1.0f, sign(Float.MIN_VALUE), 0f) + assertEquals(-1.0f, sign(-Float.MAX_VALUE), 0f) + assertEquals(-1.0f, sign(-Float.MIN_VALUE), 0f) + assertEquals(1.0f, sign(Float.POSITIVE_INFINITY), 0f) + assertEquals(-1.0f, sign(Float.NEGATIVE_INFINITY), 0f) + } + + /** + * Tests kotlin.math.sin(Double) + */ + @Test fun sinD() { + // Test for sin(Double): Double + assertEquals("Incorrect answer", 0.0, sin(0.0), 0.0) + assertEquals("Incorrect answer", 0.8414709848078965, sin(1.0), 0.0) + } + + /** + * Tests kotlin.math.sinh(Double) + */ + @Test fun sinh_D() { + // Test for special situations + assertTrue("Should return NaN", Double.isNaN(sinh(Double.NaN))) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, sinh(Double.POSITIVE_INFINITY), 0.0) + assertEquals("Should return NEGATIVE_INFINITY", + Double.NEGATIVE_INFINITY, sinh(Double.NEGATIVE_INFINITY), 0.0) + assertEquals(0.0.toBits(), sinh(0.0).toBits()) + assertEquals(+0.0.toBits(), sinh(+0.0).toBits()) + assertEquals((-0.0).toBits(), sinh(-0.0).toBits()) + + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, sinh(1234.56), 0.0) + assertEquals("Should return NEGATIVE_INFINITY", + Double.NEGATIVE_INFINITY, sinh(-1234.56), 0.0) + assertEquals("Should return 1.0000000000001666E-6", + 1.0000000000001666E-6, sinh(0.000001), 0.0) + assertEquals("Should return -1.0000000000001666E-6", + -1.0000000000001666E-6, sinh(-0.000001), 0.0) + assertEquals("Should return 5.115386441963859", 5.115386441963859, sinh(2.33482)) + assertEquals("Should return POSITIVE_INFINITY", + Double.POSITIVE_INFINITY, sinh(Double.MAX_VALUE), 0.0) + assertEquals("Should return 4.9E-324", 4.9E-324, sinh(Double.MIN_VALUE), 0.0) + } + + /** + * Tests kotlin.math.sqrt(Double) + */ + @Test fun sqrt_D() { + // Test for sqrt(Double): Double + assertEquals("Incorrect root returned2", 7.0, sqrt(49.0), 0.0) + } + + /** + * Tests kotlin.math.tan(Double) + */ + @Test fun tan_D() { + // Test for tan(Double): Double + assertEquals("Incorrect answer", 0.0, tan(0.0), 0.0) + assertEquals("Incorrect answer", 1.5574077246549023, tan(1.0)) + + } + + /** + * Tests kotlin.math.tanh(Double) + */ + @Test fun tanh_D() { + // Test for special situations + assertTrue("Should return NaN", Double.isNaN(tanh(Double.NaN))) + assertEquals("Should return +1.0", +1.0, tanh(Double.POSITIVE_INFINITY), 0.0) + assertEquals("Should return -1.0", -1.0, tanh(Double.NEGATIVE_INFINITY), 0.0) + assertEquals(0.0.toBits(), tanh(0.0).toBits()) + assertEquals(+0.0.toBits(), tanh(+0.0).toBits()) + assertEquals((-0.0).toBits(), tanh(-0.0).toBits()) + + assertEquals("Should return 1.0", 1.0, tanh(1234.56), 0.0) + assertEquals("Should return -1.0", -1.0, tanh(-1234.56), 0.0) + assertEquals("Should return 9.999999999996666E-7", + 9.999999999996666E-7, tanh(0.000001), 0.0) + assertEquals("Should return 0.981422884124941", 0.981422884124941, tanh(2.33482), 0.0) + assertEquals("Should return 1.0", 1.0, tanh(Double.MAX_VALUE), 0.0) + assertEquals("Should return 4.9E-324", 4.9E-324, tanh(Double.MIN_VALUE), 0.0) + } + + /** + * Tests kotlin.Double.ulp + */ + fun test_ulp_D() { + // Test for special cases + assertTrue("Should return NaN", Double.isNaN(ulp(Double.NaN))) + assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, ulp(Double.POSITIVE_INFINITY), 0.0) + assertEquals("Returned incorrect value", Double.POSITIVE_INFINITY, ulp(Double.NEGATIVE_INFINITY), 0.0) + assertEquals("Returned incorrect value", Double.MIN_VALUE, ulp(0.0), 0.0) + assertEquals("Returned incorrect value", Double.MIN_VALUE, ulp(+0.0), 0.0) + assertEquals("Returned incorrect value", Double.MIN_VALUE, ulp(-0.0), 0.0) + assertEquals("Returned incorrect value", pow(2.0, 971.0), ulp(Double.MAX_VALUE), 0.0) + assertEquals("Returned incorrect value", pow(2.0, 971.0), ulp(-Double.MAX_VALUE), 0.0) + + assertEquals("Returned incorrect value", Double.MIN_VALUE, ulp(Double.MIN_VALUE), 0.0) + assertEquals("Returned incorrect value", Double.MIN_VALUE, ulp(-Double.MIN_VALUE), 0.0) + + assertEquals("Returned incorrect value", 2.220446049250313E-16, ulp(1.0), 0.0) + assertEquals("Returned incorrect value", 2.220446049250313E-16, ulp(-1.0), 0.0) + assertEquals("Returned incorrect value", 2.2737367544323206E-13, ulp(1153.0), 0.0) + } + + /** + * Tests kotlin.Float.ulp + */ + fun test_ulp_f() { + // Test for special cases + assertTrue("Should return NaN", Float.isNaN(ulp(Float.NaN))) + assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, ulp(Float.POSITIVE_INFINITY), 0f) + assertEquals("Returned incorrect value", Float.POSITIVE_INFINITY, ulp(Float.NEGATIVE_INFINITY), 0f) + assertEquals("Returned incorrect value", Float.MIN_VALUE, ulp(0.0f), 0f) + assertEquals("Returned incorrect value", Float.MIN_VALUE, ulp(+0.0f), 0f) + assertEquals("Returned incorrect value", Float.MIN_VALUE, ulp(-0.0f), 0f) + assertEquals("Returned incorrect value", 2.028241E31f, ulp(Float.MAX_VALUE), 0f) + assertEquals("Returned incorrect value", 2.028241E31f, ulp(-Float.MAX_VALUE), 0f) + + assertEquals("Returned incorrect value", 1.4E-45f, ulp(Float.MIN_VALUE), 0f) + assertEquals("Returned incorrect value", 1.4E-45f, ulp(-Float.MIN_VALUE), 0f) + + assertEquals("Returned incorrect value", 1.1920929E-7f, ulp(1.0f), + 0f) + assertEquals("Returned incorrect value", 1.1920929E-7f, + ulp(-1.0f), 0f) + assertEquals("Returned incorrect value", 1.2207031E-4f, ulp(1153.0f), 0f) + assertEquals("Returned incorrect value", 5.6E-45f, ulp(9.403954E-38f), 0f) + } + + companion object { + + const val MIN_NORMAL_D: Double = 2.2250738585072014E-308 + const val MIN_NORMAL_F: Float = 1.1754943508222875E-38f + + /** + * cases for test_copySign_DD in est/Strictest + */ + internal val COPYSIGN_DD_CASES = doubleArrayOf(Double.POSITIVE_INFINITY, Double.MAX_VALUE, 3.4E302, 2.3, + MIN_NORMAL_D, MIN_NORMAL_D / 2, Double.MIN_VALUE, +0.0, 0.0, -0.0, -Double.MIN_VALUE, + -MIN_NORMAL_D / 2, -MIN_NORMAL_D, -4.5, -3.4E102, -Double.MAX_VALUE, Double.NEGATIVE_INFINITY) + + /** + * cases for test_copySign_FF in est/Strictest + */ + internal val COPYSIGN_FF_CASES = floatArrayOf(Float.POSITIVE_INFINITY, Float.MAX_VALUE, 3.4E12f, 2.3f, + MIN_NORMAL_F, MIN_NORMAL_F / 2, Float.MIN_VALUE, +0.0f, 0.0f, -0.0f, -Float.MIN_VALUE, + -MIN_NORMAL_F / 2, -MIN_NORMAL_F, -4.5f, -5.6442E21f, -Float.MAX_VALUE, Float.NEGATIVE_INFINITY) + + /** + * start number cases for test_nextTowards_DD in est/Strictest + * NEXTAFTER_DD_START_CASES[i][0] is the start number + * NEXTAFTER_DD_START_CASES[i][1] is the nextUp of start number + * NEXTAFTER_DD_START_CASES[i][2] is the nextDown of start number + */ + internal val NEXTAFTER_DD_START_CASES = arrayOf( + doubleArrayOf(3.4, 3.4000000000000004, 3.3999999999999995), + doubleArrayOf(-3.4, -3.3999999999999995, -3.4000000000000004), + doubleArrayOf(3.4233E109, 3.4233000000000005E109, 3.4232999999999996E109), + doubleArrayOf(-3.4233E109, -3.4232999999999996E109, -3.4233000000000005E109), + doubleArrayOf(+0.0, Double.MIN_VALUE, -Double.MIN_VALUE), + doubleArrayOf(0.0, Double.MIN_VALUE, -Double.MIN_VALUE), + doubleArrayOf(-0.0, Double.MIN_VALUE, -Double.MIN_VALUE), + doubleArrayOf(Double.MIN_VALUE, 1.0E-323, +0.0), + doubleArrayOf(-Double.MIN_VALUE, -0.0, -1.0E-323), + doubleArrayOf(MIN_NORMAL_D, 2.225073858507202E-308, 2.225073858507201E-308), + doubleArrayOf(-MIN_NORMAL_D, -2.225073858507201E-308, -2.225073858507202E-308), + doubleArrayOf(Double.MAX_VALUE, Double.POSITIVE_INFINITY, 1.7976931348623155E308), + doubleArrayOf(-Double.MAX_VALUE, -1.7976931348623155E308, Double.NEGATIVE_INFINITY), + doubleArrayOf(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY, Double.MAX_VALUE), + doubleArrayOf(Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, Double.NEGATIVE_INFINITY) + ) + + /** + * direction number cases for test_nextTowards_DD/test_nextTowards_FD in + * est/Strictest + */ + internal val NEXTAFTER_DD_FD_DIRECTION_CASES = doubleArrayOf(Double.POSITIVE_INFINITY, + Double.MAX_VALUE, 8.8, 3.4, 1.4, MIN_NORMAL_D, MIN_NORMAL_D / 2, + Double.MIN_VALUE, +0.0, 0.0, -0.0, -Double.MIN_VALUE, -MIN_NORMAL_D / 2, + -MIN_NORMAL_D, -1.4, -3.4, -8.8, -Double.MAX_VALUE, Double.NEGATIVE_INFINITY) + + /** + * start number cases for test_nextTowards_FD in est/Strictest + * NEXTAFTER_FD_START_CASES[i][0] is the start number + * NEXTAFTER_FD_START_CASES[i][1] is the nextUp of start number + * NEXTAFTER_FD_START_CASES[i][2] is the nextDown of start number + */ + internal val NEXTAFTER_FD_START_CASES = arrayOf(floatArrayOf(3.4f, 3.4000003f, 3.3999999f), + floatArrayOf(-3.4f, -3.3999999f, -3.4000003f), + floatArrayOf(3.4233E19f, 3.4233002E19f, 3.4232998E19f), + floatArrayOf(-3.4233E19f, -3.4232998E19f, -3.4233002E19f), + floatArrayOf(+0.0f, Float.MIN_VALUE, -Float.MIN_VALUE), + floatArrayOf(0.0f, Float.MIN_VALUE, -Float.MIN_VALUE), + floatArrayOf(-0.0f, Float.MIN_VALUE, -Float.MIN_VALUE), + floatArrayOf(Float.MIN_VALUE, 2.8E-45f, +0.0f), + floatArrayOf(-Float.MIN_VALUE, -0.0f, -2.8E-45f), + floatArrayOf(MIN_NORMAL_F, 1.1754945E-38f, 1.1754942E-38f), + floatArrayOf(-MIN_NORMAL_F, -1.1754942E-38f, -1.1754945E-38f), + floatArrayOf(Float.MAX_VALUE, Float.POSITIVE_INFINITY, 3.4028233E38f), + floatArrayOf(-Float.MAX_VALUE, -3.4028233E38f, Float.NEGATIVE_INFINITY), + floatArrayOf(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY, Float.MAX_VALUE), + floatArrayOf(Float.NEGATIVE_INFINITY, -Float.MAX_VALUE, Float.NEGATIVE_INFINITY)) + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/numbers/MathTest.kt b/backend.native/tests/stdlib_external/numbers/MathTest.kt new file mode 100644 index 00000000000..f4529614a58 --- /dev/null +++ b/backend.native/tests/stdlib_external/numbers/MathTest.kt @@ -0,0 +1,820 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.numbers + +import kotlin.math.* +import kotlin.test.* + +fun assertAlmostEquals(expected: Double, actual: Double, tolerance: Double? = null) { + val tolerance_ = tolerance?.let { abs(it) } ?: 0.000000000001 + if (abs(expected - actual) > tolerance_) { + assertEquals(expected, actual) + } +} + +fun assertAlmostEquals(expected: Float, actual: Float, tolerance: Double? = null) { + val tolerance_ = tolerance?.let { abs(it) } ?: 0.0000001 + if (abs(expected - actual) > tolerance_) { + assertEquals(expected, actual) + } +} + +class DoubleMathTest { + + @Test fun trigonometric() { + assertEquals(0.0, sin(0.0)) + assertAlmostEquals(0.0, sin(PI)) + + assertEquals(0.0, asin(0.0)) + assertAlmostEquals(PI / 2, asin(1.0)) + + assertEquals(1.0, cos(0.0)) + assertAlmostEquals(-1.0, cos(PI)) + + assertEquals(0.0, acos(1.0)) + assertAlmostEquals(PI / 2, acos(0.0)) + + assertEquals(0.0, tan(0.0)) + assertAlmostEquals(1.0, tan(PI / 4)) + + assertAlmostEquals(0.0, atan(0.0)) + assertAlmostEquals(PI / 4, atan(1.0)) + + assertAlmostEquals(PI / 4, atan2(10.0, 10.0)) + assertAlmostEquals(-PI / 4, atan2(Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)) + assertAlmostEquals(0.0, atan2(0.0, 0.0)) + assertAlmostEquals(0.0, atan2(0.0, 10.0)) + assertAlmostEquals(PI / 2, atan2(2.0, 0.0)) + + for (angle in listOf(Double.NaN, Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY)) { + assertTrue(sin(angle).isNaN(), "sin($angle)") + assertTrue(cos(angle).isNaN(), "cos($angle)") + assertTrue(tan(angle).isNaN(), "tan($angle)") + } + + for (value in listOf(Double.NaN, 1.2, -1.1)) { + assertTrue(asin(value).isNaN()) + assertTrue(acos(value).isNaN()) + } + assertTrue(atan(Double.NaN).isNaN()) + assertTrue(atan2(Double.NaN, 0.0).isNaN()) + assertTrue(atan2(0.0, Double.NaN).isNaN()) + } + + @Test fun hyperbolic() { + assertEquals(Double.POSITIVE_INFINITY, sinh(Double.POSITIVE_INFINITY)) + assertEquals(Double.NEGATIVE_INFINITY, sinh(Double.NEGATIVE_INFINITY)) + assertTrue(sinh(Double.MIN_VALUE) != 0.0) + assertTrue(sinh(710.0).isFinite()) + assertTrue(sinh(-710.0).isFinite()) + assertTrue(sinh(Double.NaN).isNaN()) + + assertEquals(Double.POSITIVE_INFINITY, cosh(Double.POSITIVE_INFINITY)) + assertEquals(Double.POSITIVE_INFINITY, cosh(Double.NEGATIVE_INFINITY)) + assertTrue(cosh(710.0).isFinite()) + assertTrue(cosh(-710.0).isFinite()) + assertTrue(cosh(Double.NaN).isNaN()) + + assertAlmostEquals(1.0, tanh(Double.POSITIVE_INFINITY)) + assertAlmostEquals(-1.0, tanh(Double.NEGATIVE_INFINITY)) + assertTrue(tanh(Double.MIN_VALUE) != 0.0) + assertTrue(tanh(Double.NaN).isNaN()) + } + + @Test fun inverseHyperbolicSin() { + for (exact in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0, Double.MIN_VALUE, -Double.MIN_VALUE, 0.00001)) { + assertEquals(exact, asinh(sinh(exact))) + } + for (approx in listOf(Double.MIN_VALUE, 0.1, 1.0, 100.0, 710.0)) { + assertAlmostEquals(approx, asinh(sinh(approx))) + assertAlmostEquals(-approx, asinh(sinh(-approx))) + } + assertTrue(asinh(Double.NaN).isNaN()) + } + + @Test fun inverseHyperbolicCos() { + for (exact in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0)) { + assertEquals(abs(exact), acosh(cosh(exact))) + } + for (approx in listOf(Double.MIN_VALUE, 0.00001, 1.0, 100.0, 710.0)) { + assertAlmostEquals(approx, acosh(cosh(approx))) + assertAlmostEquals(approx, acosh(cosh(-approx))) + } + for (invalid in listOf(-1.0, 0.0, 0.99999, Double.NaN)) { + assertTrue(acosh(invalid).isNaN()) + } + } + + @Test fun inverseHyperbolicTan() { + for (exact in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0, Double.MIN_VALUE, -Double.MIN_VALUE)) { + assertEquals(exact, atanh(tanh(exact))) + } + for (approx in listOf(0.00001)) { + assertAlmostEquals(approx, atanh(tanh(approx))) + } + + for (invalid in listOf(-1.00001, 1.00001, Double.NaN, Double.MAX_VALUE, -Double.MAX_VALUE, Double.NEGATIVE_INFINITY, Double.POSITIVE_INFINITY)) { + assertTrue(atanh(invalid).isNaN()) + } + } + + @Test fun powers() { + assertEquals(5.0, hypot(3.0, 4.0)) + assertEquals(Double.POSITIVE_INFINITY, hypot(Double.NEGATIVE_INFINITY, Double.NaN)) + assertEquals(Double.POSITIVE_INFINITY, hypot(Double.NaN, Double.POSITIVE_INFINITY)) + assertTrue(hypot(Double.NaN, 0.0).isNaN()) + + assertEquals(1.0, Double.NaN.pow(0.0)) + assertEquals(1.0, Double.POSITIVE_INFINITY.pow(0)) + assertEquals(49.0, 7.0.pow(2)) + assertEquals(0.25, 2.0.pow(-2)) + assertTrue(0.0.pow(Double.NaN).isNaN()) + assertTrue(Double.NaN.pow(-1).isNaN()) + assertTrue((-7.0).pow(1/3.0).isNaN()) + assertTrue(1.0.pow(Double.POSITIVE_INFINITY).isNaN()) + assertTrue((-1.0).pow(Double.NEGATIVE_INFINITY).isNaN()) + + assertEquals(5.0, sqrt(9.0 + 16.0)) + assertTrue(sqrt(-1.0).isNaN()) + assertTrue(sqrt(Double.NaN).isNaN()) + + assertTrue(exp(Double.NaN).isNaN()) + assertAlmostEquals(E, exp(1.0)) + assertEquals(1.0, exp(0.0)) + assertEquals(0.0, exp(Double.NEGATIVE_INFINITY)) + assertEquals(Double.POSITIVE_INFINITY, exp(Double.POSITIVE_INFINITY)) + + assertEquals(0.0, expm1(0.0)) + assertEquals(Double.MIN_VALUE, expm1(Double.MIN_VALUE)) + assertEquals(0.00010000500016667084, expm1(1e-4)) + assertEquals(-1.0, expm1(Double.NEGATIVE_INFINITY)) + assertEquals(Double.POSITIVE_INFINITY, expm1(Double.POSITIVE_INFINITY)) + } + + @Test fun logarithms() { + assertTrue(log(1.0, Double.NaN).isNaN()) + assertTrue(log(Double.NaN, 1.0).isNaN()) + assertTrue(log(-1.0, 2.0).isNaN()) + assertTrue(log(2.0, -1.0).isNaN()) + assertTrue(log(2.0, 0.0).isNaN()) + assertTrue(log(2.0, 1.0).isNaN()) + assertTrue(log(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY).isNaN()) + assertEquals(-2.0, log(0.25, 2.0)) + assertEquals(-0.5, log(2.0, 0.25)) + assertEquals(Double.NEGATIVE_INFINITY, log(Double.POSITIVE_INFINITY, 0.25)) + assertEquals(Double.POSITIVE_INFINITY, log(Double.POSITIVE_INFINITY, 2.0)) + assertEquals(Double.NEGATIVE_INFINITY, log(0.0, 2.0)) + assertEquals(Double.POSITIVE_INFINITY, log(0.0, 0.25)) + + assertTrue(ln(Double.NaN).isNaN()) + assertTrue(ln(-1.0).isNaN()) + assertEquals(1.0, ln(E)) + assertEquals(Double.NEGATIVE_INFINITY, ln(0.0)) + assertEquals(Double.POSITIVE_INFINITY, ln(Double.POSITIVE_INFINITY)) + + assertEquals(1.0, log10(10.0)) + assertAlmostEquals(-1.0, log10(0.1)) + + assertAlmostEquals(3.0, log2(8.0)) + assertEquals(-1.0, log2(0.5)) + + assertTrue(ln1p(Double.NaN).isNaN()) + assertTrue(ln1p(-1.1).isNaN()) + assertEquals(0.0, ln1p(0.0)) + assertEquals(9.999995000003334e-7, ln1p(1e-6)) + assertEquals(Double.MIN_VALUE, ln1p(Double.MIN_VALUE)) + assertEquals(Double.NEGATIVE_INFINITY, ln1p(-1.0)) + } + + @Test fun rounding() { + for (value in listOf(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY, 0.0, 1.0, -10.0)) { + assertEquals(value, ceil(value)) + assertEquals(value, floor(value)) + assertEquals(value, truncate(value)) + assertEquals(value, round(value)) + } + assertTrue(ceil(Double.NaN).isNaN()) + assertTrue(floor(Double.NaN).isNaN()) + assertTrue(truncate(Double.NaN).isNaN()) + assertTrue(round(Double.NaN).isNaN()) + val data = arrayOf( // v floor trunc round ceil + doubleArrayOf( 1.3, 1.0, 1.0, 1.0, 2.0), + doubleArrayOf(-1.3, -2.0, -1.0, -1.0, -1.0), + doubleArrayOf( 1.5, 1.0, 1.0, 2.0, 2.0), + doubleArrayOf(-1.5, -2.0, -1.0, -2.0, -1.0), + doubleArrayOf( 1.8, 1.0, 1.0, 2.0, 2.0), + doubleArrayOf(-1.8, -2.0, -1.0, -2.0, -1.0), + + doubleArrayOf( 2.3, 2.0, 2.0, 2.0, 3.0), + doubleArrayOf(-2.3, -3.0, -2.0, -2.0, -2.0), + doubleArrayOf( 2.5, 2.0, 2.0, 2.0, 3.0), + doubleArrayOf(-2.5, -3.0, -2.0, -2.0, -2.0), + doubleArrayOf( 2.8, 2.0, 2.0, 3.0, 3.0), + doubleArrayOf(-2.8, -3.0, -2.0, -3.0, -2.0) + ) + for ((v, f, t, r, c) in data) { + assertEquals(f, floor(v), "floor($v)") + assertEquals(t, truncate(v), "truncate($v)") + assertEquals(r, round(v), "round($v)") + assertEquals(c, ceil(v), "ceil($v)") + } + } + + @Test fun roundingConversion() { + assertEquals(1L, 1.0.roundToLong()) + assertEquals(1L, 1.1.roundToLong()) + assertEquals(2L, 1.5.roundToLong()) + assertEquals(3L, 2.5.roundToLong()) + assertEquals(-2L, (-2.5).roundToLong()) + assertEquals(-3L, (-2.6).roundToLong()) + assertEquals(9223372036854774784, (9223372036854774800.0).roundToLong()) + assertEquals(Long.MAX_VALUE, Double.MAX_VALUE.roundToLong()) + assertEquals(Long.MIN_VALUE, (-Double.MAX_VALUE).roundToLong()) + assertEquals(Long.MAX_VALUE, Double.POSITIVE_INFINITY.roundToLong()) + assertEquals(Long.MIN_VALUE, Double.NEGATIVE_INFINITY.roundToLong()) + + assertFails { Double.NaN.roundToLong() } + + assertEquals(1, 1.0.roundToInt()) + assertEquals(1, 1.1.roundToInt()) + assertEquals(2, 1.5.roundToInt()) + assertEquals(3, 2.5.roundToInt()) + assertEquals(-2, (-2.5).roundToInt()) + assertEquals(-3, (-2.6).roundToInt()) + assertEquals(2123456789, (2123456789.0).roundToInt()) + assertEquals(Int.MAX_VALUE, Double.MAX_VALUE.roundToInt()) + assertEquals(Int.MIN_VALUE, (-Double.MAX_VALUE).roundToInt()) + assertEquals(Int.MAX_VALUE, Double.POSITIVE_INFINITY.roundToInt()) + assertEquals(Int.MIN_VALUE, Double.NEGATIVE_INFINITY.roundToInt()) + + assertFails { Double.NaN.roundToInt() } + } + + @Test fun absoluteValue() { + assertTrue(abs(Double.NaN).isNaN()) + assertTrue(Double.NaN.absoluteValue.isNaN()) + + for (value in listOf(0.0, Double.MIN_VALUE, 0.1, 1.0, 1000.0, Double.MAX_VALUE, Double.POSITIVE_INFINITY)) { + assertEquals(value, value.absoluteValue) + assertEquals(value, (-value).absoluteValue) + assertEquals(value, abs(value)) + assertEquals(value, abs(-value)) + } + } + + @Test fun signs() { + assertTrue(sign(Double.NaN).isNaN()) + assertTrue(Double.NaN.sign.isNaN()) + + val negatives = listOf(Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, -1.0, -Double.MIN_VALUE) + for (value in negatives) { + assertEquals(-1.0, sign(value)) + assertEquals(-1.0, value.sign) + } + + val zeroes = listOf(0.0, -0.0) + for (value in zeroes) { + assertEquals(value, sign(value)) + assertEquals(value, value.sign) + } + + + val positives = listOf(Double.POSITIVE_INFINITY, Double.MAX_VALUE, 1.0, Double.MIN_VALUE) + for (value in positives) { + assertEquals(1.0, sign(value)) + assertEquals(1.0, value.sign) + } + + val allValues = negatives + positives + for (a in allValues) { + for (b in allValues) { + val r = a.withSign(b) + assertEquals(a.absoluteValue, r.absoluteValue) + assertEquals(b.sign, r.sign, "expected $a with sign bit of $b to have sign ${b.sign}") + } + + val rp0 = a.withSign(0.0) + assertEquals(1.0, rp0.sign) + assertEquals(a.absoluteValue, rp0.absoluteValue) + + val rm0 = a.withSign(-0.0) + assertEquals(-1.0, rm0.sign) + assertEquals(a.absoluteValue, rm0.absoluteValue) + + val ri = a.withSign(-1) + assertEquals(-1.0, ri.sign) + assertEquals(a.absoluteValue, ri.absoluteValue) + + val rn = a.withSign(Double.NaN) + assertEquals(a.absoluteValue, rn.absoluteValue) + } + } + + + @Test fun nextAndPrev() { + for (value in listOf(0.0, -0.0, Double.MIN_VALUE, -1.0, 2.0.pow(10))) { + val next = value.nextUp() + if (next > 0) { + assertEquals(next, value + value.ulp) + } else { + assertEquals(value, next - next.ulp) + } + + val prev = value.nextDown() + if (prev > 0) { + assertEquals(value, prev + prev.ulp) + } + else { + assertEquals(prev, value - value.ulp) + } + + val toZero = value.nextTowards(0.0) + if (toZero != 0.0) { + assertEquals(value, toZero + toZero.ulp.withSign(toZero)) + } + + assertEquals(Double.POSITIVE_INFINITY, Double.MAX_VALUE.nextUp()) + assertEquals(Double.MAX_VALUE, Double.POSITIVE_INFINITY.nextDown()) + + assertEquals(Double.NEGATIVE_INFINITY, (-Double.MAX_VALUE).nextDown()) + assertEquals((-Double.MAX_VALUE), Double.NEGATIVE_INFINITY.nextUp()) + + assertTrue(Double.NaN.ulp.isNaN()) + assertTrue(Double.NaN.nextDown().isNaN()) + assertTrue(Double.NaN.nextUp().isNaN()) + assertTrue(Double.NaN.nextTowards(0.0).isNaN()) + + assertEquals(Double.MIN_VALUE, (0.0).ulp) + assertEquals(Double.MIN_VALUE, (-0.0).ulp) + assertEquals(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY.ulp) + assertEquals(Double.POSITIVE_INFINITY, Double.NEGATIVE_INFINITY.ulp) + + val maxUlp = 2.0.pow(971) + assertEquals(maxUlp, Double.MAX_VALUE.ulp) + assertEquals(maxUlp, (-Double.MAX_VALUE).ulp) + } + } +} + +class FloatMathTest { + + companion object { + const val PI = kotlin.math.PI.toFloat() + const val E = kotlin.math.E.toFloat() + } + + @Test fun trigonometric() { + assertEquals(0.0F, sin(0.0F)) + assertAlmostEquals(0.0F, sin(PI)) + + assertEquals(0.0F, asin(0.0F)) + assertAlmostEquals(PI / 2, asin(1.0F), 0.0000002) + + assertEquals(1.0F, cos(0.0F)) + assertAlmostEquals(-1.0F, cos(PI)) + + assertEquals(0.0F, acos(1.0F)) + assertAlmostEquals(PI / 2, acos(0.0F)) + + assertEquals(0.0F, tan(0.0F)) + assertAlmostEquals(1.0F, tan(PI / 4)) + + assertAlmostEquals(0.0F, atan(0.0F)) + assertAlmostEquals(PI / 4, atan(1.0F)) + + assertAlmostEquals(PI / 4, atan2(10.0F, 10.0F)) + assertAlmostEquals(-PI / 4, atan2(Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY)) + assertAlmostEquals(0.0F, atan2(0.0F, 0.0F)) + assertAlmostEquals(0.0F, atan2(0.0F, 10.0F)) + assertAlmostEquals(PI / 2, atan2(2.0F, 0.0F)) + + for (angle in listOf(Float.NaN, Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY)) { + assertTrue(sin(angle).isNaN(), "sin($angle)") + assertTrue(cos(angle).isNaN(), "cos($angle)") + assertTrue(tan(angle).isNaN(), "tan($angle)") + } + + for (value in listOf(Float.NaN, 1.2F, -1.1F)) { + assertTrue(asin(value).isNaN()) + assertTrue(acos(value).isNaN()) + } + assertTrue(atan(Float.NaN).isNaN()) + assertTrue(atan2(Float.NaN, 0.0F).isNaN()) + assertTrue(atan2(0.0F, Float.NaN).isNaN()) + } + + @Test fun hyperbolic() { + assertEquals(Float.POSITIVE_INFINITY, sinh(Float.POSITIVE_INFINITY)) + assertEquals(Float.NEGATIVE_INFINITY, sinh(Float.NEGATIVE_INFINITY)) + assertTrue(sinh(Float.MIN_VALUE) != 0.0F) + assertTrue(sinh(89.0F).isFinite()) + assertTrue(sinh(-89.0F).isFinite()) + assertTrue(sinh(Float.NaN).isNaN()) + + assertEquals(Float.POSITIVE_INFINITY, cosh(Float.POSITIVE_INFINITY)) + assertEquals(Float.POSITIVE_INFINITY, cosh(Float.NEGATIVE_INFINITY)) + assertTrue(cosh(89.0F).isFinite()) + assertTrue(cosh(-89.0F).isFinite()) + assertTrue(cosh(Float.NaN).isNaN()) + + assertAlmostEquals(1.0F, tanh(Float.POSITIVE_INFINITY)) + assertAlmostEquals(-1.0F, tanh(Float.NEGATIVE_INFINITY)) + assertTrue(tanh(Float.MIN_VALUE) != 0.0F) + assertTrue(tanh(Float.NaN).isNaN()) + } + + @Test fun inverseHyperbolicSin() { + for (exact in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 0.0F, Float.MIN_VALUE, -Float.MIN_VALUE, 0.00001F)) { + assertEquals(exact, asinh(sinh(exact))) + } + for (approx in listOf(Float.MIN_VALUE, 0.1F, 1.0F, 89.0F)) { + assertAlmostEquals(approx, asinh(sinh(approx))) + assertAlmostEquals(-approx, asinh(sinh(-approx))) + } + assertTrue(asinh(Float.NaN).isNaN()) + } + + @Test fun inverseHyperbolicCos() { + for (exact in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 0.0F)) { + assertEquals(abs(exact), acosh(cosh(exact))) + } + for (approx in listOf(Float.MIN_VALUE, 0.1F, 1.0F, 89.0F)) { + assertAlmostEquals(approx, acosh(cosh(approx))) + assertAlmostEquals(approx, acosh(cosh(-approx))) + } + for (invalid in listOf(-1.0F, 0.0F, 0.99999F, Float.NaN)) { + assertTrue(acosh(invalid).isNaN()) + } + } + + @Test fun inverseHyperbolicTan() { + for (exact in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 0.0F, Float.MIN_VALUE, -Float.MIN_VALUE)) { + assertEquals(exact, atanh(tanh(exact))) + } + + for (approx in listOf(0.00001F)) { + assertAlmostEquals(approx, atanh(tanh(approx))) + } + + for (invalid in listOf(-1.00001F, 1.00001F, Float.NaN, Float.MAX_VALUE, -Float.MAX_VALUE, Float.NEGATIVE_INFINITY, Float.POSITIVE_INFINITY)) { + assertTrue(atanh(invalid).isNaN()) + } + } + + @Test fun powers() { + assertEquals(5.0F, hypot(3.0F, 4.0F)) + assertEquals(Float.POSITIVE_INFINITY, hypot(Float.NEGATIVE_INFINITY, Float.NaN)) + assertEquals(Float.POSITIVE_INFINITY, hypot(Float.NaN, Float.POSITIVE_INFINITY)) + assertTrue(hypot(Float.NaN, 0.0F).isNaN()) + + assertEquals(1.0F, Float.NaN.pow(0.0F)) + assertEquals(1.0F, Float.POSITIVE_INFINITY.pow(0)) + assertEquals(49.0F, 7.0F.pow(2)) + assertEquals(0.25F, 2.0F.pow(-2)) + assertTrue(0.0F.pow(Float.NaN).isNaN()) + assertTrue(Float.NaN.pow(-1).isNaN()) + assertTrue((-7.0F).pow(1/3.0F).isNaN()) + assertTrue(1.0F.pow(Float.POSITIVE_INFINITY).isNaN()) + assertTrue((-1.0F).pow(Float.NEGATIVE_INFINITY).isNaN()) + + assertEquals(5.0F, sqrt(9.0F + 16.0F)) + assertTrue(sqrt(-1.0F).isNaN()) + assertTrue(sqrt(Float.NaN).isNaN()) + + assertTrue(exp(Float.NaN).isNaN()) + assertAlmostEquals(E, exp(1.0F)) + assertEquals(1.0F, exp(0.0F)) + assertEquals(0.0F, exp(Float.NEGATIVE_INFINITY)) + assertEquals(Float.POSITIVE_INFINITY, exp(Float.POSITIVE_INFINITY)) + + assertEquals(0.0F, expm1(0.0F)) + assertEquals(-1.0F, expm1(Float.NEGATIVE_INFINITY)) + assertEquals(Float.POSITIVE_INFINITY, expm1(Float.POSITIVE_INFINITY)) + } + + @Test fun logarithms() { + assertTrue(log(1.0F, Float.NaN).isNaN()) + assertTrue(log(Float.NaN, 1.0F).isNaN()) + assertTrue(log(-1.0F, 2.0F).isNaN()) + assertTrue(log(2.0F, -1.0F).isNaN()) + assertTrue(log(2.0F, 0.0F).isNaN()) + assertTrue(log(2.0F, 1.0F).isNaN()) + assertTrue(log(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY).isNaN()) + assertEquals(-2.0F, log(0.25F, 2.0F)) + assertEquals(-0.5F, log(2.0F, 0.25F)) + assertEquals(Float.NEGATIVE_INFINITY, log(Float.POSITIVE_INFINITY, 0.25F)) + assertEquals(Float.POSITIVE_INFINITY, log(Float.POSITIVE_INFINITY, 2.0F)) + assertEquals(Float.NEGATIVE_INFINITY, log(0.0F, 2.0F)) + assertEquals(Float.POSITIVE_INFINITY, log(0.0F, 0.25F)) + + assertTrue(ln(Float.NaN).isNaN()) + assertTrue(ln(-1.0F).isNaN()) + assertAlmostEquals(1.0F, ln(E)) + assertEquals(Float.NEGATIVE_INFINITY, ln(0.0F)) + assertEquals(Float.POSITIVE_INFINITY, ln(Float.POSITIVE_INFINITY)) + + assertEquals(1.0F, log10(10.0F)) + assertAlmostEquals(-1.0F, log10(0.1F)) + + assertAlmostEquals(3.0F, log2(8.0F)) + assertEquals(-1.0F, log2(0.5F)) + + assertTrue(ln1p(Float.NaN).isNaN()) + assertTrue(ln1p(-1.1F).isNaN()) + assertEquals(0.0F, ln1p(0.0F)) + assertEquals(Float.NEGATIVE_INFINITY, ln1p(-1.0F)) + } + + @Test fun rounding() { + for (value in listOf(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY, 0.0F, 1.0F, -10.0F)) { + assertEquals(value, ceil(value)) + assertEquals(value, floor(value)) + assertEquals(value, truncate(value)) + assertEquals(value, round(value)) + } + assertTrue(ceil(Float.NaN).isNaN()) + assertTrue(floor(Float.NaN).isNaN()) + assertTrue(truncate(Float.NaN).isNaN()) + assertTrue(round(Float.NaN).isNaN()) + val data = arrayOf( // v floor trunc round ceil + floatArrayOf( 1.3F, 1.0F, 1.0F, 1.0F, 2.0F), + floatArrayOf(-1.3F, -2.0F, -1.0F, -1.0F, -1.0F), + floatArrayOf( 1.5F, 1.0F, 1.0F, 2.0F, 2.0F), + floatArrayOf(-1.5F, -2.0F, -1.0F, -2.0F, -1.0F), + floatArrayOf( 1.8F, 1.0F, 1.0F, 2.0F, 2.0F), + floatArrayOf(-1.8F, -2.0F, -1.0F, -2.0F, -1.0F), + + floatArrayOf( 2.3F, 2.0F, 2.0F, 2.0F, 3.0F), + floatArrayOf(-2.3F, -3.0F, -2.0F, -2.0F, -2.0F), + floatArrayOf( 2.5F, 2.0F, 2.0F, 2.0F, 3.0F), + floatArrayOf(-2.5F, -3.0F, -2.0F, -2.0F, -2.0F), + floatArrayOf( 2.8F, 2.0F, 2.0F, 3.0F, 3.0F), + floatArrayOf(-2.8F, -3.0F, -2.0F, -3.0F, -2.0F) + ) + for ((v, f, t, r, c) in data) { + assertEquals(f, floor(v), "floor($v)") + assertEquals(t, truncate(v), "truncate($v)") + assertEquals(r, round(v), "round($v)") + assertEquals(c, ceil(v), "ceil($v)") + } + } + + @Test fun roundingConversion() { + assertEquals(1L, 1.0F.roundToLong()) + assertEquals(1L, 1.1F.roundToLong()) + assertEquals(2L, 1.5F.roundToLong()) + assertEquals(3L, 2.5F.roundToLong()) + assertEquals(-2L, (-2.5F).roundToLong()) + assertEquals(-3L, (-2.6F).roundToLong()) + // assertEquals(9223372036854774784, (9223372036854774800.0F).roundToLong()) // platform-specific + assertEquals(Long.MAX_VALUE, Float.MAX_VALUE.roundToLong()) + assertEquals(Long.MIN_VALUE, (-Float.MAX_VALUE).roundToLong()) + assertEquals(Long.MAX_VALUE, Float.POSITIVE_INFINITY.roundToLong()) + assertEquals(Long.MIN_VALUE, Float.NEGATIVE_INFINITY.roundToLong()) + + assertFails { Float.NaN.roundToLong() } + + assertEquals(1, 1.0F.roundToInt()) + assertEquals(1, 1.1F.roundToInt()) + assertEquals(2, 1.5F.roundToInt()) + assertEquals(3, 2.5F.roundToInt()) + assertEquals(-2, (-2.5F).roundToInt()) + assertEquals(-3, (-2.6F).roundToInt()) + assertEquals(16777218, (16777218F).roundToInt()) + assertEquals(Int.MAX_VALUE, Float.MAX_VALUE.roundToInt()) + assertEquals(Int.MIN_VALUE, (-Float.MAX_VALUE).roundToInt()) + assertEquals(Int.MAX_VALUE, Float.POSITIVE_INFINITY.roundToInt()) + assertEquals(Int.MIN_VALUE, Float.NEGATIVE_INFINITY.roundToInt()) + + assertFails { Float.NaN.roundToInt() } + } + + @Test fun absoluteValue() { + assertTrue(abs(Float.NaN).isNaN()) + assertTrue(Float.NaN.absoluteValue.isNaN()) + + for (value in listOf(0.0F, Float.MIN_VALUE, 0.1F, 1.0F, 1000.0F, Float.MAX_VALUE, Float.POSITIVE_INFINITY)) { + assertEquals(value, value.absoluteValue) + assertEquals(value, (-value).absoluteValue) + assertEquals(value, abs(value)) + assertEquals(value, abs(-value)) + } + } + + @Test fun signs() { + assertTrue(sign(Float.NaN).isNaN()) + assertTrue(Float.NaN.sign.isNaN()) + + val negatives = listOf(Float.NEGATIVE_INFINITY, -Float.MAX_VALUE, -1.0F, -Float.MIN_VALUE) + for (value in negatives) { + assertEquals(-1.0F, sign(value)) + assertEquals(-1.0F, value.sign) + } + + val zeroes = listOf(0.0F, -0.0F) + for (value in zeroes) { + assertEquals(value, sign(value)) + assertEquals(value, value.sign) + } + + + val positives = listOf(Float.POSITIVE_INFINITY, Float.MAX_VALUE, 1.0F, Float.MIN_VALUE) + for (value in positives) { + assertEquals(1.0F, sign(value)) + assertEquals(1.0F, value.sign) + } + + val allValues = negatives + positives + for (a in allValues) { + for (b in allValues) { + val r = a.withSign(b) + assertEquals(a.absoluteValue, r.absoluteValue) + assertEquals(b.sign, r.sign) + } + + val rp0 = a.withSign(0.0F) + assertEquals(1.0F, rp0.sign) + assertEquals(a.absoluteValue, rp0.absoluteValue) + + val rm0 = a.withSign(-0.0F) + assertEquals(-1.0F, rm0.sign) + assertEquals(a.absoluteValue, rm0.absoluteValue) + + val ri = a.withSign(-1) + assertEquals(-1.0F, ri.sign) + assertEquals(a.absoluteValue, ri.absoluteValue) + } + } + + @Test fun nextAndPrev() { + for (value in listOf(0.0f, -0.0f, Float.MIN_VALUE, -1.0f, 2.0f.pow(10))) { + val next = value.nextUp() + if (next > 0) { + assertEquals(next, value + value.ulp) + } else { + assertEquals(value, next - next.ulp) + } + + val prev = value.nextDown() + if (prev > 0) { + assertEquals(value, prev + prev.ulp) + } + else { + assertEquals(prev, value - value.ulp) + } + + val toZero = value.nextTowards(0.0f) + if (toZero != 0.0f) { + assertEquals(value, toZero + toZero.ulp.withSign(toZero)) + } + + assertEquals(Float.POSITIVE_INFINITY, Float.MAX_VALUE.nextUp()) + assertEquals(Float.MAX_VALUE, Float.POSITIVE_INFINITY.nextDown()) + + assertEquals(Float.NEGATIVE_INFINITY, (-Float.MAX_VALUE).nextDown()) + assertEquals((-Float.MAX_VALUE), Float.NEGATIVE_INFINITY.nextUp()) + + assertTrue(Float.NaN.ulp.isNaN()) + assertTrue(Float.NaN.nextDown().isNaN()) + assertTrue(Float.NaN.nextUp().isNaN()) + assertTrue(Float.NaN.nextTowards(0.0f).isNaN()) + + assertEquals(Float.MIN_VALUE, (0.0f).ulp) + assertEquals(Float.MIN_VALUE, (-0.0f).ulp) + assertEquals(Float.POSITIVE_INFINITY, Float.POSITIVE_INFINITY.ulp) + assertEquals(Float.POSITIVE_INFINITY, Float.NEGATIVE_INFINITY.ulp) + + val maxUlp = 2.0f.pow(104) + assertEquals(maxUlp, Float.MAX_VALUE.ulp) + assertEquals(maxUlp, (-Float.MAX_VALUE).ulp) + } + } + +} + +class IntegerMathTest { + + @Test fun intSigns() { + val negatives = listOf(Int.MIN_VALUE, -65536, -1) + val positives = listOf(1, 100, 256, Int.MAX_VALUE) + negatives.forEach { assertEquals(-1, it.sign) } + positives.forEach { assertEquals(1, it.sign) } + assertEquals(0, 0.sign) + + (negatives - Int.MIN_VALUE).forEach { assertEquals(-it, it.absoluteValue) } + assertEquals(Int.MIN_VALUE, Int.MIN_VALUE.absoluteValue) + + positives.forEach { assertEquals(it, it.absoluteValue) } + } + + + @Test fun longSigns() { + val negatives = listOf(Long.MIN_VALUE, -65536L, -1L) + val positives = listOf(1L, 100L, 256L, Long.MAX_VALUE) + negatives.forEach { assertEquals(-1, it.sign) } + positives.forEach { assertEquals(1, it.sign) } + assertEquals(0, 0L.sign) + + (negatives - Long.MIN_VALUE).forEach { assertEquals(-it, it.absoluteValue) } + assertEquals(Long.MIN_VALUE, Long.MIN_VALUE.absoluteValue) + + positives.forEach { assertEquals(it, it.absoluteValue) } + } + + @Test fun IEEEremainder() { + val data = arrayOf( // a a IEEErem 2.5 + doubleArrayOf(-2.0, 0.5), + doubleArrayOf(-1.25, -1.25), + doubleArrayOf( 0.0, 0.0), + doubleArrayOf( 1.0, 1.0), + doubleArrayOf( 1.25, 1.25), + doubleArrayOf( 1.5, -1.0), + doubleArrayOf( 2.0, -0.5), + doubleArrayOf( 2.5, 0.0), + doubleArrayOf( 3.5, 1.0), + doubleArrayOf( 3.75, -1.25), + doubleArrayOf( 4.0, -1.0) + ) + for ((a, r) in data) { + assertEquals(r, a.IEEErem(2.5), "($a).IEEErem(2.5)") + } + + assertTrue(Double.NaN.IEEErem(2.5).isNaN()) + assertTrue(2.0.IEEErem(Double.NaN).isNaN()) + assertTrue(Double.POSITIVE_INFINITY.IEEErem(2.0).isNaN()) + assertTrue(2.0.IEEErem(0.0).isNaN()) + assertEquals(PI, PI.IEEErem(Double.NEGATIVE_INFINITY)) + } + + @Test fun IEEEremainderFloat() { + val data = arrayOf( // a a IEEErem 2.5 + floatArrayOf(-2.0f, 0.5f), + floatArrayOf(-1.25f, -1.25f), + floatArrayOf( 0.0f, 0.0f), + floatArrayOf( 1.0f, 1.0f), + floatArrayOf( 1.25f, 1.25f), + floatArrayOf( 1.5f, -1.0f), + floatArrayOf( 2.0f, -0.5f), + floatArrayOf( 2.5f, 0.0f), + floatArrayOf( 3.5f, 1.0f), + floatArrayOf( 3.75f, -1.25f), + floatArrayOf( 4.0f, -1.0f) + ) + for ((a, r) in data) { + assertEquals(r, a.IEEErem(2.5f), "($a).IEEErem(2.5f)") + } + + assertTrue(Float.NaN.IEEErem(2.5f).isNaN()) + assertTrue(2.0f.IEEErem(Float.NaN).isNaN()) + assertTrue(Float.POSITIVE_INFINITY.IEEErem(2.0f).isNaN()) + assertTrue(2.0f.IEEErem(0.0f).isNaN()) + assertEquals(PI.toFloat(), PI.toFloat().IEEErem(Float.NEGATIVE_INFINITY)) + } + + /* + * Special cases: + * - `atan2(0.0, 0.0)` is `0.0` + * - `atan2(0.0, x)` is `0.0` for `x > 0` and `PI` for `x < 0` + * - `atan2(-0.0, x)` is `-0.0` for 'x > 0` and `-PI` for `x < 0` + * - `atan2(y, +Inf)` is `0.0` for `0 < y < +Inf` and `-0.0` for '-Inf < y < 0` + * - `atan2(y, -Inf)` is `PI` for `0 < y < +Inf` and `-PI` for `-Inf < y < 0` + * - `atan2(y, 0.0)` is `PI/2` for `y > 0` and `-PI/2` for `y < 0` + * - `atan2(+Inf, x)` is `PI/2` for finite `x`y + * - `atan2(-Inf, x)` is `-PI/2` for finite `x` + * - `atan2(NaN, x)` and `atan2(y, NaN)` is `NaN` + */ + @Test fun atan2SpecialCases() { + + assertEquals(atan2(0.0, 0.0), 0.0) + assertEquals(atan2(0.0, 1.0), 0.0) + assertEquals(atan2(0.0, -1.0), PI) + assertEquals(atan2(-0.0, 1.0), -0.0) + assertEquals(atan2(-0.0, -1.0), -PI) + assertEquals(atan2(1.0, Double.POSITIVE_INFINITY), 0.0) + assertEquals(atan2(-1.0, Double.POSITIVE_INFINITY), -0.0) + assertEquals(atan2(1.0, Double.NEGATIVE_INFINITY), PI) + assertEquals(atan2(-1.0, Double.NEGATIVE_INFINITY), -PI) + assertEquals(atan2(1.0, 0.0), PI/2) + assertEquals(atan2(-1.0, 0.0), -PI/2) + assertEquals(atan2(Double.POSITIVE_INFINITY, 1.0), PI/2) + assertEquals(atan2(Double.NEGATIVE_INFINITY, 1.0), -PI/2) + + assertTrue(atan2(Double.NaN, 1.0).isNaN()) + assertTrue(atan2(1.0, Double.NaN).isNaN()) + } + +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/numbers/NaNPropagationTest.kt b/backend.native/tests/stdlib_external/numbers/NaNPropagationTest.kt new file mode 100644 index 00000000000..73a72c8b386 --- /dev/null +++ b/backend.native/tests/stdlib_external/numbers/NaNPropagationTest.kt @@ -0,0 +1,155 @@ +package numbers + +import kotlin.test.* +import kotlin.comparisons.* + +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) + +class NaNPropagationTest { + + 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)") + } + } + } + + @Test fun minOf() { + propagateOf2(::minOf, ::minOf, "minOf") + propagateOf3(::minOf, ::minOf, "minOf") + } + + @Test fun maxOf() { + propagateOf2(::maxOf, ::maxOf, "maxOf") + propagateOf3(::maxOf, ::maxOf, "maxOf") + } + + @Test fun arrayMin() { + propagateOf2({ a, b -> arrayOf(a, b).min()!! }, + { a, b -> arrayOf(a, b).min()!! }, + "arrayOf().min()") + } + + @Test fun arrayMax() { + propagateOf2({ a, b -> arrayOf(a, b).max()!! }, + { a, b -> arrayOf(a, b).max()!! }, + "arrayOf().max()") + } + + @Test fun primitiveArrayMin() { + propagateOf2({ a, b -> doubleArrayOf(a, b).min()!! }, + { a, b -> floatArrayOf(a, b).min()!! }, + "primitiveArrayOf().min()") + } + + @Test fun primitiveArrayMax() { + propagateOf2({ a, b -> doubleArrayOf(a, b).max()!! }, + { a, b -> floatArrayOf(a, b).max()!! }, + "primitiveArrayOf().max()") + } + + @Test fun listMin() { + propagateOf2({ a, b -> listOf(a, b).min()!! }, + { a, b -> listOf(a, b).min()!! }, + "listOf().min()") + } + + @Test fun listMax() { + propagateOf2({ a, b -> listOf(a, b).max()!! }, + { a, b -> listOf(a, b).max()!! }, + "listOf().max()") + } + + @Test fun sequenceMin() { + propagateOf2({ a, b -> sequenceOf(a, b).min()!! }, + { a, b -> sequenceOf(a, b).min()!! }, + "sequenceOf().min()") + } + + @Test fun sequenceMax() { + propagateOf2({ a, b -> sequenceOf(a, b).max()!! }, + { a, b -> sequenceOf(a, b).max()!! }, + "sequenceOf().max()") + } + +} + +//@JvmVersion +class NaNTotalOrderTest { + + 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)") + } + } + + 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)") + } + } + + @Test fun minOfT() { + totalOrderMinOf2>(::minOf, "minOf") + } + @Test fun maxOfT() { + totalOrderMaxOf2>(::maxOf, "maxOf") + } + + @Test fun arrayTMin() { + totalOrderMinOf2>({ a, b -> arrayOf(a, b).min()!! }, "arrayOf().min()") + } + @Test fun arrayTMax() { + totalOrderMaxOf2>({ a, b -> arrayOf(a, b).max()!! }, "arrayOf().max()") + } + + + @Test fun listTMin() { + totalOrderMinOf2>({ a, b -> listOf(a, b).min()!! }, "listOf().min()") + } + @Test fun listTMax() { + totalOrderMaxOf2>({ a, b -> listOf(a, b).max()!! }, "listOf().max()") + } + + + @Test fun sequenceTMin() { + totalOrderMinOf2>({ a, b -> sequenceOf(a, b).min()!! }, "sequenceOf().min()") + } + @Test fun sequenceTMax() { + totalOrderMaxOf2>({ a, b -> sequenceOf(a, b).max()!! }, "sequenceOf().max()") + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/numbers/NumbersTest.kt b/backend.native/tests/stdlib_external/numbers/NumbersTest.kt new file mode 100644 index 00000000000..b38026fcb02 --- /dev/null +++ b/backend.native/tests/stdlib_external/numbers/NumbersTest.kt @@ -0,0 +1,172 @@ +package test.numbers + +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 +} + +class NumbersTest { + + var one: Int = 1 + var oneS: Short = 1 + var oneB: Byte = 1 + + @Test fun intMinMaxValues() { + 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 } + } + + @Test fun longMinMaxValues() { + 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 } + } + + @Test fun shortMinMaxValues() { + 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() } + } + + @Test fun byteMinMaxValues() { + 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() } + } + + @Test fun doubleMinMaxValues() { + 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 } + } + + @Test fun floatMinMaxValues() { + 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 } + } + + @Test fun doubleProperties() { + 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) + } + + @Test fun floatProperties() { + 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) + } + + + 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()) + } + + 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()) + } + + @Test fun doubleToBits() { + assertEquals(0x400921fb54442d18L, kotlin.math.PI.toBits()) + assertEquals(0x400921fb54442d18L, kotlin.math.PI.toRawBits()) + assertEquals(kotlin.math.PI, Double.fromBits(0x400921fb54442d18L)) + + for (value in listOf(Double.NEGATIVE_INFINITY, -Double.MAX_VALUE, -1.0, -Double.MIN_VALUE, -0.0, 0.0, Double.POSITIVE_INFINITY, Double.MAX_VALUE, 1.0, Double.MIN_VALUE)) { + assertEquals(value, Double.fromBits(value.toBits())) + assertEquals(value, Double.fromBits(value.toRawBits())) + } + assertTrue(Double.NaN.toBits().let(Double.Companion::fromBits).isNaN()) + assertTrue(Double.NaN.toRawBits().let { Double.fromBits(it) }.isNaN()) + + assertEquals(0x7FF00000L shl 32, Double.POSITIVE_INFINITY.toBits()) + assertEquals(0xFFF00000L shl 32, Double.NEGATIVE_INFINITY.toBits()) + + assertEquals(0x7FF80000_00000000L, Double.NaN.toBits()) + assertEquals(0x7FF80000_00000000L, Double.NaN.toRawBits()) + + val bitsNaN = Double.NaN.toBits() + for (bitsDenormNaN in listOf(0xFFF80000L shl 32, bitsNaN or 1)) { + assertTrue(Double.fromBits(bitsDenormNaN).isNaN(), "expected $bitsDenormNaN represent NaN") + assertEquals(bitsNaN, Double.fromBits(bitsDenormNaN).toBits()) + } + } + + @Test fun floatToBits() { + val PI_F = kotlin.math.PI.toFloat() + assertEquals(0x40490fdb, PI_F.toBits()) + assertAlmostEquals(PI_F, Float.fromBits(0x40490fdb)) // PI_F is actually Double in JS + // -Float.MAX_VALUE, Float.MAX_VALUE, -Float.MIN_VALUE, Float.MIN_VALUE: overflow or underflow + for (value in listOf(Float.NEGATIVE_INFINITY, -1.0F, -0.0F, 0.0F, Float.POSITIVE_INFINITY, 1.0F)) { + assertEquals(value, Float.fromBits(value.toBits())) + assertEquals(value, Float.fromBits(value.toRawBits())) + } + + assertTrue(Float.NaN.toBits().let(Float.Companion::fromBits).isNaN()) + assertTrue(Float.NaN.toRawBits().let { Float.fromBits(it) }.isNaN()) + + assertEquals(0xbf800000.toInt(), (-1.0F).toBits()) + assertEquals(0x7fc00000, Float.NaN.toBits()) + assertEquals(0x7fc00000, Float.NaN.toRawBits()) + + val bitsNaN = Float.NaN.toBits() + for (bitsDenormNaN in listOf(0xFFFC0000.toInt(), bitsNaN or 1)) { + assertTrue(Float.fromBits(bitsDenormNaN).isNaN(), "expected $bitsDenormNaN represent NaN") + assertEquals(bitsNaN, Float.fromBits(bitsDenormNaN).toBits()) + } + } + + +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/properties/delegation/DelegationTest.kt b/backend.native/tests/stdlib_external/properties/delegation/DelegationTest.kt new file mode 100644 index 00000000000..4f3e59c4e6e --- /dev/null +++ b/backend.native/tests/stdlib_external/properties/delegation/DelegationTest.kt @@ -0,0 +1,61 @@ +package test.properties.delegation + +import kotlin.test.* +import kotlin.properties.* + +class NotNullVarTest() { + @Test fun doTest() { + NotNullVarTestGeneric("a", "b").doTest() + } +} + +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") + } +} + +class ObservablePropertyTest { + var result = false + + var b: Int by Delegates.observable(1, { property, old, new -> + assertEquals("b", property.name) + if (!result) assertEquals(1, old) + result = true + assertEquals(new, b, "New value has already been set") + }) + + @Test fun doTest() { + b = 4 + assertTrue(b == 4, "fail: b != 4") + assertTrue(result, "fail: result should be true") + } +} + +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 + }) + + @Test 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") + } +} diff --git a/backend.native/tests/stdlib_external/properties/delegation/MapAccessorsTest.kt b/backend.native/tests/stdlib_external/properties/delegation/MapAccessorsTest.kt new file mode 100644 index 00000000000..12c0b3ff78a --- /dev/null +++ b/backend.native/tests/stdlib_external/properties/delegation/MapAccessorsTest.kt @@ -0,0 +1,60 @@ +package test.properties.delegation.map + +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 + + + @Test 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 } + } +} + + +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 + + @Test 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) + + assertFailsWith { d } + map["d"] = null + assertEquals(null, d) + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/properties/delegation/lazy/LazyValuesTest.kt b/backend.native/tests/stdlib_external/properties/delegation/lazy/LazyValuesTest.kt new file mode 100644 index 00000000000..f6cacb85977 --- /dev/null +++ b/backend.native/tests/stdlib_external/properties/delegation/lazy/LazyValuesTest.kt @@ -0,0 +1,92 @@ +package test.properties.delegation.lazy + +import kotlin.properties.* +import kotlin.test.* + +class LazyValTest { + var result = 0 + val a by lazy { + ++result + } + + @Test fun doTest() { + a + assertTrue(a == 1, "fail: initializer should be invoked only once") + } +} + +class UnsafeLazyValTest { + var result = 0 + val a by lazy(LazyThreadSafetyMode.NONE) { + ++result + } + + @Test fun doTest() { + a + assertTrue(a == 1, "fail: initializer should be invoked only once") + } +} + +class NullableLazyValTest { + var resultA = 0 + var resultB = 0 + + val a: Int? by lazy { resultA++; null} + val b by lazy { foo() } + + @Test 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 + } +} + +class UnsafeNullableLazyValTest { + var resultA = 0 + var resultB = 0 + + val a: Int? by lazy(LazyThreadSafetyMode.NONE) { resultA++; null} + val b by lazy(LazyThreadSafetyMode.NONE) { foo() } + + @Test 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 + } +} + +class IdentityEqualsIsUsedToUnescapeLazyValTest { + var equalsCalled = 0 + private val a by lazy { ClassWithCustomEquality { equalsCalled++ } } + + @Test 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) + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/ranges/CoercionTest.kt b/backend.native/tests/stdlib_external/ranges/CoercionTest.kt new file mode 100644 index 00000000000..bcceb4dfa41 --- /dev/null +++ b/backend.native/tests/stdlib_external/ranges/CoercionTest.kt @@ -0,0 +1,118 @@ +package test.ranges + +import kotlin.test.* + +class CoercionTest { + + @Test + fun coercionsInt() { + 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) } + } + + @Test + fun coercionsLong() { + 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) } + + } + + @Test + fun coercionsDouble() { + 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()) + } + + @Test + fun coercionsComparable() { + 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]) } + } +} + +private class ComparableNumber(val value: Int) : Comparable { + override fun compareTo(other: ComparableNumber): Int = this.value - other.value + override fun toString(): String = "CV$value" +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/ranges/ProgressionLastElementTest.kt b/backend.native/tests/stdlib_external/ranges/ProgressionLastElementTest.kt new file mode 100644 index 00000000000..c4b43e76578 --- /dev/null +++ b/backend.native/tests/stdlib_external/ranges/ProgressionLastElementTest.kt @@ -0,0 +1,84 @@ +package test.ranges + +import kotlin.comparisons.* +import kotlin.test.* + + +class ProgressionLastElementTest { + + 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) + } + + @Test fun calculateFinalElement() { + // 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) + } + + @Test fun iterateToFinalElement() { + // 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/stdlib_external/ranges/RangeIterationTest.kt b/backend.native/tests/stdlib_external/ranges/RangeIterationTest.kt new file mode 100644 index 00000000000..4298a4d3b74 --- /dev/null +++ b/backend.native/tests/stdlib_external/ranges/RangeIterationTest.kt @@ -0,0 +1,233 @@ +package test.ranges + +import test.collections.behaviors.iteratorBehavior +import test.collections.compare +import kotlin.test.* + +public open class RangeIterationTestBase { + 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() + } + } + +} + +// Test data for codegen is generated from this class. If you change it, rerun GenerateTests +public class RangeIterationTest : RangeIterationTestBase() { + + @Test fun emptyConstant() { + 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()) + } + + @Test fun emptyRange() { + 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()) + } + + @Test fun oneElementRange() { + 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')) + } + + @Test fun simpleRange() { + 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')) + } + + + @Test fun simpleRangeWithNonConstantEnds() { + doTest((1 + 2)..(10 - 1), 3, 9, 1, listOf(3, 4, 5, 6, 7, 8, 9)) + doTest((1.toByte() + 2.toByte()).toByte()..(10.toByte() - 1.toByte()).toByte(), 3, 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')) + } + + @Test fun openRange() { + 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')) + } + + + @Test fun emptyDownto() { + 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()) + } + + @Test fun oneElementDownTo() { + 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')) + } + + @Test fun simpleDownTo() { + 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')) + } + + + @Test fun simpleSteppedRange() { + 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')) + } + + @Test fun simpleSteppedDownTo() { + 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')) + } + + + // 'inexact' means last element is not equal to sequence end + @Test fun inexactSteppedRange() { + 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')) + } + + // 'inexact' means last element is not equal to sequence end + @Test fun inexactSteppedDownTo() { + 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')) + } + + + @Test fun reversedEmptyRange() { + 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()) + } + + @Test fun reversedEmptyBackSequence() { + 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()) + } + + @Test fun reversedRange() { + 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')) + } + + @Test fun reversedBackSequence() { + 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')) + + } + + @Test 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')) + } + + // invariant progression.reversed().toList() == progression.toList().reversed() is preserved + // 'inexact' means that start of reversed progression is not the end of original progression, but the last element + @Test fun reversedInexactSteppedDownTo() { + 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/stdlib_external/ranges/RangeTest.kt b/backend.native/tests/stdlib_external/ranges/RangeTest.kt new file mode 100644 index 00000000000..2c6d1acdc2e --- /dev/null +++ b/backend.native/tests/stdlib_external/ranges/RangeTest.kt @@ -0,0 +1,378 @@ +package test.ranges + +import kotlin.test.* + +public class RangeTest { + @Test fun intRange() { + 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()) + } + + @Test fun byteRange() { + 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()) + } + + @Test fun shortRange() { + 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()) + } + + @Test fun longRange() { + 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()) + + } + + @Test fun charRange() { + 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()) + } + + @Test fun doubleRange() { + 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) + } + + @Test fun floatRange() { + 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) + } + + @Test fun isEmpty() { + 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()) + } + + @Test fun emptyEquals() { + 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")) + } + + @Test fun emptyHashCode() { + 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()) + } + + @Test fun comparableRange() { + 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()) + } + + private fun assertFailsWithIllegalArgument(f: () -> Unit) = assertFailsWith { f() } + + @Test fun illegalProgressionCreation() { + // create Progression explicitly with increment = 0 + assertFailsWithIllegalArgument { IntProgression.fromClosedRange(0, 5, 0) } + assertFailsWithIllegalArgument { LongProgression.fromClosedRange(0, 5, 0) } + assertFailsWithIllegalArgument { CharProgression.fromClosedRange('a', 'z', 0) } + + + assertFailsWithIllegalArgument { 0..5 step 0 } + assertFailsWithIllegalArgument { 0.toByte()..5.toByte() step 0 } + assertFailsWithIllegalArgument { 0.toShort()..5.toShort() step 0 } + assertFailsWithIllegalArgument { 0L..5L step 0L } + assertFailsWithIllegalArgument { 'a'..'z' step 0 } + + assertFailsWithIllegalArgument { 0 downTo -5 step 0 } + assertFailsWithIllegalArgument { 0.toByte() downTo -5.toByte() step 0 } + assertFailsWithIllegalArgument { 0.toShort() downTo -5.toShort() step 0 } + assertFailsWithIllegalArgument { 0L downTo -5L step 0L } + assertFailsWithIllegalArgument { 'z' downTo 'a' step 0 } + + assertFailsWithIllegalArgument { 0..5 step -2 } + assertFailsWithIllegalArgument { 0.toByte()..5.toByte() step -2 } + assertFailsWithIllegalArgument { 0.toShort()..5.toShort() step -2 } + assertFailsWithIllegalArgument { 0L..5L step -2L } + assertFailsWithIllegalArgument { 'a'..'z' step -2 } + + + assertFailsWithIllegalArgument { 0 downTo -5 step -2 } + assertFailsWithIllegalArgument { 0.toByte() downTo -5.toByte() step -2 } + assertFailsWithIllegalArgument { 0.toShort() downTo -5.toShort() step -2 } + assertFailsWithIllegalArgument { 0L downTo -5L step -2L } + assertFailsWithIllegalArgument { 'z' downTo 'a' step -2 } + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/testUtils.kt b/backend.native/tests/stdlib_external/testUtils.kt new file mode 100644 index 00000000000..c4c80180195 --- /dev/null +++ b/backend.native/tests/stdlib_external/testUtils.kt @@ -0,0 +1,4 @@ +package test + +// just a static type check +fun assertStaticTypeIs(@Suppress("UNUSED_PARAMETER") value: T) {} diff --git a/backend.native/tests/stdlib_external/text/RegexTest.kt b/backend.native/tests/stdlib_external/text/RegexTest.kt new file mode 100644 index 00000000000..929f0b34c25 --- /dev/null +++ b/backend.native/tests/stdlib_external/text/RegexTest.kt @@ -0,0 +1,191 @@ +package test.text + +import kotlin.text.* + +import kotlin.test.* + +class RegexTest { + + @Test fun matchResult() { + 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) + } + + @Test fun matchIgnoreCase() { + for (input in listOf("ascii", "shrödinger")) + assertTrue(input.toUpperCase().matches(input.toLowerCase().toRegex(RegexOption.IGNORE_CASE))) + } + + @Test fun matchSequence() { + 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()) + } + + @Test fun matchAllSequence() { + 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) + } + + @Test fun matchGroups() { + 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()) + } + } + + @Test fun matchOptionalGroup() { + 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()) + } + } + + @Test fun matchMultiline() { + 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) + } + + + @Test fun matchEntire() { + 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 }) + } + } + + @Test fun matchEntireLazyQuantor() { + val regex = "a+b+?".toRegex() + val input = StringBuilder("aaaabbbb") + + assertEquals("aaaab", regex.find(input)!!.value) + assertEquals("aaaabbbb", regex.matchEntire(input)!!.value) + } + + @Test fun escapeLiteral() { + val literal = """[-\/\\^$*+?.()|[\]{}]""" + assertTrue(Regex.fromLiteral(literal).matches(literal)) + assertTrue(Regex.escape(literal).toRegex().matches(literal)) + } + + @Test fun replace() { + 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")) + } + + @Test fun replaceEvaluator() { + val input = "/12/456/7890/" + val pattern = "\\d+".toRegex() + assertEquals("/2/3/4/", pattern.replace(input, { it.value.length.toString() } )) + } + + + @Test fun split() { + 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)) + + } + + + +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/text/StringBuilderTest.kt b/backend.native/tests/stdlib_external/text/StringBuilderTest.kt new file mode 100644 index 00000000000..7cc11a4a2be --- /dev/null +++ b/backend.native/tests/stdlib_external/text/StringBuilderTest.kt @@ -0,0 +1,64 @@ +package test.text + +import kotlin.test.* + +class StringBuilderTest { + + @Test fun stringBuild() { + val s = buildString { + append("a") + append(true) + } + assertEquals("atrue", s) + } + + @Test fun appendMany() { + assertEquals("a1", StringBuilder().append("a", "1").toString()) + assertEquals("a1", StringBuilder().append("a", 1).toString()) + assertEquals("a1", StringBuilder().append("a", StringBuilder().append("1")).toString()) + } + + @Test fun append() { + // this test is needed for JS implementation + assertEquals("em", buildString { + append("element", 2, 4) + }) + } + + @Test fun asCharSequence() { + 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()) + } + + @Test fun constructors() { + 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/stdlib_external/text/StringNumberConversionTest.kt b/backend.native/tests/stdlib_external/text/StringNumberConversionTest.kt new file mode 100644 index 00000000000..69d9260bc38 --- /dev/null +++ b/backend.native/tests/stdlib_external/text/StringNumberConversionTest.kt @@ -0,0 +1,278 @@ +package test.text + +import kotlin.test.* + +class StringNumberConversionTest { + + //@kotlin.jvm.JvmVersion + @Test fun toBoolean() { + assertEquals(true, "true".toBoolean()) + assertEquals(true, "True".toBoolean()) + assertEquals(false, "false".toBoolean()) + assertEquals(false, "not so true".toBoolean()) + } + + @Test fun toByte() { + 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, " ") + } + } + + @Test fun toShort() { + 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, " ") + } + } + + @Test fun toInt() { + 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) } + } + + //@JvmVersion + @Test fun toIntArabicDigits() { + compareConversion({ it.toInt() }, { it.toIntOrNull() }) { + assertProduces("٢٣١٩٦٠", 231960) + } + } + + @Test fun toLong() { + 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) } + } + + //@JvmVersion + @Test fun toLongArabicDigits() { + compareConversion({ it.toLong() }, { it.toLongOrNull() }) { + assertProduces("٢٣١٩٦٠٧٧٨٤٥٩", 231960778459) + } + } + + //@kotlin.jvm.JvmVersion + @Test fun toFloat() { + 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(" ") + } + } + + @Test fun toDouble() { + compareConversion(String::toDouble, String::toDoubleOrNull, ::doubleEquals) { + 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(" ") + } + } + + //@kotlin.jvm.JvmVersion + @Test fun toHexDouble() { + compareConversion(String::toDouble, String::toDoubleOrNull, ::doubleEquals) { + assertProduces("0x77p1", (0x77 shl 1).toDouble()) + assertProduces("0x.77P8", 0x77.toDouble()) + + assertFailsOrNull("0x77e1") + } + } + + //@kotlin.jvm.JvmVersion + @Test fun byteToStringWithRadix() { + 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) } + } + + //@kotlin.jvm.JvmVersion + @Test fun shortToStringWithRadix() { + 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) } + } + + //@kotlin.jvm.JvmVersion + @Test fun intToStringWithRadix() { + 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) } + + } + + //@kotlin.jvm.JvmVersion + @Test fun longToStringWithRadix() { + 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) } + } +} + + +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 doubleEquals(a: Double, b: Double?) = (a.isNaN() && b?.isNaN() ?: false) || a == b diff --git a/backend.native/tests/stdlib_external/text/StringTest.kt b/backend.native/tests/stdlib_external/text/StringTest.kt new file mode 100644 index 00000000000..642afb3b192 --- /dev/null +++ b/backend.native/tests/stdlib_external/text/StringTest.kt @@ -0,0 +1,1282 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.text + +import kotlin.test.* +import test.* +import test.collections.behaviors.iteratorBehavior +import test.collections.compare + + +fun createString(content: String): CharSequence = content +fun createStringBuilder(content: String): CharSequence = StringBuilder((content as Any).toString()) // required for Rhino JS + + +val charSequenceBuilders = listOf(::createString, ::createStringBuilder) + +fun withOneCharSequenceArg(f: ((String) -> CharSequence) -> Unit) { + for (arg1Builder in charSequenceBuilders) f(arg1Builder) +} + +fun withOneCharSequenceArg(arg1: String, f: (CharSequence) -> Unit) + = withOneCharSequenceArg { arg1Builder -> f(arg1Builder(arg1)) } + +fun withTwoCharSequenceArgs(f: ((String) -> CharSequence, (String) -> CharSequence) -> Unit) { + for (arg1Builder in charSequenceBuilders) + for (arg2Builder in charSequenceBuilders) + f(arg1Builder, arg2Builder) +} + +fun assertContentEquals(expected: String, actual: CharSequence, message: String? = null) { + assertEquals(expected, actual.toString(), message) +} + +// 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' + +class StringTest { + + @Test fun isEmptyAndBlank() = withOneCharSequenceArg { arg1 -> + class Case(val value: String?, val isNull: Boolean = false, val isEmpty: Boolean = false, val isBlank: Boolean = false) + + val cases = listOf( + Case(null, isNull = true), + Case("", isEmpty = true, isBlank = true), + Case(" \r\n\t\u00A0", isBlank = true), + Case(" Some ") + ) + + for (case in cases) { + val value = case.value?.let { arg1(it) } + assertEquals(case.isNull || case.isEmpty, value.isNullOrEmpty(), "failed for case '$value'") + assertEquals(case.isNull || case.isBlank, value.isNullOrBlank(), "failed for case '$value'") + if (value != null) + { + assertEquals(case.isEmpty, value.isEmpty(), "failed for case '$value'") + assertEquals(case.isBlank, value.isBlank(), "failed for case '$value'") + } + } + } + + @Test fun orEmpty() { + val s: String? = "hey" + val ns: String? = null + + assertEquals("hey", s.orEmpty()) + assertEquals("", ns.orEmpty()) + } + + @Test fun startsWithString() { + 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)) + } + + @Test fun startsWithStringForCharSequence() = withTwoCharSequenceArgs { arg1, arg2 -> + fun String.startsWithCs(prefix: String, ignoreCase: Boolean = false): Boolean = + arg1(this).startsWith(arg2(prefix), ignoreCase) + + assertTrue("abcd".startsWithCs("ab")) + assertTrue("abcd".startsWithCs("abcd")) + assertTrue("abcd".startsWithCs("a")) + assertFalse("abcd".startsWithCs("abcde")) + assertFalse("abcd".startsWithCs("b")) + assertFalse("".startsWithCs("a")) + assertTrue("some".startsWithCs("")) + assertTrue("".startsWithCs("")) + + assertFalse("abcd".startsWithCs("aB", ignoreCase = false)) + assertTrue("abcd".startsWithCs("aB", ignoreCase = true)) + } + + @Test fun endsWithString() { + 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("")) + } + + @Test fun endsWithStringForCharSequence() = withTwoCharSequenceArgs { arg1, arg2 -> + fun String.endsWithCs(suffix: String, ignoreCase: Boolean = false): Boolean = + arg1(this).endsWith(arg2(suffix), ignoreCase) + + assertTrue("abcd".endsWithCs("d")) + assertTrue("abcd".endsWithCs("abcd")) + assertFalse("abcd".endsWithCs("b")) + assertFalse("strö".endsWithCs("RÖ", ignoreCase = false)) + assertTrue("strö".endsWithCs("RÖ", ignoreCase = true)) + assertFalse("".endsWithCs("a")) + assertTrue("some".endsWithCs("")) + assertTrue("".endsWithCs("")) + } + + @Test fun startsWithChar() = withOneCharSequenceArg { arg1 -> + fun String.startsWith(char: Char, ignoreCase: Boolean = false): Boolean = + arg1(this).startsWith(char, ignoreCase) + + assertTrue("abcd".startsWith('a')) + assertFalse("abcd".startsWith('b')) + assertFalse("abcd".startsWith('A', ignoreCase = false)) + assertTrue("abcd".startsWith('A', ignoreCase = true)) + assertFalse("".startsWith('a')) + } + + @Test fun endsWithChar() = withOneCharSequenceArg { arg1 -> + fun String.endsWith(char: Char, ignoreCase: Boolean = false): Boolean = + arg1(this).endsWith(char, ignoreCase) + + assertTrue("abcd".endsWith('d')) + assertFalse("abcd".endsWith('b')) + assertFalse("strö".endsWith('Ö', ignoreCase = false)) + assertTrue("strö".endsWith('Ö', ignoreCase = true)) + assertFalse("".endsWith('a')) + } + + @Test fun commonPrefix() = withTwoCharSequenceArgs { arg1, arg2 -> + fun String.commonPrefixWith(other: String, ignoreCase: Boolean = false): String = + arg1(this).commonPrefixWith(arg2(other), ignoreCase) + + assertEquals("", "".commonPrefixWith("")) + assertEquals("", "any".commonPrefixWith("")) + assertEquals("", "".commonPrefixWith("any")) + assertEquals("", "some".commonPrefixWith("any")) + + assertEquals("an", "annual".commonPrefixWith("any")) + assertEquals("an", "annual".commonPrefixWith("Any", ignoreCase = true)) + assertEquals("", "annual".commonPrefixWith("Any", ignoreCase = false)) + // surrogate pairs + val dth54 = "\uD83C\uDC58" // domino tile horizontal 5-4 + val dth55 = "\uD83C\uDC59" // domino tile horizontal 5-5 + assertEquals("", dth54.commonPrefixWith(dth55)) + assertEquals(dth54, "$dth54$dth54".commonPrefixWith("$dth54$dth55")) + } + + @Test fun commonSuffix() = withTwoCharSequenceArgs { arg1, arg2 -> + fun String.commonSuffixWith(other: String, ignoreCase: Boolean = false): String = + arg1(this).commonSuffixWith(arg2(other), ignoreCase) + + assertEquals("", "".commonSuffixWith("")) + assertEquals("", "any".commonSuffixWith("")) + assertEquals("", "".commonSuffixWith("any")) + assertEquals("", "some".commonSuffixWith("any")) + + assertEquals("ly", "yearly".commonSuffixWith("monthly")) + assertEquals("strö", "strö".commonSuffixWith("BISTRÖ", ignoreCase = true)) + assertEquals("", "yearly".commonSuffixWith("HARDLY", ignoreCase = false)) + // surrogate pairs + val dth54 = "\uD83C\uDC58" // domino tile horizontal 5-4 + val kimono = "\uD83D\uDC58" // kimono + assertEquals("", dth54.commonSuffixWith(kimono)) + assertEquals("$dth54", "d$dth54".commonSuffixWith("s$dth54")) + } + + @Test fun capitalize() { + assertEquals("A", "A".capitalize()) + assertEquals("A", "a".capitalize()) + assertEquals("Abcd", "abcd".capitalize()) + assertEquals("Abcd", "Abcd".capitalize()) + } + + @Test fun decapitalize() { + assertEquals("a", "A".decapitalize()) + assertEquals("a", "a".decapitalize()) + assertEquals("abcd", "abcd".decapitalize()) + assertEquals("abcd", "Abcd".decapitalize()) + assertEquals("uRL", "URL".decapitalize()) + } + + @Test fun slice() { + 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)) + } + + @Test fun sliceCharSequence() = withOneCharSequenceArg { arg1 -> + val iter = listOf(4, 3, 0, 1) + + val data = arg1("ABCDabcd") + // ABCDabcd + // 01234567 + assertEquals("BCDabc", data.slice(1..6).toString()) + assertEquals("baD", data.slice(5 downTo 3).toString()) + assertEquals("aDAB", data.slice(iter).toString()) + } + + @Test fun reverse() { + assertEquals("dcba", "abcd".reversed()) + assertEquals("4321", "1234".reversed()) + assertEquals("", "".reversed()) + } + + @Test fun reverseCharSequence() = withOneCharSequenceArg { arg1 -> + fun String.reversedCs(): CharSequence = arg1(this).reversed() + + assertContentEquals("dcba", "abcd".reversedCs()) + assertContentEquals("4321", "1234".reversedCs()) + assertContentEquals("", "".reversedCs()) + } + + @Test fun indices() = withOneCharSequenceArg { arg1 -> + fun String.indices(): IntRange = arg1(this).indices + + assertEquals(0..4, "abcde".indices()) + assertEquals(0..0, "a".indices()) + assertTrue("".indices().isEmpty()) + } + + @Test fun replaceRange() = withTwoCharSequenceArgs { arg1, arg2 -> + val s = arg1("sample text") + val replacement = arg2("??") + + assertContentEquals("sa??e text", s.replaceRange(2, 5, replacement)) + assertContentEquals("sa?? text", s.replaceRange(2..5, replacement)) + assertFails { + s.replaceRange(5..2, replacement) + } + assertFails { + s.replaceRange(5, 2, replacement) + } + + // symmetry with indices + assertContentEquals(replacement.toString(), s.replaceRange(s.indices, replacement)) + } + + @Test fun removeRange() = withOneCharSequenceArg("sample text") { s -> + assertContentEquals("sae text", s.removeRange(2, 5)) + assertContentEquals("sa text", s.removeRange(2..5)) + + assertContentEquals(s.toString(), s.removeRange(2,2)) + + // symmetry with indices + assertContentEquals("", s.removeRange(s.indices)) + + // symmetry with replaceRange + assertContentEquals(s.toString().replaceRange(2, 5, ""), s.removeRange(2, 5)) + assertContentEquals(s.toString().replaceRange(2..5, ""), s.removeRange(2..5)) + } + + @Test fun substringDelimited() { + 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")) + + } + + @Test fun replaceDelimited() { + 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")) + } + + @Test fun repeat() = withOneCharSequenceArg { arg1 -> + fun String.repeat(n: Int): String = arg1(this).repeat(n) + + assertFails { "foo".repeat(-1) } + assertEquals("", "foo".repeat(0)) + assertEquals("foo", "foo".repeat(1)) + assertEquals("foofoo", "foo".repeat(2)) + assertEquals("foofoofoo", "foo".repeat(3)) + + assertEquals("", "".repeat(Int.MAX_VALUE)) + assertEquals("aaaaaaaaaaaaa", "a".repeat(13)) + } + + @Test fun stringIterator() = withOneCharSequenceArg("239") { data -> + var sum = 0 + for(c in data) + sum += (c - '0') + assertTrue(sum == 14) + } + + @Test fun trimStart() = withOneCharSequenceArg { arg1 -> + fun String.trimStartCS(): CharSequence = arg1(this).trimStart() + assertContentEquals("", "".trimStartCS()) + assertContentEquals("a", "a".trimStartCS()) + assertContentEquals("a", " a".trimStartCS()) + assertContentEquals("a", " a".trimStartCS()) + assertContentEquals("a ", " a ".trimStartCS()) + assertContentEquals("a b", " a b".trimStartCS()) + assertContentEquals("a b ", " a b ".trimStartCS()) + assertContentEquals("a", " \u00A0 a".trimStartCS()) + + assertContentEquals("a", "\ta".trimStartCS()) + assertContentEquals("a", "\t\ta".trimStartCS()) + assertContentEquals("a", "\ra".trimStartCS()) + assertContentEquals("a", "\na".trimStartCS()) + + assertContentEquals("a=", arg1("-=-=a=").trimStart('-','=')) + assertContentEquals("123a", arg1("ab123a").trimStart { !it.isAsciiDigit() }) + } + + @Test fun trimEnd() = withOneCharSequenceArg { arg1 -> + fun String.trimEndCS(): CharSequence = arg1(this).trimEnd() + assertContentEquals("", "".trimEndCS()) + assertContentEquals("a", "a".trimEndCS()) + assertContentEquals("a", "a ".trimEndCS()) + assertContentEquals("a", "a ".trimEndCS()) + assertContentEquals(" a", " a ".trimEndCS()) + assertContentEquals("a b", "a b ".trimEndCS()) + assertContentEquals(" a b", " a b ".trimEndCS()) + assertContentEquals("a", "a \u00A0 ".trimEndCS()) + + assertContentEquals("a", "a\t".trimEndCS()) + assertContentEquals("a", "a\t\t".trimEndCS()) + assertContentEquals("a", "a\r".trimEndCS()) + assertContentEquals("a", "a\n".trimEndCS()) + + assertContentEquals("=a", arg1("=a=-=-").trimEnd('-','=')) + assertContentEquals("ab123", arg1("ab123a").trimEnd { !it.isAsciiDigit() }) + } + + @Test fun trimStartAndEnd() = withOneCharSequenceArg { arg1 -> + val examples = arrayOf("a", + " a ", + " a ", + " a b ", + "\ta\tb\t", + "\t\ta\t\t", + "\ra\r", + "\na\n", + " \u00A0 a \u00A0 " + ) + + for ((source, example) in examples.map { it to arg1(it) }) { + assertContentEquals(source.trimEnd().trimStart(), example.trim()) + assertContentEquals(source.trimStart().trimEnd(), example.trim()) + } + + val examplesForPredicate = arrayOf("123", + "-=123=-" + ) + + val trimChars = charArrayOf('-', '=') + val trimPredicate = { it: Char -> !it.isAsciiDigit() } + for ((source, example) in examplesForPredicate.map { it to arg1(it) }) { + assertContentEquals(source.trimStart(*trimChars).trimEnd(*trimChars), example.trim(*trimChars)) + assertContentEquals(source.trimStart(trimPredicate).trimEnd(trimPredicate), example.trim(trimPredicate)) + } + } + + @Test fun padStart() = withOneCharSequenceArg { arg1 -> + val s = arg1("s") + assertContentEquals("s", s.padStart(0)) + assertContentEquals("s", s.padStart(1)) + assertContentEquals("--s", s.padStart(3, '-')) + assertContentEquals(" ", arg1("").padStart(2)) + assertFails { + s.padStart(-1) + } + } + + @Test fun padEnd() = withOneCharSequenceArg { arg1 -> + val s = arg1("s") + assertContentEquals("s", s.padEnd(0)) + assertContentEquals("s", s.padEnd(1)) + assertContentEquals("s--", s.padEnd(3, '-')) + assertContentEquals(" ", arg1("").padEnd(2)) + assertFails { + s.padEnd(-1) + } + } + + @Test fun removePrefix() = withOneCharSequenceArg("pre") { prefix -> + assertEquals("fix", "prefix".removePrefix(prefix), "Removes prefix") + assertEquals("prefix", "preprefix".removePrefix(prefix), "Removes prefix once") + assertEquals("sample", "sample".removePrefix(prefix)) + assertEquals("sample", "sample".removePrefix("")) + } + + @Test fun removeSuffix() = withOneCharSequenceArg("fix") { suffix -> + assertEquals("suf", "suffix".removeSuffix(suffix), "Removes suffix") + assertEquals("suffix", "suffixfix".removeSuffix(suffix), "Removes suffix once") + assertEquals("sample", "sample".removeSuffix(suffix)) + assertEquals("sample", "sample".removeSuffix("")) + } + + @Test fun removeSurrounding() = withOneCharSequenceArg { arg1 -> + val pre = arg1("<") + val post = arg1(">") + assertEquals("value", "".removeSurrounding(pre, post)) + assertEquals("", "<>".removeSurrounding(pre, post), "Removes surrounding once") + assertEquals("", "value>".removeSurrounding(pre, post), "Only removes surrounding when both prefix and suffix present") + assertEquals("value", "value".removeSurrounding(pre, post)) + + assertEquals("<->", "<->".removeSurrounding(arg1("<-"), arg1("->")), "Does not remove overlapping prefix and suffix") + } + + @Test fun removePrefixCharSequence() = withTwoCharSequenceArgs { arg1, arg2 -> + fun String.removePrefix(prefix: String) = arg1(this).removePrefix(arg2(prefix)) + val prefix = "pre" + + assertContentEquals("fix", "prefix".removePrefix(prefix), "Removes prefix") + assertContentEquals("prefix", "preprefix".removePrefix(prefix), "Removes prefix once") + assertContentEquals("sample", "sample".removePrefix(prefix)) + assertContentEquals("sample", "sample".removePrefix("")) + } + + @Test fun removeSuffixCharSequence() = withTwoCharSequenceArgs { arg1, arg2 -> + fun String.removeSuffix(suffix: String) = arg1(this).removeSuffix(arg2(suffix)) + val suffix = "fix" + + assertContentEquals("suf", "suffix".removeSuffix(suffix), "Removes suffix") + assertContentEquals("suffix", "suffixfix".removeSuffix(suffix), "Removes suffix once") + assertContentEquals("sample", "sample".removeSuffix(suffix)) + assertContentEquals("sample", "sample".removeSuffix("")) + } + + @Test fun removeSurroundingCharSequence() = withTwoCharSequenceArgs { arg1, arg2 -> + fun String.removeSurrounding(prefix: String, postfix: String) = arg1(this).removeSurrounding(arg2(prefix), arg2(postfix)) + + assertContentEquals("value", "".removeSurrounding("<", ">")) + assertContentEquals("", "<>".removeSurrounding("<", ">"), "Removes surrounding once") + assertContentEquals(""), "Only removes surrounding when both prefix and suffix present") + assertContentEquals("value>", "value>".removeSurrounding("<", ">"), "Only removes surrounding when both prefix and suffix present") + assertContentEquals("value", "value".removeSurrounding("<", ">")) + + assertContentEquals("<->", "<->".removeSurrounding("<-", "->"), "Does not remove overlapping prefix and suffix") + } + + /* + // unit test commented out until rangesDelimitiedBy would become public + + test fun rangesDelimitedBy() { + assertEquals(listOf(0..2, 4..3, 5..7), "abc--def".rangesDelimitedBy('-').toList()) + assertEquals(listOf(0..2, 5..7, 9..10), "abc--def-xy".rangesDelimitedBy("--", "-").toList()) + assertEquals(listOf(0..2, 7..9, 14..16), "123
456
789".rangesDelimitedBy("
", ignoreCase = true).toList()) + assertEquals(listOf(2..2, 4..6), "a=b=c=d".rangesDelimitedBy("=", startIndex = 2, limit = 2).toList()) + + val s = "sample" + assertEquals(listOf(s.indices), s.rangesDelimitedBy("-").toList()) + assertEquals(listOf(s.indices), s.rangesDelimitedBy("-", startIndex = -1).toList()) + assertTrue(s.rangesDelimitedBy("-", startIndex = s.length).single().isEmpty()) + } + */ + + + @Test fun split() = withOneCharSequenceArg { arg1 -> + operator fun String.unaryPlus(): CharSequence = arg1(this) + + assertEquals(listOf(""), (+"").split(";")) + assertEquals(listOf("test"), (+"test").split(*charArrayOf()), "empty list of delimiters, none matched -> entire string returned") + assertEquals(listOf("test"), (+"test").split(*arrayOf()), "empty list of delimiters, none matched -> entire string returned") + + assertEquals(listOf("abc", "def", "123;456"), (+"abc;def,123;456").split(';', ',', limit = 3)) + assertEquals(listOf("abc", "def", "123", "456"), (+"abc
def
123
456").split("
", ignoreCase = true)) + + assertEquals(listOf("abc", "def", "123", "456"), (+"abc=-def==123=456").split("==", "=-", "=")) + + assertEquals(listOf("", "a", "b", "c", ""), (+"abc").split("")) + assertEquals(listOf("", "a", "b", "b", "a", ""), (+"abba").split("", "a")) + assertEquals(listOf("", "", "b", "b", "", ""), (+"abba").split("a", "")) + } + + @Test fun splitToLines() = withOneCharSequenceArg { arg1 -> + val string = arg1("first line\rsecond line\nthird line\r\nlast line") + assertEquals(listOf("first line", "second line", "third line", "last line"), string.lines()) + + + val singleLine = arg1("single line") + assertEquals(listOf(singleLine.toString()), singleLine.lines()) + } + + + @Test fun indexOfAnyChar() = withOneCharSequenceArg("abracadabra") { string -> + val chars = charArrayOf('d', 'b') + assertEquals(1, string.indexOfAny(chars)) + assertEquals(6, string.indexOfAny(chars, startIndex = 2)) + assertEquals(-1, string.indexOfAny(chars, startIndex = 9)) + + assertEquals(8, string.lastIndexOfAny(chars)) + assertEquals(6, string.lastIndexOfAny(chars, startIndex = 7)) + assertEquals(-1, string.lastIndexOfAny(chars, startIndex = 0)) + + assertEquals(-1, string.indexOfAny(charArrayOf())) + } + + @Test fun indexOfAnyCharIgnoreCase() = withOneCharSequenceArg("abraCadabra") { string -> + val chars = charArrayOf('B', 'c') + assertEquals(1, string.indexOfAny(chars, ignoreCase = true)) + assertEquals(4, string.indexOfAny(chars, startIndex = 2, ignoreCase = true)) + assertEquals(-1, string.indexOfAny(chars, startIndex = 9, ignoreCase = true)) + + assertEquals(8, string.lastIndexOfAny(chars, ignoreCase = true)) + assertEquals(4, string.lastIndexOfAny(chars, startIndex = 7, ignoreCase = true)) + assertEquals(-1, string.lastIndexOfAny(chars, startIndex = 0, ignoreCase = true)) + } + + @Test fun indexOfAnyString() = withOneCharSequenceArg("abracadabra") { string -> + val substrings = listOf("rac", "ra") + assertEquals(2, string.indexOfAny(substrings)) + assertEquals(9, string.indexOfAny(substrings, startIndex = 3)) + assertEquals(2, string.indexOfAny(substrings.reversed())) + assertEquals(-1, string.indexOfAny(substrings, 10)) + + assertEquals(9, string.lastIndexOfAny(substrings)) + assertEquals(2, string.lastIndexOfAny(substrings, startIndex = 8)) + assertEquals(2, string.lastIndexOfAny(substrings.reversed(), startIndex = 8)) + assertEquals(-1, string.lastIndexOfAny(substrings, 1)) + + assertEquals(0, string.indexOfAny(listOf("dab", "")), "empty strings are not ignored") + assertEquals(-1, string.indexOfAny(listOf())) + } + + @Test fun indexOfAnyStringIgnoreCase() = withOneCharSequenceArg("aBraCadaBrA") { string -> + val substrings = listOf("rAc", "Ra") + + assertEquals(2, string.indexOfAny(substrings, ignoreCase = true)) + assertEquals(9, string.indexOfAny(substrings, startIndex = 3, ignoreCase = true)) + assertEquals(-1, string.indexOfAny(substrings, startIndex = 10, ignoreCase = true)) + + assertEquals(9, string.lastIndexOfAny(substrings, ignoreCase = true)) + assertEquals(2, string.lastIndexOfAny(substrings, startIndex = 8, ignoreCase = true)) + assertEquals(-1, string.lastIndexOfAny(substrings, startIndex = 1, ignoreCase = true)) + } + + @Test fun findAnyOfStrings() = withOneCharSequenceArg("abracadabra") { string -> + val substrings = listOf("rac", "ra") + assertEquals(2 to "rac", string.findAnyOf(substrings)) + assertEquals(9 to "ra", string.findAnyOf(substrings, startIndex = 3)) + assertEquals(2 to "ra", string.findAnyOf(substrings.reversed())) + assertEquals(null, string.findAnyOf(substrings, 10)) + + assertEquals(9 to "ra", string.findLastAnyOf(substrings)) + assertEquals(2 to "rac", string.findLastAnyOf(substrings, startIndex = 8)) + assertEquals(2 to "ra", string.findLastAnyOf(substrings.reversed(), startIndex = 8)) + assertEquals(null, string.findLastAnyOf(substrings, 1)) + + assertEquals(0 to "", string.findAnyOf(listOf("dab", "")), "empty strings are not ignored") + assertEquals(null, string.findAnyOf(listOf())) + } + + @Test fun findAnyOfStringsIgnoreCase() = withOneCharSequenceArg("aBraCadaBrA") { string -> + val substrings = listOf("rAc", "Ra") + + assertEquals(2 to substrings[0], string.findAnyOf(substrings, ignoreCase = true)) + assertEquals(9 to substrings[1], string.findAnyOf(substrings, startIndex = 3, ignoreCase = true)) + assertEquals(null, string.findAnyOf(substrings, startIndex = 10, ignoreCase = true)) + + assertEquals(9 to substrings[1], string.findLastAnyOf(substrings, ignoreCase = true)) + assertEquals(2 to substrings[0], string.findLastAnyOf(substrings, startIndex = 8, ignoreCase = true)) + assertEquals(null, string.findLastAnyOf(substrings, startIndex = 1, ignoreCase = true)) + } + + @Test fun indexOfChar() = withOneCharSequenceArg("bcedef") { string -> + assertEquals(-1, string.indexOf('a')) + assertEquals(2, string.indexOf('e')) + assertEquals(2, string.indexOf('e', 2)) + assertEquals(4, string.indexOf('e', 3)) + assertEquals(4, string.lastIndexOf('e')) + assertEquals(2, string.lastIndexOf('e', 3)) + + for (startIndex in -1..string.length+1) { + assertEquals(string.indexOfAny(charArrayOf('e'), startIndex), string.indexOf('e', startIndex)) + assertEquals(string.lastIndexOfAny(charArrayOf('e'), startIndex), string.lastIndexOf('e', startIndex)) + } + + } + + @Test fun indexOfCharIgnoreCase() = withOneCharSequenceArg("bCEdef") { string -> + assertEquals(-1, string.indexOf('a', ignoreCase = true)) + assertEquals(2, string.indexOf('E', ignoreCase = true)) + assertEquals(2, string.indexOf('e', 2, ignoreCase = true)) + assertEquals(4, string.indexOf('E', 3, ignoreCase = true)) + assertEquals(4, string.lastIndexOf('E', ignoreCase = true)) + assertEquals(2, string.lastIndexOf('e', 3, ignoreCase = true)) + + + for (startIndex in -1..string.length+1){ + assertEquals(string.indexOfAny(charArrayOf('e'), startIndex, ignoreCase = true), string.indexOf('E', startIndex, ignoreCase = true)) + assertEquals(string.lastIndexOfAny(charArrayOf('E'), startIndex, ignoreCase = true), string.lastIndexOf('e', startIndex, ignoreCase = true)) + } + } + + @Test fun indexOfString() = withOneCharSequenceArg("bceded") { string -> + for (index in string.indices) + assertEquals(index, string.indexOf("", index)) + assertEquals(1, string.indexOf("ced")) + assertEquals(4, string.indexOf("ed", 3)) + assertEquals(-1, string.indexOf("abcdefgh")) + } + + @Test fun indexOfStringIgnoreCase() = withOneCharSequenceArg("bceded") { string -> + for (index in string.indices) + assertEquals(index, string.indexOf("", index, ignoreCase = true)) + assertEquals(1, string.indexOf("cEd", ignoreCase = true)) + assertEquals(4, string.indexOf("Ed", 3, ignoreCase = true)) + assertEquals(-1, string.indexOf("abcdefgh", ignoreCase = true)) + } + + + @Test fun contains() = withTwoCharSequenceArgs { arg1, arg2 -> + operator fun String.contains(other: String): Boolean = arg1(this).contains(arg2(other)) + operator fun String.contains(other: Char): Boolean = arg1(this).contains(other) + + assertTrue("pl" in "sample") + assertFalse("PL" in "sample") + assertTrue(arg1("sömple").contains(arg2("Ö"), ignoreCase = true)) + + assertTrue("" in "sample") + assertTrue("" in "") + + assertTrue('ö' in "sömple") + assertFalse('Ö' in "sömple") + assertTrue(arg1("sömple").contains('Ö', ignoreCase = true)) + } + + @Test fun equalsIgnoreCase() { + 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)) + } + + + @Test fun replace() { + 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("", "-")) + } + + @Test fun replaceFirst() { + 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("", "-")) + } + + @Test fun count() = withOneCharSequenceArg("hello there\tfoo\nbar") { text -> + val whitespaceCount = text.count { it.isWhitespace() } + assertEquals(3, whitespaceCount) + } + + @Test fun testSplitByChar() = withOneCharSequenceArg("ab\n[|^$&\\]^cd") { s -> + s.split('b').let { list -> + assertEquals(2, list.size) + assertEquals("a", list[0]) + assertEquals("\n[|^$&\\]^cd", list[1]) + } + s.split('^').let { list -> + assertEquals(3, list.size) + assertEquals("cd", list[2]) + } + s.split('.').let { list -> + assertEquals(1, list.size) + assertEquals(s.toString(), list[0]) + } + } + + @Test fun forEach() = withOneCharSequenceArg("abcd1234") { data -> + var count = 0 + val sb = StringBuilder() + data.forEach { + count++ + sb.append(it) + } + assertEquals(data.length, count) + assertEquals(data.toString(), sb.toString()) + } + + @Test + fun onEach() = withOneCharSequenceArg("abcd") { data -> + val result = StringBuilder() + val newData = data.onEach { result.append(it + 1) } + assertEquals("bcde", result.toString()) + assertTrue(data === newData) + + // static types test + assertStaticTypeIs("x".onEach { }) + assertStaticTypeIs(result.onEach { }) + } + + + @Test fun filter() { + assertEquals("acdca", ("abcdcba").filter { !it.equals('b') }) + assertEquals("1234", ("a1b2c3d4").filter { it.isAsciiDigit() }) + } + + @Test fun filterCharSequence() = withOneCharSequenceArg { arg1 -> + assertContentEquals("acdca", arg1("abcdcba").filter { !it.equals('b') }) + assertContentEquals("1234", arg1("a1b2c3d4").filter { it.isAsciiDigit() }) + } + + @Test fun filterNot() { + assertEquals("acdca", ("abcdcba").filterNot { it.equals('b') }) + assertEquals("abcd", ("a1b2c3d4").filterNot { it.isAsciiDigit() }) + } + + @Test fun filterNotCharSequence() = withOneCharSequenceArg { arg1 -> + assertContentEquals("acdca", arg1("abcdcba").filterNot { it.equals('b') }) + assertContentEquals("abcd", arg1("a1b2c3d4").filterNot { it.isAsciiDigit() }) + } + + @Test fun filterIndexed() { + val data = "abedcf" + assertEquals("abdf", data.filterIndexed { index, c -> c == 'a' + index }) + } + + @Test fun filterIndexedCharSequence() = withOneCharSequenceArg("abedcf") { data -> + assertContentEquals("abdf", data.filterIndexed { index, c -> c == 'a' + index }) + } + + @Test fun all() = withOneCharSequenceArg("AbCd") { data -> + assertTrue { + data.all { it.isAsciiLetter() } + } + assertFalse { + data.all { it.isAsciiUpperCase() } + } + } + + @Test fun any() = withOneCharSequenceArg("a1bc") { data -> + assertTrue { + data.any() { it.isAsciiDigit() } + } + assertFalse { + data.any() { it.isAsciiUpperCase() } + } + } + + @Test fun find() = withOneCharSequenceArg("a1b2c3") { data -> + assertEquals('1', data.first { it.isAsciiDigit() }) + assertNull(data.firstOrNull { it.isAsciiUpperCase() }) + } + + @Test fun findNot() = withOneCharSequenceArg("1a2b3c") { data -> + assertEquals('a', data.filterNot { it.isAsciiDigit() }.firstOrNull()) + assertNull(data.filterNot { it.isAsciiLetter() || it.isAsciiDigit() }.firstOrNull()) + } + + @Test fun partition() { + val data = "a1b2c3" + val pair = data.partition { it.isAsciiDigit() } + assertEquals("123", pair.first, "pair.first") + assertEquals("abc", pair.second, "pair.second") + } + + @Test fun partitionCharSequence() = withOneCharSequenceArg("a1b2c3") { data -> + val pair = data.partition { it.isAsciiDigit() } + assertContentEquals("123", pair.first, "pair.first") + assertContentEquals("abc", pair.second, "pair.second") + } + + @Test fun zipWithNext() = withOneCharSequenceArg { arg1 -> + assertEquals(listOf("ab", "bc"), arg1("abc").zipWithNext { a: Char, b: Char -> a.toString() + b }) + assertTrue(arg1("").zipWithNext { a: Char, b: Char -> a.toString() + b }.isEmpty()) + assertTrue(arg1("a").zipWithNext { a: Char, b: Char -> a.toString() + b }.isEmpty()) + } + + @Test fun zipWithNextPairs() = withOneCharSequenceArg { arg1 -> + assertEquals(listOf('a' to 'b', 'b' to 'c'), arg1("abc").zipWithNext()) + assertTrue(arg1("").zipWithNext().isEmpty()) + assertTrue(arg1("a").zipWithNext().isEmpty()) + } + + + @Test + fun chunked() = withOneCharSequenceArg { arg1 -> + val size = 7 + val data = arg1("abcdefg") + val result = data.chunked(4) + assertEquals(listOf("abcd", "efg"), result) + + val result2 = data.chunked(3) { it.reversed().toString() } + assertEquals(listOf("cba", "fed", "g"), result2) + + data.toString().let { expectedSingleChunk -> + assertEquals(expectedSingleChunk, data.chunked(size).single()) + assertEquals(expectedSingleChunk, data.chunked(size + 3).single()) + } + + assertTrue(arg1("").chunked(3).isEmpty()) + + for (illegalValue in listOf(Int.MIN_VALUE, -1, 0)) { + assertFailsWith("size $illegalValue") { data.chunked(illegalValue) } + } + + for (chunkSize in 1..size + 1) { + compare(data.chunked(chunkSize).iterator(), data.chunkedSequence(chunkSize).iterator()) { iteratorBehavior() } + } + } + + + @Test + fun windowed() = withOneCharSequenceArg { arg1 -> + val size = 7 + val data = arg1("abcdefg") + val result = data.windowed(4, 2) + assertEquals(listOf("abcd", "cdef"), result) + + val resultPartial = data.windowed(4, 2, partialWindows = true) + assertEquals(listOf("abcd", "cdef", "efg", "g"), resultPartial) + + val result2 = data.windowed(2, 3) { it.reversed().toString() } + assertEquals(listOf("ba", "ed"), result2) + val result2partial = data.windowed(2, 3, partialWindows = true) { it.reversed().toString() } + assertEquals(listOf("ba", "ed", "g"), result2partial) + + assertEquals(data.chunked(2), data.windowed(2, 2, partialWindows = true)) + + assertEquals(data.take(2), data.windowed(2, size).single()) + assertEquals(data.take(3), data.windowed(3, size + 3).single()) + + + assertEquals(data.toString(), data.windowed(size, 1).single()) + assertTrue(data.windowed(size + 1, 1).isEmpty()) + + val result3partial = data.windowed(size, 1, partialWindows = true) + result3partial.forEachIndexed { index, window -> + assertEquals(size - index, window.length, "size of window#$index") + } + + assertTrue(arg1("").windowed(3, 2).isEmpty()) + + for (illegalValue in listOf(Int.MIN_VALUE, -1, 0)) { + assertFailsWith("size $illegalValue") { data.windowed(illegalValue, 1) } + assertFailsWith("step $illegalValue") { data.windowed(1, illegalValue) } + } + + for (window in 1..size + 1) { + for (step in 1..size + 1) { + compare(data.windowed(window, step).iterator(), data.windowedSequence(window, step).iterator()) { iteratorBehavior() } + compare(data.windowed(window, step, partialWindows = true).iterator(), + data.windowedSequence(window, step, partialWindows = true).iterator()) { iteratorBehavior() } + } + } + } + + @Test fun map() = withOneCharSequenceArg { arg1 -> + assertEquals(listOf('a', 'b', 'c'), arg1("abc").map { it }) + + assertEquals(listOf(true, false, true), arg1("AbC").map { it.isAsciiUpperCase() }) + + assertEquals(listOf(), arg1("").map { it.isAsciiUpperCase() }) + + assertEquals(listOf(97, 98, 99), arg1("abc").map { it.toInt() }) + } + + @Test fun mapTo() = withOneCharSequenceArg { arg1 -> + val result1 = arrayListOf() + val return1 = arg1("abc").mapTo(result1, { it }) + assertEquals(result1, return1) + assertEquals(arrayListOf('a', 'b', 'c'), result1) + + val result2 = arrayListOf() + val return2 = arg1("AbC").mapTo(result2, { it.isAsciiUpperCase() }) + assertEquals(result2, return2) + assertEquals(arrayListOf(true, false, true), result2) + + val result3 = arrayListOf() + val return3 = arg1("").mapTo(result3, { it.isAsciiUpperCase() }) + assertEquals(result3, return3) + assertEquals(arrayListOf(), result3) + + val result4 = arrayListOf() + val return4 = arg1("abc").mapTo(result4, { it.toInt() }) + assertEquals(result4, return4) + assertEquals(arrayListOf(97, 98, 99), result4) + } + + @Test fun flatMap() = withOneCharSequenceArg("abcd") { data -> + val result = data.flatMap { ('a'..it) + ' ' } + assertEquals("a ab abc abcd ".toList(), result) + } + + @Test fun fold() = withOneCharSequenceArg { arg1 -> + // calculate number of digits in the string + val data = arg1("a1b2c3def") + val result = data.fold(0, { digits, c -> if(c.isAsciiDigit()) digits + 1 else digits } ) + assertEquals(3, result) + + //simulate all method + assertEquals(true, arg1("ABCD").fold(true, { r, c -> r && c.isAsciiUpperCase() })) + + //get string back + assertEquals(data.toString(), data.fold("", { s, c -> s + c })) + } + + @Test fun foldRight() = withOneCharSequenceArg { arg1 -> + // calculate number of digits in the string + val data = arg1("a1b2c3def") + val result = data.foldRight(0, { c, digits -> if(c.isAsciiDigit()) digits + 1 else digits }) + assertEquals(3, result) + + //simulate all method + assertEquals(true, arg1("ABCD").foldRight(true, { c, r -> r && c.isAsciiUpperCase() })) + + //get string back + assertEquals(data.toString(), data.foldRight("", { s, c -> "" + s + c })) + } + + @Test fun reduceIndexed() = withOneCharSequenceArg { arg1 -> + // get the 3rd character + assertEquals('c', arg1("bacfd").reduceIndexed { index, v, c -> if (index == 2) c else v }) + + expect('c') { + "ab".reduceIndexed { index, acc, e -> + assertEquals(1, index) + assertEquals('a', acc) + assertEquals('b', e) + e + (e - acc) + } + } + + assertFailsWith { + arg1("").reduceIndexed { _, _, _ -> '\n' } + } + } + + @Test fun reduceRightIndexed() = withOneCharSequenceArg { arg1 -> + // get the 3rd character + assertEquals('c', arg1("bacfd").reduceRightIndexed { index, c, v -> if (index == 2) c else v }) + + expect('c') { + "ab".reduceRightIndexed { index, e, acc -> + assertEquals(0, index) + assertEquals('b', acc) + assertEquals('a', e) + acc + (acc - e) + } + } + + assertFailsWith { + arg1("").reduceRightIndexed { _, _, _ -> '\n' } + } + } + + @Test fun reduce() = withOneCharSequenceArg { arg1 -> + // get the smallest character(by char value) + assertEquals('a', arg1("bacfd").reduce { v, c -> if (v > c) c else v }) + + assertFailsWith { + arg1("").reduce { _, _ -> '\n' } + } + } + + @Test fun reduceRight() = withOneCharSequenceArg { arg1 -> + // get the smallest character(by char value) + assertEquals('a', arg1("bacfd").reduceRight { c, v -> if (v > c) c else v }) + + assertFailsWith { + arg1("").reduceRight { _, _ -> '\n' } + } + } + + @Test fun groupBy() = withOneCharSequenceArg("abAbaABcD") { data -> + // group characters by their case + val result = data.groupBy { it.isAsciiUpperCase() } + assertEquals(2, result.size) + assertEquals(listOf('a','b','b','a','c'), result[false]) + assertEquals(listOf('A','A','B','D'), result[true]) + } + + @Test fun joinToString() { + 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) + } + + @Test fun joinTo() { + val data = "kotlin".toList() + val sb = StringBuilder() + data.joinTo(sb, "^", "<", ">") + assertEquals("", sb.toString()) + } + + + @Test fun dropWhile() { + val data = "ab1cd2" + assertEquals("1cd2", data.dropWhile { it.isAsciiLetter() }) + assertEquals("", data.dropWhile { true }) + assertEquals("ab1cd2", data.dropWhile { false }) + } + + @Test fun dropWhileCharSequence() = withOneCharSequenceArg("ab1cd2") { data -> + assertContentEquals("1cd2", data.dropWhile { it.isAsciiLetter() }) + assertContentEquals("", data.dropWhile { true }) + assertContentEquals("ab1cd2", data.dropWhile { false }) + } + + + @Test fun drop() { + val data = "abcd1234" + assertEquals("d1234", data.drop(3)) + assertFails { + data.drop(-2) + } + assertEquals("", data.drop(data.length + 5)) + } + + @Test fun dropCharSequence() = withOneCharSequenceArg("abcd1234") { data -> + assertContentEquals("d1234", data.drop(3)) + assertFails { + data.drop(-2) + } + assertContentEquals("", data.drop(data.length + 5)) + } + + @Test fun takeWhile() { + val data = "ab1cd2" + assertEquals("ab", data.takeWhile { it.isAsciiLetter() }) + assertEquals("", data.takeWhile { false }) + assertEquals("ab1cd2", data.takeWhile { true }) + } + + @Test fun takeWhileCharSequence() = withOneCharSequenceArg("ab1cd2") { data -> + assertContentEquals("ab", data.takeWhile { it.isAsciiLetter() }) + assertContentEquals("", data.takeWhile { false }) + assertContentEquals("ab1cd2", data.takeWhile { true }) + } + + @Test fun take() { + val data = "abcd1234" + assertEquals("abc", data.take(3)) + assertFails { + data.take(-7) + } + assertEquals(data, data.take(data.length + 42)) + } + + @Test fun takeCharSequence() = withOneCharSequenceArg("abcd1234") { data -> + assertEquals("abc", data.take(3)) + assertFails { + data.take(-7) + } + assertContentEquals(data.toString(), data.take(data.length + 42)) + } + + + @Test fun testReplaceAllClosure() = withOneCharSequenceArg("test123zzz") { s -> + val result = s.replace("\\d+".toRegex()) { mr -> + "[" + mr.value + "]" + } + assertEquals("test[123]zzz", result) + } + + @Test fun testReplaceAllClosureAtStart() = withOneCharSequenceArg("123zzz") { s -> + val result = s.replace("\\d+".toRegex()) { mr -> + "[" + mr.value + "]" + } + assertEquals("[123]zzz", result) + } + + @Test fun testReplaceAllClosureAtEnd() = withOneCharSequenceArg("test123") { s -> + val result = s.replace("\\d+".toRegex()) { mr -> + "[" + mr.value + "]" + } + assertEquals("test[123]", result) + } + + @Test fun testReplaceAllClosureEmpty() = withOneCharSequenceArg("") { s -> + val result = s.replace("\\d+".toRegex()) { _ -> + "x" + } + assertEquals("", result) + + } + + @Test fun trimMargin() { + // 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()) + } + + @Test fun trimIndent() { + // 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() }) + } + + @Test fun testIndent() { + 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/stdlib_external/text/harmony_regex/AllCodePointsTest.kt b/backend.native/tests/stdlib_external/text/harmony_regex/AllCodePointsTest.kt new file mode 100644 index 00000000000..a5c99b4e5af --- /dev/null +++ b/backend.native/tests/stdlib_external/text/harmony_regex/AllCodePointsTest.kt @@ -0,0 +1,65 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.text.harmony_regex + +import kotlin.text.* +import kotlin.test.* + +class AllCodePointsTest { + + fun assertTrue(msg: String, value: Boolean) = assertTrue(value, msg) + fun assertFalse(msg: String, value: Boolean) = assertFalse(value, msg) + + fun codePointToString(codePoint: Int): String { + val charArray = Char.toChars(codePoint) + return fromCharArray(charArray, 0, charArray.size) + } + + // TODO: Here is a performance problem: an execution of this test requires much more time than it in Kotlin/JVM. + @Test fun test() { + // Regression for HARMONY-3145 + var p = Regex("(\\p{all})+") + var res = true + var cnt = 0 + var s: String + for (i in 0..1114111) { + s = codePointToString(i) + if (!s.matches(p)) { + cnt++ + res = false + } + } + assertTrue(res) + assertEquals(0, cnt) + + p = Regex("(\\P{all})+") + res = true + cnt = 0 + + for (i in 0..1114111) { + s = codePointToString(i) + if (!s.matches(p)) { + cnt++ + res = false + } + } + + assertFalse(res) + assertEquals(0x110000, cnt) + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/text/harmony_regex/MatchResultTest.kt b/backend.native/tests/stdlib_external/text/harmony_regex/MatchResultTest.kt new file mode 100644 index 00000000000..3ee6763f928 --- /dev/null +++ b/backend.native/tests/stdlib_external/text/harmony_regex/MatchResultTest.kt @@ -0,0 +1,449 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.text.harmony_regex + +import kotlin.text.* +import kotlin.test.* + +class MatchResultTest { + + fun assertTrue(msg: String, value: Boolean) = assertTrue(value, msg) + fun assertFalse(msg: String, value: Boolean) = assertFalse(value, msg) + + internal var testPatterns = arrayOf("(a|b)*abb", "(1*2*3*4*)*567", "(a|b|c|d)*aab", "(1|2|3|4|5|6|7|8|9|0)(1|2|3|4|5|6|7|8|9|0)*", "(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)*", "(a|b)*(a|b)*A(a|b)*lice.*", "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)(a|b|c|d|e|f|g|h|" + "i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)*(1|2|3|4|5|6|7|8|9|0)*|while|for|struct|if|do") + + internal var groupPatterns = arrayOf("(a|b)*aabb", "((a)|b)*aabb", "((a|b)*)a(abb)", "(((a)|(b))*)aabb", "(((a)|(b))*)aa(b)b", "(((a)|(b))*)a(a(b)b)") + + @Test fun testReplaceAll() { + val input = "aabfooaabfooabfoob" + val pattern = "a*b" + val regex = Regex(pattern) + + assertEquals("-foo-foo-foo-", regex.replace(input, "-")) + } + + @Test fun testReplaceFirst() { + val input = "zzzdogzzzdogzzz" + val pattern = "dog" + val regex = Regex(pattern) + + assertEquals("zzzcatzzzdogzzz", regex.replaceFirst(input, "cat")) + } + + /* + * Class under test for String group(int) + */ + @Test fun testGroupint() { + val positiveTestString = "ababababbaaabb" + + // test IndexOutOfBoundsException + // // + for (i in groupPatterns.indices) { + val regex = Regex(groupPatterns[i]) + val result = regex.matchEntire(positiveTestString)!! + try { + // groupPattern equals to number of groups + // of the specified pattern + // // + result.groups[i + 2] + fail("IndexOutBoundsException expected") + result.groups[i + 100] + fail("IndexOutBoundsException expected") + result.groups[-1] + fail("IndexOutBoundsException expected") + result.groups[-100] + fail("IndexOutBoundsException expected") + } catch (e: IndexOutOfBoundsException) { + } + } + + val groupResults = arrayOf( + arrayOf("a"), + arrayOf("a", "a"), + arrayOf("ababababba", "a", "abb"), + arrayOf("ababababba", "a", "a", "b"), + arrayOf("ababababba", "a", "a", "b", "b"), + arrayOf("ababababba", "a", "a", "b", "abb", "b") + ) + + for (i in groupPatterns.indices) { + val regex = Regex(groupPatterns[i]) + val result = regex.matchEntire(positiveTestString)!! + for (j in 0..groupResults[i].size - 1) { + assertEquals(groupResults[i][j], result.groupValues[j + 1], "i: $i j: $j") + } + } + + } + + @Test fun testGroup() { + val positiveTestString = "ababababbaaabb" + val negativeTestString = "gjhfgdsjfhgcbv" + for (element in groupPatterns) { + val regex = Regex(element) + val result = regex.matchEntire(positiveTestString)!! + assertEquals(positiveTestString, result.groupValues[0]) + assertEquals(positiveTestString, result.groups[0]!!.value) + assertEquals(0 until positiveTestString.length, result.groups[0]!!.range) + } + + for (element in groupPatterns) { + val regex = Regex(element) + val result = regex.matchEntire(negativeTestString) + assertEquals(result, null) + } + } + + @Test fun testGroupPossessive() { + val regex = Regex("((a)|(b))++c") + assertEquals("a", regex.matchEntire("aac")!!.groupValues[1]) + } + + @Test fun testMatchesMisc() { + val posSeq = arrayOf( + arrayOf("abb", "ababb", "abababbababb", "abababbababbabababbbbbabb"), + arrayOf("213567", "12324567", "1234567", "213213567", "21312312312567", "444444567"), + arrayOf("abcdaab", "aab", "abaab", "cdaab", "acbdadcbaab"), + arrayOf("213234567", "3458", "0987654", "7689546432", "0398576", "98432", "5"), + arrayOf("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ" + "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ"), + arrayOf("ababbaAabababblice", "ababbaAliceababab", "ababbAabliceaaa", "abbbAbbbliceaaa", "Alice"), + arrayOf("a123", "bnxnvgds156", "for", "while", "if", "struct")) + + for (i in testPatterns.indices) { + val regex = Regex(testPatterns[i]) + for (j in 0..posSeq[i].size - 1) { + assertTrue("Incorrect match: " + testPatterns[i] + " vs " + posSeq[i][j], regex.matches(posSeq[i][j])) + } + } + } + + @Test fun testMatchesQuantifiers() { + val testPatternsSingles = arrayOf("a{5}", "a{2,4}", "a{3,}") + val testPatternsMultiple = arrayOf("((a)|(b)){1,2}abb", "((a)|(b)){2,4}", "((a)|(b)){3,}") + + val stringSingles = arrayOf( + arrayOf("aaaaa", "aaa"), + arrayOf("aa", "a", "aaa", "aaaaaa", "aaaa", "aaaaa"), + arrayOf("aaa", "a", "aaaa", "aa") + ) + + val stringMultiples = arrayOf( + arrayOf("ababb", "aba"), + arrayOf("ab", "b", "bab", "ababa", "abba", "abababbb"), + arrayOf("aba", "b", "abaa", "ba") + ) + + for (i in testPatternsSingles.indices) { + val regex = Regex(testPatternsSingles[i]) + for (j in 0..stringSingles.size / 2 - 1) { + assertTrue("Match expected, but failed: " + regex.pattern + " : " + stringSingles[i][j], + regex.matches(stringSingles[i][j * 2]) + ) + assertFalse("Match failure expected, but match succeed: " + regex.pattern + " : " + stringSingles[i][j * 2 + 1], + regex.matches(stringSingles[i][j * 2 + 1]) + ) + } + } + + for (i in testPatternsMultiple.indices) { + val regex = Regex(testPatternsMultiple[i]) + for (j in 0..stringMultiples.size / 2 - 1) { + assertTrue("Match expected, but failed: " + regex.pattern + " : " + stringMultiples[i][j], + regex.matches(stringMultiples[i][j * 2]) + ) + assertFalse("Match failure expected, but match succeed: " + regex.pattern + " : " + stringMultiples[i][j * 2 + 1], + regex.matches(stringMultiples[i][j * 2 + 1]) + ) + } + } + + // Test for the optimized '.+' quantifier node. + assertFalse(Regex(".+abc").matches("abc")) + assertFalse(Regex(".+\nabc", RegexOption.DOT_MATCHES_ALL).matches("\nabc")) + assertFalse(Regex(".+").matches("")) + assertFalse(Regex(".+\n", RegexOption.DOT_MATCHES_ALL).matches("\n")) + assertFalse(Regex(".+abc").containsMatchIn("abc")) + assertFalse(Regex(".+\nabc", RegexOption.DOT_MATCHES_ALL).containsMatchIn("\nabc")) + assertFalse(Regex(".+").containsMatchIn("")) + assertFalse(Regex(".+\n", RegexOption.DOT_MATCHES_ALL).containsMatchIn("\n")) + + assertTrue(Regex(".+abc").matches("aabc")) + assertTrue(Regex(".+\nabc", RegexOption.DOT_MATCHES_ALL).matches("a\nabc")) + assertTrue(Regex(".+").matches("a")) + assertTrue(Regex(".+\n", RegexOption.DOT_MATCHES_ALL).matches("a\n")) + assertTrue(Regex(".+abc").containsMatchIn("aabc")) + assertTrue(Regex(".+\nabc", RegexOption.DOT_MATCHES_ALL).containsMatchIn("a\nabc")) + assertTrue(Regex(".+").containsMatchIn("a")) + assertTrue(Regex(".+\n", RegexOption.DOT_MATCHES_ALL).containsMatchIn("a\n")) + } + + @Test fun testQuantVsGroup() { + val patternString = "(d{1,3})((a|c)*)(d{1,3})((a|c)*)(d{1,3})" + val testString = "dacaacaacaaddaaacaacaaddd" + + val regex = Regex(patternString) + + val result = regex.matchEntire(testString)!! + assertEquals("dacaacaacaaddaaacaacaaddd", result.groupValues[0]) + assertEquals("d", result.groupValues[1]) + assertEquals("acaacaacaa", result.groupValues[2]) + assertEquals("dd", result.groupValues[4]) + assertEquals("aaacaacaa", result.groupValues[5]) + assertEquals("ddd", result.groupValues[7]) + } + + /* + * Class under test for boolean find() + */ + @Test fun testFind() { + var testPattern = "(abb)" + var testString = "cccabbabbabbabbabb" + val regex = Regex(testPattern) + var result = regex.find(testString) + var start = 3 + var end = 6 + while (result != null) { + assertEquals(start, result.groups[1]!!.range.start) + assertEquals(end, result.groups[1]!!.range.endInclusive + 1) + + start = end + end += 3 + result = result.next() + } + + testPattern = "(\\d{1,3})" + testString = "aaaa123456789045" + + val regex2 = Regex(testPattern) + var result2 = regex2.find(testString) + start = 4 + val length = 3 + while (result2 != null) { + assertEquals(testString.substring(start, start + length), result2.groupValues[1]) + start += length + result2 = result2.next() + } + } + + @Test fun testSEOLsymbols() { + val regex = Regex("^a\\(bb\\[$") + assertTrue(regex.matches("a(bb[")) + } + + @Test fun testGroupCount() { + for (i in groupPatterns.indices) { + val regex = Regex(groupPatterns[i]) + val result = regex.matchEntire("ababababbaaabb")!! + assertEquals(i + 1, result.groups.size - 1) + } + } + + @Test fun testReluctantQuantifiers() { + val regex = Regex("(ab*)*b") + val result = regex.matchEntire("abbbb") + if (result != null) { + assertEquals("abbb", result.groupValues[1]) + } else { + fail("Match expected: (ab*)*b vs abbbb") + } + } + + @Test fun testEnhancedFind() { + val input = "foob" + val pattern = "a*b" + val regex = Regex(pattern) + val result = regex.find(input)!! + assertEquals("b", result.groupValues[0]) + } + + @Test fun testPosCompositeGroup() { + val posExamples = arrayOf("aabbcc", "aacc", "bbaabbcc") + val negExamples = arrayOf("aabb", "bb", "bbaabb") + val posPat = Regex("(aa|bb){1,3}+cc") + val negPat = Regex("(aa|bb){1,3}+bb") + + for (element in posExamples) { + assertTrue(posPat.matches(element)) + } + + for (element in negExamples) { + assertFalse(negPat.matches(element)) + } + + assertTrue(Regex("(aa|bb){1,3}+bb").matches("aabbaabb")) + } + + @Test fun testPosAltGroup() { + val posExamples = arrayOf("aacc", "bbcc", "cc") + val negExamples = arrayOf("bb", "aa") + val posPat = Regex("(aa|bb)?+cc") + val negPat = Regex("(aa|bb)?+bb") + + for (element in posExamples) { + assertTrue(posPat.toString() + " vs: " + element, posPat.matches(element)) + } + + for (element in negExamples) { + assertFalse(negPat.matches(element)) + } + + assertTrue(Regex("(aa|bb)?+bb").matches("aabb")) + } + + @Test fun testRelCompGroup() { + var res = "" + for (i in 0..3) { + val regex = Regex("((aa|bb){$i,3}?).*cc") + val result = regex.matchEntire("aaaaaacc") + assertTrue(regex.toString() + " vs: " + "aaaaaacc", result != null) + assertEquals(res, result!!.groupValues[1]) + res += "aa" + } + } + + @Test fun testRelAltGroup() { + var regex = Regex("((aa|bb)??).*cc") + var result = regex.matchEntire("aacc") + assertTrue(regex.toString() + " vs: " + "aacc", result != null) + assertEquals("", result!!.groupValues[1]) + + regex = Regex("((aa|bb)??)cc") + result = regex.matchEntire("aacc") + assertTrue(regex.toString() + " vs: " + "aacc", result != null) + assertEquals("aa", result!!.groupValues[1]) + } + + @Test fun testIgnoreCase() { + var regex = Regex("(aa|bb)*", RegexOption.IGNORE_CASE) + assertTrue(regex.matches("aAbb")) + + regex = Regex("(a|b|c|d|e)*", RegexOption.IGNORE_CASE) + assertTrue(regex.matches("aAebbAEaEdebbedEccEdebbedEaedaebEbdCCdbBDcdcdADa")) + + regex = Regex("[a-e]*", RegexOption.IGNORE_CASE) + assertTrue(regex.matches("aAebbAEaEdebbedEccEdebbedEaedaebEbdCCdbBDcdcdADa")) + } + + @Test fun testQuoteReplacement() { + assertEquals("\\\\aaCC\\$1", Regex.escapeReplacement("\\aaCC$1")) + } + + @Test fun testOverFlow() { + var regex = Regex("(a*)*") + var result = regex.matchEntire("aaa") + assertTrue(result != null) + assertEquals("", result!!.groupValues[1]) + + assertTrue(Regex("(1+)\\1+").matches("11")) + assertTrue(Regex("(1+)(2*)\\2+").matches("11")) + + regex = Regex("(1+)\\1*") + result = regex.matchEntire("11") + + assertTrue(result != null) + assertEquals("11", result!!.groupValues[1]) + + regex = Regex("((1+)|(2+))(\\2+)") + result = regex.matchEntire("11") + + assertTrue(result != null) + assertEquals("1", result!!.groupValues[2]) + assertEquals("1", result.groupValues[1]) + assertEquals("1", result.groupValues[4]) + assertEquals("", result.groupValues[3]) + } + + @Test fun testUnicode() { + assertTrue(Regex("\\x61a").matches("aa")) + assertTrue(Regex("\\u0061a").matches("aa")) + assertTrue(Regex("\\0141a").matches("aa")) + assertTrue(Regex("\\0777").matches("?7")) + } + + @Test fun testUnicodeCategory() { + assertTrue(Regex("\\p{Ll}").matches("k")) // Unicode lower case + assertTrue(Regex("\\P{Ll}").matches("K")) // Unicode non-lower + // case + assertTrue(Regex("\\p{Lu}").matches("K")) // Unicode upper case + assertTrue(Regex("\\P{Lu}").matches("k")) // Unicode non-upper + // case combinations + assertTrue(Regex("[\\p{L}&&[^\\p{Lu}]]").matches("k")) + assertTrue(Regex("[\\p{L}&&[^\\p{Ll}]]").matches("K")) + assertFalse(Regex("[\\p{L}&&[^\\p{Lu}]]").matches("K")) + assertFalse(Regex("[\\p{L}&&[^\\p{Ll}]]").matches("k")) + + // category/character combinations + assertFalse(Regex("[\\p{L}&&[^a-z]]").matches("k")) + assertTrue(Regex("[\\p{L}&&[^a-z]]").matches("K")) + + assertTrue(Regex("[\\p{Lu}a-z]").matches("k")) + assertTrue(Regex("[a-z\\p{Lu}]").matches("k")) + + assertFalse(Regex("[\\p{Lu}a-d]").matches("k")) + assertTrue(Regex("[a-d\\p{Lu}]").matches("K")) + + assertFalse(Regex("[\\p{L}&&[^\\p{Lu}&&[^G]]]").matches("K")) + + } + + @Test fun testSplitEmpty() { + + val regex = Regex("") + val s = regex.split("", 0) + + assertEquals(1, s.size) + assertEquals("", s[0]) + } + + @Test fun testFindDollar() { + val regex = Regex("a$") + val result = regex.find("a\n") + assertTrue(result != null) + assertEquals("a", result!!.groupValues[0]) + } + + /* + * Regression test for HARMONY-674 + */ + @Test fun testPatternMatcher() { + assertTrue(Regex("(?:\\d+)(?:pt)").matches("14pt")) + } + + /** + * Inspired by HARMONY-3360 + */ + @Test fun test3360() { + val str = "!\"#%&'(),-./" + val regex = Regex("\\s") + assertFalse(regex.containsMatchIn(str)) + } + + /** + * Regression test for HARMONY-3360 + */ + @Test fun testGeneralPunctuationCategory() { + val s = arrayOf(",", "!", "\"", "#", "%", "&", "'", "(", ")", "-", ".", "/") + val regexp = "\\p{P}" + + for (i in s.indices) { + val regex = Regex(regexp) + assertTrue(regex.containsMatchIn(s[i])) + } + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/text/harmony_regex/MatchResultTest2.kt b/backend.native/tests/stdlib_external/text/harmony_regex/MatchResultTest2.kt new file mode 100644 index 00000000000..611ed053594 --- /dev/null +++ b/backend.native/tests/stdlib_external/text/harmony_regex/MatchResultTest2.kt @@ -0,0 +1,117 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.text.harmony_regex + +import kotlin.text.* +import kotlin.test.* + +class MatchResultTest2 { + + @Test fun testErrorConditions2() { + // Test match cursors in absence of a match + val regex = Regex("(foo[0-9])(bar[a-z])") + var result = regex.find("foo1barzfoo2baryfoozbar5") + + assertTrue(result != null) + assertEquals(0, result!!.range.start) + assertEquals(7, result.range.endInclusive) + assertEquals(0, result.groups[0]!!.range.start) + assertEquals(7, result.groups[0]!!.range.endInclusive) + assertEquals(0, result.groups[1]!!.range.start) + assertEquals(3, result.groups[1]!!.range.endInclusive) + assertEquals(4, result.groups[2]!!.range.start) + assertEquals(7, result.groups[2]!!.range.endInclusive) + + try { + result.groups[3] + fail("IndexOutOfBoundsException expected") + } catch (e: IndexOutOfBoundsException) { + } + + try { + result.groupValues[3] + fail("IndexOutOfBoundsException expected") + } catch (e: IndexOutOfBoundsException) { + } + + try { + result.groups[-1] + fail("IndexOutOfBoundsException expected") + } catch (e: IndexOutOfBoundsException) { + } + + try { + result.groupValues[-1] + fail("IndexOutOfBoundsException expected") + } catch (e: IndexOutOfBoundsException) { + } + + result = result.next() + assertTrue(result != null) + assertEquals(8, result!!.range.start) + assertEquals(15, result.range.endInclusive) + assertEquals(8, result.groups[0]!!.range.start) + assertEquals(15, result.groups[0]!!.range.endInclusive) + assertEquals(8, result.groups[1]!!.range.start) + assertEquals(11, result.groups[1]!!.range.endInclusive) + assertEquals(12, result.groups[2]!!.range.start) + assertEquals(15, result.groups[2]!!.range.endInclusive) + + try { + result.groups[3] + fail("IndexOutOfBoundsException expected") + } catch (e: IndexOutOfBoundsException) { + } + + try { + result.groupValues[3] + fail("IndexOutOfBoundsException expected") + } catch (e: IndexOutOfBoundsException) { + } + + try { + result.groups[-1] + fail("IndexOutOfBoundsException expected") + } catch (e: IndexOutOfBoundsException) { + } + + try { + result.groupValues[-1] + fail("IndexOutOfBoundsException expected") + } catch (e: IndexOutOfBoundsException) { + } + + result = result.next() + assertFalse(result != null) + } + + /* + * Regression test for HARMONY-997 + */ + @Test fun testReplacementBackSlash() { + val str = "replace me" + val replacedString = "me" + val substitutionString = "\\" + val regex = Regex(replacedString) + try { + regex.replace(str, substitutionString) + fail("IllegalArgumentException should be thrown") + } catch (e: IllegalArgumentException) { + } + } + +} diff --git a/backend.native/tests/stdlib_external/text/harmony_regex/ModeTest.kt b/backend.native/tests/stdlib_external/text/harmony_regex/ModeTest.kt new file mode 100644 index 00000000000..a068e0b0ee8 --- /dev/null +++ b/backend.native/tests/stdlib_external/text/harmony_regex/ModeTest.kt @@ -0,0 +1,117 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.text.harmony_regex + +import kotlin.text.* +import kotlin.test.* + +class ModeTest { + + /** + * Tests Pattern compilation modes and modes triggered in pattern strings + */ + @Test fun testCase() { + var regex: Regex + var result: MatchResult? + + regex = Regex("([a-z]+)[0-9]+") + result = regex.find("cAT123#dog345") + assertNotNull(result) + assertEquals("dog", result!!.groupValues[1]) + assertNull(result.next()) + + regex = Regex("([a-z]+)[0-9]+", RegexOption.IGNORE_CASE) + result = regex.find("cAt123#doG345") + assertNotNull(result) + assertEquals("cAt", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("doG", result!!.groupValues[1]) + assertNull(result.next()) + + regex = Regex("(?i)([a-z]+)[0-9]+") + result = regex.find("cAt123#doG345") + assertNotNull(result) + assertEquals("cAt", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("doG", result!!.groupValues[1]) + assertNull(result.next()) + } + + @Test fun testMultiline() { + var regex: Regex + var result: MatchResult? + + regex = Regex("^foo") + result = regex.find("foobar") + assertNotNull(result) + assertTrue(result!!.range.start == 0 && result.range.endInclusive == 2) + assertTrue(result.groups[0]!!.range.start == 0 && result.groups[0]!!.range.endInclusive == 2) + assertNull(result.next()) + + result = regex.find("barfoo") + assertNull(result) + + regex = Regex("foo$") + result = regex.find("foobar") + assertNull(result) + + result = regex.find("barfoo") + assertNotNull(result) + assertTrue(result!!.range.start == 3 && result.range.endInclusive == 5) + assertTrue(result.groups[0]!!.range.start == 3 && result.groups[0]!!.range.endInclusive == 5) + assertNull(result.next()) + + regex = Regex("^foo([0-9]*)", RegexOption.MULTILINE) + result = regex.find("foo1bar\nfoo2foo3\nbarfoo4") + assertNotNull(result) + assertEquals("1", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("2", result!!.groupValues[1]) + assertNull(result.next()) + + regex = Regex("foo([0-9]*)$", RegexOption.MULTILINE) + result = regex.find("foo1bar\nfoo2foo3\nbarfoo4") + assertNotNull(result) + assertEquals("3", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("4", result!!.groupValues[1]) + assertNull(result.next()) + + regex = Regex("(?m)^foo([0-9]*)") + result = regex.find("foo1bar\nfoo2foo3\nbarfoo4") + assertNotNull(result) + assertEquals("1", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("2", result!!.groupValues[1]) + assertNull(result.next()) + + regex = Regex("(?m)foo([0-9]*)$") + result = regex.find("foo1bar\nfoo2foo3\nbarfoo4") + assertNotNull(result) + assertEquals("3", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("4", result!!.groupValues[1]) + assertNull(result.next()) + } + +} diff --git a/backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternErrorTest.kt b/backend.native/tests/stdlib_external/text/harmony_regex/PatternErrorTest.kt similarity index 54% rename from backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternErrorTest.kt rename to backend.native/tests/stdlib_external/text/harmony_regex/PatternErrorTest.kt index 7daea215ac7..010816430e3 100644 --- a/backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternErrorTest.kt +++ b/backend.native/tests/stdlib_external/text/harmony_regex/PatternErrorTest.kt @@ -14,30 +14,31 @@ * limitations under the License. */ +package test.text.harmony_regex + import kotlin.text.* import kotlin.test.* -fun testCompileErrors() { - // empty regex string - no exception should be thrown - Regex("") +class PatternErrorTest { - // note: invalid regex syntax checked in PatternSyntaxExceptionTest + @Test fun testCompileErrors() { + // empty regex string - no exception should be thrown + Regex("") - // flags = 0 should raise no exception - Regex("foo", emptySet()) + // note: invalid regex syntax checked in PatternSyntaxExceptionTest + + // flags = 0 should raise no exception + Regex("foo", emptySet()) + + // check that all valid flags accepted without exception + val options = setOf( + RegexOption.UNIX_LINES, + RegexOption.IGNORE_CASE, + RegexOption.MULTILINE, + RegexOption.CANON_EQ, + RegexOption.COMMENTS, + RegexOption.DOT_MATCHES_ALL) + Regex("foo", options) + } - // check that all valid flags accepted without exception - val options = setOf( - RegexOption.UNIX_LINES, - RegexOption.IGNORE_CASE, - RegexOption.MULTILINE, - RegexOption.CANON_EQ, - RegexOption.COMMENTS, - RegexOption.DOT_MATCHES_ALL) - Regex("foo", options) } - -fun box() { - testCompileErrors() -} - diff --git a/backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternSyntaxExceptionTest.kt b/backend.native/tests/stdlib_external/text/harmony_regex/PatternSyntaxExceptionTest.kt similarity index 62% rename from backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternSyntaxExceptionTest.kt rename to backend.native/tests/stdlib_external/text/harmony_regex/PatternSyntaxExceptionTest.kt index 346c6514b20..a53aff5692e 100644 --- a/backend.native/tests/external/stdlib/text/RegexTest/harmony/PatternSyntaxExceptionTest.kt +++ b/backend.native/tests/stdlib_external/text/harmony_regex/PatternSyntaxExceptionTest.kt @@ -14,32 +14,31 @@ * limitations under the License. */ +package test.text.harmony_regex + import kotlin.text.* import kotlin.test.* -fun testCase() { - val regex = "(" - try { - Regex(regex) - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { - // TODO: Check the exception's properties. +class PatternSyntaxExceptionTest { + + @Test fun testCase() { + val regex = "(" + try { + Regex(regex) + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + // TODO: Check the exception's properties. + } + } -} + @Test fun testCase2() { + val regex = "[4-" + try { + Regex(regex) + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } -fun testCase2() { - val regex = "[4-" - try { - Regex(regex) - fail("PatternSyntaxException expected") - } catch (e: PatternSyntaxException) { } - } - - -fun box() { - testCase() - testCase2() -} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/text/harmony_regex/PatternTest.kt b/backend.native/tests/stdlib_external/text/harmony_regex/PatternTest.kt new file mode 100644 index 00000000000..521336cc5e8 --- /dev/null +++ b/backend.native/tests/stdlib_external/text/harmony_regex/PatternTest.kt @@ -0,0 +1,1256 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.text.harmony_regex + +import kotlin.text.* +import kotlin.test.* + +class PatternTest { + + fun assertTrue(msg: String, value: Boolean) = assertTrue(value, msg) + fun assertFalse(msg: String, value: Boolean) = assertFalse(value, msg) + + internal var testPatterns = arrayOf("(a|b)*abb", "(1*2*3*4*)*567", "(a|b|c|d)*aab", "(1|2|3|4|5|6|7|8|9|0)(1|2|3|4|5|6|7|8|9|0)*", "(abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ)*", "(a|b)*(a|b)*A(a|b)*lice.*", "(a|b|c|d|e|f|g|h|i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)(a|b|c|d|e|f|g|h|" + "i|j|k|l|m|n|o|p|q|r|s|t|u|v|w|x|y|z)*(1|2|3|4|5|6|7|8|9|0)*|while|for|struct|if|do", "x(?c)y", "x(?cc)y", "x(?:c)y") + + @Test fun testCommentsInPattern() { + val p = Regex("ab# this is a comment\ncd", RegexOption.COMMENTS) + assertTrue(p.matches("abcd")) + } + + @Test fun testSplitCharSequenceint() { + // Splitting CharSequence which ends with pattern. + // Harmony regress tests. + assertEquals(",,".split(",".toRegex(), 3).toTypedArray().size, 3) + assertEquals(",,".split(",".toRegex(), 4).toTypedArray().size, 3) + assertEquals(Regex("o").split("boo:and:foo", 5).size, 5) + assertEquals(Regex("b").split("ab", 0).size, 2) + var s: List + var regex = Regex("x") + s = regex.split("zxx:zzz:zxx", 10) + assertEquals(s.size, 5) + s = regex.split("zxx:zzz:zxx", 3) + assertEquals(s.size, 3) + s = regex.split("zxx:zzz:zxx", 0) + assertEquals(s.size, 5) + + // Other splitting. + // Negative limit + regex = Regex("b") + s = regex.split("abccbadfebb", 0) + assertEquals(s.size, 5) + s = regex.split("", 0) + assertEquals(s.size, 1) + regex = Regex("") + s = regex.split("", 0) + assertEquals(s.size, 1) + s = regex.split("abccbadfe", 0) + assertEquals(s.size, 11) + + // positive limit + regex = Regex("b") + s = regex.split("abccbadfebb", 12) + assertEquals(s.size, 5) + s = regex.split("", 6) + assertEquals(s.size, 1) + regex = Regex("") + s = regex.split("", 11) + assertEquals(s.size, 1) + s = regex.split("abccbadfe", 15) + assertEquals(s.size, 11) + + regex = Regex("b") + s = regex.split("abccbadfebb", 5) + assertEquals(s.size, 5) + s = regex.split("", 1) + assertEquals(s.size, 1) + regex = Regex("") + s = regex.split("", 1) + assertEquals(s.size, 1) + s = regex.split("abccbadfe", 11) + assertEquals(s.size, 11) + + regex = Regex("b") + s = regex.split("abccbadfebb", 3) + assertEquals(s.size, 3) + regex = Regex("") + s = regex.split("abccbadfe", 5) + assertEquals(s.size, 5) + } + + @Test fun testFlags() { + var baseString: String + var testString: String + var regex: Regex + + baseString = "((?i)|b)a" + testString = "A" + regex = Regex(baseString) + assertFalse(regex.matches(testString)) + + baseString = "(?i)a|b" + testString = "A" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "(?i)a|b" + testString = "B" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "c|(?i)a|b" + testString = "B" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "(?i)a|(?s)b" + testString = "B" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "(?i)a|(?-i)b" + testString = "B" + regex = Regex(baseString) + assertFalse(regex.matches(testString)) + + baseString = "(?i)a|(?-i)c|b" + testString = "B" + regex = Regex(baseString) + assertFalse(regex.matches(testString)) + + baseString = "(?i)a|(?-i)c|(?i)b" + testString = "B" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "(?i)a|(?-i)b" + testString = "A" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "((?i))a" + testString = "A" + regex = Regex(baseString) + assertFalse(regex.matches(testString)) + + baseString = "|(?i)|a" + testString = "A" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "(?i)((?s)a.)" + testString = "A\n" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "(?i)((?-i)a)" + testString = "A" + regex = Regex(baseString) + assertFalse(regex.matches(testString)) + + baseString = "(?i)(?s:a.)" + testString = "A\n" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "(?i)fgh(?s:aa)" + testString = "fghAA" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "(?i)((?-i))a" + testString = "A" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "abc(?i)d" + testString = "ABCD" + regex = Regex(baseString) + assertFalse(regex.matches(testString)) + + testString = "abcD" + assertTrue(regex.matches(testString)) + + baseString = "a(?i)a(?-i)a(?i)a(?-i)a" + testString = "aAaAa" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + testString = "aAAAa" + assertFalse(regex.matches(testString)) + } + + fun Set.containsOnly(vararg options: RegexOption): Boolean { + val toCheck = options.toSet() + return size == toCheck.size && containsAll(toCheck) + } + + @Test fun testFlagsMethod() { + val a = kotlin.text.Regex("sdf") + var baseString: String + var regex: Regex + + baseString = "(?-i)" + regex = Regex(baseString) + + baseString = "(?idmsux)abc(?-i)vg(?-dmu)" + regex = Regex(baseString) + assertTrue(regex.options.containsOnly(RegexOption.DOT_MATCHES_ALL, RegexOption.COMMENTS)) + + baseString = "(?idmsux)abc|(?-i)vg|(?-dmu)" + regex = Regex(baseString) + assertTrue(regex.options.containsOnly(RegexOption.DOT_MATCHES_ALL, RegexOption.COMMENTS)) + + baseString = "(?is)a((?x)b.)" + regex = Regex(baseString) + assertTrue(regex.options.containsOnly(RegexOption.DOT_MATCHES_ALL, RegexOption.IGNORE_CASE)) + + baseString = "(?i)a((?-i))" + regex = Regex(baseString) + assertTrue(regex.options.containsOnly(RegexOption.IGNORE_CASE)) + + baseString = "((?i)a)" + regex = Regex(baseString) + assertTrue(regex.options.isEmpty()) + + regex = Regex("(?is)abc") + assertTrue(regex.options.containsOnly(RegexOption.IGNORE_CASE, RegexOption.DOT_MATCHES_ALL)) + } + + @Test fun testCompileStringint() { + /* + * this tests are needed to verify that appropriate exceptions are hrown + */ + var pattern = "b)a" + try { + Regex(pattern) + fail("Expected a PatternSyntaxException when compiling pattern: " + pattern) + } catch (e: PatternSyntaxException) { + // pass + } + + pattern = "bcde)a" + try { + Regex(pattern) + fail("Expected a PatternSyntaxException when compiling pattern: " + pattern) + } catch (e: PatternSyntaxException) { + // pass + } + + pattern = "bbg())a" + try { + Regex(pattern) + fail("Expected a PatternSyntaxException when compiling pattern: " + pattern) + } catch (e: PatternSyntaxException) { + // pass + } + + pattern = "cdb(?i))a" + try { + Regex(pattern) + fail("Expected a PatternSyntaxException when compiling pattern: " + pattern) + } catch (e: PatternSyntaxException) { + // pass + } + + /* + * This pattern should compile (Originally it is a regression test for HARMONY-2127) + */ + pattern = "x(?c)y" + Regex(pattern) + + /* + * This pattern doesn't match any string, but should be compiled anyway + */ + pattern = "(b\\u0001)a" + Regex(pattern) + } + + + @Test fun testQuantCompileNeg() { + val patterns = arrayOf("5{,2}", "{5asd", "{hgdhg", "{5,hjkh", "{,5hdsh", "{5,3shdfkjh}") + for (element in patterns) { + try { + Regex(element) + fail("PatternSyntaxException was expected, but compilation succeeds") + } catch (pse: PatternSyntaxException) { + continue + } + + } + } + + @Test fun testQuantCompilePos() { + val patterns = arrayOf("abc{2,}", "abc{5}") + for (element in patterns) { + Regex(element) + } + } + + @Test fun testQuantComposition() { + val pattern = "(a{1,3})aab" + val regex = Regex(pattern) + val result = regex.matchEntire("aaab") + assertNotNull(result) + assertEquals(result!!.groups[1]!!.range.start, 0) + assertEquals(result.groupValues[1], "a") + } + + @Test fun testTimeZoneIssue() { + val regex = Regex("GMT(\\+|\\-)(\\d+)(:(\\d+))?") + val result = regex.matchEntire("GMT-9:45") + assertNotNull(result) + assertEquals("-", result!!.groupValues[1]) + assertEquals("9", result.groupValues[2]) + assertEquals(":45", result.groupValues[3]) + assertEquals("45", result.groupValues[4]) + } + + @Test fun testCompileRanges() { + val correctTestPatterns = arrayOf("[^]*abb]*", "[^a-d[^m-p]]*abb", "[a-d\\d]*abb", "[abc]*abb", + "[a-e&&[de]]*abb", "[^abc]*abb", "[a-e&&[^de]]*abb", "[a-z&&[^m-p]]*abb", "[a-d[m-p]]*abb", + "[a-zA-Z]*abb", "[+*?]*abb", "[^+*?]*abb") + + val inputSecuence = arrayOf("kkkk", "admpabb", "abcabcd124654abb", "abcabccbacababb", + "dededededededeedabb", "gfdhfghgdfghabb", "accabacbcbaabb", "acbvfgtyabb", "adbcacdbmopabcoabb", + "jhfkjhaSDFGHJkdfhHNJMjkhfabb", "+*??+*abb", "sdfghjkabb") + + for (i in correctTestPatterns.indices) { + assertTrue("pattern: " + correctTestPatterns[i] + " input: " + inputSecuence[i], + Regex(correctTestPatterns[i]).matches(inputSecuence[i])) + } + + val wrongInputSecuence = arrayOf("]", "admpkk", "abcabcd124k654abb", "abwcabccbacababb", + "abababdeababdeabb", "abcabcacbacbabb", "acdcbecbaabb", "acbotyabb", "adbcaecdbmopabcoabb", + "jhfkjhaSDFGHJk;dfhHNJMjkhfabb", "+*?a?+*abb", "sdf+ghjkabb") + + for (i in correctTestPatterns.indices) { + assertFalse("pattern: " + correctTestPatterns[i] + " input: " + wrongInputSecuence[i], + Regex(correctTestPatterns[i]).matches(wrongInputSecuence[i])) + } + } + + @Test fun testRangesSpecialCases() { + val neg_patterns = arrayOf("[a-&&[b-c]]", "[a-\\w]", "[b-a]", "[]") + + for (element in neg_patterns) { + try { + Regex(element) + fail("PatternSyntaxException was expected: " + element) + } catch (pse: PatternSyntaxException) { + } + + } + + val pos_patterns = arrayOf("[-]+", "----", "[a-]+", "a-a-a-a-aa--", "[\\w-a]+", "123-2312--aaa-213", "[a-]]+", "-]]]]]]]]]]]]]]]") + + var i = 0 + while (i < pos_patterns.size) { + val pat = pos_patterns[i++] + val inp = pos_patterns[i] + assertTrue("pattern: $pat input: $inp", Regex(pat).matches(inp)) + i++ + } + } + + @Test fun testZeroSymbols() { + assertTrue(Regex("[\u0000]*abb").matches("\u0000\u0000\u0000\u0000\u0000\u0000abb")) + } + + @Test fun testEscapes() { + val regex = Regex("\\Q{]()*?") + assertTrue(regex.matches("{]()*?")) + } + + @Test fun testRegressions() { + // Bug 181 + Regex("[\\t-\\r]") + + // HARMONY-4472 + Regex("a*.+") + + // Bug187 + Regex("|(?idmsux-idmsux)|(?idmsux-idmsux)|[^|\\[-\\0274|\\,-\\\\[^|W\\}\\nq\\x65\\002\\xFE\\05\\06\\00\\x66\\x47i\\,\\xF2\\=\\06\\u0EA4\\x9B\\x3C\\f\\|\\{\\xE5\\05\\r\\u944A\\xCA\\e|\\x19\\04\\x07\\04\\u607B\\023\\0073\\x91Tr\\0150\\x83]]?(?idmsux-idmsux:\\p{Alpha}{7}?)||(?<=[^\\uEC47\\01\\02\\u3421\\a\\f\\a\\013q\\035w\\e])(?<=\\p{Punct}{0,}?)(?=^\\p{Lower})(?!\\b{8,14})(?[\\x3E-\\]])|(?idmsux-idmsux:\\p{Punct})|(?[|\\n\\042\\uB09F\\06\\u0F2B\\uC96D\\x89\\uC166\\xAA|\\04-\\][^|\\a\\|\\rx\\04\\uA770\\n\\02\\t\\052\\056\\0274\\|\\=\\07\\e|\\00-\\x1D&&[^\\005\\uB15B\\uCDAC\\n\\x74\\0103\\0147\\uD91B\\n\\062G\\u9B4B\\077\\}\\0324&&[^\\0302\\,\\0221\\04\\u6D16\\04xy\\uD193\\[\\061\\06\\045\\x0F|\\e\\xBB\\f\\u1B52\\023\\u3AD2\\033\\007\\022\\}\\x66\\uA63FJ-\\0304]]]]{0,0})||(?^+)|(?![^|\\|\\nJ\\t\\<\\04E\\\\\\t\\01\\\\\\02\\|\\=\\}\\xF3\\uBEC2\\032K\\014\\uCC5F\\072q\\|\\0153\\xD9\\0322\\uC6C8[^\\t\\0342\\x34\\x91\\06\\{\\xF1\\a\\u1710\\?\\xE7\\uC106\\02pF\\<&&[^|\\]\\064\\u381D\\u50CF\\eO&&[^|\\06\\x2F\\04\\045\\032\\u8536W\\0377\\0017|\\x06\\uE5FA\\05\\xD4\\020\\04c\\xFC\\02H\\x0A\\r]]]]+?)(?idmsux-idmsux)|(?[\\{-\\0207|\\06-\\0276\\p{XDigit}])(?idmsux-idmsux:[^|\\x52\\0012\\]u\\xAD\\0051f\\0142\\\\l\\|\\050\\05\\f\\t\\u7B91\\r\\u7763\\{|h\\0104\\a\\f\\0234\\u2D4F&&^\\P{InGreek}]))") + + // HARMONY-5858 + Regex("\\u6211", RegexOption.LITERAL) + } + + @Test fun testOrphanQuantifiers() { + try { + Regex("+++++") + fail("PatternSyntaxException expected") + } catch (pse: PatternSyntaxException) { + } + + } + + @Test fun testOrphanQuantifiers2() { + try { + Regex("\\d+*") + fail("PatternSyntaxException expected") + } catch (pse: PatternSyntaxException) { + } + + } + + @Test fun testBug197() { + val vals = arrayOf(":", 2, arrayOf("boo", "and:foo"), + ":", 5, arrayOf("boo", "and", "foo"), + ":", 0, arrayOf("boo", "and", "foo"), + ":", 3, arrayOf("boo", "and", "foo"), + ":", 1, arrayOf("boo:and:foo"), + "o", 5, arrayOf("b", "", ":and:f", "", ""), + "o", 4, arrayOf("b", "", ":and:f", "o"), + "o", 0, arrayOf("b", "", ":and:f", "", "") + ) + + var i = 0 + while (i < vals.size / 3) { + val res = Regex(vals[i++].toString()).split("boo:and:foo", (vals[i++] as Int)) + val expectedRes = vals[i++] as Array + + assertEquals(expectedRes.size, res.size) + + for (j in expectedRes.indices) { + assertEquals(expectedRes[j], res[j]) + } + } + } + + @Test fun testURIPatterns() { + val URI_REGEXP_STR = "^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"; + val SCHEME_REGEXP_STR = "^[a-zA-Z]{1}[\\w+-.]+$"; + val REL_URI_REGEXP_STR = "^(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"; + val IPV6_REGEXP_STR = "^[0-9a-fA-F\\:\\.]+(\\%\\w+)?$"; + val IPV6_REGEXP_STR2 = "^\\[[0-9a-fA-F\\:\\.]+(\\%\\w+)?\\]$"; + val IPV4_REGEXP_STR = "^[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}\\.[0-9]{1,3}$"; + val HOSTNAME_REGEXP_STR = "\\w+[\\w\\-\\.]*"; + + Regex(URI_REGEXP_STR) + Regex(REL_URI_REGEXP_STR) + Regex(SCHEME_REGEXP_STR) + Regex(IPV4_REGEXP_STR) + Regex(IPV6_REGEXP_STR) + Regex(IPV6_REGEXP_STR2) + Regex(HOSTNAME_REGEXP_STR) + } + + @Test fun testFindBoundaryCases1() { + val regex = Regex(".*\n") + val result = regex.find("a\n") + + assertNotNull(result) + assertEquals("a\n", result!!.value) + } + + @Test fun testFindBoundaryCases2() { + val regex = Regex(".*A") + val result = regex.find("aAa") + + assertNotNull(result) + assertEquals("aA", result!!.value) + + } + + @Test fun testFindBoundaryCases3() { + val regex = Regex(".*A") + val result = regex.find("a\naA\n") + + assertNotNull(result) + assertEquals("aA", result!!.value) + + } + + @Test fun testFindBoundaryCases4() { + val regex = Regex("A.*") + val result = regex.find("A\n") + + assertNotNull(result) + assertEquals("A", result!!.value) + + } + + @Test fun testFindBoundaryCases5() { + val regex = Regex(".*A.*") + var result = regex.find("\nA\naaa\nA\naaAaa\naaaA\n") + val expected = arrayOf("A", "A", "aaAaa", "aaaA") + + var k = 0 + while (result != null) { + assertEquals(expected[k], result.value) + result = result.next() + k++ + } + } + + @Test fun testFindBoundaryCases6() { + val regex = Regex(".*") + var result = regex.find("\na\n") + val expected = arrayOf("", "a", "", "") + + var k = 0 + while (result != null) { + assertEquals(expected[k], result.value) + k++ + result = result.next() + } + } + + @Test fun testBackReferences() { + var regex = Regex("(\\((\\w*):(.*):(\\2)\\))") + var result = regex.find("(start1: word :start1)(start2: word :start2)") + + var k = 1 + while (result != null) { + assertEquals("start" + k, result.groupValues[2]) + assertEquals(" word ", result.groupValues[3]) + assertEquals("start" + k, result.groupValues[4]) + k++ + result = result.next() + } + + assertEquals(3, k) + regex = Regex(".*(.)\\1") + assertTrue(regex.matches("saa")) + } + + @Test fun testNewLine() { + val regex = Regex("(^$)*\n", RegexOption.MULTILINE) + var result = regex.find("\r\n\n") + var counter = 0 + while (result != null) { + counter++ + result = result.next() + } + assertEquals(2, counter) + } + + @Test fun testFindGreedy() { + val regex = Regex(".*aaa", RegexOption.DOT_MATCHES_ALL) + val result = regex.matchEntire("aaaa\naaa\naaaaaa") + assertNotNull(result) + assertEquals(14, result!!.range.endInclusive) + } + + @Test fun testSOLQuant() { + val regex = Regex("$*", RegexOption.MULTILINE) + var result = regex.find("\n\n") + var counter = 0 + while (result != null) { + counter++ + result = result.next() + } + assertEquals(3, counter) + } + + @Test fun testIllegalEscape() { + try { + Regex("\\y") + fail("PatternSyntaxException expected") + } catch (pse: PatternSyntaxException) { + } + } + + @Test fun testEmptyFamily() { + Regex("\\p{Lower}") + } + + @Test fun testNonCaptConstr() { + // Flags + var regex = Regex("(?i)b*(?-i)a*") + assertTrue(regex.matches("bBbBaaaa")) + assertFalse(regex.matches("bBbBAaAa")) + + // Non-capturing groups + regex = Regex("(?i:b*)a*") + assertTrue(regex.matches("bBbBaaaa")) + assertFalse(regex.matches("bBbBAaAa")) + + // 1 2 3 4 5 6 7 8 9 10 11 + regex = Regex("(?:-|(-?\\d+\\d\\d\\d))?(?:-|-(\\d\\d))?(?:-|-(\\d\\d))?(T)?(?:(\\d\\d):(\\d\\d):(\\d\\d)(\\.\\d+)?)?(?:(?:((?:\\+|\\-)\\d\\d):(\\d\\d))|(Z))?") + val result = regex.matchEntire("-1234-21-31T41:51:61.789+71:81") + assertNotNull(result) + assertEquals("-1234", result!!.groupValues[1]) + assertEquals("21", result.groupValues[2]) + assertEquals("31", result.groupValues[3]) + assertEquals("T", result.groupValues[4]) + assertEquals("41", result.groupValues[5]) + assertEquals("51", result.groupValues[6]) + assertEquals("61", result.groupValues[7]) + assertEquals(".789", result.groupValues[8]) + assertEquals("+71", result.groupValues[9]) + assertEquals("81", result.groupValues[10]) + + // positive lookahead + regex = Regex(".*\\.(?=log$).*$") + assertTrue(regex.matches("a.b.c.log")) + assertFalse(regex.matches("a.b.c.log.")) + + // negative lookahead + regex = Regex(".*\\.(?!log$).*$") + assertFalse(regex.matches("abc.log")) + assertTrue(regex.matches("abc.logg")) + + // positive lookbehind + regex = Regex(".*(?<=abc)\\.log$") + assertFalse(regex.matches("cde.log")) + assertTrue(regex.matches("abc.log")) + + // negative lookbehind + regex = Regex(".*(?a*)abb") + assertFalse(regex.matches("aaabb")) + regex = Regex("(?>a*)bb") + assertTrue(regex.matches("aaabb")) + + regex = Regex("(?>a|aa)aabb") + assertTrue(regex.matches("aaabb")) + regex = Regex("(?>aa|a)aabb") + assertFalse(regex.matches("aaabb")) + + // quantifiers over look ahead + regex = Regex(".*(?<=abc)*\\.log$") + assertTrue(regex.matches("cde.log")) + regex = Regex(".*(?<=abc)+\\.log$") + assertFalse(regex.matches("cde.log")) + } + + @Test fun testCompilePatternWithTerminatorMark() { + val regex = Regex("a\u0000\u0000cd") + assertTrue(regex.matches("a\u0000\u0000cd")) + } + + @Test fun testAlternations() { + var baseString = "|a|bc" + var regex = Regex(baseString) + assertTrue(regex.matches("")) + + baseString = "a||bc" + regex = Regex(baseString) + assertTrue(regex.matches("")) + + baseString = "a|bc|" + regex = Regex(baseString) + assertTrue(regex.matches("")) + + baseString = "a|b|" + regex = Regex(baseString) + assertTrue(regex.matches("")) + + baseString = "a(|b|cd)e" + regex = Regex(baseString) + assertTrue(regex.matches("ae")) + + baseString = "a(b||cd)e" + regex = Regex(baseString) + assertTrue(regex.matches("ae")) + + baseString = "a(b|cd|)e" + regex = Regex(baseString) + assertTrue(regex.matches("ae")) + + baseString = "a(b|c|)e" + regex = Regex(baseString) + assertTrue(regex.matches("ae")) + + baseString = "a(|)e" + regex = Regex(baseString) + assertTrue(regex.matches("ae")) + + baseString = "|" + regex = Regex(baseString) + assertTrue(regex.matches("")) + + baseString = "a(?:|)e" + regex = Regex(baseString) + assertTrue(regex.matches("ae")) + + baseString = "a||||bc" + regex = Regex(baseString) + assertTrue(regex.matches("")) + + baseString = "(?i-is)|a" + regex = Regex(baseString) + assertTrue(regex.matches("a")) + } + + @Test fun testMatchWithGroups() { + var baseString = "jwkerhjwehrkwjehrkwjhrwkjehrjwkehrjkwhrkwehrkwhrkwrhwkhrwkjehr" + var pattern = ".*(..).*\\1.*" + assertTrue(Regex(pattern).matches(baseString)) + + baseString = "saa" + pattern = ".*(.)\\1" + assertTrue(Regex(pattern).matches(baseString)) + assertTrue(Regex(pattern).containsMatchIn(baseString)) + } + + @Test fun testSplitEmptyCharSequence() { + val s1 = "" + val arr = s1.split(":".toRegex()) + assertEquals(arr.size, 1) + } + + @Test fun testSplitEndsWithPattern() { + assertEquals(",,".split(",".toRegex(), 3).toTypedArray().size, 3) + assertEquals(",,".split(",".toRegex(), 4).toTypedArray().size, 3) + + assertEquals(Regex("o").split("boo:and:foo", 5).size, 5) + assertEquals(Regex("b").split("ab", 0).size, 2) + } + + @Test fun testCaseInsensitiveFlag() { + assertTrue(Regex("(?i-:AbC)").matches("ABC")) + } + + @Test fun testEmptyGroups() { + var regex = Regex("ab(?>)cda") + assertTrue(regex.matches("abcda")) + + regex = Regex("ab()") + assertTrue(regex.matches("ab")) + + regex = Regex("abc(?:)(..)") + assertTrue(regex.matches("abcgf")) + } + + @Test fun testCompileNonCaptGroup() { + var isCompiled = false + + try { + Regex("(?:)", RegexOption.CANON_EQ) + Regex("(?:)", setOf(RegexOption.CANON_EQ, RegexOption.DOT_MATCHES_ALL)) + Regex("(?:)", setOf(RegexOption.CANON_EQ, RegexOption.IGNORE_CASE)) + Regex("(?:)", setOf(RegexOption.CANON_EQ, RegexOption.COMMENTS, RegexOption.UNIX_LINES)) + isCompiled = true + } catch (e: PatternSyntaxException) { + println(e) + } + assertTrue(isCompiled) + } + + @Test fun testEmbeddedFlags() { + var baseString = "(?i)((?s)a)" + var testString = "A" + var regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "(?x)(?i)(?s)(?d)a" + testString = "A" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "(?x)(?i)(?s)(?d)a." + testString = "a\n" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "abc(?x:(?i)(?s)(?d)a.)" + testString = "abcA\n" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + + baseString = "abc((?x)d)(?i)(?s)a" + testString = "abcdA" + regex = Regex(baseString) + assertTrue(regex.matches(testString)) + } + + @Test fun testAltWithFlags() { + Regex("|(?i-xi)|()") + } + + @Test fun testRestoreFlagsAfterGroup() { + val baseString = "abc((?x)d) a" + val testString = "abcd a" + val regex = Regex(baseString) + assertTrue(regex.matches(testString)) + } + + @Test fun testCanonEqFlag() { + + /* + * for decompositions see + * http://www.unicode.org/Public/4.0-Update/UnicodeData-4.0.0.txt + * http://www.unicode.org/reports/tr15/#Decomposition + */ + var baseString: String + var testString: String + var regex: Regex + + baseString = "ab(a*)\\u0001" + regex = Regex(baseString, RegexOption.CANON_EQ) + + baseString = "a(abcdf)d" + regex = Regex(baseString, RegexOption.CANON_EQ) + + baseString = "aabcdfd" + regex = Regex(baseString, RegexOption.CANON_EQ) + + // \u01E0 -> \u0226\u0304 ->\u0041\u0307\u0304 + // \u00CC -> \u0049\u0300 + + baseString = "\u01E0\u00CCcdb(ac)" + testString = "\u0226\u0304\u0049\u0300cdbac" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\u01E0cdb(a\u00CCc)" + testString = "\u0041\u0307\u0304cdba\u0049\u0300c" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "a\u00CC" + testString = "a\u0049\u0300" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\u0226\u0304cdb(ac\u0049\u0300)" + testString = "\u01E0cdbac\u00CC" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "cdb(?:\u0041\u0307\u0304\u00CC)" + testString = "cdb\u0226\u0304\u0049\u0300" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\u01E0[a-c]\u0049\u0300cdb(ac)" + testString = "\u01E0b\u00CCcdbac" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\u01E0|\u00CCcdb(ac)" + testString = "\u0041\u0307\u0304" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\u00CC?cdb(ac)*(\u01E0)*[a-c]" + testString = "cdb\u0041\u0307\u0304b" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "a\u0300" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.containsMatchIn("a\u00E0a")) + + baseString = "\u7B20\uF9F8abc" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches("\uF9F8\uF9F8abc")) + + // \u01F9 -> \u006E\u0300 + // \u00C3 -> \u0041\u0303 + + baseString = "cdb(?:\u00C3\u006E\u0300)" + testString = "cdb\u0041\u0303\u01F9" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + // \u014C -> \u004F\u0304 + // \u0163 -> \u0074\u0327 + + baseString = "cdb(?:\u0163\u004F\u0304)" + testString = "cdb\u0074\u0327\u014C" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + // \u00E1->a\u0301 + // canonical ordering takes place \u0301\u0327 -> \u0327\u0301 + + baseString = "c\u0327\u0301" + testString = "c\u0301\u0327" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + /* + * Hangul decompositions + */ + // \uD4DB->\u1111\u1171\u11B6 + // \uD21E->\u1110\u116D\u11B5 + // \uD264->\u1110\u1170 + // not Hangul:\u0453->\u0433\u0301 + baseString = "a\uD4DB\u1111\u1171\u11B6\uD264" + regex = Regex(baseString, RegexOption.CANON_EQ) + + baseString = "\u0453c\uD4DB" + regex = Regex(baseString, RegexOption.CANON_EQ) + + baseString = "a\u1110\u116D\u11B5b\uD21Ebc" + regex = Regex(baseString, RegexOption.CANON_EQ) + + baseString = "\uD4DB\uD21E\u1110\u1170cdb(ac)" + testString = "\u1111\u1171\u11B6\u1110\u116D\u11B5\uD264cdbac" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\uD4DB\uD264cdb(a\uD21Ec)" + testString = "\u1111\u1171\u11B6\u1110\u1170cdba\u1110\u116D\u11B5c" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "a\uD4DB" + testString = "a\u1111\u1171\u11B6" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "a\uD21E" + testString = "a\u1110\u116D\u11B5" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\u1111\u1171\u11B6cdb(ac\u1110\u116D\u11B5)" + testString = "\uD4DBcdbac\uD21E" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "cdb(?:\u1111\u1171\u11B6\uD21E)" + testString = "cdb\uD4DB\u1110\u116D\u11B5" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\uD4DB[a-c]\u1110\u116D\u11B5cdb(ac)" + testString = "\uD4DBb\uD21Ecdbac" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\uD4DB|\u00CCcdb(ac)" + testString = "\u1111\u1171\u11B6" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\uD4DB|\u00CCcdb(ac)" + testString = "\u1111\u1171" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertFalse(regex.matches(testString)) + + baseString = "\u00CC?cdb(ac)*(\uD4DB)*[a-c]" + testString = "cdb\u1111\u1171\u11B6b" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + baseString = "\uD4DB" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertTrue(regex.containsMatchIn("a\u1111\u1171\u11B6a")) + + baseString = "\u1111" + regex = Regex(baseString, RegexOption.CANON_EQ) + assertFalse(regex.containsMatchIn("bcda\uD4DBr")) + } + + @Test fun testIndexesCanonicalEq() { + var baseString: String + var testString: String + var regex: Regex + var result: MatchResult? + + baseString = "\uD4DB" + testString = "bcda\u1111\u1171\u11B6awr" + regex = Regex(baseString, RegexOption.CANON_EQ) + result = regex.find(testString) + assertNotNull(result) + assertEquals(result!!.range.start, 4) + assertEquals(result.range.endInclusive, 6) + + baseString = "\uD4DB\u1111\u1171\u11B6" + testString = "bcda\u1111\u1171\u11B6\uD4DBawr" + regex = Regex(baseString, RegexOption.CANON_EQ) + result = regex.find(testString) // Use the same testString + assertNotNull(result) + assertEquals(result!!.range.start, 4) + assertEquals(result.range.endInclusive, 7) + + baseString = "\uD4DB\uD21E\u1110\u1170" + testString = "abcabc\u1111\u1171\u11B6\u1110\u116D\u11B5\uD264cdbac" + regex = Regex(baseString, RegexOption.CANON_EQ) + result = regex.find(testString) + assertNotNull(result) + assertEquals(result!!.range.start, 6) + assertEquals(result.range.endInclusive, 12) + } + + @Test fun testCanonEqFlagWithSupplementaryCharacters() { + + /* + * \u1D1BF->\u1D1BB\u1D16F->\u1D1B9\u1D165\u1D16F in UTF32 + * \uD834\uDDBF->\uD834\uDDBB\uD834\uDD6F + * ->\uD834\uDDB9\uD834\uDD65\uD834\uDD6F in UTF16 + */ + var patString = "abc\uD834\uDDBFef" + var testString = "abc\uD834\uDDB9\uD834\uDD65\uD834\uDD6Fef" + var regex = Regex(patString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + testString = "abc\uD834\uDDBB\uD834\uDD6Fef" + assertTrue(regex.matches(testString)) + + patString = "abc\uD834\uDDBB\uD834\uDD6Fef" + testString = "abc\uD834\uDDBFef" + regex = Regex(patString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + testString = "abc\uD834\uDDB9\uD834\uDD65\uD834\uDD6Fef" + assertTrue(regex.matches(testString)) + + patString = "abc\uD834\uDDB9\uD834\uDD65\uD834\uDD6Fef" + testString = "abc\uD834\uDDBFef" + regex = Regex(patString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + + testString = "abc\uD834\uDDBB\uD834\uDD6Fef" + assertTrue(regex.matches(testString)) + + /* + * testSupplementary characters with no decomposition + */ + patString = "a\uD9A0\uDE8Ebc\uD834\uDDBB\uD834\uDD6Fe\uDE8Ef" + testString = "a\uD9A0\uDE8Ebc\uD834\uDDBFe\uDE8Ef" + regex = Regex(patString, RegexOption.CANON_EQ) + assertTrue(regex.matches(testString)) + } + + @Test fun testRangesWithSurrogatesSupplementary() { + var patString = "[abc\uD8D2]" + var testString = "\uD8D2" + var regex = Regex(patString) + assertTrue(regex.matches(testString)) + + testString = "a" + assertTrue(regex.matches(testString)) + + testString = "ef\uD8D2\uDD71gh" + assertFalse(regex.containsMatchIn(testString)) + + testString = "ef\uD8D2gh" + assertTrue(regex.containsMatchIn(testString)) + + patString = "[abc\uD8D3&&[c\uD8D3]]" + testString = "c" + regex = Regex(patString) + assertTrue(regex.matches(testString)) + + testString = "a" + assertFalse(regex.matches(testString)) + + testString = "ef\uD8D3\uDD71gh" + assertFalse(regex.containsMatchIn(testString)) + + testString = "ef\uD8D3gh" + assertTrue(regex.containsMatchIn(testString)) + + patString = "[abc\uD8D3\uDBEE\uDF0C&&[c\uD8D3\uDBEE\uDF0C]]" + testString = "c" + regex = Regex(patString) + assertTrue(regex.matches(testString)) + + testString = "\uDBEE\uDF0C" + assertTrue(regex.matches(testString)) + + testString = "ef\uD8D3\uDD71gh" + assertFalse(regex.containsMatchIn(testString)) + + testString = "ef\uD8D3gh" + assertTrue(regex.containsMatchIn(testString)) + + patString = "[abc\uDBFC]\uDDC2cd" + testString = "\uDBFC\uDDC2cd" + regex = Regex(patString) + assertFalse(regex.matches(testString)) + + testString = "a\uDDC2cd" + assertTrue(regex.matches(testString)) + } + + @Test fun testSequencesWithSurrogatesSupplementary() { + var patString = "abcd\uD8D3" + var testString = "abcd\uD8D3\uDFFC" + var regex = Regex(patString) + assertFalse(regex.containsMatchIn(testString)) + + testString = "abcd\uD8D3abc" + assertTrue(regex.containsMatchIn(testString)) + + patString = "ab\uDBEFcd" + testString = "ab\uDBEFcd" + regex = Regex(patString) + assertTrue(regex.matches(testString)) + + patString = "\uDFFCabcd" + testString = "\uD8D3\uDFFCabcd" + regex = Regex(patString) + assertFalse(regex.containsMatchIn(testString)) + + testString = "abc\uDFFCabcdecd" + assertTrue(regex.containsMatchIn(testString)) + + patString = "\uD8D3\uDFFCabcd" + testString = "abc\uD8D3\uD8D3\uDFFCabcd" + regex = Regex(patString) + assertTrue(regex.containsMatchIn(testString)) + } + + @Test fun testPredefinedClassesWithSurrogatesSupplementary() { + var patString = "[123\\D]" + var testString = "a" + var regex = Regex(patString) + assertTrue(regex.containsMatchIn(testString)) + + testString = "5" + assertFalse(regex.containsMatchIn(testString)) + + testString = "3" + assertTrue(regex.containsMatchIn(testString)) + + // low surrogate + testString = "\uDFC4" + assertTrue(regex.containsMatchIn(testString)) + + // high surrogate + testString = "\uDADA" + assertTrue(regex.containsMatchIn(testString)) + + testString = "\uDADA\uDFC4" + assertTrue(regex.containsMatchIn(testString)) + + testString = "5" + assertFalse(regex.containsMatchIn(testString)) + + testString = "3" + assertTrue(regex.containsMatchIn(testString)) + + // low surrogate + testString = "\uDFC4" + assertTrue(regex.containsMatchIn(testString)) + + // high surrogate + testString = "\uDADA" + assertTrue(regex.containsMatchIn(testString)) + + testString = "\uDADA\uDFC4" + assertTrue(regex.containsMatchIn(testString)) + + // surrogate characters + patString = "\\p{Cs}" + testString = "\uD916\uDE27" + regex = Regex(patString) + /* + * see http://www.unicode.org/reports/tr18/#Supplementary_Characters we + * have to treat text as code points not code units. \\p{Cs} matches any + * surrogate character but here testString is a one code point + * consisting of two code units (two surrogate characters) so we find + * nothing + */ + assertFalse(regex.containsMatchIn(testString)) + + // swap low and high surrogates + testString = "\uDE27\uD916" + assertTrue(regex.containsMatchIn(testString)) + + patString = "[\uD916\uDE271\uD91623&&[^\\p{Cs}]]" + testString = "1" + regex = Regex(patString) + assertTrue(regex.containsMatchIn(testString)) + + testString = "\uD916" + regex = Regex(patString) + assertFalse(regex.containsMatchIn(testString)) + + testString = "\uD916\uDE27" + regex = Regex(patString) + assertTrue(regex.containsMatchIn(testString)) + + // \uD9A0\uDE8E=\u7828E + // \u78281=\uD9A0\uDE81 + patString = "[a-\uD9A0\uDE8E]" + testString = "\uD9A0\uDE81" + regex = Regex(patString) + assertTrue(regex.matches(testString)) + } + + @Test fun testDotConstructionWithSurrogatesSupplementary() { + var patString = "." + var testString = "\uD9A0\uDE81" + var regex = Regex(patString) + assertTrue(regex.matches(testString)) + + testString = "\uDE81" + assertTrue(regex.matches(testString)) + + testString = "\uD9A0" + assertTrue(regex.matches(testString)) + + testString = "\n" + assertFalse(regex.matches(testString)) + + patString = ".*\uDE81" + testString = "\uD9A0\uDE81\uD9A0\uDE81\uD9A0\uDE81" + regex = Regex(patString) + assertFalse(regex.matches(testString)) + + testString = "\uD9A0\uDE81\uD9A0\uDE81\uDE81" + assertTrue(regex.matches(testString)) + + patString = ".*" + testString = "\uD9A0\uDE81\n\uD9A0\uDE81\uD9A0\n\uDE81" + regex = Regex(patString, RegexOption.DOT_MATCHES_ALL) + assertTrue(regex.matches(testString)) + } + + @Test fun testQuantifiersWithSurrogatesSupplementary() { + val patString = "\uD9A0\uDE81*abc" + var testString = "\uD9A0\uDE81\uD9A0\uDE81abc" + val regex = Regex(patString) + assertTrue(regex.matches(testString)) + + testString = "abc" + assertTrue(regex.matches(testString)) + } + + @Test fun testAlternationsWithSurrogatesSupplementary() { + val patString = "\uDE81|\uD9A0\uDE81|\uD9A0" + var testString = "\uD9A0" + val regex = Regex(patString) + assertTrue(regex.matches(testString)) + + testString = "\uDE81" + assertTrue(regex.matches(testString)) + + testString = "\uD9A0\uDE81" + assertTrue(regex.matches(testString)) + + testString = "\uDE81\uD9A0" + assertFalse(regex.matches(testString)) + } + + @Test fun testGroupsWithSurrogatesSupplementary() { + + // this pattern matches nothing + var patString = "(\uD9A0)\uDE81" + var testString = "\uD9A0\uDE81" + var regex = Regex(patString) + assertFalse(regex.matches(testString)) + + patString = "(\uD9A0)" + testString = "\uD9A0\uDE81" + regex = Regex(patString, RegexOption.DOT_MATCHES_ALL) + assertFalse(regex.containsMatchIn(testString)) + } +} diff --git a/backend.native/tests/stdlib_external/text/harmony_regex/PatternTest2.kt b/backend.native/tests/stdlib_external/text/harmony_regex/PatternTest2.kt new file mode 100644 index 00000000000..53ea11d1019 --- /dev/null +++ b/backend.native/tests/stdlib_external/text/harmony_regex/PatternTest2.kt @@ -0,0 +1,1195 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.text.harmony_regex + +import kotlin.text.* +import kotlin.test.* + +class PatternTest2 { + + fun assertTrue(msg: String, value: Boolean) = assertTrue(value, msg) + fun assertFalse(msg: String, value: Boolean) = assertFalse(value, msg) + + /** + * Tests simple pattern compilation and matching methods + */ + @Test fun testSimpleMatch() { + val regex = Regex("foo.*") + + var testString = "foo123" + assertTrue(regex.matches(testString)) + assertTrue(regex.containsMatchIn(testString, 0)) + assertTrue(regex.lookingAt(testString)) + + testString = "fox" + assertFalse(regex.matches(testString)) + assertFalse(regex.containsMatchIn(testString, 0)) + assertFalse(regex.lookingAt(testString)) + + assertTrue(Regex("foo.*").matches("foo123")) + assertFalse(Regex("foo.*").matches("fox")) + assertFalse(Regex("bar").matches("foobar")) + assertTrue(Regex("").matches("")) + } + + @Test fun testCursors() { + val regex: Regex + var result: MatchResult? + + try { + regex = Regex("foo") + + result = regex.find("foobar") + assertNotNull(result) + assertEquals(0, result!!.range.start) + assertEquals(3, result.range.endInclusive + 1) + assertNull(result.next()) + + + result = regex.find("barfoobar") + assertNotNull(result) + assertEquals(3, result!!.range.start) + assertEquals(6, result.range.endInclusive + 1) + assertNull(result.next()) + + result = regex.find("barfoo") + assertNotNull(result) + assertEquals(3, result!!.range.start) + assertEquals(6, result.range.endInclusive + 1) + assertNull(result.next()) + + result = regex.find("foobarfoobarfoo") + assertNotNull(result) + assertEquals(0, result!!.range.start) + assertEquals(3, result.range.endInclusive + 1) + result = result.next() + assertNotNull(result) + assertEquals(6, result!!.range.start) + assertEquals(9, result.range.endInclusive + 1) + result = result.next() + assertNotNull(result) + assertEquals(12, result!!.range.start) + assertEquals(15, result.range.endInclusive + 1) + assertNull(result.next()) + + result = regex.find("foobarfoobarfoo", 0) + assertNotNull(result) + assertEquals(0, result!!.range.start) + assertEquals(3, result.range.endInclusive + 1) + + result = regex.find("foobarfoobarfoo", 4) + assertNotNull(result) + assertEquals(6, result!!.range.start) + assertEquals(9, result.range.endInclusive + 1) + } catch (e: PatternSyntaxException) { + println(e.message) + fail() + } + + } + + @Test fun testGroups() { + val regex: Regex + var result: MatchResult? + + regex = Regex("(p[0-9]*)#?(q[0-9]*)") + + result = regex.find("p1#q3p2q42p5p71p63#q888") + assertNotNull(result) + assertEquals(0, result!!.range.start) + assertEquals(5, result.range.endInclusive + 1) + assertEquals(3, result.groups.size) + assertEquals(0, result.groups[0]!!.range.start) + assertEquals(5, result.groups[0]!!.range.endInclusive + 1) + assertEquals(0, result.groups[1]!!.range.start) + assertEquals(2, result.groups[1]!!.range.endInclusive + 1) + assertEquals(3, result.groups[2]!!.range.start) + assertEquals(5, result.groups[2]!!.range.endInclusive + 1) + assertEquals("p1#q3", result.value) + assertEquals("p1#q3", result.groupValues[0]) + assertEquals("p1", result.groupValues[1]) + assertEquals("q3", result.groupValues[2]) + + result = result.next() + assertNotNull(result) + assertEquals(5, result!!.range.start) + assertEquals(10, result.range.endInclusive + 1) + assertEquals(3, result.groups.size) + assertEquals(10, result.groups[0]!!.range.endInclusive + 1) + assertEquals(5, result.groups[1]!!.range.start) + assertEquals(7, result.groups[1]!!.range.endInclusive + 1) + assertEquals(7, result.groups[2]!!.range.start) + assertEquals(10, result.groups[2]!!.range.endInclusive + 1) + assertEquals("p2q42", result.value) + assertEquals("p2q42", result.groupValues[0]) + assertEquals("p2", result.groupValues[1]) + assertEquals("q42", result.groupValues[2]) + + result = result.next() + assertNotNull(result) + assertEquals(15, result!!.range.start) + assertEquals(23, result.range.endInclusive + 1) + assertEquals(3, result.groups.size) + assertEquals(15, result.groups[0]!!.range.start) + assertEquals(23, result.groups[0]!!.range.endInclusive + 1) + assertEquals(15, result.groups[1]!!.range.start) + assertEquals(18, result.groups[1]!!.range.endInclusive + 1) + assertEquals(19, result.groups[2]!!.range.start) + assertEquals(23, result.groups[2]!!.range.endInclusive + 1) + assertEquals("p63#q888", result.value) + assertEquals("p63#q888", result.groupValues[0]) + assertEquals("p63", result.groupValues[1]) + assertEquals("q888", result.groupValues[2]) + assertNull(result.next()) + } + + @Test fun testReplace() { + var regex: Regex + + // Note: examples from book, + // Hitchens, Ron, 2002, "Java NIO", O'Reilly, page 171 + regex = Regex("a*b") + + var testString = "aabfooaabfooabfoob" + assertTrue(regex.replace(testString, "-") == "-foo-foo-foo-") + assertTrue(regex.replaceFirst(testString, "-") == "-fooaabfooabfoob") + + regex = Regex("([bB])yte") + + testString = "Byte for byte" + assertTrue(regex.replaceFirst(testString, "$1ite") == "Bite for byte") + assertTrue(regex.replace(testString, "$1ite") == "Bite for bite") + + regex = Regex("\\d\\d\\d\\d([- ])") + + testString = "card #1234-5678-1234" + assertTrue(regex.replaceFirst(testString, "xxxx$1") == "card #xxxx-5678-1234") + assertTrue(regex.replace(testString, "xxxx$1") == "card #xxxx-xxxx-1234") + + regex = Regex("(up|left)( *)(right|down)") + + testString = "left right, up down" + assertTrue(regex.replaceFirst(testString, "$3$2$1") == "right left, up down") + assertTrue(regex.replace(testString, "$3$2$1") == "right left, down up") + + regex = Regex("([CcPp][hl]e[ea]se)") + + testString = "I want cheese. Please." + assertTrue(regex.replaceFirst(testString, " $1 ") == "I want cheese . Please.") + assertTrue(regex.replace(testString, " $1 ") == "I want cheese . Please .") + } + + @Test fun testEscapes() { + var regex: Regex + var result: MatchResult? + + // Test \\ sequence + regex = Regex("([a-z]+)\\\\([a-z]+);") + result = regex.find("fred\\ginger;abbott\\costello;jekell\\hyde;") + assertNotNull(result) + assertEquals("fred", result!!.groupValues[1]) + assertEquals("ginger", result.groupValues[2]) + result = result.next() + assertNotNull(result) + assertEquals("abbott", result!!.groupValues[1]) + assertEquals("costello", result.groupValues[2]) + result = result.next() + assertNotNull(result) + assertEquals("jekell", result!!.groupValues[1]) + assertEquals("hyde", result.groupValues[2]) + assertNull(result.next()) + + // Test \n, \t, \r, \f, \e, \a sequences + regex = Regex("([a-z]+)[\\n\\t\\r\\f\\e\\a]+([a-z]+)") + result = regex.find("aa\nbb;cc\u0009\rdd;ee\u000C\u001Bff;gg\n\u0007hh") + assertNotNull(result) + assertEquals("aa", result!!.groupValues[1]) + assertEquals("bb", result.groupValues[2]) + result = result.next() + assertNotNull(result) + assertEquals("cc", result!!.groupValues[1]) + assertEquals("dd", result.groupValues[2]) + result = result.next() + assertNotNull(result) + assertEquals("ee", result!!.groupValues[1]) + assertEquals("ff", result.groupValues[2]) + result = result.next() + assertNotNull(result) + assertEquals("gg", result!!.groupValues[1]) + assertEquals("hh", result.groupValues[2]) + assertNull(result.next()) + + // Test \\u and \\x sequences + regex = Regex("([0-9]+)[\\u0020:\\x21];") + result = regex.find("11:;22 ;33-;44!;") + assertNotNull(result) + assertEquals("11", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("22", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("44", result!!.groupValues[1]) + assertNull(result.next()) + + // Test invalid unicode sequences // TODO: Double check it. + try { + regex = Regex("\\u") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\u;") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\u002") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\u002;") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + // Test invalid hex sequences + try { + regex = Regex("\\x") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\x;") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\xa") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\xa;") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + // Test \0 (octal) sequences (1, 2 and 3 digit) + regex = Regex("([0-9]+)[\\07\\040\\0160];") + result = regex.find("11\u0007;22:;33 ;44p;") + assertNotNull(result) + assertEquals("11", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("33", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("44", result!!.groupValues[1]) + assertNull(result.next()) + + // Test invalid octal sequences + try { + regex = Regex("\\08") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\0") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\0;") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + // Test \c (control character) sequence + regex = Regex("([0-9]+)[\\cA\\cB\\cC\\cD];") + result = regex.find("11\u0001;22:;33\u0002;44p;55\u0003;66\u0004;") + assertNotNull(result) + assertEquals("11", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("33", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("55", result!!.groupValues[1]) + result = result.next() + assertNotNull(result) + assertEquals("66", result!!.groupValues[1]) + assertNull(result.next()) + + // More thorough control escape test + // Ensure that each escape matches exactly the corresponding + // character + // code and no others (well, from 0-255 at least) + for (i in 0..25) { + regex = Regex("\\c${'A' + i}") + var match_char = -1 + for (j in 0..255) { + if (regex.matches("${j.toChar()}")) { + assertEquals(-1, match_char) + match_char = j + } + } + assertTrue(match_char == i + 1) + } + + + // Test invalid control escapes + try { + regex = Regex("\\c") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + } + + @Test fun testCharacterClasses() { + var regex: Regex + + // Test one character range + regex = Regex("[p].*[l]") + assertTrue(regex.matches("paul")) + assertTrue(regex.matches("pool")) + assertFalse(regex.matches("pong")) + assertTrue(regex.matches("pl")) + + // Test two character range + regex = Regex("[pm].*[lp]") + assertTrue(regex.matches("prop")) + assertTrue(regex.matches("mall")) + assertFalse(regex.matches("pong")) + assertTrue(regex.matches("pill")) + + // Test range including [ and ] + regex = Regex("[<\\[].*[\\]>]") + assertTrue(regex.matches("")) + assertTrue(regex.matches("[bar]")) + assertFalse(regex.matches("{foobar]")) + assertTrue(regex.matches("") + assertTrue(regex.matches("")) + assertFalse(regex.matches("")) + val result = regex.find("xyz zzz") + assertNotNull(result) + assertNotNull(result!!.next()) + assertNull(result.next()!!.next()) + + // Test \S (not whitespace) // TODO: We've removed \f from string since kotlin doesn't recognize this escape in a string. + regex = Regex("<[a-z] \\S[0-9][\\S\n]+[^\\S]221>") + assertTrue(regex.matches("")) + assertTrue(regex.matches("")) + assertFalse(regex.matches("")) + assertTrue(regex.matches("")) + regex = Regex("<[a-z] \\S[0-9][\\S\n]+[^\\S]221[\\S&&[^abc]]>") + assertTrue(regex.matches("")) + assertTrue(regex.matches("")) + assertFalse(regex.matches("")) + assertFalse(regex.matches("")) + assertFalse(regex.matches("")) + assertTrue(regex.matches("")) + + // Test \w (ascii word) + regex = Regex("<\\w+\\s[0-9]+;[^\\w]\\w+/[\\w$]+;") + assertTrue(regex.matches(""); + * m = p.matcher(""); assertTrue(m.matches()); m = p.matcher(""); + * assertTrue(m.matches()); m = p.matcher(""); + * assertFalse(m.matches()); + */ + regex = Regex("\\p{Lower}+") + assertTrue(regex.matches("abcdefghijklmnopqrstuvwxyz")) + + // Invalid uses of \p{Lower} + try { + regex = Regex("\\p") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\p;") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\p{") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\p{;") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\p{Lower") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\p{Lower;") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + // Test \p{Upper} + /* + * FIXME: Requires complex range processing p = Regex("<\\p{Upper}\\d\\P{Upper}:[\\p{Upper}z]\\s[^\\P{Upper}]>"); + * m = p.matcher(""); assertTrue(m.matches()); m = p.matcher(""); + * assertTrue(m.matches()); m = p.matcher(""); + * assertFalse(m.matches()); + */ + regex = Regex("\\p{Upper}+") + assertTrue(regex.matches("ABCDEFGHIJKLMNOPQRSTUVWXYZ")) + + // Invalid uses of \p{Upper} + try { + regex = Regex("\\p{Upper") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\p{Upper;") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + // Test \p{ASCII} + /* + * FIXME: Requires complex range processing p = Regex("<\\p{ASCII}\\d\\P{ASCII}:[\\p{ASCII}\u1234]\\s[^\\P{ASCII}]>"); + * m = p.matcher(""); assertTrue(m.matches()); m = + * p.matcher(""); assertTrue(m.matches()); m = + * p.matcher("<\u00846#:E E>"); assertFalse(m.matches()) + */ + regex = Regex("\\p{ASCII}") + for (i in 0 until 0x80) { + assertTrue(regex.matches("${i.toChar()}")) + } + for (i in 0x80..0xff) { + assertFalse(regex.matches("${i.toChar()}")) + } + + // Invalid uses of \p{ASCII} + try { + regex = Regex("\\p{ASCII") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + try { + regex = Regex("\\p{ASCII;") + fail("PatternSyntaxException expected") + } catch (e: PatternSyntaxException) { + } + + // Test \p{Alpha} + // TODO + + // Test \p{Digit} + // TODO + + // Test \p{XDigit} + // TODO + + // Test \p{Alnum} + // TODO + + // Test \p{Punct} + // TODO + + // Test \p{Graph} + // TODO + + // Test \p{Print} + // TODO + + // Test \p{Blank} + // TODO + + // Test \p{Space} + // TODO + + // Test \p{Cntrl} + // TODO + } + + @Test fun testUnicodeCategories() { + // Test Unicode categories using \p and \P + // One letter codes: L, M, N, P, S, Z, C + // Two letter codes: Lu, Nd, Sc, Sm, ... + // See java.lang.Character and Unicode standard for complete list + // TODO + // Test \p{L} + // TODO + + // Test \p{N} + // TODO + + // ... etc + + // Test two letter codes: + // From unicode.org: + // Lu + // Ll + // Lt + // Lm + // Lo + // Mn + // Mc + // Me + // Nd + // Nl + // No + // Pc + // Pd + // Ps + // Pe + // Pi + // Pf + // Po + // Sm + // Sc + // Sk + // So + // Zs + // Zl + // Zp + // Cc + // Cf + // Cs + // Co + // Cn + } + + @Test fun testUnicodeBlocks() { + var regex: Regex + + // Test Unicode blocks using \p and \P + for (block in UBlocks) { + regex = Regex("\\p{In" + block.name + "}") + if (block.low > 0) { + assertFalse(regex.matches((block.low - 1).toChar().toString())) + } + for (i in block.low..block.high) { + assertTrue(regex.matches(i.toChar().toString())) + } + if (block.high < 0xFFFF) { + assertFalse(regex.matches((block.high + 1).toChar().toString())) + } + + regex = Regex("\\P{In" + block.name + "}") + if (block.low > 0) { + assertTrue(regex.matches((block.low - 1).toChar().toString())) + } + for (i in block.low..block.high) { + assertFalse("assert: Regex: $regex, match to: ${i.toChar()} ($i)", regex.matches(i.toChar().toString())) + } + if (block.high < 0xFFFF) { + assertTrue(regex.matches((block.high + 1).toChar().toString())) + } + + } + } + + @Test fun testCapturingGroups() { + // Test simple capturing groups + // TODO + + // Test grouping without capture (?:...) + // TODO + + // Test combination of grouping and capture + // TODO + + // Test \ sequence with capturing and non-capturing groups + // TODO + + // Test \ with out of range + // TODO + } + + @Test fun testRepeats() { + // Test ? + // TODO + + // Test * + // TODO + + // Test + + // TODO + + // Test {}, including 0, 1 and more + // TODO + + // Test {,}, including 0, 1 and more + // TODO + + // Test {,}, with n1 < n2, n1 = n2 and n1 > n2 (illegal?) + // TODO + } + + @Test fun testAnchors() { + // Test ^, default and MULTILINE + // TODO + + // Test $, default and MULTILINE + // TODO + + // Test \b (word boundary) + // TODO + + // Test \B (not a word boundary) + // TODO + + // Test \A (beginning of string) + // TODO + + // Test \Z (end of string) + // TODO + + // Test \z (end of string) + // TODO + + // Test \G + // TODO + + // Test positive lookahead using (?=...) + // TODO + + // Test negative lookahead using (?!...) + // TODO + + // Test positive lookbehind using (?<=...) + // TODO + + // Test negative lookbehind using (?...) + // TODO + + // Test (?onflags-offflags) + // Valid flags are i,m,d,s,u,x + // TODO + + // Test (?onflags-offflags:...) + // TODO + + // Test \Q, \E + regex = Regex("[a-z]+;\\Q[a-z]+;\\Q(foo.*);\\E[0-9]+") + assertTrue(regex.matches("abc;[a-z]+;\\Q(foo.*);411")) + assertFalse(regex.matches("abc;def;foo42;555")) + assertFalse(regex.matches("abc;\\Qdef;\\Qfoo99;\\E123")) + + regex = Regex("[a-z]+;(foo[0-9]-\\Q(...)\\E);[0-9]+") + val result = regex.matchEntire("abc;foo5-(...);123") + assertNotNull(result) + assertEquals("foo5-(...)", result!!.groupValues[1]) + assertFalse(regex.matches("abc;foo9-(xxx);789")) + + regex = Regex("[a-z]+;(bar[0-9]-[a-z\\Q$-\\E]+);[0-9]+") + assertTrue(regex.matches("abc;bar0-def$-;123")) + + regex = Regex("[a-z]+;(bar[0-9]-[a-z\\Q-$\\E]+);[0-9]+") + assertTrue(regex.matches("abc;bar0-def$-;123")) + + regex = Regex("[a-z]+;(bar[0-9]-[a-z\\Q[0-9]\\E]+);[0-9]+") + assertTrue(regex.matches("abc;bar0-def[99]-]0x[;123")); + + regex = Regex("[a-z]+;(bar[0-9]-[a-z\\[0\\-9\\]]+);[0-9]+") + assertTrue(regex.matches("abc;bar0-def[99]-]0x[;123")) + + // Test # + // TODO + } + + @Test fun testCompile1() { + val regex = Regex("[0-9A-Za-z][0-9A-Za-z\\x2e\\x3a\\x2d\\x5f]*") + val name = "iso-8859-1" + assertTrue(regex.matches(name)) + } + + @Test fun testCompile2() { + val findString = "\\Qimport\\E" + val regex = Regex(findString) + regex.containsMatchIn("import a.A;\n\n import b.B;\nclass C {}", 0) + } + + @Test fun testCompile3() { + var regex: Regex + var result: MatchResult? + + regex = Regex("a$") + result = regex.find("a\n") + assertNotNull(result) + assertEquals("a", result!!.value) + assertNull(result.next()) + + regex = Regex("(a$)") + result = regex.find("a\n") + assertNotNull(result) + assertEquals("a", result!!.value) + assertEquals("a", result.groupValues[1]) + assertNull(result.next()) + + regex = Regex("^.*$", RegexOption.MULTILINE) + + result = regex.find("a\n") + assertNotNull(result) + assertEquals("a", result!!.value) + assertNull(result.next()) + + result = regex.find("a\nb\n") + assertNotNull(result) + assertEquals("a", result!!.value) + result = result.next() + assertNotNull(result) + assertEquals("b", result!!.value) + assertNull(result.next()) + + result = regex.find("a\nb") + assertNotNull(result) + assertEquals("a", result!!.value) + result = result.next() + assertNotNull(result) + assertEquals("b", result!!.value) + assertNull(result.next()) + + result = regex.find("\naa\r\nbb\rcc\n\n") + assertNotNull(result) + assertTrue(result!!.value == "") + result = result.next() + assertNotNull(result) + assertEquals("aa", result!!.value) + result = result.next() + assertNotNull(result) + assertEquals("bb", result!!.value) + result = result.next() + assertNotNull(result) + assertEquals("cc", result!!.value) + result = result.next() + assertNotNull(result) + assertTrue(result!!.value == "") + assertNull(result.next()) + + result = regex.find("a") + assertNotNull(result) + assertEquals("a", result!!.value) + assertNull(result.next()) + + result = regex.find("") + assertNull(result) + + regex = Regex("^.*$") + result = regex.find("") + assertNotNull(result) + assertTrue(result!!.value == "") + assertNull(result.next()) + } + + @Test fun testCompile4() { + val findString = "\\Qpublic\\E" + val text = StringBuilder(" public class Class {\n" + " public class Class {") + val regex = Regex(findString) + + val result = regex.find(text) + assertNotNull(result) + assertEquals(4, result!!.range.start) + + // modify text + text.length = 0 + text.append("Text have been changed.") + + assertNull(regex.find(text)) + } + + @Test fun testCompile5() { + val p = Regex("^[0-9]") + val s = p.split("12", 0) + assertEquals("", s[0]) + assertEquals("2", s[1]) + assertEquals(2, s.size) + } + + private class UBInfo(var low: Int, var high: Int, var name: String) + + // A table representing the unicode categories + // private static UBInfo[] UCategories = { + // Lu + // Ll + // Lt + // Lm + // Lo + // Mn + // Mc + // Me + // Nd + // Nl + // No + // Pc + // Pd + // Ps + // Pe + // Pi + // Pf + // Po + // Sm + // Sc + // Sk + // So + // Zs + // Zl + // Zp + // Cc + // Cf + // Cs + // Co + // Cn + // }; + + // A table representing the unicode character blocks + private val UBlocks = arrayOf( + /* 0000; 007F; Basic Latin */ + UBInfo(0x0000, 0x007F, "BasicLatin"), // Character.UnicodeBlock.BASIC_LATIN + /* 0080; 00FF; Latin-1 Supplement */ + UBInfo(0x0080, 0x00FF, "Latin-1Supplement"), // Character.UnicodeBlock.LATIN_1_SUPPLEMENT + /* 0100; 017F; Latin Extended-A */ + UBInfo(0x0100, 0x017F, "LatinExtended-A"), // Character.UnicodeBlock.LATIN_EXTENDED_A + /* 0180; 024F; Latin Extended-B */ + // new UBInfo (0x0180,0x024F,"InLatinExtended-B"), // + // Character.UnicodeBlock.LATIN_EXTENDED_B + /* 0250; 02AF; IPA Extensions */ + UBInfo(0x0250, 0x02AF, "IPAExtensions"), // Character.UnicodeBlock.IPA_EXTENSIONS + /* 02B0; 02FF; Spacing Modifier Letters */ + UBInfo(0x02B0, 0x02FF, "SpacingModifierLetters"), // Character.UnicodeBlock.SPACING_MODIFIER_LETTERS + /* 0300; 036F; Combining Diacritical Marks */ + UBInfo(0x0300, 0x036F, "CombiningDiacriticalMarks"), // Character.UnicodeBlock.COMBINING_DIACRITICAL_MARKS + /* 0370; 03FF; Greek */ + UBInfo(0x0370, 0x03FF, "Greek"), // Character.UnicodeBlock.GREEK + /* 0400; 04FF; Cyrillic */ + UBInfo(0x0400, 0x04FF, "Cyrillic"), // Character.UnicodeBlock.CYRILLIC + /* 0530; 058F; Armenian */ + UBInfo(0x0530, 0x058F, "Armenian"), // Character.UnicodeBlock.ARMENIAN + /* 0590; 05FF; Hebrew */ + UBInfo(0x0590, 0x05FF, "Hebrew"), // Character.UnicodeBlock.HEBREW + /* 0600; 06FF; Arabic */ + UBInfo(0x0600, 0x06FF, "Arabic"), // Character.UnicodeBlock.ARABIC + /* 0700; 074F; Syriac */ + UBInfo(0x0700, 0x074F, "Syriac"), // Character.UnicodeBlock.SYRIAC + /* 0780; 07BF; Thaana */ + UBInfo(0x0780, 0x07BF, "Thaana"), // Character.UnicodeBlock.THAANA + /* 0900; 097F; Devanagari */ + UBInfo(0x0900, 0x097F, "Devanagari"), // Character.UnicodeBlock.DEVANAGARI + /* 0980; 09FF; Bengali */ + UBInfo(0x0980, 0x09FF, "Bengali"), // Character.UnicodeBlock.BENGALI + /* 0A00; 0A7F; Gurmukhi */ + UBInfo(0x0A00, 0x0A7F, "Gurmukhi"), // Character.UnicodeBlock.GURMUKHI + /* 0A80; 0AFF; Gujarati */ + UBInfo(0x0A80, 0x0AFF, "Gujarati"), // Character.UnicodeBlock.GUJARATI + /* 0B00; 0B7F; Oriya */ + UBInfo(0x0B00, 0x0B7F, "Oriya"), // Character.UnicodeBlock.ORIYA + /* 0B80; 0BFF; Tamil */ + UBInfo(0x0B80, 0x0BFF, "Tamil"), // Character.UnicodeBlock.TAMIL + /* 0C00; 0C7F; Telugu */ + UBInfo(0x0C00, 0x0C7F, "Telugu"), // Character.UnicodeBlock.TELUGU + /* 0C80; 0CFF; Kannada */ + UBInfo(0x0C80, 0x0CFF, "Kannada"), // Character.UnicodeBlock.KANNADA + /* 0D00; 0D7F; Malayalam */ + UBInfo(0x0D00, 0x0D7F, "Malayalam"), // Character.UnicodeBlock.MALAYALAM + /* 0D80; 0DFF; Sinhala */ + UBInfo(0x0D80, 0x0DFF, "Sinhala"), // Character.UnicodeBlock.SINHALA + /* 0E00; 0E7F; Thai */ + UBInfo(0x0E00, 0x0E7F, "Thai"), // Character.UnicodeBlock.THAI + /* 0E80; 0EFF; Lao */ + UBInfo(0x0E80, 0x0EFF, "Lao"), // Character.UnicodeBlock.LAO + /* 0F00; 0FFF; Tibetan */ + UBInfo(0x0F00, 0x0FFF, "Tibetan"), // Character.UnicodeBlock.TIBETAN + /* 1000; 109F; Myanmar */ + UBInfo(0x1000, 0x109F, "Myanmar"), // Character.UnicodeBlock.MYANMAR + /* 10A0; 10FF; Georgian */ + UBInfo(0x10A0, 0x10FF, "Georgian"), // Character.UnicodeBlock.GEORGIAN + /* 1100; 11FF; Hangul Jamo */ + UBInfo(0x1100, 0x11FF, "HangulJamo"), // Character.UnicodeBlock.HANGUL_JAMO + /* 1200; 137F; Ethiopic */ + UBInfo(0x1200, 0x137F, "Ethiopic"), // Character.UnicodeBlock.ETHIOPIC + /* 13A0; 13FF; Cherokee */ + UBInfo(0x13A0, 0x13FF, "Cherokee"), // Character.UnicodeBlock.CHEROKEE + /* 1400; 167F; Unified Canadian Aboriginal Syllabics */ + UBInfo(0x1400, 0x167F, "UnifiedCanadianAboriginalSyllabics"), // Character.UnicodeBlock.UNIFIED_CANADIAN_ABORIGINAL_SYLLABICS + /* 1680; 169F; Ogham */ + UBInfo(0x1680, 0x169F, "Ogham"), // Character.UnicodeBlock.OGHAM + /* 16A0; 16FF; Runic */ + UBInfo(0x16A0, 0x16FF, "Runic"), // Character.UnicodeBlock.RUNIC + /* 1780; 17FF; Khmer */ + UBInfo(0x1780, 0x17FF, "Khmer"), // Character.UnicodeBlock.KHMER + /* 1800; 18AF; Mongolian */ + UBInfo(0x1800, 0x18AF, "Mongolian"), // Character.UnicodeBlock.MONGOLIAN + /* 1E00; 1EFF; Latin Extended Additional */ + UBInfo(0x1E00, 0x1EFF, "LatinExtendedAdditional"), // Character.UnicodeBlock.LATIN_EXTENDED_ADDITIONAL + /* 1F00; 1FFF; Greek Extended */ + UBInfo(0x1F00, 0x1FFF, "GreekExtended"), // Character.UnicodeBlock.GREEK_EXTENDED + /* 2000; 206F; General Punctuation */ + UBInfo(0x2000, 0x206F, "GeneralPunctuation"), // Character.UnicodeBlock.GENERAL_PUNCTUATION + /* 2070; 209F; Superscripts and Subscripts */ + UBInfo(0x2070, 0x209F, "SuperscriptsandSubscripts"), // Character.UnicodeBlock.SUPERSCRIPTS_AND_SUBSCRIPTS + /* 20A0; 20CF; Currency Symbols */ + UBInfo(0x20A0, 0x20CF, "CurrencySymbols"), // Character.UnicodeBlock.CURRENCY_SYMBOLS + /* 20D0; 20FF; Combining Marks for Symbols */ + UBInfo(0x20D0, 0x20FF, "CombiningMarksforSymbols"), // Character.UnicodeBlock.COMBINING_MARKS_FOR_SYMBOLS + /* 2100; 214F; Letterlike Symbols */ + UBInfo(0x2100, 0x214F, "LetterlikeSymbols"), // Character.UnicodeBlock.LETTERLIKE_SYMBOLS + /* 2150; 218F; Number Forms */ + UBInfo(0x2150, 0x218F, "NumberForms"), // Character.UnicodeBlock.NUMBER_FORMS + /* 2190; 21FF; Arrows */ + UBInfo(0x2190, 0x21FF, "Arrows"), // Character.UnicodeBlock.ARROWS + /* 2200; 22FF; Mathematical Operators */ + UBInfo(0x2200, 0x22FF, "MathematicalOperators"), // Character.UnicodeBlock.MATHEMATICAL_OPERATORS + /* 2300; 23FF; Miscellaneous Technical */ + UBInfo(0x2300, 0x23FF, "MiscellaneousTechnical"), // Character.UnicodeBlock.MISCELLANEOUS_TECHNICAL + /* 2400; 243F; Control Pictures */ + UBInfo(0x2400, 0x243F, "ControlPictures"), // Character.UnicodeBlock.CONTROL_PICTURES + /* 2440; 245F; Optical Character Recognition */ + UBInfo(0x2440, 0x245F, "OpticalCharacterRecognition"), // Character.UnicodeBlock.OPTICAL_CHARACTER_RECOGNITION + /* 2460; 24FF; Enclosed Alphanumerics */ + UBInfo(0x2460, 0x24FF, "EnclosedAlphanumerics"), // Character.UnicodeBlock.ENCLOSED_ALPHANUMERICS + /* 2500; 257F; Box Drawing */ + UBInfo(0x2500, 0x257F, "BoxDrawing"), // Character.UnicodeBlock.BOX_DRAWING + /* 2580; 259F; Block Elements */ + UBInfo(0x2580, 0x259F, "BlockElements"), // Character.UnicodeBlock.BLOCK_ELEMENTS + /* 25A0; 25FF; Geometric Shapes */ + UBInfo(0x25A0, 0x25FF, "GeometricShapes"), // Character.UnicodeBlock.GEOMETRIC_SHAPES + /* 2600; 26FF; Miscellaneous Symbols */ + UBInfo(0x2600, 0x26FF, "MiscellaneousSymbols"), // Character.UnicodeBlock.MISCELLANEOUS_SYMBOLS + /* 2700; 27BF; Dingbats */ + UBInfo(0x2700, 0x27BF, "Dingbats"), // Character.UnicodeBlock.DINGBATS + /* 2800; 28FF; Braille Patterns */ + UBInfo(0x2800, 0x28FF, "BraillePatterns"), // Character.UnicodeBlock.BRAILLE_PATTERNS + /* 2E80; 2EFF; CJK Radicals Supplement */ + UBInfo(0x2E80, 0x2EFF, "CJKRadicalsSupplement"), // Character.UnicodeBlock.CJK_RADICALS_SUPPLEMENT + /* 2F00; 2FDF; Kangxi Radicals */ + UBInfo(0x2F00, 0x2FDF, "KangxiRadicals"), // Character.UnicodeBlock.KANGXI_RADICALS + /* 2FF0; 2FFF; Ideographic Description Characters */ + UBInfo(0x2FF0, 0x2FFF, "IdeographicDescriptionCharacters"), // Character.UnicodeBlock.IDEOGRAPHIC_DESCRIPTION_CHARACTERS + /* 3000; 303F; CJK Symbols and Punctuation */ + UBInfo(0x3000, 0x303F, "CJKSymbolsandPunctuation"), // Character.UnicodeBlock.CJK_SYMBOLS_AND_PUNCTUATION + /* 3040; 309F; Hiragana */ + UBInfo(0x3040, 0x309F, "Hiragana"), // Character.UnicodeBlock.HIRAGANA + /* 30A0; 30FF; Katakana */ + UBInfo(0x30A0, 0x30FF, "Katakana"), // Character.UnicodeBlock.KATAKANA + /* 3100; 312F; Bopomofo */ + UBInfo(0x3100, 0x312F, "Bopomofo"), // Character.UnicodeBlock.BOPOMOFO + /* 3130; 318F; Hangul Compatibility Jamo */ + UBInfo(0x3130, 0x318F, "HangulCompatibilityJamo"), // Character.UnicodeBlock.HANGUL_COMPATIBILITY_JAMO + /* 3190; 319F; Kanbun */ + UBInfo(0x3190, 0x319F, "Kanbun"), // Character.UnicodeBlock.KANBUN + /* 31A0; 31BF; Bopomofo Extended */ + UBInfo(0x31A0, 0x31BF, "BopomofoExtended"), // Character.UnicodeBlock.BOPOMOFO_EXTENDED + /* 3200; 32FF; Enclosed CJK Letters and Months */ + UBInfo(0x3200, 0x32FF, "EnclosedCJKLettersandMonths"), // Character.UnicodeBlock.ENCLOSED_CJK_LETTERS_AND_MONTHS + /* 3300; 33FF; CJK Compatibility */ + UBInfo(0x3300, 0x33FF, "CJKCompatibility"), // Character.UnicodeBlock.CJK_COMPATIBILITY + /* 3400; 4DB5; CJK Unified Ideographs Extension A */ + UBInfo(0x3400, 0x4DB5, "CJKUnifiedIdeographsExtensionA"), // Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS_EXTENSION_A + /* 4E00; 9FFF; CJK Unified Ideographs */ + UBInfo(0x4E00, 0x9FFF, "CJKUnifiedIdeographs"), // Character.UnicodeBlock.CJK_UNIFIED_IDEOGRAPHS + /* A000; A48F; Yi Syllables */ + UBInfo(0xA000, 0xA48F, "YiSyllables"), // Character.UnicodeBlock.YI_SYLLABLES + /* A490; A4CF; Yi Radicals */ + UBInfo(0xA490, 0xA4CF, "YiRadicals"), // Character.UnicodeBlock.YI_RADICALS + /* AC00; D7A3; Hangul Syllables */ + UBInfo(0xAC00, 0xD7A3, "HangulSyllables"), // Character.UnicodeBlock.HANGUL_SYLLABLES + /* D800; DB7F; High Surrogates */ + /* DB80; DBFF; High Private Use Surrogates */ + /* DC00; DFFF; Low Surrogates */ + /* E000; F8FF; Private Use */ + /* F900; FAFF; CJK Compatibility Ideographs */ + UBInfo(0xF900, 0xFAFF, "CJKCompatibilityIdeographs"), // Character.UnicodeBlock.CJK_COMPATIBILITY_IDEOGRAPHS + /* FB00; FB4F; Alphabetic Presentation Forms */ + UBInfo(0xFB00, 0xFB4F, "AlphabeticPresentationForms"), // Character.UnicodeBlock.ALPHABETIC_PRESENTATION_FORMS + /* FB50; FDFF; Arabic Presentation Forms-A */ + UBInfo(0xFB50, 0xFDFF, "ArabicPresentationForms-A"), // Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_A + /* FE20; FE2F; Combining Half Marks */ + UBInfo(0xFE20, 0xFE2F, "CombiningHalfMarks"), // Character.UnicodeBlock.COMBINING_HALF_MARKS + /* FE30; FE4F; CJK Compatibility Forms */ + UBInfo(0xFE30, 0xFE4F, "CJKCompatibilityForms"), // Character.UnicodeBlock.CJK_COMPATIBILITY_FORMS + /* FE50; FE6F; Small Form Variants */ + UBInfo(0xFE50, 0xFE6F, "SmallFormVariants"), // Character.UnicodeBlock.SMALL_FORM_VARIANTS + /* FE70; FEFE; Arabic Presentation Forms-B */ + // new UBInfo (0xFE70,0xFEFE,"InArabicPresentationForms-B"), // + // Character.UnicodeBlock.ARABIC_PRESENTATION_FORMS_B + /* FEFF; FEFF; Specials */ + UBInfo(0xFEFF, 0xFEFF, "Specials"), // Character.UnicodeBlock.SPECIALS + /* FF00; FFEF; Halfwidth and Fullwidth Forms */ + UBInfo(0xFF00, 0xFFEF, "HalfwidthandFullwidthForms"), // Character.UnicodeBlock.HALFWIDTH_AND_FULLWIDTH_FORMS + /* FFF0; FFFD; Specials */ + UBInfo(0xFFF0, 0xFFFD, "Specials") // Character.UnicodeBlock.SPECIALS + ) +} diff --git a/backend.native/tests/stdlib_external/text/harmony_regex/ReplaceTest.kt b/backend.native/tests/stdlib_external/text/harmony_regex/ReplaceTest.kt new file mode 100644 index 00000000000..9f888d01bf4 --- /dev/null +++ b/backend.native/tests/stdlib_external/text/harmony_regex/ReplaceTest.kt @@ -0,0 +1,84 @@ +/* Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.text.harmony_regex + +import kotlin.text.* +import kotlin.test.* + +class ReplaceTest { + + @Test fun testSimpleReplace() { + val target: String + val pattern: String + val repl: String + + target = "foobarfobarfoofo1" + pattern = "fo[^o]" + repl = "xxx" + + val regex = Regex(pattern) + + assertEquals("foobarxxxarfoofo1", regex.replaceFirst(target, repl)) + assertEquals("foobarxxxarfooxxx", regex.replace(target, repl)) + } + + @Test fun testCaptureReplace() { + var target: String + var pattern: String + var repl: String + var s: String + var regex: Regex + + target = "[31]foo;bar[42];[99]xyz" + pattern = "\\[([0-9]+)\\]([a-z]+)" + repl = "$2[$1]" + + regex = Regex(pattern) + s = regex.replaceFirst(target, repl) + assertEquals("foo[31];bar[42];[99]xyz", s) + s = regex.replace(target, repl) + assertEquals("foo[31];bar[42];xyz[99]", s) + + target = "[31]foo(42)bar{63}zoo;[12]abc(34)def{56}ghi;{99}xyz[88]xyz(77)xyz;" + pattern = "\\[([0-9]+)\\]([a-z]+)\\(([0-9]+)\\)([a-z]+)\\{([0-9]+)\\}([a-z]+)" + repl = "[$5]$6($3)$4{$1}$2" + regex = Regex(pattern) + s = regex.replaceFirst(target, repl) + assertEquals("[63]zoo(42)bar{31}foo;[12]abc(34)def{56}ghi;{99}xyz[88]xyz(77)xyz;", s) + s = regex.replace(target, repl) + assertEquals("[63]zoo(42)bar{31}foo;[56]ghi(34)def{12}abc;{99}xyz[88]xyz(77)xyz;", s) + } + + @Test fun testEscapeReplace() { + val target: String + val pattern: String + var repl: String + var s: String + + target = "foo'bar''foo" + pattern = "'" + repl = "\\'" + s = target.replace(pattern.toRegex(), repl) + assertEquals("foo'bar''foo", s) + repl = "\\\\'" + s = target.replace(pattern.toRegex(), repl) + assertEquals("foo\\'bar\\'\\'foo", s) + repl = "\\$3" + s = target.replace(pattern.toRegex(), repl) + assertEquals("foo$3bar$3$3foo", s) + } +} diff --git a/backend.native/tests/stdlib_external/text/harmony_regex/SplitTest.kt b/backend.native/tests/stdlib_external/text/harmony_regex/SplitTest.kt new file mode 100644 index 00000000000..7b4be3d57c3 --- /dev/null +++ b/backend.native/tests/stdlib_external/text/harmony_regex/SplitTest.kt @@ -0,0 +1,155 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.text.harmony_regex + +import kotlin.text.* +import kotlin.test.* + +class SplitTest { + + @Test fun testSimple() { + val p = Regex("/") + val results = p.split("have/you/done/it/right") + val expected = arrayOf("have", "you", "done", "it", "right") + assertEquals(expected.size, results.size) + for (i in expected.indices) { + assertEquals(results[i], expected[i]) + } + } + + @Test fun testSplit1() { + var p = Regex(" ") + + val input = "poodle zoo" + var tokens: List + + tokens = p.split(input, 1) + assertEquals(1, tokens.size) + assertTrue(tokens[0] == input) + tokens = p.split(input, 2) + assertEquals(2, tokens.size) + assertEquals("poodle", tokens[0]) + assertEquals("zoo", tokens[1]) + tokens = p.split(input, 5) + assertEquals(2, tokens.size) + assertEquals("poodle", tokens[0]) + assertEquals("zoo", tokens[1]) + tokens = p.split(input, 0) + assertEquals(2, tokens.size) + assertEquals("poodle", tokens[0]) + assertEquals("zoo", tokens[1]) + tokens = p.split(input) + assertEquals(2, tokens.size) + assertEquals("poodle", tokens[0]) + assertEquals("zoo", tokens[1]) + + p = Regex("d") + + tokens = p.split(input, 1) + assertEquals(1, tokens.size) + assertTrue(tokens[0] == input) + tokens = p.split(input, 2) + assertEquals(2, tokens.size) + assertEquals("poo", tokens[0]) + assertEquals("le zoo", tokens[1]) + tokens = p.split(input, 5) + assertEquals(2, tokens.size) + assertEquals("poo", tokens[0]) + assertEquals("le zoo", tokens[1]) + tokens = p.split(input, 0) + assertEquals(2, tokens.size) + assertEquals("poo", tokens[0]) + assertEquals("le zoo", tokens[1]) + tokens = p.split(input) + assertEquals(2, tokens.size) + assertEquals("poo", tokens[0]) + assertEquals("le zoo", tokens[1]) + + p = Regex("o") + + tokens = p.split(input, 1) + assertEquals(1, tokens.size) + assertTrue(tokens[0] == input) + tokens = p.split(input, 2) + assertEquals(2, tokens.size) + assertEquals("p", tokens[0]) + assertEquals("odle zoo", tokens[1]) + tokens = p.split(input, 5) + assertEquals(5, tokens.size) + assertEquals("p", tokens[0]) + assertTrue(tokens[1] == "") + assertEquals("dle z", tokens[2]) + assertTrue(tokens[3] == "") + assertTrue(tokens[4] == "") + tokens = p.split(input, 0) + assertEquals(5, tokens.size) + assertEquals("p", tokens[0]) + assertTrue(tokens[1] == "") + assertEquals("dle z", tokens[2]) + assertTrue(tokens[3] == "") + assertTrue(tokens[4] == "") + tokens = p.split(input) + assertEquals(5, tokens.size) + assertEquals("p", tokens[0]) + assertTrue(tokens[1] == "") + assertEquals("dle z", tokens[2]) + assertTrue(tokens[3] == "") + assertTrue(tokens[4] == "") + } + + @Test fun testSplit2() { + val p = Regex("") + var s: List + s = p.split("a", 0) + assertEquals(3, s.size) + assertEquals("", s[0]) + assertEquals("a", s[1]) + assertEquals("", s[2]) + + s = p.split("", 0) + assertEquals(1, s.size) + assertEquals("", s[0]) + + s = p.split("abcd", 0) + assertEquals(6, s.size) + assertEquals("", s[0]) + assertEquals("a", s[1]) + assertEquals("b", s[2]) + assertEquals("c", s[3]) + assertEquals("d", s[4]) + assertEquals("", s[5]) + } + + @Test fun testSplitSupplementaryWithEmptyString() { + + /* + * See http://www.unicode.org/reports/tr18/#Supplementary_Characters We + * have to treat text as code points not code units. + */ + val p = Regex("") + val s: List + s = p.split("a\ud869\uded6b", 0) + assertEquals(5, s.size) + assertEquals("", s[0]) + assertEquals("a", s[1]) + assertEquals("\ud869\uded6", s[2]) + assertEquals("b", s[3]) + assertEquals("", s[4]) + } + +} diff --git a/backend.native/tests/stdlib_external/utils/KotlinVersionTest.kt b/backend.native/tests/stdlib_external/utils/KotlinVersionTest.kt new file mode 100644 index 00000000000..4a159cab855 --- /dev/null +++ b/backend.native/tests/stdlib_external/utils/KotlinVersionTest.kt @@ -0,0 +1,58 @@ +package test.utils + +import kotlin.test.* + + +class KotlinVersionTest { + + @Test fun currentVersion() { + 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)) + } + + @Test fun componentValidation() { + 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) + } + } + } + } + } + + @Test fun versionComparison() { + val v100 = KotlinVersion(1, 0, 0) + val v107 = KotlinVersion(1, 0, 7) + val v110 = KotlinVersion(1, 1, 0) + val v114 = KotlinVersion(1, 1, 4) + val v115 = KotlinVersion(1, 1, 50) + val v120 = KotlinVersion(1, 2, 0) + val v122 = KotlinVersion(1, 2, 20) + val v2 = KotlinVersion(2, 0, 0) + + val sorted = listOf(v100, v107, v110, v114, v115, v120, v122, v2) + for ((prev, next) in sorted.zip(sorted.drop(1))) { // use zipWithNext in 1.2 + val message = "next: $next, prev: $prev" + assertTrue(next > prev, message) + assertTrue(next.isAtLeast(prev.major, prev.minor, prev.patch), message) + assertTrue(next.isAtLeast(prev.major, prev.minor), message) + assertTrue(next.isAtLeast(next.major, next.minor, next.patch), message) + assertTrue(next.isAtLeast(next.major, next.minor), message) + assertFalse(prev.isAtLeast(next.major, next.minor, next.patch), message) + } + } +} + diff --git a/backend.native/tests/stdlib_external/utils/LazyTest.kt b/backend.native/tests/stdlib_external/utils/LazyTest.kt new file mode 100644 index 00000000000..2da65b61814 --- /dev/null +++ b/backend.native/tests/stdlib_external/utils/LazyTest.kt @@ -0,0 +1,41 @@ +package test.utils + +import kotlin.* +import kotlin.test.* + +class LazyTest { + + @Test fun initializationCalledOnce() { + 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) + } + + @Test fun alreadyInitialized() { + val lazyInt = lazyOf(1) + + assertTrue(lazyInt.isInitialized()) + assertEquals(1, lazyInt.value) + } + + + @Test fun lazyToString() { + 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) + } +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/utils/PreconditionsTest.kt b/backend.native/tests/stdlib_external/utils/PreconditionsTest.kt new file mode 100644 index 00000000000..58b4179dfdb --- /dev/null +++ b/backend.native/tests/stdlib_external/utils/PreconditionsTest.kt @@ -0,0 +1,127 @@ +package test.utils + +import kotlin.test.* + +class PreconditionsTest() { + + @Test fun passingRequire() { + require(true) + + var called = false + require(true) { called = true; "some message" } + assertFalse(called) + } + + @Test fun failingRequire() { + val error = assertFailsWith { + require(false) + } + assertNotNull(error.message) + } + + @Test fun failingRequireWithLazyMessage() { + val error = assertFailsWith { + require(false) { "Hello" } + } + assertEquals("Hello", error.message) + } + + @Test fun passingCheck() { + check(true) + + var called = false + check(true) { called = true; "some message" } + assertFalse(called) + } + + @Test fun failingCheck() { + val error = assertFailsWith { + check(false) + } + assertNotNull(error.message) + } + + @Test fun failingCheckWithLazyMessage() { + val error = assertFailsWith { + check(false) { "Hello" } + } + assertEquals("Hello", error.message) + } + + @Test fun requireNotNull() { + val s1: String? = "S1" + val r1: String = requireNotNull(s1) + assertEquals("S1", r1) + } + + @Test fun requireNotNullFails() { + assertFailsWith { + val s2: String? = null + requireNotNull(s2) + } + } + + @Test fun requireNotNullWithLazyMessage() { + val error = assertFailsWith { + val obj: Any? = null + requireNotNull(obj) { "Message" } + } + assertEquals("Message", error.message) + + var lazyCalled: Boolean = false + requireNotNull("not null") { + lazyCalled = true + "Message" + } + assertFalse(lazyCalled, "Message is not evaluated if the condition is met") + } + + @Test fun checkNotNull() { + val s1: String? = "S1" + val r1: String = checkNotNull(s1) + assertEquals("S1", r1) + } + + @Test fun checkNotNullFails() { + assertFailsWith { + val s2: String? = null + checkNotNull(s2) + } + } + + //@kotlin.jvm.JvmVersion + @Test fun passingAssert() { + assert(true) + var called = false + assert(true) { called = true; "some message" } + + assertFalse(called) + } + + + //@kotlin.jvm.JvmVersion + @Test fun failingAssert() { + val error = assertFailsWith { + assert(false) + } + assertEquals("Assertion failed", error.message) + } + + + // TODO: Uncomment. Disbled due to a serialization bug with assertFailsWith + //@kotlin.jvm.JvmVersion + //@Test fun failingAssertWithMessage() { + // val error = assertFailsWith { + // assert(false) { "Hello" } + // } + // assertEquals("Hello", error.message) + //} + + @Test fun error() { + val error = assertFailsWith { + error("There was a problem") + } + assertEquals("There was a problem", error.message) + } + +} \ No newline at end of file diff --git a/backend.native/tests/stdlib_external/utils/TODOTest.kt b/backend.native/tests/stdlib_external/utils/TODOTest.kt new file mode 100644 index 00000000000..44cb831749c --- /dev/null +++ b/backend.native/tests/stdlib_external/utils/TODOTest.kt @@ -0,0 +1,66 @@ +/* + * Copyright 2010-2016 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package test.utils + +import kotlin.* +import kotlin.test.* + +class TODOTest { + private class PartiallyImplementedClass { + public val prop: String get() = TODO() + @Suppress("UNREACHABLE_CODE", "CAST_NEVER_SUCCEEDS") + 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!!) + } + + + @Test fun usage() { + 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/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy index 2c5621aea68..588be6a3da0 100644 --- a/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy +++ b/buildSrc/plugins/src/main/groovy/org/jetbrains/kotlin/KonanTest.groovy @@ -24,6 +24,7 @@ import org.jetbrains.kotlin.konan.target.* import org.jetbrains.kotlin.konan.properties.* import static org.jetbrains.kotlin.konan.util.VisibleNamedKt.* +import javax.inject.Inject import java.util.regex.Pattern abstract class KonanTest extends JavaExec { @@ -353,10 +354,15 @@ class BuildKonanTest extends ExtKonanTest { // create list of tests to compile def compileFiles = new ArrayList() compileList.each { - project.file(it).eachFileRecurse { - if (it.isFile() && it.name.endsWith(".kt") && !excludeFiles.contains(it.absolutePath)) { - compileFiles.add(it.absolutePath) + def file = project.file(it) + if (file.isDirectory()) { + file.eachFileRecurse { + if (it.isFile() && it.name.endsWith(".kt") && !excludeFiles.contains(it.absolutePath)) { + compileFiles.add(it.absolutePath) + } } + } else { + compileFiles.add(file.absolutePath) } } compileFiles @@ -384,10 +390,26 @@ class BuildKonanTest extends ExtKonanTest { * Runs test built with Konan's TestRunner */ class RunKonanTest extends ExtKonanTest { + public def buildTaskName = 'buildKonanTests' + public def runnerLogger = Logger.SILENT + public def useFilter = true + enum Logger { + GTEST, + TEAMCITY, + SIMPLE, + SILENT + } + + @Inject RunKonanTest() { super() - dependsOn('buildKonanTests') + dependsOn(buildTaskName) + } + + RunKonanTest(def depends) { + buildTaskName = depends + dependsOn(buildTaskName) } @Override @@ -400,8 +422,10 @@ class RunKonanTest extends ExtKonanTest { void executeTest() { arguments = arguments ?: [] // Print only test's output - arguments.add("--ktest_logger=SILENT") - arguments.add("--ktest_filter=" + convertToPattern(source)) + arguments.add("--ktest_logger=" + runnerLogger.toString()) + if (useFilter) { + arguments.add("--ktest_filter=" + convertToPattern(source)) + } super.executeTest() } @@ -412,6 +436,13 @@ class RunKonanTest extends ExtKonanTest { } } +class RunStdlibTest extends RunKonanTest { + + RunStdlibTest() { + super('buildKonanStdlibTests') + } +} + /** * Compiles and executes test as a standalone binary */ diff --git a/runtime/src/main/kotlin/kotlin/KotlinVersion.kt b/runtime/src/main/kotlin/kotlin/KotlinVersion.kt index e11a0754206..c1363ca2670 100644 --- a/runtime/src/main/kotlin/kotlin/KotlinVersion.kt +++ b/runtime/src/main/kotlin/kotlin/KotlinVersion.kt @@ -36,7 +36,7 @@ public class KotlinVersion(val major: Int, val minor: Int, val patch: Int) : Com require(major in 0..MAX_COMPONENT_VALUE && minor in 0..MAX_COMPONENT_VALUE && patch in 0..MAX_COMPONENT_VALUE) { "Version components are out of range: $major.$minor.$patch" } - return major shl 16 + minor shl 8 + patch + return major.shl(16) + minor.shl(8) + patch } /** @@ -84,6 +84,6 @@ public class KotlinVersion(val major: Int, val minor: Int, val patch: Int) : Com * Returns the current version of the Kotlin standard library. */ // TODO: get from metadata or hardcode automatically during build - public val CURRENT: KotlinVersion = KotlinVersion(1, 1, 4) + public val CURRENT: KotlinVersion = KotlinVersion(1, 2, 0) } } diff --git a/runtime/src/main/kotlin/kotlin/collections/Collections.kt b/runtime/src/main/kotlin/kotlin/collections/Collections.kt index 710c4685db1..a4b560c92d9 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Collections.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Collections.kt @@ -1187,7 +1187,7 @@ public fun List.takeLast(n: Int): List { for (index in size - n .. size - 1) list.add(this[index]) } else { - for (item in this.listIterator(n)) + for (item in this.listIterator(size - n)) list.add(item) } return list @@ -2257,6 +2257,39 @@ public fun List.requireNoNulls(): List { return this as List } +/** + * Splits this collection into a list of lists each not exceeding the given [size]. + * + * The last list in the resulting list may have less elements than the given [size]. + * + * @param size the number of elements to take in each list, must be positive and can be greater than the number of elements in this collection. + * + * @sample samples.collections.Collections.Transformations.chunked + */ +@SinceKotlin("1.2") +public fun Iterable.chunked(size: Int): List> { + return windowed(size, size, partialWindows = true) +} + +/** + * Splits this collection into several lists each not exceeding the given [size] + * and applies the given [transform] function to an each. + * + * @return list of results of the [transform] applied to an each list. + * + * Note that the list passed to the [transform] function is ephemeral and is valid only inside that function. + * You should not store it or allow it to escape in some way, unless you made a snapshot of it. + * The last list may have less elements than the given [size]. + * + * @param size the number of elements to take in each list, must be positive and can be greater than the number of elements in this collection. + * + * @sample samples.text.Strings.chunkedTransform + */ +@SinceKotlin("1.2") +public fun Iterable.chunked(size: Int, transform: (List) -> R): List { + return windowed(size, size, partialWindows = true, transform = transform) +} + /** * Returns a list containing all elements of the original collection without the first occurrence of the given [element]. */ @@ -2426,6 +2459,83 @@ public inline fun Collection.plusElement(element: T): List { return plus(element) } +/** + * Returns a list of snapshots of the window of the given [size] + * sliding along this collection with the given [step], where each + * snapshot is a list. + * + * Several last lists may have less elements than the given [size]. + * + * Both [size] and [step] must be positive and can be greater than the number of elements in this collection. + * @param size the number of elements to take in each window + * @param step the number of elements to move the window forward by on an each step, by default 1 + * @param partialWindows controls whether or not to keep partial windows in the end if any, + * by default `false` which means partial windows won't be preserved + * + * @sample samples.collections.Sequences.Transformations.takeWindows + */ +@SinceKotlin("1.2") +public fun Iterable.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false): List> { + checkWindowSizeStep(size, step) + if (this is RandomAccess && this is List) { + val thisSize = this.size + val result = ArrayList>((thisSize + step - 1) / step) + var index = 0 + while (index < thisSize) { + val windowSize = size.coerceAtMost(thisSize - index) + if (windowSize < size && !partialWindows) break + result.add(List(windowSize) { this[it + index] }) + index += step + } + return result + } + val result = ArrayList>() + windowedIterator(iterator(), size, step, partialWindows, reuseBuffer = false).forEach { + result.add(it) + } + return result +} + +/** + * Returns a list of results of applying the given [transform] function to + * an each list representing a view over the window of the given [size] + * sliding along this collection with the given [step]. + * + * Note that the list passed to the [transform] function is ephemeral and is valid only inside that function. + * You should not store it or allow it to escape in some way, unless you made a snapshot of it. + * Several last lists may have less elements than the given [size]. + * + * Both [size] and [step] must be positive and can be greater than the number of elements in this collection. + * @param size the number of elements to take in each window + * @param step the number of elements to move the window forward by on an each step, by default 1 + * @param partialWindows controls whether or not to keep partial windows in the end if any, + * by default `false` which means partial windows won't be preserved + * + * @sample samples.collections.Sequences.Transformations.averageWindows + */ +@SinceKotlin("1.2") +public fun Iterable.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false, transform: (List) -> R): List { + checkWindowSizeStep(size, step) + if (this is RandomAccess && this is List) { + val thisSize = this.size + val result = ArrayList((thisSize + step - 1) / step) + val window = MovingSubList(this) + var index = 0 + while (index < thisSize) { + window.move(index, (index + size).coerceAtMost(thisSize)) + if (!partialWindows && window.size < size) break + result.add(transform(window)) + index += step + } + return result + } + val result = ArrayList() + windowedIterator(iterator(), size, step, partialWindows, reuseBuffer = true).forEach { + result.add(transform(it)) + } + return result +} + /** * Returns a list of pairs built from elements of both collections with same indexes. List has length of shortest collection. */ @@ -2470,6 +2580,40 @@ public inline fun Iterable.zip(other: Iterable, transform: (T, R return list } +/** + * Returns a list of pairs of each two adjacent elements in this collection. + * + * The returned list is empty if this collection contains less than two elements. + * + * @sample samples.collections.Collections.Transformations.zipWithNext + */ +@SinceKotlin("1.2") +public fun Iterable.zipWithNext(): List> { + return zipWithNext { a, b -> a to b } +} + +/** + * Returns a list containing the results of applying the given [transform] function + * to an each pair of two adjacent elements in this collection. + * + * The returned list is empty if this collection contains less than two elements. + * + * @sample samples.collections.Collections.Transformations.zipWithNextToFindDeltas + */ +@SinceKotlin("1.2") +public inline fun Iterable.zipWithNext(transform: (a: T, b: T) -> R): List { + val iterator = iterator() + if (!iterator.hasNext()) return emptyList() + val result = mutableListOf() + var current = iterator.next() + while (iterator.hasNext()) { + val next = iterator.next() + result.add(transform(current, next)) + current = next + } + return result +} + /** * Appends the string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied. * diff --git a/runtime/src/main/kotlin/kotlin/collections/Maps.kt b/runtime/src/main/kotlin/kotlin/collections/Maps.kt index 8f114e2eda3..2cfd43ba3f5 100644 --- a/runtime/src/main/kotlin/kotlin/collections/Maps.kt +++ b/runtime/src/main/kotlin/kotlin/collections/Maps.kt @@ -595,6 +595,81 @@ public inline operator fun MutableMap.plusAssign(map: Map Map.minus(key: K): Map + = this.toMutableMap().apply { minusAssign(key) }.optimizeReadOnlyMap() + +/** + * Returns a map containing all entries of the original map except those entries + * the keys of which are contained in the given [keys] collection. + * + * The returned map preserves the entry iteration order of the original map. + */ +@SinceKotlin("1.1") +public operator fun Map.minus(keys: Iterable): Map + = this.toMutableMap().apply { minusAssign(keys) }.optimizeReadOnlyMap() + +/** + * Returns a map containing all entries of the original map except those entries + * the keys of which are contained in the given [keys] array. + * + * The returned map preserves the entry iteration order of the original map. + */ +@SinceKotlin("1.1") +public operator fun Map.minus(keys: Array): Map + = this.toMutableMap().apply { minusAssign(keys) }.optimizeReadOnlyMap() + +/** + * Returns a map containing all entries of the original map except those entries + * the keys of which are contained in the given [keys] sequence. + * + * The returned map preserves the entry iteration order of the original map. + */ +@SinceKotlin("1.1") +public operator fun Map.minus(keys: Sequence): Map + = this.toMutableMap().apply { minusAssign(keys) }.optimizeReadOnlyMap() + +/** + * Removes the entry with the given [key] from this mutable map. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline operator fun MutableMap.minusAssign(key: K) { + remove(key) +} + +/** + * Removes all entries the keys of which are contained in the given [keys] collection from this mutable map. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline operator fun MutableMap.minusAssign(keys: Iterable) { + this.keys.removeAll(keys) +} + +/** + * Removes all entries the keys of which are contained in the given [keys] array from this mutable map. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline operator fun MutableMap.minusAssign(keys: Array) { + this.keys.removeAll(keys) +} + +/** + * Removes all entries from the keys of which are contained in the given [keys] sequence from this mutable map. + */ +@SinceKotlin("1.1") +@kotlin.internal.InlineOnly +public inline operator fun MutableMap.minusAssign(keys: Sequence) { + this.keys.removeAll(keys) +} + @kotlin.internal.InlineExposed internal fun Map.optimizeReadOnlyMap() = when (size) { 0 -> emptyMap() diff --git a/runtime/src/main/kotlin/kotlin/collections/SlidingWindow.kt b/runtime/src/main/kotlin/kotlin/collections/SlidingWindow.kt new file mode 100644 index 00000000000..fc29541c35d --- /dev/null +++ b/runtime/src/main/kotlin/kotlin/collections/SlidingWindow.kt @@ -0,0 +1,210 @@ +/* + * Copyright 2010-2017 JetBrains s.r.o. + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package kotlin.collections + +import kotlin.coroutines.experimental.buildIterator + +internal fun checkWindowSizeStep(size: Int, step: Int) { + require(size > 0 && step > 0) { + if (size != step) + "Both size $size and step $step must be greater than zero." + else + "size $size must be greater than zero." + } +} + +internal fun Sequence.windowedSequence(size: Int, step: Int, partialWindows: Boolean, reuseBuffer: Boolean): Sequence> { + checkWindowSizeStep(size, step) + return Sequence { windowedIterator(iterator(), size, step, partialWindows, reuseBuffer) } +} + +internal fun windowedIterator(iterator: Iterator, size: Int, step: Int, partialWindows: Boolean, reuseBuffer: Boolean): Iterator> { + if (!iterator.hasNext()) return EmptyIterator + return buildIterator> { + val gap = step - size + if (gap >= 0) { + var buffer = ArrayList(size) + var skip = 0 + for (e in iterator) { + if (skip > 0) { skip -= 1; continue } + buffer.add(e) + if (buffer.size == size) { + yield(buffer) + if (reuseBuffer) buffer.clear() else buffer = ArrayList(size) + skip = gap + } + } + if (buffer.isNotEmpty()) { + if (partialWindows || buffer.size == size) yield(buffer) + } + } else { + val buffer = RingBuffer(size) + for (e in iterator) { + buffer.add(e) + if (buffer.isFull()) { + yield(if (reuseBuffer) buffer else ArrayList(buffer)) + buffer.removeFirst(step) + } + } + if (partialWindows) { + while (buffer.size > step) { + yield(if (reuseBuffer) buffer else ArrayList(buffer)) + buffer.removeFirst(step) + } + if (buffer.isNotEmpty()) yield(buffer) + } + } + } +} + +internal class MovingSubList(private val list: List) : AbstractList(), RandomAccess { + private var fromIndex: Int = 0 + private var _size: Int = 0 + + fun move(fromIndex: Int, toIndex: Int) { + checkRangeIndexes(fromIndex, toIndex, list.size) + this.fromIndex = fromIndex + this._size = toIndex - fromIndex + } + + override fun get(index: Int): E { + checkElementIndex(index, _size) + + return list[fromIndex + index] + } + + override val size: Int get() = _size +} + + +/** + * Provides ring buffer implementation. + * + * Buffer overflow is not allowed so [add] doesn't overwrite tail but raises an exception. + */ +private class RingBuffer(val capacity: Int): AbstractList(), RandomAccess { + init { + require(capacity >= 0) { "ring buffer capacity should not be negative but it is $capacity" } + } + + private val buffer = arrayOfNulls(capacity) + private var startIndex: Int = 0 + + override var size: Int = 0 + private set + + override fun get(index: Int): T { + checkElementIndex(index, size) + @Suppress("UNCHECKED_CAST") + return buffer[startIndex.forward(index)] as T + } + + fun isFull() = size == capacity + + override fun iterator(): Iterator = object : AbstractIterator() { + private var count = size + private var index = startIndex + + override fun computeNext() { + if (count == 0) { + done() + } else { + @Suppress("UNCHECKED_CAST") + setNext(buffer[index] as T) + index = index.forward(1) + count-- + } + } + } + + @Suppress("UNCHECKED_CAST") + override fun toArray(array: Array): Array { + val result: Array = + if (array.size < this.size) array.copyOf(this.size) else array as Array + + val size = this.size + + var widx = 0 + var idx = startIndex + + while (widx < size && idx < capacity) { + result[widx] = buffer[idx] as T + widx++ + idx++ + } + + idx = 0 + while (widx < size) { + result[widx] = buffer[idx] as T + widx++ + idx++ + } + if (result.size > this.size) result[this.size] = null + + return result as Array + } + + override fun toArray(): Array { + return toArray(arrayOfNulls(size)) + } + + /** + * Add [element] to the buffer or fail with [IllegalStateException] if no free space available in the buffer + */ + fun add(element: T) { + if (isFull()) { + throw IllegalStateException("ring buffer is full") + } + + buffer[startIndex.forward(size)] = element + size++ + } + + /** + * Removes [n] first elements from the buffer or fails with [IllegalArgumentException] if not enough elements in the buffer to remove + */ + fun removeFirst(n: Int) { + require(n >= 0) { "n shouldn't be negative but it is $n" } + require(n <= size) { "n shouldn't be greater than the buffer size: n = $n, size = $size" } + + if (n > 0) { + val start = startIndex + val end = start.forward(n) + + if (start > end) { + buffer.fill(null, start, capacity) + buffer.fill(null, 0, end) + } else { + buffer.fill(null, start, end) + } + + startIndex = end + size -= n + } + } + + + @Suppress("NOTHING_TO_INLINE") + private inline fun Int.forward(n: Int): Int = (this + n) % capacity + + // TODO: replace with Array.fill from stdlib when available in common + private fun Array.fill(element: T, fromIndex: Int = 0, toIndex: Int = size): Unit { + for (idx in fromIndex .. toIndex-1) { + this[idx] = element + } + } +} \ No newline at end of file diff --git a/runtime/src/main/kotlin/kotlin/sequences/Sequences.kt b/runtime/src/main/kotlin/kotlin/sequences/Sequences.kt index b018cec164c..53dfb13b8d9 100644 --- a/runtime/src/main/kotlin/kotlin/sequences/Sequences.kt +++ b/runtime/src/main/kotlin/kotlin/sequences/Sequences.kt @@ -17,6 +17,7 @@ package kotlin.sequences import kotlin.comparisons.* +import kotlin.coroutines.experimental.* /** @@ -1718,6 +1719,43 @@ public fun Sequence.requireNoNulls(): Sequence { return map { it ?: throw IllegalArgumentException("null element found in $this.") } } +/** + * Splits this sequence into a sequence of lists each not exceeding the given [size]. + * + * The last list in the resulting sequence may have less elements than the given [size]. + * + * @param size the number of elements to take in each list, must be positive and can be greater than the number of elements in this sequence. + * + * @sample samples.collections.Collections.Transformations.chunked + * + * The operation is _intermediate_ and _stateful_. + */ +@SinceKotlin("1.2") +public fun Sequence.chunked(size: Int): Sequence> { + return windowed(size, size, partialWindows = true) +} + +/** + * Splits this sequence into several lists each not exceeding the given [size] + * and applies the given [transform] function to an each. + * + * @return sequence of results of the [transform] applied to an each list. + * + * Note that the list passed to the [transform] function is ephemeral and is valid only inside that function. + * You should not store it or allow it to escape in some way, unless you made a snapshot of it. + * The last list may have less elements than the given [size]. + * + * @param size the number of elements to take in each list, must be positive and can be greater than the number of elements in this sequence. + * + * @sample samples.text.Strings.chunkedTransform + * + * The operation is _intermediate_ and _stateful_. + */ +@SinceKotlin("1.2") +public fun Sequence.chunked(size: Int, transform: (List) -> R): Sequence { + return windowed(size, size, partialWindows = true, transform = transform) +} + /** * Returns a sequence containing all elements of the original sequence without the first occurrence of the given [element]. */ @@ -1853,6 +1891,48 @@ public inline fun Sequence.plusElement(element: T): Sequence { return plus(element) } +/** + * Returns a sequence of snapshots of the window of the given [size] + * sliding along this sequence with the given [step], where each + * snapshot is a list. + * + * Several last lists may have less elements than the given [size]. + * + * Both [size] and [step] must be positive and can be greater than the number of elements in this sequence. + * @param size the number of elements to take in each window + * @param step the number of elements to move the window forward by on an each step, by default 1 + * @param partialWindows controls whether or not to keep partial windows in the end if any, + * by default `false` which means partial windows won't be preserved + * + * @sample samples.collections.Sequences.Transformations.takeWindows + */ +@SinceKotlin("1.2") +public fun Sequence.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false): Sequence> { + return windowedSequence(size, step, partialWindows, reuseBuffer = false) +} + +/** + * Returns a sequence of results of applying the given [transform] function to + * an each list representing a view over the window of the given [size] + * sliding along this sequence with the given [step]. + * + * Note that the list passed to the [transform] function is ephemeral and is valid only inside that function. + * You should not store it or allow it to escape in some way, unless you made a snapshot of it. + * Several last lists may have less elements than the given [size]. + * + * Both [size] and [step] must be positive and can be greater than the number of elements in this sequence. + * @param size the number of elements to take in each window + * @param step the number of elements to move the window forward by on an each step, by default 1 + * @param partialWindows controls whether or not to keep partial windows in the end if any, + * by default `false` which means partial windows won't be preserved + * + * @sample samples.collections.Sequences.Transformations.averageWindows + */ +@SinceKotlin("1.2") +public fun Sequence.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false, transform: (List) -> R): Sequence { + return windowedSequence(size, step, partialWindows, reuseBuffer = true).map(transform) +} + /** * Returns a sequence of pairs built from elements of both sequences with same indexes. * Resulting sequence has length of shortest input sequence. @@ -1868,6 +1948,44 @@ public fun Sequence.zip(other: Sequence, transform: (T, R) -> V) return MergingSequence(this, other, transform) } +/** + * Returns a sequence of pairs of each two adjacent elements in this sequence. + * + * The returned sequence is empty if this sequence contains less than two elements. + * + * @sample samples.collections.Collections.Transformations.zipWithNext + * + * The operation is _intermediate_ and _stateless_. + */ +@SinceKotlin("1.2") +public fun Sequence.zipWithNext(): Sequence> { + return zipWithNext { a, b -> a to b } +} + +/** + * Returns a sequence containing the results of applying the given [transform] function + * to an each pair of two adjacent elements in this sequence. + * + * The returned sequence is empty if this sequence contains less than two elements. + * + * @sample samples.collections.Collections.Transformations.zipWithNextToFindDeltas + * + * The operation is _intermediate_ and _stateless_. + */ +@SinceKotlin("1.2") +public fun Sequence.zipWithNext(transform: (a: T, b: T) -> R): Sequence { + return buildSequence result@ { + val iterator = iterator() + if (!iterator.hasNext()) return@result + var current = iterator.next() + while (iterator.hasNext()) { + val next = iterator.next() + yield(transform(current, next)) + current = next + } + } +} + /** * Appends the string from all the elements separated using [separator] and using the given [prefix] and [postfix] if supplied. * diff --git a/runtime/src/main/kotlin/kotlin/text/Strings.kt b/runtime/src/main/kotlin/kotlin/text/Strings.kt index 79b9d858d33..d2f5ce3b2ac 100644 --- a/runtime/src/main/kotlin/kotlin/text/Strings.kt +++ b/runtime/src/main/kotlin/kotlin/text/Strings.kt @@ -2288,6 +2288,72 @@ public inline fun CharSequence.sumByDouble(selector: (Char) -> Double): Double { return sum } +/** + * Splits this char sequence into a list of strings each not exceeding the given [size]. + * + * The last string in the resulting list may have less characters than the given [size]. + * + * @param size the number of elements to take in each string, must be positive and can be greater than the number of elements in this char sequence. + * + * @sample samples.collections.Collections.Transformations.chunked + */ +@SinceKotlin("1.2") +public fun CharSequence.chunked(size: Int): List { + return windowed(size, size, partialWindows = true) +} + +/** + * Splits this char sequence into several char sequences each not exceeding the given [size] + * and applies the given [transform] function to an each. + * + * @return list of results of the [transform] applied to an each char sequence. + * + * Note that the char sequence passed to the [transform] function is ephemeral and is valid only inside that function. + * You should not store it or allow it to escape in some way, unless you made a snapshot of it. + * The last char sequence may have less characters than the given [size]. + * + * @param size the number of elements to take in each char sequence, must be positive and can be greater than the number of elements in this char sequence. + * + * @sample samples.text.Strings.chunkedTransform + */ +@SinceKotlin("1.2") +public fun CharSequence.chunked(size: Int, transform: (CharSequence) -> R): List { + return windowed(size, size, partialWindows = true, transform = transform) +} + +/** + * Splits this char sequence into a sequence of strings each not exceeding the given [size]. + * + * The last string in the resulting sequence may have less characters than the given [size]. + * + * @param size the number of elements to take in each string, must be positive and can be greater than the number of elements in this char sequence. + * + * @sample samples.collections.Collections.Transformations.chunked + */ +@SinceKotlin("1.2") +public fun CharSequence.chunkedSequence(size: Int): Sequence { + return chunkedSequence(size) { it.toString() } +} + +/** + * Splits this char sequence into several char sequences each not exceeding the given [size] + * and applies the given [transform] function to an each. + * + * @return sequence of results of the [transform] applied to an each char sequence. + * + * Note that the char sequence passed to the [transform] function is ephemeral and is valid only inside that function. + * You should not store it or allow it to escape in some way, unless you made a snapshot of it. + * The last char sequence may have less characters than the given [size]. + * + * @param size the number of elements to take in each char sequence, must be positive and can be greater than the number of elements in this char sequence. + * + * @sample samples.text.Strings.chunkedTransformToSequence + */ +@SinceKotlin("1.2") +public fun CharSequence.chunkedSequence(size: Int, transform: (CharSequence) -> R): Sequence { + return windowedSequence(size, size, partialWindows = true, transform = transform) +} + /** * Splits the original char sequence into pair of char sequences, * where *first* char sequence contains characters for which [predicate] yielded `true`, @@ -2324,6 +2390,102 @@ public inline fun String.partition(predicate: (Char) -> Boolean): Pair { + return windowed(size, step, partialWindows) { it.toString() } +} + +/** + * Returns a list of results of applying the given [transform] function to + * an each char sequence representing a view over the window of the given [size] + * sliding along this char sequence with the given [step]. + * + * Note that the char sequence passed to the [transform] function is ephemeral and is valid only inside that function. + * You should not store it or allow it to escape in some way, unless you made a snapshot of it. + * Several last char sequences may have less characters than the given [size]. + * + * Both [size] and [step] must be positive and can be greater than the number of elements in this char sequence. + * @param size the number of elements to take in each window + * @param step the number of elements to move the window forward by on an each step, by default 1 + * @param partialWindows controls whether or not to keep partial windows in the end if any, + * by default `false` which means partial windows won't be preserved + * + * @sample samples.collections.Sequences.Transformations.averageWindows + */ +@SinceKotlin("1.2") +public fun CharSequence.windowed(size: Int, step: Int = 1, partialWindows: Boolean = false, transform: (CharSequence) -> R): List { + checkWindowSizeStep(size, step) + val thisSize = this.length + val result = ArrayList((thisSize + step - 1) / step) + var index = 0 + while (index < thisSize) { + val end = index + size + val coercedEnd = if (end > thisSize) { if (partialWindows) thisSize else break } else end + result.add(transform(subSequence(index, coercedEnd))) + index += step + } + return result +} + +/** + * Returns a sequence of snapshots of the window of the given [size] + * sliding along this char sequence with the given [step], where each + * snapshot is a string. + * + * Several last strings may have less characters than the given [size]. + * + * Both [size] and [step] must be positive and can be greater than the number of elements in this char sequence. + * @param size the number of elements to take in each window + * @param step the number of elements to move the window forward by on an each step, by default 1 + * @param partialWindows controls whether or not to keep partial windows in the end if any, + * by default `false` which means partial windows won't be preserved + * + * @sample samples.collections.Sequences.Transformations.takeWindows + */ +@SinceKotlin("1.2") +public fun CharSequence.windowedSequence(size: Int, step: Int = 1, partialWindows: Boolean = false): Sequence { + return windowedSequence(size, step, partialWindows) { it.toString() } +} + +/** + * Returns a sequence of results of applying the given [transform] function to + * an each char sequence representing a view over the window of the given [size] + * sliding along this char sequence with the given [step]. + * + * Note that the char sequence passed to the [transform] function is ephemeral and is valid only inside that function. + * You should not store it or allow it to escape in some way, unless you made a snapshot of it. + * Several last char sequences may have less characters than the given [size]. + * + * Both [size] and [step] must be positive and can be greater than the number of elements in this char sequence. + * @param size the number of elements to take in each window + * @param step the number of elements to move the window forward by on an each step, by default 1 + * @param partialWindows controls whether or not to keep partial windows in the end if any, + * by default `false` which means partial windows won't be preserved + * + * @sample samples.collections.Sequences.Transformations.averageWindows + */ +@SinceKotlin("1.2") +public fun CharSequence.windowedSequence(size: Int, step: Int = 1, partialWindows: Boolean = false, transform: (CharSequence) -> R): Sequence { + checkWindowSizeStep(size, step) + val windows = (if (partialWindows) indices else 0 until length - size + 1) step step + return windows.asSequence().map { index -> transform(subSequence(index, (index + size).coerceAtMost(length))) } +} + /** * Returns a list of pairs built from characters of both char sequences with same indexes. List has length of shortest char sequence. */ @@ -2343,6 +2505,37 @@ public inline fun CharSequence.zip(other: CharSequence, transform: (a: Char, return list } +/** + * Returns a list of pairs of each two adjacent characters in this char sequence. + * + * The returned list is empty if this char sequence contains less than two characters. + * + * @sample samples.collections.Collections.Transformations.zipWithNext + */ +@SinceKotlin("1.2") +public fun CharSequence.zipWithNext(): List> { + return zipWithNext { a, b -> a to b } +} + +/** + * Returns a list containing the results of applying the given [transform] function + * to an each pair of two adjacent characters in this char sequence. + * + * The returned list is empty if this char sequence contains less than two characters. + * + * @sample samples.collections.Collections.Transformations.zipWithNextToFindDeltas + */ +@SinceKotlin("1.2") +public inline fun CharSequence.zipWithNext(transform: (a: Char, b: Char) -> R): List { + val size = length - 1 + if (size < 1) return emptyList() + val result = ArrayList(size) + for (index in 0..size - 1) { + result.add(transform(this[index], this[index + 1])) + } + return result +} + /** * Creates an [Iterable] instance that wraps the original char sequence returning its characters when being iterated. */