Skip to content

Commit

Permalink
Add testcase for sigils
Browse files Browse the repository at this point in the history
Summary: Import the snapshot from the Erlang LS project, so we can use it to drive support for docstrings in the grammar/HIR. Original file is licensed via Apache 2.

Reviewed By: michalmuskala

Differential Revision: D56884509

fbshipit-source-id: 6ad51cfb2ed6f5669f7467d1c6b5232d02e912ef
  • Loading branch information
robertoaloi authored and facebook-github-bot committed May 16, 2024
1 parent d197467 commit 0b99dae
Show file tree
Hide file tree
Showing 3 changed files with 276 additions and 0 deletions.
12 changes: 12 additions & 0 deletions crates/elp/src/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1632,6 +1632,18 @@ mod tests {
);
}

#[test_case(false ; "rebar")]
#[test_case(true ; "buck")]
fn parse_otp27_sigils(buck: bool) {
simple_snapshot_expect_error(
args_vec!["parse-elp", "--module", "otp27_sigils"],
"diagnostics",
expect_file!("../resources/test/diagnostics/parse_otp27_sigils.jsonl"),
buck,
None,
);
}

#[track_caller]
fn simple_snapshot(
args: Vec<OsString>,
Expand Down
136 changes: 136 additions & 0 deletions crates/elp/src/resources/test/diagnostics/parse_otp27_sigils.jsonl
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
module specified: otp27_sigils
Diagnostics reported in 1 modules:
otp27_sigils: 133
10:5-10:6::[Error] [P1711] Syntax Error
10:14-10:15::[Error] [P1711] Syntax Error
10:20-10:21::[Error] [P1711] Syntax Error
11:4-11:5::[Error] [P1711] Syntax Error
11:14-11:15::[Error] [P1711] Syntax Error
11:20-11:21::[Error] [P1711] Syntax Error
12:4-12:5::[Error] [P1711] Syntax Error
12:14-12:15::[Error] [P1711] Syntax Error
12:20-12:21::[Error] [P1711] Syntax Error
13:4-13:5::[Error] [P1711] Syntax Error
13:14-13:15::[Error] [P1711] Syntax Error
13:20-13:21::[Error] [P1711] Syntax Error
14:4-14:5::[Error] [P1711] Syntax Error
14:14-14:15::[Error] [P1711] Syntax Error
14:20-14:21::[Error] [P1711] Syntax Error
16:5-16:6::[Error] [P1711] Syntax Error
16:14-16:15::[Error] [P1711] Syntax Error
16:20-16:21::[Error] [P1711] Syntax Error
17:4-17:5::[Error] [P1711] Syntax Error
17:14-17:15::[Error] [P1711] Syntax Error
17:20-17:21::[Error] [P1711] Syntax Error
18:4-18:5::[Error] [P1711] Syntax Error
18:14-18:15::[Error] [P1711] Syntax Error
18:20-18:21::[Error] [P1711] Syntax Error
19:4-19:5::[Error] [P1711] Syntax Error
19:14-19:15::[Error] [P1711] Syntax Error
19:20-19:21::[Error] [P1711] Syntax Error
20:4-20:5::[Error] [P1711] Syntax Error
20:14-20:15::[Error] [P1711] Syntax Error
20:20-20:21::[Error] [P1711] Syntax Error
22:5-22:6::[Error] [P1711] Syntax Error
22:14-22:15::[Error] [P1711] Syntax Error
22:20-22:21::[Error] [P1711] Syntax Error
23:4-23:5::[Error] [P1711] Syntax Error
23:14-23:15::[Error] [P1711] Syntax Error
23:20-23:21::[Error] [P1711] Syntax Error
24:4-24:5::[Error] [P1711] Syntax Error
24:14-24:15::[Error] [P1711] Syntax Error
24:20-24:21::[Error] [P1711] Syntax Error
25:4-25:5::[Error] [P1711] Syntax Error
25:14-25:15::[Error] [P1711] Syntax Error
25:20-25:21::[Error] [P1711] Syntax Error
26:4-26:5::[Error] [P1711] Syntax Error
26:14-26:15::[Error] [P1711] Syntax Error
26:20-26:21::[Error] [P1711] Syntax Error
28:5-28:6::[Error] [P1711] Syntax Error
28:14-28:15::[Error] [P1711] Syntax Error
28:18-28:19::[Warning] [W0004] Missing '.'
28:20-28:21::[Error] [P1711] Syntax Error
29:4-29:5::[Error] [P1711] Syntax Error
29:14-29:15::[Error] [P1711] Syntax Error
29:20-29:21::[Error] [P1711] Syntax Error
30:4-30:5::[Error] [P1711] Syntax Error
30:14-30:15::[Error] [P1711] Syntax Error
30:20-30:21::[Error] [P1711] Syntax Error
31:4-31:5::[Error] [P1711] Syntax Error
31:14-31:15::[Error] [P1711] Syntax Error
31:20-31:21::[Error] [P1711] Syntax Error
32:4-32:5::[Error] [P1711] Syntax Error
32:14-32:15::[Error] [P1711] Syntax Error
32:20-32:21::[Error] [P1711] Syntax Error
34:5-34:6::[Error] [P1711] Syntax Error
34:14-34:15::[Error] [P1711] Syntax Error
34:20-34:21::[Error] [P1711] Syntax Error
35:4-35:5::[Error] [P1711] Syntax Error
35:14-35:15::[Error] [P1711] Syntax Error
35:20-35:21::[Error] [P1711] Syntax Error
36:4-36:5::[Error] [P1711] Syntax Error
36:14-36:15::[Error] [P1711] Syntax Error
36:20-36:21::[Error] [P1711] Syntax Error
37:4-37:5::[Error] [P1711] Syntax Error
37:14-37:15::[Error] [P1711] Syntax Error
37:20-37:21::[Error] [P1711] Syntax Error
38:4-38:5::[Error] [P1711] Syntax Error
38:14-38:15::[Error] [P1711] Syntax Error
38:20-38:21::[Error] [P1711] Syntax Error
40:5-40:6::[Error] [P1711] Syntax Error
40:14-40:15::[Error] [P1711] Syntax Error
40:20-40:21::[Error] [P1711] Syntax Error
41:4-41:5::[Error] [P1711] Syntax Error
41:14-41:15::[Error] [P1711] Syntax Error
41:20-41:21::[Error] [P1711] Syntax Error
42:4-42:5::[Error] [P1711] Syntax Error
42:14-42:15::[Error] [P1711] Syntax Error
42:20-42:21::[Error] [P1711] Syntax Error
43:4-43:5::[Error] [P1711] Syntax Error
43:14-43:15::[Error] [P1711] Syntax Error
43:20-43:21::[Error] [P1711] Syntax Error
44:4-44:5::[Error] [P1711] Syntax Error
44:14-44:15::[Error] [P1711] Syntax Error
44:20-44:21::[Error] [P1711] Syntax Error
46:5-46:6::[Error] [P1711] Syntax Error
47:4-47:5::[Error] [P1711] Syntax Error
48:4-48:5::[Error] [P1711] Syntax Error
49:4-49:5::[Error] [P1711] Syntax Error
50:4-50:5::[Error] [P1711] Syntax Error
52:5-52:6::[Error] [P1711] Syntax Error
53:4-53:5::[Error] [P1711] Syntax Error
54:4-54:5::[Error] [P1711] Syntax Error
55:4-55:5::[Error] [P1711] Syntax Error
56:4-56:5::[Error] [P1711] Syntax Error
58:5-58:7::[Error] [P1711] Syntax Error
58:14-58:15::[Error] [P1711] Syntax Error
58:20-58:21::[Error] [P1711] Syntax Error
58:22-58:23::[Error] [P1711] Syntax Error
59:4-59:5::[Error] [P1711] Syntax Error
59:6-59:7::[Error] [P1711] Syntax Error
59:14-59:15::[Error] [P1711] Syntax Error
59:20-59:21::[Error] [P1711] Syntax Error
59:22-59:23::[Error] [P1711] Syntax Error
60:4-60:5::[Error] [P1711] Syntax Error
60:6-60:7::[Error] [P1711] Syntax Error
60:14-60:15::[Error] [P1711] Syntax Error
60:20-60:21::[Error] [P1711] Syntax Error
60:22-60:23::[Error] [P1711] Syntax Error
61:4-61:5::[Error] [P1711] Syntax Error
61:6-61:7::[Error] [P1711] Syntax Error
61:14-61:15::[Error] [P1711] Syntax Error
61:20-61:21::[Error] [P1711] Syntax Error
61:22-61:23::[Error] [P1711] Syntax Error
62:4-62:5::[Error] [P1711] Syntax Error
62:6-62:7::[Error] [P1711] Syntax Error
62:14-62:15::[Error] [P1711] Syntax Error
62:20-62:21::[Error] [P1711] Syntax Error
62:22-62:23::[Error] [P1711] Syntax Error
64:5-64:6::[Error] [P1711] Syntax Error
64:14-64:15::[Error] [P1711] Syntax Error
64:20-64:21::[Error] [P1711] Syntax Error
65:4-65:5::[Error] [P1711] Syntax Error
75:4-75:5::[Error] [P1711] syntax error before: '~'
75:5-78:7::[Warning] [W0006] this statement has no effect
79:8-79:10::[Warning] [W0004] Missing '.'
127:8-127:23::[Warning] [W0002] Unused macro (THIS_IS_THE_END)
128 changes: 128 additions & 0 deletions test_projects/diagnostics/app_a/src/otp27_sigils.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
% Sample module from https://github.com/erlang-ls/grammar/blob/main/tests/snap/sigil.erl
-module(otp27_sigils).

-export([f/0, g/0]).

-doc """
Sigil examples
""".
-spec f() -> ok.
f() ->
~(monkey ~2..0b\n),
~b(monkey ~2..0b\n),
~B(monkey ~2..0b\n), % verbatim
~s(monkey ~2..0b\n),
~S(monkey ~2..0b\n), % verbatim

~{monkey ~2..0b\n},
~b{monkey ~2..0b\n},
~B{monkey ~2..0b\n}, % verbatim
~s{monkey ~2..0b\n},
~S{monkey ~2..0b\n}, % verbatim

~[monkey ~2..0b\n],
~b[monkey ~2..0b\n],
~B[monkey ~2..0b\n], % verbatim
~s[monkey ~2..0b\n],
~S[monkey ~2..0b\n], % verbatim

~<monkey ~2..0b\n>,
~b<monkey ~2..0b\n>,
~B<monkey ~2..0b\n>, % verbatim
~s<monkey ~2..0b\n>,
~S<monkey ~2..0b\n>, % verbatim

~/monkey ~2..0b\n/,
~b/monkey ~2..0b\n/,
~B/monkey ~2..0b\n/, % verbatim
~s/monkey ~2..0b\n/,
~S/monkey ~2..0b\n/, % verbatim

~|monkey ~2..0b\n|,
~b|monkey ~2..0b\n|,
~B|monkey ~2..0b\n|, % verbatim
~s|monkey ~2..0b\n|,
~S|monkey ~2..0b\n|, % verbatim

~'monkey ~2..0b\n',
~b'monkey ~2..0b\n',
~B'monkey ~2..0b\n', % verbatim
~s'monkey ~2..0b\n',
~S'monkey ~2..0b\n', % verbatim

~"monkey ~2..0b\n",
~b"monkey ~2..0b\n",
~B"monkey ~2..0b\n", % verbatim
~s"monkey ~2..0b\n",
~S"monkey ~2..0b\n", % verbatim

~`monkey ~2..0b\n`,
~b`monkey ~2..0b\n`,
~B`monkey ~2..0b\n`, % verbatim
~s`monkey ~2..0b\n`,
~S`monkey ~2..0b\n`, % verbatim

~#monkey ~2..0b\n#,
~b#monkey ~2..0b\n#,
~B#monkey ~2..0b\n#, % verbatim
~s#monkey ~2..0b\n#,
~S#monkey ~2..0b\n#, % verbatim

X = lists:seq(1,3), % just to check is syntax highlight is still ok
ok.

-spec g() -> ok. % just to check is syntax highlight is still ok
g() ->
~"""
monkey ~2..0b\n
business
""",
~b""""
monkey ~2..0b\n
"""
business
"""",
~B"""""
monkey ~2..0b\n
"""
business
""""",
~s""""""
monkey ~2..0b\n
"""
business
"""""",
~S"""""""
monkey ~2..0b\n
"""
business
""""""",
X = lists:seq(1,3), % just to check is syntax highlight is still ok

<<"\"\\µA\""/utf8>> = <<$",$\\,194,181,$A,$">> =
~b"""
"\\µA"
""" = ~b'"\\µA"' =
~B"""
"\µA"
""" = ~B<"\µA"> =
~"""
"\µA"
""" = ~"\"\\µA\"" = ~/"\\µA"/
X = lists:seq(1,3), % just to check is syntax highlight is still ok

[$",$\\,$µ,$A,$"] =
~s"""
"\\µA"
""" = ~s"\"\\µA\"" = ~s["\\µA"] =
~S"""
"\µA"
""" = ~S("\µA") =
"""
"\µA"
""" = "\"\\µA\""
X = lists:seq(1,3), % just to check is syntax highlight is still ok

ok.

-define(THIS_IS_THE_END, "end").

0 comments on commit 0b99dae

Please sign in to comment.