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
//! Function context insertion tests
use super::*;
#[test]
fn test_jq_keyword_autocomplete_no_dot_prefix() {
// Test that jq keywords like "then", "else", "end" don't get a dot prefix
let json = r#"{"services": [{"capacityProviderStrategy": [{"base": 0}]}]}"#;
let mut app = test_app(json);
// Step 1: Type the beginning of an if statement
app.input
.textarea
.insert_str(".services | if has(\"capacityProviderStrategy\")");
app.query
.as_mut()
.unwrap()
.execute(".services | if has(\"capacityProviderStrategy\")");
// Step 2: Type partial "the" to trigger autocomplete for "then"
app.input.textarea.insert_str(" the");
// Step 3: Accept "then" from autocomplete
// This should NOT add a dot before "then"
insert_suggestion_from_app(&mut app, &test_suggestion("then"));
// Should produce: .services | if has("capacityProviderStrategy") then
// NOT: .services | if has("capacityProviderStrategy") .then
assert_eq!(
app.input.query(),
".services | if has(\"capacityProviderStrategy\") then"
);
// Verify no extra dot was added
assert!(
!app.input.query().contains(" .then"),
"Should not have dot before 'then' keyword"
);
}
#[test]
fn test_jq_keyword_else_autocomplete() {
// Test "else" keyword autocomplete
let json = r#"{"value": 42}"#;
let mut app = test_app(json);
// Type an if-then statement
app.input
.textarea
.insert_str("if .value > 10 then \"high\" el");
// Accept "else" from autocomplete
insert_suggestion_from_app(&mut app, &test_suggestion("else"));
// Should produce: if .value > 10 then "high" else
// NOT: if .value > 10 then "high" .else
assert_eq!(app.input.query(), "if .value > 10 then \"high\" else");
assert!(
!app.input.query().contains(".else"),
"Should not have dot before 'else' keyword"
);
}
#[test]
fn test_jq_keyword_end_autocomplete() {
// Test "end" keyword autocomplete
let json = r#"{"value": 42}"#;
let mut app = test_app(json);
// Type a complete if-then-else statement
app.input
.textarea
.insert_str("if .value > 10 then \"high\" else \"low\" en");
// Accept "end" from autocomplete
insert_suggestion_from_app(&mut app, &test_suggestion("end"));
// Should produce: if .value > 10 then "high" else "low" end
// NOT: if .value > 10 then "high" else "low" .end
assert_eq!(
app.input.query(),
"if .value > 10 then \"high\" else \"low\" end"
);
assert!(
!app.input.query().contains(".end"),
"Should not have dot before 'end' keyword"
);
}