Skip to content

stdlib tests: fix indentation #3071

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 20, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
202 changes: 104 additions & 98 deletions stdlib/private/StdlibCollectionUnittest/CheckCollectionType.swift.gyb
Original file line number Diff line number Diff line change
Expand Up @@ -1596,83 +1596,87 @@ extension TestSuite {
}
}
% end

self.test("\(testNamePrefix)/distance(from:to:)/semantics")
.forEach(in: distanceFromToTests) { (test) in
let c = toCollection(0..<20)
let backwards = (test.startOffset > test.endOffset)
if backwards && !collectionIsBidirectional {
expectCrashLater()
}
.forEach(in: distanceFromToTests) {
test in
let c = toCollection(0..<20)
let backwards = (test.startOffset > test.endOffset)
if backwards && !collectionIsBidirectional {
expectCrashLater()
}

let d = c.distance(
from: c.nthIndex(test.startOffset), to: c.nthIndex(test.endOffset))
expectEqual(
numericCast(test.expectedDistance),
d, stackTrace: SourceLocStack().with(test.loc))
let d = c.distance(
from: c.nthIndex(test.startOffset), to: c.nthIndex(test.endOffset))
expectEqual(
numericCast(test.expectedDistance),
d, stackTrace: SourceLocStack().with(test.loc))
}

self.test("\(testNamePrefix)/index(_:offsetBy: n)/semantics")
.forEach(in: indexOffsetByTests.filter(
{$0.limit == nil && $0.distance >= 0}
)) { (test) in
let max = 10
let c = toCollection(0..<max)

if test.expectedOffset! >= max {
expectCrashLater()
}
let new = c.index(
c.nthIndex(test.startOffset),
offsetBy: numericCast(test.distance))

// Since the `nthIndex(offset:)` method performs the same operation
// (i.e. advances `c.startIndex` by `test.distance`, it would be
// silly to compare index values. Luckily the underlying collection
// contains exactly index offsets.
expectEqual(test.expectedOffset!, extractValue(c[new]).value,
stackTrace: SourceLocStack().with(test.loc))
.forEach(
in: indexOffsetByTests.filter { $0.limit == nil && $0.distance >= 0 }
) {
test in
let max = 10
let c = toCollection(0..<max)

if test.expectedOffset! >= max {
expectCrashLater()
}
let new = c.index(
c.nthIndex(test.startOffset),
offsetBy: numericCast(test.distance))

// Since the `nthIndex(offset:)` method performs the same operation
// (i.e. advances `c.startIndex` by `test.distance`, it would be
// silly to compare index values. Luckily the underlying collection
// contains exactly index offsets.
expectEqual(test.expectedOffset!, extractValue(c[new]).value,
stackTrace: SourceLocStack().with(test.loc))
}

self.test("\(testNamePrefix)/formIndex(_:offsetBy: n)/semantics")
.forEach(in: indexOffsetByTests.filter(
{$0.limit == nil && $0.distance >= 0}
)) { (test) in
let max = 10
let c = toCollection(0..<max)
.forEach(
in: indexOffsetByTests.filter { $0.limit == nil && $0.distance >= 0 }
) {
test in
let max = 10
let c = toCollection(0..<max)

var new = c.nthIndex(test.startOffset)
var new = c.nthIndex(test.startOffset)

if test.expectedOffset! >= max {
expectCrashLater()
}
c.formIndex(&new, offsetBy: numericCast(test.distance))
expectEqual(test.expectedOffset!, extractValue(c[new]).value,
stackTrace: SourceLocStack().with(test.loc))
if test.expectedOffset! >= max {
expectCrashLater()
}
c.formIndex(&new, offsetBy: numericCast(test.distance))
expectEqual(test.expectedOffset!, extractValue(c[new]).value,
stackTrace: SourceLocStack().with(test.loc))
}

% for function_name in ['index', 'formIndex']:
self.test("\(testNamePrefix)/${function_name}(_:offsetBy: -n)/semantics")
.forEach(in: indexOffsetByTests.filter(
{$0.limit == nil && $0.distance < 0}
)) { (test) in
let c = toCollection(0..<20)
.forEach(
in: indexOffsetByTests.filter { $0.limit == nil && $0.distance < 0 }
) {
test in
let c = toCollection(0..<20)
% if function_name is 'index':
let start = c.nthIndex(test.startOffset)
let start = c.nthIndex(test.startOffset)
% else:
var new = c.nthIndex(test.startOffset)
var new = c.nthIndex(test.startOffset)
% end

if test.expectedOffset! < 0 || !collectionIsBidirectional {
expectCrashLater()
}
if test.expectedOffset! < 0 || !collectionIsBidirectional {
expectCrashLater()
}
% if function_name is 'index':
let new = c.index(start, offsetBy: numericCast(test.distance))
let new = c.index(start, offsetBy: numericCast(test.distance))
% else:
c.formIndex(&new, offsetBy: numericCast(test.distance))
c.formIndex(&new, offsetBy: numericCast(test.distance))
% end
expectEqual(test.expectedOffset!, extractValue(c[new]).value,
stackTrace: SourceLocStack().with(test.loc))
expectEqual(test.expectedOffset!, extractValue(c[new]).value,
stackTrace: SourceLocStack().with(test.loc))
}
% end

Expand Down Expand Up @@ -1716,55 +1720,57 @@ extension TestSuite {
}

self.test("\(testNamePrefix)/index(_:offsetBy: -n, limitedBy:)/semantics")
.forEach(in: indexOffsetByTests.filter(
{$0.limit != nil && $0.distance < 0}
)) { (test) in
let c = toCollection(0..<20)
let limit = c.nthIndex(test.limit.unsafelyUnwrapped)
if collectionIsBidirectional {
let new = c.index(
c.nthIndex(test.startOffset),
offsetBy: numericCast(test.distance),
limitedBy: limit)
if let expectedOffset = test.expectedOffset {
expectEqual(c.nthIndex(expectedOffset), new!,
stackTrace: SourceLocStack().with(test.loc))
} else {
expectEmpty(new)
}
.forEach(
in: indexOffsetByTests.filter { $0.limit != nil && $0.distance < 0 }
) {
test in
let c = toCollection(0..<20)
let limit = c.nthIndex(test.limit.unsafelyUnwrapped)
if collectionIsBidirectional {
let new = c.index(
c.nthIndex(test.startOffset),
offsetBy: numericCast(test.distance),
limitedBy: limit)
if let expectedOffset = test.expectedOffset {
expectEqual(c.nthIndex(expectedOffset), new!,
stackTrace: SourceLocStack().with(test.loc))
} else {
expectCrashLater()
_ = c.index(
c.nthIndex(test.startOffset),
offsetBy: numericCast(test.distance),
limitedBy: limit)
expectEmpty(new)
}
} else {
expectCrashLater()
_ = c.index(
c.nthIndex(test.startOffset),
offsetBy: numericCast(test.distance),
limitedBy: limit)
}
}

self.test("\(testNamePrefix)/formIndex(_:offsetBy: -n, limitedBy:)/semantics")
.forEach(in: indexOffsetByTests.filter(
{$0.limit != nil && $0.distance < 0}
)) { (test) in
let c = toCollection(0..<20)
let limit = c.nthIndex(test.limit.unsafelyUnwrapped)
var new = c.nthIndex(test.startOffset)
if collectionIsBidirectional {
let exact = c.formIndex(
&new,
offsetBy: numericCast(test.distance),
limitedBy: limit)
if let expectedOffset = test.expectedOffset {
expectEqual(c.nthIndex(expectedOffset), new,
stackTrace: SourceLocStack().with(test.loc))
expectTrue(exact, stackTrace: SourceLocStack().with(test.loc))
} else {
expectEqual(limit, new, stackTrace: SourceLocStack().with(test.loc))
expectFalse(exact, stackTrace: SourceLocStack().with(test.loc))
}
.forEach(
in: indexOffsetByTests.filter { $0.limit != nil && $0.distance < 0 }
) {
test in
let c = toCollection(0..<20)
let limit = c.nthIndex(test.limit.unsafelyUnwrapped)
var new = c.nthIndex(test.startOffset)
if collectionIsBidirectional {
let exact = c.formIndex(
&new,
offsetBy: numericCast(test.distance),
limitedBy: limit)
if let expectedOffset = test.expectedOffset {
expectEqual(c.nthIndex(expectedOffset), new,
stackTrace: SourceLocStack().with(test.loc))
expectTrue(exact, stackTrace: SourceLocStack().with(test.loc))
} else {
expectCrashLater()
_ = c.formIndex(&new, offsetBy: numericCast(test.distance), limitedBy: limit)
expectEqual(limit, new, stackTrace: SourceLocStack().with(test.loc))
expectFalse(exact, stackTrace: SourceLocStack().with(test.loc))
}
} else {
expectCrashLater()
_ = c.formIndex(&new, offsetBy: numericCast(test.distance), limitedBy: limit)
}
}

}
Expand Down