Skip to content

Commit 59b191c

Browse files
authored
Merge pull request RustPython#4457 from harupy/remove-useless-string-from
Remove useless `String::from` in tests
2 parents 211bdb0 + 6e7be1e commit 59b191c

File tree

2 files changed

+66
-66
lines changed

2 files changed

+66
-66
lines changed

compiler/parser/src/context.rs

Lines changed: 36 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -51,127 +51,127 @@ mod tests {
5151

5252
#[test]
5353
fn test_assign_name() {
54-
let source = String::from("x = (1, 2, 3)");
55-
let parse_ast = parse_program(&source, "<test>").unwrap();
54+
let source = "x = (1, 2, 3)";
55+
let parse_ast = parse_program(source, "<test>").unwrap();
5656
insta::assert_debug_snapshot!(parse_ast);
5757
}
5858

5959
#[test]
6060
fn test_assign_tuple() {
61-
let source = String::from("(x, y) = (1, 2, 3)");
62-
let parse_ast = parse_program(&source, "<test>").unwrap();
61+
let source = "(x, y) = (1, 2, 3)";
62+
let parse_ast = parse_program(source, "<test>").unwrap();
6363
insta::assert_debug_snapshot!(parse_ast);
6464
}
6565

6666
#[test]
6767
fn test_assign_list() {
68-
let source = String::from("[x, y] = (1, 2, 3)");
69-
let parse_ast = parse_program(&source, "<test>").unwrap();
68+
let source = "[x, y] = (1, 2, 3)";
69+
let parse_ast = parse_program(source, "<test>").unwrap();
7070
insta::assert_debug_snapshot!(parse_ast);
7171
}
7272

7373
#[test]
7474
fn test_assign_attribute() {
75-
let source = String::from("x.y = (1, 2, 3)");
76-
let parse_ast = parse_program(&source, "<test>").unwrap();
75+
let source = "x.y = (1, 2, 3)";
76+
let parse_ast = parse_program(source, "<test>").unwrap();
7777
insta::assert_debug_snapshot!(parse_ast);
7878
}
7979

8080
#[test]
8181
fn test_assign_subscript() {
82-
let source = String::from("x[y] = (1, 2, 3)");
83-
let parse_ast = parse_program(&source, "<test>").unwrap();
82+
let source = "x[y] = (1, 2, 3)";
83+
let parse_ast = parse_program(source, "<test>").unwrap();
8484
insta::assert_debug_snapshot!(parse_ast);
8585
}
8686

8787
#[test]
8888
fn test_assign_starred() {
89-
let source = String::from("(x, *y) = (1, 2, 3)");
90-
let parse_ast = parse_program(&source, "<test>").unwrap();
89+
let source = "(x, *y) = (1, 2, 3)";
90+
let parse_ast = parse_program(source, "<test>").unwrap();
9191
insta::assert_debug_snapshot!(parse_ast);
9292
}
9393

9494
#[test]
9595
fn test_assign_for() {
96-
let source = String::from("for x in (1, 2, 3): pass");
97-
let parse_ast = parse_program(&source, "<test>").unwrap();
96+
let source = "for x in (1, 2, 3): pass";
97+
let parse_ast = parse_program(source, "<test>").unwrap();
9898
insta::assert_debug_snapshot!(parse_ast);
9999
}
100100

101101
#[test]
102102
fn test_assign_list_comp() {
103-
let source = String::from("x = [y for y in (1, 2, 3)]");
104-
let parse_ast = parse_program(&source, "<test>").unwrap();
103+
let source = "x = [y for y in (1, 2, 3)]";
104+
let parse_ast = parse_program(source, "<test>").unwrap();
105105
insta::assert_debug_snapshot!(parse_ast);
106106
}
107107

108108
#[test]
109109
fn test_assign_set_comp() {
110-
let source = String::from("x = {y for y in (1, 2, 3)}");
111-
let parse_ast = parse_program(&source, "<test>").unwrap();
110+
let source = "x = {y for y in (1, 2, 3)}";
111+
let parse_ast = parse_program(source, "<test>").unwrap();
112112
insta::assert_debug_snapshot!(parse_ast);
113113
}
114114

115115
#[test]
116116
fn test_assign_with() {
117-
let source = String::from("with 1 as x: pass");
118-
let parse_ast = parse_program(&source, "<test>").unwrap();
117+
let source = "with 1 as x: pass";
118+
let parse_ast = parse_program(source, "<test>").unwrap();
119119
insta::assert_debug_snapshot!(parse_ast);
120120
}
121121

122122
#[test]
123123
fn test_assign_named_expr() {
124-
let source = String::from("if x:= 1: pass");
125-
let parse_ast = parse_program(&source, "<test>").unwrap();
124+
let source = "if x:= 1: pass";
125+
let parse_ast = parse_program(source, "<test>").unwrap();
126126
insta::assert_debug_snapshot!(parse_ast);
127127
}
128128

129129
#[test]
130130
fn test_ann_assign_name() {
131-
let source = String::from("x: int = 1");
132-
let parse_ast = parse_program(&source, "<test>").unwrap();
131+
let source = "x: int = 1";
132+
let parse_ast = parse_program(source, "<test>").unwrap();
133133
insta::assert_debug_snapshot!(parse_ast);
134134
}
135135

136136
#[test]
137137
fn test_aug_assign_name() {
138-
let source = String::from("x += 1");
139-
let parse_ast = parse_program(&source, "<test>").unwrap();
138+
let source = "x += 1";
139+
let parse_ast = parse_program(source, "<test>").unwrap();
140140
insta::assert_debug_snapshot!(parse_ast);
141141
}
142142

143143
#[test]
144144
fn test_aug_assign_attribute() {
145-
let source = String::from("x.y += (1, 2, 3)");
146-
let parse_ast = parse_program(&source, "<test>").unwrap();
145+
let source = "x.y += (1, 2, 3)";
146+
let parse_ast = parse_program(source, "<test>").unwrap();
147147
insta::assert_debug_snapshot!(parse_ast);
148148
}
149149

150150
#[test]
151151
fn test_aug_assign_subscript() {
152-
let source = String::from("x[y] += (1, 2, 3)");
153-
let parse_ast = parse_program(&source, "<test>").unwrap();
152+
let source = "x[y] += (1, 2, 3)";
153+
let parse_ast = parse_program(source, "<test>").unwrap();
154154
insta::assert_debug_snapshot!(parse_ast);
155155
}
156156

157157
#[test]
158158
fn test_del_name() {
159-
let source = String::from("del x");
160-
let parse_ast = parse_program(&source, "<test>").unwrap();
159+
let source = "del x";
160+
let parse_ast = parse_program(source, "<test>").unwrap();
161161
insta::assert_debug_snapshot!(parse_ast);
162162
}
163163

164164
#[test]
165165
fn test_del_attribute() {
166-
let source = String::from("del x.y");
167-
let parse_ast = parse_program(&source, "<test>").unwrap();
166+
let source = "del x.y";
167+
let parse_ast = parse_program(source, "<test>").unwrap();
168168
insta::assert_debug_snapshot!(parse_ast);
169169
}
170170

171171
#[test]
172172
fn test_del_subscript() {
173-
let source = String::from("del x[y]");
174-
let parse_ast = parse_program(&source, "<test>").unwrap();
173+
let source = "del x[y]";
174+
let parse_ast = parse_program(source, "<test>").unwrap();
175175
insta::assert_debug_snapshot!(parse_ast);
176176
}
177177
}

compiler/parser/src/parser.rs

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -124,43 +124,43 @@ mod tests {
124124

125125
#[test]
126126
fn test_parse_string() {
127-
let source = String::from("'Hello world'");
128-
let parse_ast = parse_program(&source, "<test>").unwrap();
127+
let source = "'Hello world'";
128+
let parse_ast = parse_program(source, "<test>").unwrap();
129129
insta::assert_debug_snapshot!(parse_ast);
130130
}
131131

132132
#[test]
133133
fn test_parse_f_string() {
134-
let source = String::from("f'Hello world'");
135-
let parse_ast = parse_program(&source, "<test>").unwrap();
134+
let source = "f'Hello world'";
135+
let parse_ast = parse_program(source, "<test>").unwrap();
136136
insta::assert_debug_snapshot!(parse_ast);
137137
}
138138

139139
#[test]
140140
fn test_parse_print_hello() {
141-
let source = String::from("print('Hello world')");
142-
let parse_ast = parse_program(&source, "<test>").unwrap();
141+
let source = "print('Hello world')";
142+
let parse_ast = parse_program(source, "<test>").unwrap();
143143
insta::assert_debug_snapshot!(parse_ast);
144144
}
145145

146146
#[test]
147147
fn test_parse_print_2() {
148-
let source = String::from("print('Hello world', 2)");
149-
let parse_ast = parse_program(&source, "<test>").unwrap();
148+
let source = "print('Hello world', 2)";
149+
let parse_ast = parse_program(source, "<test>").unwrap();
150150
insta::assert_debug_snapshot!(parse_ast);
151151
}
152152

153153
#[test]
154154
fn test_parse_kwargs() {
155-
let source = String::from("my_func('positional', keyword=2)");
156-
let parse_ast = parse_program(&source, "<test>").unwrap();
155+
let source = "my_func('positional', keyword=2)";
156+
let parse_ast = parse_program(source, "<test>").unwrap();
157157
insta::assert_debug_snapshot!(parse_ast);
158158
}
159159

160160
#[test]
161161
fn test_parse_if_elif_else() {
162-
let source = String::from("if 1: 10\nelif 2: 20\nelse: 30");
163-
let parse_ast = parse_program(&source, "<test>").unwrap();
162+
let source = "if 1: 10\nelif 2: 20\nelse: 30";
163+
let parse_ast = parse_program(source, "<test>").unwrap();
164164
insta::assert_debug_snapshot!(parse_ast);
165165
}
166166

@@ -192,64 +192,64 @@ class Foo(A, B):
192192

193193
#[test]
194194
fn test_parse_dict_comprehension() {
195-
let source = String::from("{x1: x2 for y in z}");
196-
let parse_ast = parse_expression(&source, "<test>").unwrap();
195+
let source = "{x1: x2 for y in z}";
196+
let parse_ast = parse_expression(source, "<test>").unwrap();
197197
insta::assert_debug_snapshot!(parse_ast);
198198
}
199199

200200
#[test]
201201
fn test_parse_list_comprehension() {
202-
let source = String::from("[x for y in z]");
203-
let parse_ast = parse_expression(&source, "<test>").unwrap();
202+
let source = "[x for y in z]";
203+
let parse_ast = parse_expression(source, "<test>").unwrap();
204204
insta::assert_debug_snapshot!(parse_ast);
205205
}
206206

207207
#[test]
208208
fn test_parse_double_list_comprehension() {
209-
let source = String::from("[x for y, y2 in z for a in b if a < 5 if a > 10]");
210-
let parse_ast = parse_expression(&source, "<test>").unwrap();
209+
let source = "[x for y, y2 in z for a in b if a < 5 if a > 10]";
210+
let parse_ast = parse_expression(source, "<test>").unwrap();
211211
insta::assert_debug_snapshot!(parse_ast);
212212
}
213213

214214
#[test]
215215
fn test_parse_generator_comprehension() {
216-
let source = String::from("(x for y in z)");
217-
let parse_ast = parse_expression(&source, "<test>").unwrap();
216+
let source = "(x for y in z)";
217+
let parse_ast = parse_expression(source, "<test>").unwrap();
218218
insta::assert_debug_snapshot!(parse_ast);
219219
}
220220

221221
#[test]
222222
fn test_parse_named_expression_generator_comprehension() {
223-
let source = String::from("(x := y + 1 for y in z)");
224-
let parse_ast = parse_expression(&source, "<test>").unwrap();
223+
let source = "(x := y + 1 for y in z)";
224+
let parse_ast = parse_expression(source, "<test>").unwrap();
225225
insta::assert_debug_snapshot!(parse_ast);
226226
}
227227

228228
#[test]
229229
fn test_parse_if_else_generator_comprehension() {
230-
let source = String::from("(x if y else y for y in z)");
231-
let parse_ast = parse_expression(&source, "<test>").unwrap();
230+
let source = "(x if y else y for y in z)";
231+
let parse_ast = parse_expression(source, "<test>").unwrap();
232232
insta::assert_debug_snapshot!(parse_ast);
233233
}
234234

235235
#[test]
236236
fn test_parse_boolop_or() {
237-
let source = String::from("x or y");
238-
let parse_ast = parse_expression(&source, "<test>").unwrap();
237+
let source = "x or y";
238+
let parse_ast = parse_expression(source, "<test>").unwrap();
239239
insta::assert_debug_snapshot!(parse_ast);
240240
}
241241

242242
#[test]
243243
fn test_parse_boolop_and() {
244-
let source = String::from("x and y");
245-
let parse_ast = parse_expression(&source, "<test>").unwrap();
244+
let source = "x and y";
245+
let parse_ast = parse_expression(source, "<test>").unwrap();
246246
insta::assert_debug_snapshot!(parse_ast);
247247
}
248248

249249
#[test]
250250
fn test_slice() {
251-
let source = String::from("x[1:2:3]");
252-
let parse_ast = parse_expression(&source, "<test>").unwrap();
251+
let source = "x[1:2:3]";
252+
let parse_ast = parse_expression(source, "<test>").unwrap();
253253
insta::assert_debug_snapshot!(parse_ast);
254254
}
255255

0 commit comments

Comments
 (0)