@@ -16,40 +16,6 @@ fn basic_literal() {
16
16
. stdout_only ( "hello world" ) ;
17
17
}
18
18
19
- #[ test]
20
- fn escaped_tab ( ) {
21
- new_ucmd ! ( )
22
- . args ( & [ "hello\\ t world" ] )
23
- . succeeds ( )
24
- . stdout_only ( "hello\t world" ) ;
25
- }
26
-
27
- #[ test]
28
- fn escaped_newline ( ) {
29
- new_ucmd ! ( )
30
- . args ( & [ "hello\\ n world" ] )
31
- . succeeds ( )
32
- . stdout_only ( "hello\n world" ) ;
33
- }
34
-
35
- #[ test]
36
- fn escaped_slash ( ) {
37
- new_ucmd ! ( )
38
- . args ( & [ "hello\\ \\ world" ] )
39
- . succeeds ( )
40
- . stdout_only ( "hello\\ world" ) ;
41
- }
42
-
43
- #[ test]
44
- fn unescaped_double_quote ( ) {
45
- new_ucmd ! ( ) . args ( & [ "\\ \" " ] ) . succeeds ( ) . stdout_only ( "\" " ) ;
46
- }
47
-
48
- #[ test]
49
- fn escaped_hex ( ) {
50
- new_ucmd ! ( ) . args ( & [ "\\ x41" ] ) . succeeds ( ) . stdout_only ( "A" ) ;
51
- }
52
-
53
19
#[ test]
54
20
fn test_missing_escaped_hex_value ( ) {
55
21
new_ucmd ! ( )
@@ -58,17 +24,12 @@ fn test_missing_escaped_hex_value() {
58
24
. stderr_only ( "printf: missing hexadecimal number in escape\n " ) ;
59
25
}
60
26
61
- #[ test]
62
- fn escaped_octal ( ) {
63
- new_ucmd ! ( ) . args ( & [ "\\ 101" ] ) . succeeds ( ) . stdout_only ( "A" ) ;
64
- }
65
-
66
27
#[ test]
67
28
fn escaped_octal_and_newline ( ) {
68
29
new_ucmd ! ( )
69
- . args ( & [ "\\ 0377\\ n" ] )
30
+ . args ( & [ "\\ 101 \\ 0377\\ n" ] )
70
31
. succeeds ( )
71
- . stdout_only ( "\x1F 7\n " ) ;
32
+ . stdout_only ( "A \x1F 7\n " ) ;
72
33
}
73
34
74
35
#[ test]
@@ -145,38 +106,6 @@ fn escaped_unrecognized() {
145
106
new_ucmd ! ( ) . args ( & [ "c\\ d" ] ) . succeeds ( ) . stdout_only ( "c\\ d" ) ;
146
107
}
147
108
148
- #[ test]
149
- fn sub_string ( ) {
150
- new_ucmd ! ( )
151
- . args ( & [ "hello %s" , "world" ] )
152
- . succeeds ( )
153
- . stdout_only ( "hello world" ) ;
154
- }
155
-
156
- #[ test]
157
- fn sub_multi_field ( ) {
158
- new_ucmd ! ( )
159
- . args ( & [ "%s %s" , "hello" , "world" ] )
160
- . succeeds ( )
161
- . stdout_only ( "hello world" ) ;
162
- }
163
-
164
- #[ test]
165
- fn sub_repeat_format_str ( ) {
166
- new_ucmd ! ( )
167
- . args ( & [ "%s." , "hello" , "world" ] )
168
- . succeeds ( )
169
- . stdout_only ( "hello.world." ) ;
170
- }
171
-
172
- #[ test]
173
- fn sub_string_ignore_escapes ( ) {
174
- new_ucmd ! ( )
175
- . args ( & [ "hello %s" , "\\ tworld" ] )
176
- . succeeds ( )
177
- . stdout_only ( "hello \\ tworld" ) ;
178
- }
179
-
180
109
#[ test]
181
110
fn sub_b_string_handle_escapes ( ) {
182
111
new_ucmd ! ( )
@@ -705,27 +634,11 @@ fn sub_any_asterisk_second_param_with_integer() {
705
634
}
706
635
707
636
#[ test]
708
- fn sub_any_specifiers_no_params ( ) {
709
- new_ucmd ! ( )
710
- . args ( & [ "%ztlhLji" , "3" ] ) //spell-checker:disable-line
711
- . succeeds ( )
712
- . stdout_only ( "3" ) ;
713
- }
714
-
715
- #[ test]
716
- fn sub_any_specifiers_after_first_param ( ) {
717
- new_ucmd ! ( )
718
- . args ( & [ "%0ztlhLji" , "3" ] ) //spell-checker:disable-line
719
- . succeeds ( )
720
- . stdout_only ( "3" ) ;
721
- }
722
-
723
- #[ test]
724
- fn sub_any_specifiers_after_period ( ) {
725
- new_ucmd ! ( )
726
- . args ( & [ "%0.ztlhLji" , "3" ] ) //spell-checker:disable-line
727
- . succeeds ( )
728
- . stdout_only ( "3" ) ;
637
+ fn sub_any_specifiers ( ) {
638
+ // spell-checker:disable-next-line
639
+ for format in [ "%ztlhLji" , "%0ztlhLji" , "%0.ztlhLji" ] {
640
+ new_ucmd ! ( ) . args ( & [ format, "3" ] ) . succeeds ( ) . stdout_only ( "3" ) ;
641
+ }
729
642
}
730
643
731
644
#[ test]
@@ -1027,33 +940,23 @@ fn pad_string() {
1027
940
}
1028
941
1029
942
#[ test]
1030
- fn format_spec_zero_char_fails ( ) {
1031
- // It is invalid to have the format spec '%0c'
1032
- new_ucmd ! ( ) . args ( & [ "%0c" , "3" ] ) . fails_with_code ( 1 ) ;
1033
- }
1034
-
1035
- #[ test]
1036
- fn format_spec_zero_string_fails ( ) {
1037
- // It is invalid to have the format spec '%0s'
1038
- new_ucmd ! ( ) . args ( & [ "%0s" , "3" ] ) . fails_with_code ( 1 ) ;
1039
- }
1040
-
1041
- #[ test]
1042
- fn invalid_precision_fails ( ) {
1043
- // It is invalid to have length of output string greater than i32::MAX
1044
- new_ucmd ! ( )
1045
- . args ( & [ "%.*d" , "2147483648" , "0" ] )
1046
- . fails ( )
1047
- . stderr_is ( "printf: invalid precision: '2147483648'\n " ) ;
943
+ fn format_spec_zero_fails ( ) {
944
+ // It is invalid to have the format spec
945
+ for format in [ "%0c" , "%0s" ] {
946
+ new_ucmd ! ( ) . args ( & [ format, "3" ] ) . fails_with_code ( 1 ) ;
947
+ }
1048
948
}
1049
949
1050
950
#[ test]
1051
- fn float_invalid_precision_fails ( ) {
951
+ fn invalid_precision_tests ( ) {
1052
952
// It is invalid to have length of output string greater than i32::MAX
1053
- new_ucmd ! ( )
1054
- . args ( & [ "%.*f" , "2147483648" , "0" ] )
1055
- . fails ( )
1056
- . stderr_is ( "printf: invalid precision: '2147483648'\n " ) ;
953
+ for format in [ "%.*d" , "%.*f" ] {
954
+ let expected_error = "printf: invalid precision: '2147483648'\n " ;
955
+ new_ucmd ! ( )
956
+ . args ( & [ format, "2147483648" , "0" ] )
957
+ . fails ( )
958
+ . stderr_is ( expected_error) ;
959
+ }
1057
960
}
1058
961
1059
962
// The following padding-tests test for the cases in which flags in ['0', ' '] are given.
@@ -1385,3 +1288,28 @@ fn float_arg_with_whitespace() {
1385
1288
. fails ( )
1386
1289
. stderr_contains ( "expected a numeric value" ) ;
1387
1290
}
1291
+
1292
+ #[ test]
1293
+ fn mb_input ( ) {
1294
+ for format in [ "\" á" , "\' á" , "'\u{e1} " ] {
1295
+ new_ucmd ! ( )
1296
+ . args ( & [ "%04x\n " , format] )
1297
+ . succeeds ( )
1298
+ . stdout_only ( "00e1\n " ) ;
1299
+ }
1300
+
1301
+ let cases = vec ! [
1302
+ ( "\" á=" , "=" ) ,
1303
+ ( "\' á-" , "-" ) ,
1304
+ ( "\' á=-==" , "=-==" ) ,
1305
+ ( "'\u{e1} ++" , "++" ) ,
1306
+ ] ;
1307
+
1308
+ for ( format, expected) in cases {
1309
+ new_ucmd ! ( )
1310
+ . args ( & [ "%04x\n " , format] )
1311
+ . succeeds ( )
1312
+ . stdout_is ( "00e1\n " )
1313
+ . stderr_is ( format ! ( "printf: warning: {expected}: character(s) following character constant have been ignored\n " ) ) ;
1314
+ }
1315
+ }
0 commit comments