Remove useless String::from

Signed-off-by: harupy <hkawamura0130@gmail.com>
This commit is contained in:
harupy 2023-01-16 21:27:57 +09:00
parent 163cb5cd67
commit f260785da4
2 changed files with 66 additions and 66 deletions

View file

@ -51,127 +51,127 @@ mod tests {
#[test] #[test]
fn test_assign_name() { fn test_assign_name() {
let source = String::from("x = (1, 2, 3)"); let source = "x = (1, 2, 3)";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_assign_tuple() { fn test_assign_tuple() {
let source = String::from("(x, y) = (1, 2, 3)"); let source = "(x, y) = (1, 2, 3)";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_assign_list() { fn test_assign_list() {
let source = String::from("[x, y] = (1, 2, 3)"); let source = "[x, y] = (1, 2, 3)";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_assign_attribute() { fn test_assign_attribute() {
let source = String::from("x.y = (1, 2, 3)"); let source = "x.y = (1, 2, 3)";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_assign_subscript() { fn test_assign_subscript() {
let source = String::from("x[y] = (1, 2, 3)"); let source = "x[y] = (1, 2, 3)";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_assign_starred() { fn test_assign_starred() {
let source = String::from("(x, *y) = (1, 2, 3)"); let source = "(x, *y) = (1, 2, 3)";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_assign_for() { fn test_assign_for() {
let source = String::from("for x in (1, 2, 3): pass"); let source = "for x in (1, 2, 3): pass";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_assign_list_comp() { fn test_assign_list_comp() {
let source = String::from("x = [y for y in (1, 2, 3)]"); let source = "x = [y for y in (1, 2, 3)]";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_assign_set_comp() { fn test_assign_set_comp() {
let source = String::from("x = {y for y in (1, 2, 3)}"); let source = "x = {y for y in (1, 2, 3)}";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_assign_with() { fn test_assign_with() {
let source = String::from("with 1 as x: pass"); let source = "with 1 as x: pass";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_assign_named_expr() { fn test_assign_named_expr() {
let source = String::from("if x:= 1: pass"); let source = "if x:= 1: pass";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_ann_assign_name() { fn test_ann_assign_name() {
let source = String::from("x: int = 1"); let source = "x: int = 1";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_aug_assign_name() { fn test_aug_assign_name() {
let source = String::from("x += 1"); let source = "x += 1";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_aug_assign_attribute() { fn test_aug_assign_attribute() {
let source = String::from("x.y += (1, 2, 3)"); let source = "x.y += (1, 2, 3)";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_aug_assign_subscript() { fn test_aug_assign_subscript() {
let source = String::from("x[y] += (1, 2, 3)"); let source = "x[y] += (1, 2, 3)";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_del_name() { fn test_del_name() {
let source = String::from("del x"); let source = "del x";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_del_attribute() { fn test_del_attribute() {
let source = String::from("del x.y"); let source = "del x.y";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_del_subscript() { fn test_del_subscript() {
let source = String::from("del x[y]"); let source = "del x[y]";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
} }

View file

@ -124,43 +124,43 @@ mod tests {
#[test] #[test]
fn test_parse_string() { fn test_parse_string() {
let source = String::from("'Hello world'"); let source = "'Hello world'";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_f_string() { fn test_parse_f_string() {
let source = String::from("f'Hello world'"); let source = "f'Hello world'";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_print_hello() { fn test_parse_print_hello() {
let source = String::from("print('Hello world')"); let source = "print('Hello world')";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_print_2() { fn test_parse_print_2() {
let source = String::from("print('Hello world', 2)"); let source = "print('Hello world', 2)";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_kwargs() { fn test_parse_kwargs() {
let source = String::from("my_func('positional', keyword=2)"); let source = "my_func('positional', keyword=2)";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_if_elif_else() { fn test_parse_if_elif_else() {
let source = String::from("if 1: 10\nelif 2: 20\nelse: 30"); let source = "if 1: 10\nelif 2: 20\nelse: 30";
let parse_ast = parse_program(&source, "<test>").unwrap(); let parse_ast = parse_program(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
@ -192,64 +192,64 @@ class Foo(A, B):
#[test] #[test]
fn test_parse_dict_comprehension() { fn test_parse_dict_comprehension() {
let source = String::from("{x1: x2 for y in z}"); let source = "{x1: x2 for y in z}";
let parse_ast = parse_expression(&source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_list_comprehension() { fn test_parse_list_comprehension() {
let source = String::from("[x for y in z]"); let source = "[x for y in z]";
let parse_ast = parse_expression(&source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_double_list_comprehension() { fn test_parse_double_list_comprehension() {
let source = String::from("[x for y, y2 in z for a in b if a < 5 if a > 10]"); let source = "[x for y, y2 in z for a in b if a < 5 if a > 10]";
let parse_ast = parse_expression(&source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_generator_comprehension() { fn test_parse_generator_comprehension() {
let source = String::from("(x for y in z)"); let source = "(x for y in z)";
let parse_ast = parse_expression(&source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_named_expression_generator_comprehension() { fn test_parse_named_expression_generator_comprehension() {
let source = String::from("(x := y + 1 for y in z)"); let source = "(x := y + 1 for y in z)";
let parse_ast = parse_expression(&source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_if_else_generator_comprehension() { fn test_parse_if_else_generator_comprehension() {
let source = String::from("(x if y else y for y in z)"); let source = "(x if y else y for y in z)";
let parse_ast = parse_expression(&source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_boolop_or() { fn test_parse_boolop_or() {
let source = String::from("x or y"); let source = "x or y";
let parse_ast = parse_expression(&source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_parse_boolop_and() { fn test_parse_boolop_and() {
let source = String::from("x and y"); let source = "x and y";
let parse_ast = parse_expression(&source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }
#[test] #[test]
fn test_slice() { fn test_slice() {
let source = String::from("x[1:2:3]"); let source = "x[1:2:3]";
let parse_ast = parse_expression(&source, "<test>").unwrap(); let parse_ast = parse_expression(source, "<test>").unwrap();
insta::assert_debug_snapshot!(parse_ast); insta::assert_debug_snapshot!(parse_ast);
} }