Skip to content

Commit e2a90ce

Browse files
committed
Fixes.
1 parent fd79e7d commit e2a90ce

3 files changed

Lines changed: 143 additions & 25 deletions

File tree

crates/config/src/shapes/input.rs

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,8 +36,13 @@ config_struct!(
3636
pub struct FileInput {
3737
pub file: FilePath,
3838

39-
#[serde(default, alias = "match", skip_serializing_if = "Option::is_none")]
40-
pub matches: Option<String>,
39+
#[serde(
40+
default,
41+
alias = "match",
42+
alias = "matches",
43+
skip_serializing_if = "Option::is_none"
44+
)]
45+
pub content: Option<String>,
4146

4247
#[serde(default)]
4348
pub optional: bool,
@@ -53,9 +58,9 @@ impl FileInput {
5358

5459
for (key, value) in uri.query {
5560
match key.as_str() {
56-
"match" | "matches" => {
61+
"content" | "match" | "matches" => {
5762
if !value.is_empty() {
58-
input.matches = Some(value);
63+
input.content = Some(value);
5964
}
6065
}
6166
"optional" => {

crates/config/tests/input_shape_test.rs

Lines changed: 9 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,6 @@ mod input_shape {
305305
fn errors_for_unknown_protocol() {
306306
Input::parse("unknown://test").unwrap();
307307
}
308-
309-
#[test]
310-
#[should_panic(expected = "parent relative paths are not supported")]
311-
fn errors_for_parent_relative_from_project() {
312-
Input::parse("../test").unwrap();
313-
}
314-
315-
// #[test]
316-
// #[should_panic(expected = "parent relative paths are not supported")]
317-
// fn errors_for_parent_relative_from_workspace() {
318-
// Input::parse("/../test").unwrap();
319-
// }
320308
}
321309

322310
mod parse_object {
@@ -354,7 +342,7 @@ mod input_shape {
354342
Input::WorkspaceFile({
355343
let mut inner = create_file_input("/root/file.txt");
356344
inner.optional = true;
357-
inner.matches = Some("a|b|c".into());
345+
inner.content = Some("a|b|c".into());
358346
inner
359347
})
360348
);
@@ -415,15 +403,15 @@ mod input_shape {
415403
fn supports_matches_field() {
416404
let input = create_file_input("file.txt?matches=abc");
417405

418-
assert_eq!(input.matches.unwrap(), "abc");
406+
assert_eq!(input.content.unwrap(), "abc");
419407

420408
let input = create_file_input("file.txt?match=abc");
421409

422-
assert_eq!(input.matches.unwrap(), "abc");
410+
assert_eq!(input.content.unwrap(), "abc");
423411

424412
let input = create_file_input("file.txt?matches");
425413

426-
assert!(input.matches.is_none());
414+
assert!(input.content.is_none());
427415
}
428416

429417
#[test]
@@ -541,21 +529,21 @@ mod input_shape {
541529
let input = create_glob_input("!project/file.*");
542530

543531
assert_eq!(input.glob, "!project/file.*");
544-
assert_eq!(input.get_path(), "project/file.*");
532+
assert_eq!(input.get_path(), "!project/file.*");
545533
assert!(!input.is_workspace_relative());
546534
assert!(input.is_negated());
547535

548536
let input = create_glob_input("!./project/file.*");
549537

550538
assert_eq!(input.glob, "!project/file.*");
551-
assert_eq!(input.get_path(), "project/file.*");
539+
assert_eq!(input.get_path(), "!project/file.*");
552540
assert!(!input.is_workspace_relative());
553541
assert!(input.is_negated());
554542

555543
let input = create_glob_input("./!project/file.*");
556544

557545
assert_eq!(input.glob, "!project/file.*");
558-
assert_eq!(input.get_path(), "project/file.*");
546+
assert_eq!(input.get_path(), "!project/file.*");
559547
assert!(!input.is_workspace_relative());
560548
assert!(input.is_negated());
561549
}
@@ -575,14 +563,14 @@ mod input_shape {
575563
let input = create_glob_input("!/root/file.*");
576564

577565
assert_eq!(input.glob, "!/root/file.*");
578-
assert_eq!(input.get_path(), "root/file.*");
566+
assert_eq!(input.get_path(), "!root/file.*");
579567
assert!(input.is_workspace_relative());
580568
assert!(input.is_negated());
581569

582570
let input = create_glob_input("/!root/file.*");
583571

584572
assert_eq!(input.glob, "!/root/file.*");
585-
assert_eq!(input.get_path(), "root/file.*");
573+
assert_eq!(input.get_path(), "!root/file.*");
586574
assert!(input.is_workspace_relative());
587575
assert!(input.is_negated());
588576
}

crates/config/tests/task_config_test.rs

Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -270,6 +270,131 @@ inputs:
270270
);
271271
}
272272

273+
#[test]
274+
fn supports_path_protocols() {
275+
let config = test_parse_config(
276+
r"
277+
inputs:
278+
- file:///ws/path?match=a|b|c
279+
- 'glob:///ws/glob/**/*'
280+
- 'glob:///!ws/glob/**/*'
281+
- file://proj/path?optional
282+
- 'glob://proj/glob/{a,b,c}'
283+
- 'glob://!proj/glob/{a,b,c}?cache=false'
284+
",
285+
load_config_from_code,
286+
);
287+
288+
assert_eq!(
289+
config.inputs.unwrap(),
290+
vec![
291+
Input::WorkspaceFile({
292+
let mut inner = create_file_input("/ws/path");
293+
inner.content = Some("a|b|c".into());
294+
inner
295+
}),
296+
Input::WorkspaceGlob(create_glob_input("/ws/glob/**/*")),
297+
Input::WorkspaceGlob(create_glob_input("!/ws/glob/**/*")),
298+
Input::ProjectFile({
299+
let mut inner = create_file_input("proj/path");
300+
inner.optional = true;
301+
inner
302+
}),
303+
Input::ProjectGlob(create_glob_input("proj/glob/{a,b,c}")),
304+
Input::ProjectGlob({
305+
let mut inner = create_glob_input("!proj/glob/{a,b,c}");
306+
inner.cache = false;
307+
inner
308+
}),
309+
]
310+
);
311+
}
312+
313+
#[test]
314+
fn supports_path_objects() {
315+
let config = test_parse_config(
316+
r"
317+
inputs:
318+
- file: '/ws/path'
319+
content: 'a|b|c'
320+
- glob: '/ws/glob/**/*'
321+
- glob: '/!ws/glob/**/*'
322+
- file: proj/path
323+
optional: true
324+
- glob: 'proj/glob/{a,b,c}'
325+
- glob: '!proj/glob/{a,b,c}'
326+
cache: false
327+
",
328+
load_config_from_code,
329+
);
330+
331+
assert_eq!(
332+
config.inputs.unwrap(),
333+
vec![
334+
Input::WorkspaceFile({
335+
let mut inner = create_file_input("/ws/path");
336+
inner.content = Some("a|b|c".into());
337+
inner
338+
}),
339+
Input::WorkspaceGlob(create_glob_input("/ws/glob/**/*")),
340+
Input::WorkspaceGlob(create_glob_input("!/ws/glob/**/*")),
341+
Input::ProjectFile({
342+
let mut inner = create_file_input("proj/path");
343+
inner.optional = true;
344+
inner
345+
}),
346+
Input::ProjectGlob(create_glob_input("proj/glob/{a,b,c}")),
347+
Input::ProjectGlob({
348+
let mut inner = create_glob_input("!proj/glob/{a,b,c}");
349+
inner.cache = false;
350+
inner
351+
}),
352+
]
353+
);
354+
}
355+
356+
#[test]
357+
fn supports_mixing_path_formats() {
358+
let config = test_parse_config(
359+
r"
360+
inputs:
361+
- file: '/ws/path'
362+
content: 'a|b|c'
363+
- '/ws/glob/**/*'
364+
- 'glob:///!ws/glob/**/*'
365+
- 'file://proj/path?optional'
366+
- 'proj/glob/{a,b,c}'
367+
- glob: '!proj/glob/{a,b,c}'
368+
cache: false
369+
",
370+
load_config_from_code,
371+
);
372+
373+
assert_eq!(
374+
config.inputs.unwrap(),
375+
vec![
376+
Input::WorkspaceFile({
377+
let mut inner = create_file_input("/ws/path");
378+
inner.content = Some("a|b|c".into());
379+
inner
380+
}),
381+
Input::WorkspaceGlob(create_glob_input("/ws/glob/**/*")),
382+
Input::WorkspaceGlob(create_glob_input("!/ws/glob/**/*")),
383+
Input::ProjectFile({
384+
let mut inner = create_file_input("proj/path");
385+
inner.optional = true;
386+
inner
387+
}),
388+
Input::ProjectGlob(create_glob_input("proj/glob/{a,b,c}")),
389+
Input::ProjectGlob({
390+
let mut inner = create_glob_input("!proj/glob/{a,b,c}");
391+
inner.cache = false;
392+
inner
393+
}),
394+
]
395+
);
396+
}
397+
273398
#[test]
274399
fn supports_env_vars() {
275400
let config = test_parse_config(

0 commit comments

Comments
 (0)