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