-
Notifications
You must be signed in to change notification settings - Fork 6
/
test_parser_post_process.rs
81 lines (71 loc) · 2.48 KB
/
test_parser_post_process.rs
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
// Copyright (c) Meta Platforms, Inc. and affiliates.
//
// This source code is licensed under the MIT license found in the
// LICENSE file in the root directory of this source tree
///
/// Tests the process_trailing_dots method of the `parser_post_process` module.
#[cfg(test)]
mod process_trailing_dots_tests {
use std::collections::HashSet;
use parser_post_process::ParserPostprocessor;
use parser_post_process::AUTOCOMPLETE_TOKEN;
fn test_harness(input_code: &str, expected: &str, error_segments: Option<HashSet<usize>>) {
let parser_post_processor = ParserPostprocessor::new();
// Use specified error_segments or default to all lines
let err_lines = error_segments.unwrap_or(HashSet::from_iter(0..input_code.lines().count()));
let actual = parser_post_processor.postprocess(input_code, err_lines);
println!("INPUT:\n{}", input_code.to_string().replace('\n', "\\n"));
println!("EXPECTED:\n{}", expected.to_string().replace('\n', "\\n"));
println!("ACTUAL:\n{}\n\n", actual.replace('\n', "\\n"));
assert_eq!(expected.to_string(), actual);
}
#[test]
fn test_simple() {
test_harness("x = a.\n", &format!("x = a.{}\n", AUTOCOMPLETE_TOKEN), None);
test_harness("x = a\n", "x = a\n", None);
}
#[test]
fn test_dots_complex() {
test_harness(
"x = a.b.\n",
&format!("x = a.b.{}\n", AUTOCOMPLETE_TOKEN),
None,
);
test_harness("x = .\n", "x = .\n", None);
test_harness("x = . ", "x = .", None);
test_harness("x '\n.'", "x '\n.'", None);
}
#[test]
fn test_lambda_ellipsis() {
test_harness(
"lambda x,y: ...\nx = lambda x,y: ...",
"lambda x,y: ...\nx = lambda x,y: ...",
None,
);
}
#[test]
fn test_long_floats() {
test_harness(
"timestamp3 = 9223372036854775810.\n",
"timestamp3 = 9223372036854775810.\n",
None,
);
test_harness(
"not_scientific = 1111111111111111.\n",
"not_scientific = 1111111111111111.\n",
None,
);
}
#[test]
fn test_alphanumeral_vars() {
test_harness("a123.\n", &format!("a123.{}\n", AUTOCOMPLETE_TOKEN), None);
}
#[test]
fn test_internal_trailing_dot() {
test_harness(
"x. = 123\n",
&format!("x.{}= 123\n", AUTOCOMPLETE_TOKEN),
None,
);
}
}