From f260785da478adb7eebb7af6dd908d686a169d38 Mon Sep 17 00:00:00 2001 From: harupy Date: Mon, 16 Jan 2023 21:27:57 +0900 Subject: [PATCH] Remove useless String::from Signed-off-by: harupy --- parser/src/context.rs | 72 +++++++++++++++++++++---------------------- parser/src/parser.rs | 60 ++++++++++++++++++------------------ 2 files changed, 66 insertions(+), 66 deletions(-) diff --git a/parser/src/context.rs b/parser/src/context.rs index 56fdc35..f10e105 100644 --- a/parser/src/context.rs +++ b/parser/src/context.rs @@ -51,127 +51,127 @@ mod tests { #[test] fn test_assign_name() { - let source = String::from("x = (1, 2, 3)"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "x = (1, 2, 3)"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_assign_tuple() { - let source = String::from("(x, y) = (1, 2, 3)"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "(x, y) = (1, 2, 3)"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_assign_list() { - let source = String::from("[x, y] = (1, 2, 3)"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "[x, y] = (1, 2, 3)"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_assign_attribute() { - let source = String::from("x.y = (1, 2, 3)"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "x.y = (1, 2, 3)"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_assign_subscript() { - let source = String::from("x[y] = (1, 2, 3)"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "x[y] = (1, 2, 3)"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_assign_starred() { - let source = String::from("(x, *y) = (1, 2, 3)"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "(x, *y) = (1, 2, 3)"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_assign_for() { - let source = String::from("for x in (1, 2, 3): pass"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "for x in (1, 2, 3): pass"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_assign_list_comp() { - let source = String::from("x = [y for y in (1, 2, 3)]"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "x = [y for y in (1, 2, 3)]"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_assign_set_comp() { - let source = String::from("x = {y for y in (1, 2, 3)}"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "x = {y for y in (1, 2, 3)}"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_assign_with() { - let source = String::from("with 1 as x: pass"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "with 1 as x: pass"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_assign_named_expr() { - let source = String::from("if x:= 1: pass"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "if x:= 1: pass"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_ann_assign_name() { - let source = String::from("x: int = 1"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "x: int = 1"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_aug_assign_name() { - let source = String::from("x += 1"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "x += 1"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_aug_assign_attribute() { - let source = String::from("x.y += (1, 2, 3)"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "x.y += (1, 2, 3)"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_aug_assign_subscript() { - let source = String::from("x[y] += (1, 2, 3)"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "x[y] += (1, 2, 3)"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_del_name() { - let source = String::from("del x"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "del x"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_del_attribute() { - let source = String::from("del x.y"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "del x.y"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_del_subscript() { - let source = String::from("del x[y]"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "del x[y]"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } } diff --git a/parser/src/parser.rs b/parser/src/parser.rs index fb18155..82d8ded 100644 --- a/parser/src/parser.rs +++ b/parser/src/parser.rs @@ -124,43 +124,43 @@ mod tests { #[test] fn test_parse_string() { - let source = String::from("'Hello world'"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "'Hello world'"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_f_string() { - let source = String::from("f'Hello world'"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "f'Hello world'"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_print_hello() { - let source = String::from("print('Hello world')"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "print('Hello world')"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_print_2() { - let source = String::from("print('Hello world', 2)"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "print('Hello world', 2)"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_kwargs() { - let source = String::from("my_func('positional', keyword=2)"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "my_func('positional', keyword=2)"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_if_elif_else() { - let source = String::from("if 1: 10\nelif 2: 20\nelse: 30"); - let parse_ast = parse_program(&source, "").unwrap(); + let source = "if 1: 10\nelif 2: 20\nelse: 30"; + let parse_ast = parse_program(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } @@ -192,64 +192,64 @@ class Foo(A, B): #[test] fn test_parse_dict_comprehension() { - let source = String::from("{x1: x2 for y in z}"); - let parse_ast = parse_expression(&source, "").unwrap(); + let source = "{x1: x2 for y in z}"; + let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_list_comprehension() { - let source = String::from("[x for y in z]"); - let parse_ast = parse_expression(&source, "").unwrap(); + let source = "[x for y in z]"; + let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] 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 parse_ast = parse_expression(&source, "").unwrap(); + let source = "[x for y, y2 in z for a in b if a < 5 if a > 10]"; + let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_generator_comprehension() { - let source = String::from("(x for y in z)"); - let parse_ast = parse_expression(&source, "").unwrap(); + let source = "(x for y in z)"; + let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_named_expression_generator_comprehension() { - let source = String::from("(x := y + 1 for y in z)"); - let parse_ast = parse_expression(&source, "").unwrap(); + let source = "(x := y + 1 for y in z)"; + let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_if_else_generator_comprehension() { - let source = String::from("(x if y else y for y in z)"); - let parse_ast = parse_expression(&source, "").unwrap(); + let source = "(x if y else y for y in z)"; + let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_boolop_or() { - let source = String::from("x or y"); - let parse_ast = parse_expression(&source, "").unwrap(); + let source = "x or y"; + let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_parse_boolop_and() { - let source = String::from("x and y"); - let parse_ast = parse_expression(&source, "").unwrap(); + let source = "x and y"; + let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); } #[test] fn test_slice() { - let source = String::from("x[1:2:3]"); - let parse_ast = parse_expression(&source, "").unwrap(); + let source = "x[1:2:3]"; + let parse_ast = parse_expression(source, "").unwrap(); insta::assert_debug_snapshot!(parse_ast); }