Skip to content

Commit c11eb40

Browse files
committed
Iterate over more documented operators, now that the documentation has improved; now 3460 tests.
Replace hard-coded lists of real-number types, and of arithmetic and logical operators I’m testing, with lists added to SwiftIntTypes.py, which becomes a bit of a misnomer. Separate them into ones which only work on integer types, and those which also allow reals. Do a double loop, over just the integers and then the reals as well. Change the run line to allow importing StdlibUnittest with help from Dmitri, which I won't actually need until I do result type checking. Approved by Dmitri. Swift SVN r24029
1 parent c80d5f0 commit c11eb40

File tree

2 files changed

+51
-18
lines changed

2 files changed

+51
-18
lines changed

utils/SwiftIntTypes.py

+26
Original file line numberDiff line numberDiff line change
@@ -74,3 +74,29 @@ def should_define_truncating_bit_pattern_init(src_ty, dst_ty):
7474

7575
return False
7676

77+
def all_integer_type_names():
78+
return [self_ty.stdlib_name for self_ty in all_integer_types(0)]
79+
80+
def all_real_number_type_names():
81+
return ['Float', 'Double'] #TODO Float80 for i386 & x86_64
82+
83+
def all_numeric_type_names():
84+
return all_integer_type_names() + all_real_number_type_names()
85+
86+
# Swift_Programming_Language/Expressions.html
87+
88+
def all_integer_binary_operator_names():
89+
return ['<<', '>>', '&*', '&/', '&%', '&', '&+', '&-', '|', '^']
90+
91+
def all_integer_or_real_binary_operator_names():
92+
return ['*', '/', '%', '+', '-', '..<', '...']
93+
94+
def all_arithmetic_comparison_operator_names():
95+
return ['<', '<=', '>', '>=', '==', '!=']
96+
97+
def all_integer_assignment_operator_names():
98+
return ['<<=', '>>=', '&=', '^=', '|=']
99+
100+
def all_integer_or_real_assignment_operator_names():
101+
return ['=', '*=', '/=', '%=', '+=', '-=']
102+
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,34 @@
11
// RUN: rm -rf %t && mkdir -p %t && %S/../../utils/gyb %s -o %t/main.swift
2-
// RUN: %S/../../utils/line-directive %t/main.swift -- %swift -verify -parse %t/main.swift
2+
// RUN: %S/../../utils/line-directive %t/main.swift -- %target-build-swift -parse -Xfrontend -verify %t/main.swift
33

4-
% from SwiftIntTypes import all_integer_types
5-
% integer_types_array = [self_ty.stdlib_name for self_ty in all_integer_types(0)]
6-
// integer_types_array: ${integer_types_array}
7-
% floating_types_array = ['Float', 'Double']
8-
% typesToTest = floating_types_array + integer_types_array
9-
// typesToTest: ${typesToTest}
4+
% from SwiftIntTypes import all_numeric_type_names, all_integer_type_names, \
5+
% all_integer_binary_operator_names, all_integer_or_real_binary_operator_names, \
6+
% all_arithmetic_comparison_operator_names, all_integer_assignment_operator_names, \
7+
% all_integer_or_real_assignment_operator_names
108

11-
% operatorsToTest = ['=', '*', '/', '%', '==', '!=', '>', '<', '>=', '<='] # TODO: Restore '+', '-', when rdar://18695154 is fixed.
12-
// operatorsToTest: ${operatorsToTest} _The Swift Programming Language_ "Basic Operators," binary non-logical ops
13-
//TODO: Better error regex, verify the type of the result
9+
% int_ops = all_integer_binary_operator_names() + all_integer_assignment_operator_names()
10+
% arith_ops = all_integer_or_real_binary_operator_names() + \
11+
% all_arithmetic_comparison_operator_names() + all_integer_or_real_assignment_operator_names()
12+
13+
//TODO: Better error regex, verify the type of the result, Float80 for i386 & x86_64
1414

1515
func testIteratedOperations() {
16-
% for T1 in typesToTest:
17-
% for T2 in typesToTest:
18-
% for op in operatorsToTest:
19-
if true {
20-
var x1_${T1}: ${T1} = 0
21-
var x2_${T2}: ${T2} = 0
22-
x1_${T1} ${op} x2_${T2} ${ "// expected-error{{ }}" if T1 != T2 else "" }
23-
}
16+
% for typesToTest, operatorsToTest in zip([all_integer_type_names(), all_numeric_type_names()], \
17+
% [int_ops, arith_ops]):
18+
% operatorsToTest = [x for x in operatorsToTest if not '+' in x and not '-' in x]
19+
%# TODO: rm when rdar://18695154 is fixed.
20+
// typesToTest: ${typesToTest}, operatorsToTest: ${operatorsToTest}
21+
% for T1 in typesToTest:
22+
% for T2 in typesToTest:
23+
% for op in operatorsToTest:
24+
if true {
25+
var x1_${T1}: ${T1} = 0
26+
var x2_${T2}: ${T2} = 0
27+
x1_${T1} ${op} x2_${T2} ${ "// expected-error{{ }}" if T1 != T2 else "" }
28+
}
29+
%end
2430
%end
2531
%end
2632
%end
33+
2734
}

0 commit comments

Comments
 (0)