-
Notifications
You must be signed in to change notification settings - Fork 10.4k
/
Copy pathGenerateSliceTests.py
69 lines (57 loc) · 2.28 KB
/
GenerateSliceTests.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
#!/usr/bin/env python2
import itertools
traversal_options = [ 'Forward', 'Bidirectional', 'RandomAccess' ]
base_kind_options = [ 'Defaulted', 'Minimal' ]
mutable_options = [ False, True ]
for traversal, base_kind, mutable in itertools.product(
traversal_options, base_kind_options, mutable_options):
# Test Slice<Base> and MutableSlice<Base> of various collections using value
# types as elements.
wrapper_types = [ 'Slice', 'MutableSlice' ] if mutable else [ 'Slice' ]
for WrapperType in wrapper_types:
for name, prefix, suffix in [
('FullWidth', '[]', '[]'),
('WithPrefix', '[ -9999, -9998, -9997 ]', '[]'),
('WithSuffix', '[]', '[ -9999, -9998, -9997 ]'),
('WithPrefixAndSuffix', '[ -9999, -9998, -9997, -9996, -9995 ]', '[ -9994, -9993, -9992 ]')
]:
Base = '%s%s%sCollection' % (base_kind, traversal, 'Mutable' if mutable else '')
testFilename = WrapperType + '_Of_' + Base + '_' + name + '.swift'
testFile = open(testFilename + '.gyb', 'w')
testFile.write("""
//// Automatically Generated From validation-test/stdlib/Inputs/GenerateSliceTests.py
//////// Do Not Edit Directly!
// -*- swift -*-
// RUN: rm -rf %t ; mkdir -p %t
// RUN: %S/../../../utils/gyb %s -o %t/{testFilename} -D test_path="%S"
// RUN: %S/../../../utils/line-directive %t/{testFilename} -- %target-build-swift %t/{testFilename} -o %t/{testFilename}.a.out
// RUN: %S/../../../utils/line-directive %t/{testFilename} -- %target-run %t/{testFilename}.a.out
// REQUIRES: executable_test
// FIXME: the test is too slow when the standard library is not optimized.
// REQUIRES: optimized_stdlib
import StdlibUnittest
var SliceTests = TestSuite("CollectionType")
% import gyb
% TSliceTest = gyb.parseTemplate("{{}}/Inputs/slice.gyb".format(test_path))
% SliceTest = gyb.executeTemplate(
% TSliceTest,
% traversal='{traversal}',
% base_kind='{base_kind}',
% mutable={mutable},
% WrapperType='{WrapperType}',
% name='{name}',
% prefix={prefix},
% suffix={suffix})
${{SliceTest}}
runAllTests()
""".format(
testFilename=testFilename,
traversal=traversal,
base_kind=base_kind,
mutable=mutable,
WrapperType=WrapperType,
name=name,
prefix=prefix,
suffix=suffix
))
testFile.close()