Skip to content

Commit add2bce

Browse files
committed
Revise doc comments and add test
1 parent f817803 commit add2bce

File tree

2 files changed

+19
-3
lines changed

2 files changed

+19
-3
lines changed

stdlib/public/core/IntegerParsing.swift

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ extension FixedWidthInteger {
102102
///
103103
/// The string passed as `text` may begin with a plus or minus sign character
104104
/// (`+` or `-`), followed by one or more numeric digits (`0-9`) or letters
105-
/// (`a-z` or `A-Z`). The string is case-insensitive.
105+
/// (`a-z` or `A-Z`). Parsing of the string is case insensitive.
106106
///
107107
/// let x = Int("123")
108108
/// // x == 123
@@ -116,7 +116,7 @@ extension FixedWidthInteger {
116116
/// // z == 123
117117
///
118118
/// If `text` is in an invalid format or contains characters that are out of
119-
/// range for the given `radix`, or if the value it denotes in the given
119+
/// bounds for the given `radix`, or if the value it denotes in the given
120120
/// `radix` is not representable, the result is `nil`. For example, the
121121
/// following conversions result in `nil`:
122122
///
@@ -171,8 +171,9 @@ extension FixedWidthInteger {
171171
/// Int(" 100") // Includes whitespace
172172
/// Int("21-50") // Invalid format
173173
/// Int("ff6600") // Characters out of bounds
174+
/// Int("10000000000000000000000000") // Out of range
174175
///
175-
/// - Parameter description: The ASCII representation of a number in base 10.
176+
/// - Parameter description: The ASCII representation of a number.
176177
@_semantics("optimize.sil.specialize.generic.partial.never")
177178
@inline(__always)
178179
public init?(_ description: String) {

test/stdlib/Integers.swift.gyb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,21 @@ tests.test("extendingOrTruncating") {
364364
expectEqual(129, UInt8(extendingOrTruncating: 129 + 1024 as UDWord))
365365
}
366366

367+
tests.test("Parsing/LosslessStringConvertible") {
368+
func _toArray<T: LosslessStringConvertible>(_ text: String) -> [T] {
369+
return text.split(separator: " ").map { T(String($0)) }.flatMap { $0 }
370+
}
371+
372+
let i: [Int] = _toArray("1 2 3")
373+
expectEqual(i.count, 3)
374+
expectEqual(i[0], 1)
375+
expectEqual(i[1], 2)
376+
expectEqual(i[2], 3)
377+
378+
let j: [Int] = _toArray("21-50 ff6600 10000000000000000000000000")
379+
expectEqual(j.count, 0)
380+
}
381+
367382
tests.test("HeterogeneousEquality") {
368383
expectTrue(-1 as DWord != UDWord.max)
369384
expectTrue(DWord.max == UDWord.max / 2)

0 commit comments

Comments
 (0)