diff --git a/libraries/stdlib/samples/test/samples/ranges/ranges.kt b/libraries/stdlib/samples/test/samples/ranges/ranges.kt new file mode 100644 index 00000000000..cf5c614f814 --- /dev/null +++ b/libraries/stdlib/samples/test/samples/ranges/ranges.kt @@ -0,0 +1,43 @@ +/* + * 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 samples.ranges + +import samples.* +import java.sql.Date + +class Ranges { + + @Sample + fun rangeFromComparable() { + val start = Date.valueOf("2017-01-01") + val end = Date.valueOf("2017-12-31") + val range = start..end + assertPrints(range, "2017-01-01..2017-12-31") + } + + @Sample + fun rangeFromDouble() { + val range = 1.0..100.0 + assertPrints(range, "1.0..100.0") + } + + @Sample + fun rangeFromFloat() { + val range = 1f..100f + assertPrints(range, "1.0..100.0") + } +} \ No newline at end of file diff --git a/libraries/stdlib/src/kotlin/ranges/Ranges.kt b/libraries/stdlib/src/kotlin/ranges/Ranges.kt index 602ff40de78..eb6af2c70b5 100644 --- a/libraries/stdlib/src/kotlin/ranges/Ranges.kt +++ b/libraries/stdlib/src/kotlin/ranges/Ranges.kt @@ -105,6 +105,7 @@ private class ClosedFloatRange ( * Creates a range from this [Comparable] value to the specified [that] value. * * This value needs to be smaller than [that] value, otherwise the returned range will be empty. + * @sample samples.ranges.Ranges.rangeFromComparable */ public operator fun > T.rangeTo(that: T): ClosedRange = ComparableRange(this, that) @@ -112,6 +113,7 @@ public operator fun > T.rangeTo(that: T): ClosedRange = Comp * Creates a range from this [Double] value to the specified [that] value. * * Numbers are compared with the ends of this range according to IEEE-754. + * @sample samples.ranges.Ranges.rangeFromDouble */ @SinceKotlin("1.1") public operator fun Double.rangeTo(that: Double): ClosedFloatingPointRange = ClosedDoubleRange(this, that) @@ -120,6 +122,7 @@ public operator fun Double.rangeTo(that: Double): ClosedFloatingPointRange