@@ -24,38 +24,38 @@ void FormatStringTests()
24
24
String . Format ( "{0, -10 :0.000}" , 1 ) ;
25
25
26
26
// BAD: Invalid format string
27
- String . Format ( "{ 0}" , 1 ) ;
27
+ String . Format ( "{ 0}" , 1 ) ; // $ Alert
28
28
29
29
// BAD: Invalid format string
30
- String . Format ( "{0,--1}" , 1 ) ;
30
+ String . Format ( "{0,--1}" , 1 ) ; // $ Alert
31
31
32
32
// BAD: Invalid format string
33
- String . Format ( "{0:{}}" , 1 ) ;
33
+ String . Format ( "{0:{}}" , 1 ) ; // $ Alert
34
34
35
35
// BAD: Invalid format string
36
- String . Format ( "%d" , 1 ) ;
36
+ String . Format ( "%d" , 1 ) ; // $ Alert Sink
37
37
38
38
// BAD: } { in the middle.
39
- String . Format ( "{{0}-{1}}" , 0 , 1 ) ;
39
+ String . Format ( "{{0}-{1}}" , 0 , 1 ) ; // $ Alert
40
40
41
41
// BAD: This is invalid
42
- String . Format ( "{0}}" , 0 , 1 ) ;
42
+ String . Format ( "{0}}" , 0 , 1 ) ; // $ Alert
43
43
44
44
// BAD: Invalid
45
- string . Format ( "{foo{0}}" , 0 ) ;
45
+ string . Format ( "{foo{0}}" , 0 ) ; // $ Alert
46
46
47
47
// GOOD: {{ is output as {
48
- String . Format ( "{{sdc}}" , 0 ) ;
48
+ String . Format ( "{{sdc}}{0} " , 0 ) ;
49
49
50
50
// BAD: Invalid: Stray }
51
- String . Format ( "}" , 0 ) ;
51
+ String . Format ( "}{0} " , 0 ) ; // $ Alert
52
52
53
53
// GOOD: {{ output as {
54
- String . Format ( "new {0} ({1} => {{" , 0 ) ;
54
+ String . Format ( "new {0} ({1} => {{" , 0 , 1 ) ;
55
55
56
56
// GOOD: Literal {{ and }}
57
- String . Format ( "{{ " , "" ) ;
58
- String . Format ( "{{{{}}" , "" ) ;
57
+ String . Format ( "{0}{{ " , 0 ) ;
58
+ String . Format ( "{0} {{{{ }}" , 0 ) ;
59
59
}
60
60
61
61
IFormatProvider fp ;
@@ -72,49 +72,49 @@ void FormatMethodTests()
72
72
Format ( "}" , 0 ) ;
73
73
74
74
// BAD: All of these are format methods with an invalid string.
75
- String . Format ( "}" , 0 ) ;
76
- String . Format ( "}" , ps ) ;
77
- String . Format ( fp , "}" , ps ) ;
78
- String . Format ( "}" , 0 , 1 ) ;
79
- String . Format ( "}" , 0 , 1 , 2 ) ;
80
- String . Format ( "}" , 0 , 1 , 2 , 3 ) ;
81
-
82
- sb . AppendFormat ( "}" , 0 ) ;
83
- sb . AppendFormat ( "}" , ps ) ;
84
- sb . AppendFormat ( fp , "}" , ps ) ;
85
- sb . AppendFormat ( "}" , 0 , 1 ) ;
86
- sb . AppendFormat ( "}" , 0 , 1 , 2 ) ;
87
- sb . AppendFormat ( "}" , 0 , 1 , 2 , 3 ) ;
88
-
89
- Console . WriteLine ( "}" , 0 ) ;
90
- Console . WriteLine ( "}" , ps ) ;
91
- Console . WriteLine ( "}" , 0 , 1 ) ;
92
- Console . WriteLine ( "}" , 0 , 1 , 2 ) ;
93
- Console . WriteLine ( "}" , 0 , 1 , 2 , 3 ) ;
94
-
95
- tw . WriteLine ( "}" , 0 ) ;
96
- tw . WriteLine ( "}" , ps ) ;
97
- tw . WriteLine ( "}" , 0 , 1 ) ;
98
- tw . WriteLine ( "}" , 0 , 1 , 2 ) ;
99
- tw . WriteLine ( "}" , 0 , 1 , 2 , 3 ) ;
100
-
101
- System . Diagnostics . Debug . WriteLine ( "}" , ps ) ;
102
- System . Diagnostics . Trace . TraceError ( "}" , 0 ) ;
103
- System . Diagnostics . Trace . TraceInformation ( "}" , 0 ) ;
104
- System . Diagnostics . Trace . TraceWarning ( "}" , 0 ) ;
105
- ts . TraceInformation ( "}" , 0 ) ;
106
-
107
- Console . Write ( "}" , 0 ) ;
108
- Console . Write ( "}" , 0 , 1 ) ;
109
- Console . Write ( "}" , 0 , 1 , 2 ) ;
110
- Console . Write ( "}" , 0 , 1 , 2 , 3 ) ;
75
+ String . Format ( "}" , 0 ) ; // $ Alert
76
+ String . Format ( "}" , ps ) ; // $ Alert
77
+ String . Format ( fp , "}" , ps ) ; // $ Alert
78
+ String . Format ( "}" , 0 , 1 ) ; // $ Alert
79
+ String . Format ( "}" , 0 , 1 , 2 ) ; // $ Alert
80
+ String . Format ( "}" , 0 , 1 , 2 , 3 ) ; // $ Alert
81
+
82
+ sb . AppendFormat ( "}" , 0 ) ; // $ Alert
83
+ sb . AppendFormat ( "}" , ps ) ; // $ Alert
84
+ sb . AppendFormat ( fp , "}" , ps ) ; // $ Alert
85
+ sb . AppendFormat ( "}" , 0 , 1 ) ; // $ Alert
86
+ sb . AppendFormat ( "}" , 0 , 1 , 2 ) ; // $ Alert
87
+ sb . AppendFormat ( "}" , 0 , 1 , 2 , 3 ) ; // $ Alert
88
+
89
+ Console . WriteLine ( "}" , 0 ) ; // $ Alert
90
+ Console . WriteLine ( "}" , ps ) ; // $ Alert
91
+ Console . WriteLine ( "}" , 0 , 1 ) ; // $ Alert
92
+ Console . WriteLine ( "}" , 0 , 1 , 2 ) ; // $ Alert
93
+ Console . WriteLine ( "}" , 0 , 1 , 2 , 3 ) ; // $ Alert
94
+
95
+ tw . WriteLine ( "}" , 0 ) ; // $ Alert
96
+ tw . WriteLine ( "}" , ps ) ; // $ Alert
97
+ tw . WriteLine ( "}" , 0 , 1 ) ; // $ Alert
98
+ tw . WriteLine ( "}" , 0 , 1 , 2 ) ; // $ Alert
99
+ tw . WriteLine ( "}" , 0 , 1 , 2 , 3 ) ; // $ Alert
100
+
101
+ System . Diagnostics . Debug . WriteLine ( "}" , ps ) ; // $ Alert
102
+ System . Diagnostics . Trace . TraceError ( "}" , 0 ) ; // $ Alert
103
+ System . Diagnostics . Trace . TraceInformation ( "}" , 0 ) ; // $ Alert
104
+ System . Diagnostics . Trace . TraceWarning ( "}" , 0 ) ; // $ Alert
105
+ ts . TraceInformation ( "}" , 0 ) ; // $ Alert
106
+
107
+ Console . Write ( "}" , 0 ) ; // $ Alert
108
+ Console . Write ( "}" , 0 , 1 ) ; // $ Alert
109
+ Console . Write ( "}" , 0 , 1 , 2 ) ; // $ Alert
110
+ Console . Write ( "}" , 0 , 1 , 2 , 3 ) ; // $ Alert
111
111
112
112
System . Diagnostics . Debug . WriteLine ( "}" , "" ) ; // GOOD
113
113
System . Diagnostics . Debug . Write ( "}" , "" ) ; // GOOD
114
114
115
- System . Diagnostics . Debug . Assert ( true , "Error" , "}" , ps ) ;
116
- sw . Write ( "}" , 0 ) ;
117
- System . Diagnostics . Debug . Print ( "}" , ps ) ;
115
+ System . Diagnostics . Debug . Assert ( true , "Error" , "}" , ps ) ; // $ Alert
116
+ sw . Write ( "}" , 0 ) ; // $ Alert
117
+ System . Diagnostics . Debug . Print ( "}" , ps ) ; // $ Alert
118
118
119
119
Console . WriteLine ( "}" ) ; // GOOD
120
120
}
0 commit comments