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
69
70
71
// autocorrect: false
use super::*;
use autocorrect_derive::GrammarParser;
use pest::Parser as P;
use pest_derive::Parser;
#[derive(GrammarParser, Parser)]
#[grammar = "../grammar/elixir.pest"]
struct ElixirParser;
#[cfg(test)]
mod tests {
use super::*;
use indoc::indoc;
use pretty_assertions::assert_eq;
#[test]
fn it_format_elixir() {
let example = indoc! { r###"
defmodule Test do
@moduledoc """
多行注释第1行
multiline comment第2行
"""
def hello do
# 单行comment注释
str1 = "hello你好双引号"
str2 = 'hello你好单引号'
str3 = ~s(hello你好)
str4 = ~c(hello你好)
multiline_str = ~S"""
多行字符串第1行
多行string第2行
"""
pattern1 = ~r/hello正则/
pattern2 = Regex.compile("hello正则")
end
end
"###};
let expect = indoc! {r###"
defmodule Test do
@moduledoc """
多行注释第 1 行
multiline comment 第 2 行
"""
def hello do
# 单行 comment 注释
str1 = "hello 你好双引号"
str2 = 'hello 你好单引号'
str3 = ~s(hello 你好)
str4 = ~c(hello 你好)
multiline_str = ~S"""
多行字符串第 1 行
多行 string 第 2 行
"""
pattern1 = ~r/hello正则/
pattern2 = Regex.compile("hello正则")
end
end
"###};
assert_eq!(expect, format_for(example, "elixir").to_string());
}
}