autocorrect/code/
python.rs1use super::*;
3use autocorrect_derive::GrammarParser;
4use pest::Parser as P;
5use pest_derive::Parser;
6#[derive(GrammarParser, Parser)]
7#[grammar = "../grammar/python.pest"]
8struct PythonParser;
9
10#[cfg(test)]
11mod tests {
12 use super::*;
13 use indoc::indoc;
14 use pretty_assertions::assert_eq;
15
16 #[test]
17 fn it_format_python() {
18 let example = indoc! {r###"
19 '''
20 这是多行1注释
21 这是多行2注释
22 这是多行3注释
23 '''
24 def hello(a):
25 multi_str = """
26 第1行多行字符串
27 第2行多行字符串
28 """
29
30 re = r'包含#regexp测试'
31 re1 = r"""
32 包含re0测试
33 包含re1测试
34 """
35 re2 = re.compile( "hello你" + "world好")
36
37 # 第4个注释
38 print("你好hello世界")
39 print('你好hello世界')
40 "###};
41
42 let expect = indoc! {r###"
43 '''
44 这是多行 1 注释
45 这是多行 2 注释
46 这是多行 3 注释
47 '''
48 def hello(a):
49 multi_str = """
50 第 1 行多行字符串
51 第 2 行多行字符串
52 """
53
54 re = r'包含#regexp测试'
55 re1 = r"""
56 包含re0测试
57 包含re1测试
58 """
59 re2 = re.compile( "hello你" + "world好")
60
61 # 第 4 个注释
62 print("你好 hello 世界")
63 print('你好 hello 世界')
64 "###};
65
66 assert_eq!(expect, format_for(example, "python").to_string());
67 }
68}