Skip to content

Commit 5797d53

Browse files
committed
Add more tests for config parsing
1 parent c405db6 commit 5797d53

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed

crates/prek/src/config.rs

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1362,6 +1362,60 @@ mod tests {
13621362
"};
13631363
let result = serde_saphyr::from_str::<Config>(yaml).unwrap();
13641364
insta::assert_debug_snapshot!(result);
1365+
1366+
let yaml = indoc::indoc! {r"
1367+
repos:
1368+
- rev: v1.0.0
1369+
repo: local
1370+
hooks:
1371+
- id: typos
1372+
"};
1373+
let err = serde_saphyr::from_str::<Config>(yaml).unwrap_err();
1374+
insta::assert_snapshot!(err, @"
1375+
error: line 5 column 9: missing field `name` at line 5, column 9
1376+
--> <input>:5:9
1377+
|
1378+
3 | repo: local
1379+
4 | hooks:
1380+
5 | - id: typos
1381+
| ^ missing field `name` at line 5, column 9
1382+
");
1383+
1384+
let yaml = indoc::indoc! {r"
1385+
repos:
1386+
- rev: v1.0.0
1387+
repo: meta
1388+
hooks:
1389+
- id: typos
1390+
"};
1391+
let err = serde_saphyr::from_str::<Config>(yaml).unwrap_err();
1392+
insta::assert_snapshot!(err, @"
1393+
error: line 5 column 9: unknown meta hook id `typos` at line 5, column 9
1394+
--> <input>:5:9
1395+
|
1396+
3 | repo: meta
1397+
4 | hooks:
1398+
5 | - id: typos
1399+
| ^ unknown meta hook id `typos` at line 5, column 9
1400+
");
1401+
1402+
let yaml = indoc::indoc! {r"
1403+
repos:
1404+
- rev: v1.0.0
1405+
repo: builtin
1406+
hooks:
1407+
- id: typos
1408+
"};
1409+
let err = serde_saphyr::from_str::<Config>(yaml).unwrap_err();
1410+
insta::assert_snapshot!(err, @"
1411+
error: line 5 column 9: unknown builtin hook id `typos` at line 5, column 9
1412+
--> <input>:5:9
1413+
|
1414+
3 | repo: builtin
1415+
4 | hooks:
1416+
5 | - id: typos
1417+
| ^ unknown builtin hook id `typos` at line 5, column 9
1418+
");
13651419
}
13661420

13671421
#[test]

0 commit comments

Comments
 (0)