Skip to content

Commit 63abd05

Browse files
Add tests for end; clause in query pipelines (#432)
## Product change and motivation Add tests for `end;` statements Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
1 parent 0721e5e commit 63abd05

1 file changed

Lines changed: 73 additions & 0 deletions

File tree

rust/parser/test/pipeline.rs

Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -103,3 +103,76 @@ fetch {
103103
let parsed = parse_queries(queries).unwrap();
104104
assert_eq!(parsed.len(), 4);
105105
}
106+
107+
#[test]
108+
fn test_single_pipeline_with_optional_end() {
109+
// end; is optional for a single pipeline
110+
let query_without_end = r#"match
111+
$x isa movie;
112+
insert
113+
$x has rating 5;"#;
114+
let parsed_without = parse_query(query_without_end).unwrap();
115+
assert!(!parsed_without.has_explicit_end());
116+
117+
let query_with_end = r#"match
118+
$x isa movie;
119+
insert
120+
$x has rating 5;
121+
end;"#;
122+
let parsed_with = parse_query(query_with_end).unwrap();
123+
assert!(parsed_with.has_explicit_end());
124+
125+
// parse_queries with a single query should return exactly one query
126+
// and it should be equivalent to parse_query
127+
let parsed_queries = parse_queries(query_with_end).unwrap();
128+
assert_eq!(parsed_queries.len(), 1);
129+
assert!(parsed_queries[0].has_explicit_end());
130+
assert_eq!(parsed_with.to_string(), parsed_queries[0].to_string());
131+
}
132+
133+
#[test]
134+
fn test_schema_query_with_optional_end() {
135+
// end; is optional for schema queries
136+
let query_without_end = r#"define
137+
entity movie;"#;
138+
let parsed_without = parse_query(query_without_end).unwrap();
139+
assert!(!parsed_without.has_explicit_end());
140+
141+
let query_with_end = r#"define
142+
entity movie;
143+
end;"#;
144+
let parsed_with = parse_query(query_with_end).unwrap();
145+
assert!(parsed_with.has_explicit_end());
146+
}
147+
148+
#[test]
149+
fn test_all_pipeline_stages_with_end() {
150+
// Various pipeline stage combinations with end;
151+
let queries = r#"match
152+
$x isa person;
153+
end;
154+
155+
match
156+
$x isa person;
157+
select $x;
158+
end;
159+
160+
match
161+
$x isa person;
162+
delete $x;
163+
end;
164+
165+
match
166+
$x isa person, has name $n;
167+
reduce $count = count($n);
168+
end;
169+
170+
insert
171+
$x isa person, has name "Alice";
172+
end;"#;
173+
let parsed = parse_queries(queries).unwrap();
174+
assert_eq!(parsed.len(), 5);
175+
for i in 0..5 {
176+
assert!(parsed[i].has_explicit_end(), "Query {} should have explicit end", i);
177+
}
178+
}

0 commit comments

Comments
 (0)