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
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
use codebook::queries::LanguageType;
use super::utils::{assert_spelling, assert_spelling_at};
#[test]
fn test_elixir_simple() {
let sample_text = r#"
defmodule Calculatr do
# This is an exampl module that performz calculashuns
def add(numbr1, numbr2) do
resalt = numbr1 + numbr2
resalt
end
end
"#;
// "numbr" is flagged at the two parameter definitions only; the usages
// in `numbr1 + numbr2` are not definitions. "resalt" is flagged at the
// `=` binding, not at the bare return usage.
assert_spelling_at(
LanguageType::Elixir,
sample_text,
&[
("Calculatr", &[0]),
("exampl", &[0]),
("performz", &[0]),
("calculashuns", &[0]),
("numbr", &[0, 1]),
("resalt", &[0]),
],
);
}
#[test]
fn test_elixir_binary_operator_bindings() {
// Only `=` and comprehension generators (`<-`) bind variables. The left
// side of any other binary operator (arithmetic, `|>`, ...) is a usage
// and must not be flagged.
let sample_text = r#"
defmodule Sample do
def process(itemms) do
for itemm <- itemms, do: itemm * 2
end
def pipeline(inputt) do
inputt |> IO.inspect()
end
end
"#;
assert_spelling_at(
LanguageType::Elixir,
sample_text,
&[
// Parameter definition only, not the `<- itemms` usage.
("itemms", &[0]),
// The `<-` generator binding; occurrence 0 is inside "itemms",
// occurrence 3 is the `itemm * 2` usage.
("itemm", &[1]),
// Parameter definition only, not the `inputt |>` usage.
("inputt", &[0]),
],
);
}
#[test]
fn test_elixir_comment_location() {
let sample_elixir = r#"
# Structur definition with misspellings
"#;
assert_spelling(LanguageType::Elixir, sample_elixir, &["Structur"], &[]);
}
#[test]
fn test_elixir_module() {
let sample_elixir = r#"
defmodule UserAccaunt do
@moduledoc """
This module handels user accaunts
"""
defstruct [:usrrnamee, :ballancee, :intrest_rate]
def create_accaunt(name) do
%UserAccaunt{
usrrnamee: name,
ballancee: 0,
intrest_rate: 0.05
}
end
end
"#;
// Struct fields are flagged both in the defstruct atom list and as keys
// in the struct literal; "Accaunt" at the module def and struct literal.
// Lowercase "accaunt" occurrence 0 is inside "accaunts" in the
// moduledoc; occurrence 1 is the flagged create_accaunt def.
assert_spelling_at(
LanguageType::Elixir,
sample_elixir,
&[
("Accaunt", &[0, 1]),
("handels", &[0]),
("accaunts", &[0]),
("usrrnamee", &[0, 1]),
("ballancee", &[0, 1]),
("intrest", &[0, 1]),
("accaunt", &[1]),
],
);
}
#[test]
fn test_elixir_functions() {
let sample_elixir = r#"
defmodule ProcessingPipeline do
# Handles incomming data procesing
def proccess_data(input) do
input
|> validatte()
|> transfrom()
|> persiste()
end
defp validatte(data) do
# Performz validation logik
data
end
defp transfrom(data) do
# Aplies transformation ruls
data
end
defp persiste(data) do
# Savs to databse
data
end
end
"#;
// Function names are flagged both at the pipeline call sites
// (occurrence 0) and at their defp definitions (occurrence 1).
assert_spelling_at(
LanguageType::Elixir,
sample_elixir,
&[
("Aplies", &[0]),
("Performz", &[0]),
("Savs", &[0]),
("databse", &[0]),
("incomming", &[0]),
("logik", &[0]),
("persiste", &[0, 1]),
("proccess", &[0]),
("procesing", &[0]),
("ruls", &[0]),
("transfrom", &[0, 1]),
("validatte", &[0, 1]),
],
);
}
#[test]
fn test_elixir_pattern_matching() {
let sample_elixir = r#"
defmodule PatternMatcher do
def handle_responce({:ok, resalt}) do
{:succes, resalt}
end
def handle_responce({:error, reson}) do
{:failur, reson}
end
def parse_mesage(%{type: "notfication", conten: conten}) do
process_notfication(conten)
end
end
"#;
// Atoms (:succes, :failur), map keys ("conten:"), string patterns
// ("notfication"), function definition names, call names
// (process_notfication), and call arguments (conten occurrence 2) are
// flagged; pattern-bound variables (resalt, reson, conten occurrence 1)
// are not.
assert_spelling_at(
LanguageType::Elixir,
sample_elixir,
&[
("conten", &[0, 2]),
("failur", &[0]),
("mesage", &[0]),
("notfication", &[0, 1]),
("responce", &[0, 1]),
("succes", &[0]),
],
);
}