Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0765174

Browse files
committed
validate step has tests && tests before solution
Signed-off-by: shmck <shawn.j.mckay@gmail.com>
1 parentf6159c4 commit0765174

File tree

2 files changed

+31
-6
lines changed

2 files changed

+31
-6
lines changed

‎src/utils/validateCommits.ts

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,21 +3,21 @@
33
exportfunctionvalidateCommitOrder(positions:string[]):boolean{
44
// loop over positions
55
consterrors:number[]=[];
6-
letprevious={level:0,step:0};
7-
letcurrent={level:0,step:0};
6+
letprevious={level:0,step:0,type:""};
7+
letcurrent={level:0,step:0,type:""};
88
positions.forEach((position:string,index:number)=>{
99
if(position==="INIT"){
1010
if(previous.level!==0&&previous.step!==0){
1111
errors.push(index);
1212
}
13-
current={level:0,step:0};
13+
current={level:0,step:0,type:""};
1414
return;
1515
}else{
1616
//@deprecate - remove L|Q
1717
constlevelMatch=position.match(/^(?<level>[0-9]+)$/);
1818
//@deprecate - remove S|Q|A
1919
conststepMatch=position.match(
20-
/^(?<level>[0-9]+)\.(?<step>[0-9]+):[T|S]$/
20+
/^(?<level>[0-9]+)\.(?<step>[0-9]+):(?<stepType>[T|S])$/
2121
);
2222
if(levelMatch){
2323
// allows next level or step
@@ -27,7 +27,7 @@ export function validateCommitOrder(positions: string[]): boolean {
2727
return;
2828
}
2929
constlevel=Number(levelString);
30-
current={ level,step:0};
30+
current={ level,step:0,type:""};
3131
}elseif(stepMatch){
3232
// allows next level or step
3333
if(!stepMatch?.groups?.level||!stepMatch?.groups.step){
@@ -38,13 +38,26 @@ export function validateCommitOrder(positions: string[]): boolean {
3838

3939
constlevel=Number(levelString);
4040
conststep=Number(stepString);
41-
current={ level, step};
41+
consttype=stepMatch?.groups.stepType;
42+
43+
constsameStep=previous.level===level&&previous.step===step;
44+
45+
if(
46+
// tests should come before the solution
47+
(sameStep&&type==="T"&&previous.type==="S")||
48+
// step should have tests
49+
(!sameStep&&type==="S")
50+
){
51+
errors.push(index);
52+
}
53+
current={ level, step, type};
4254
}else{
4355
// error
4456
console.warn(`Invalid commit position:${position}`);
4557
return;
4658
}
4759
if(
60+
// levels or steps are out of order
4861
current.level<previous.level||
4962
(current.level===previous.level&&current.step<previous.step)
5063
){

‎tests/commitOrder.test.ts

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ describe("commitOrder", () => {
1414
"1",
1515
"1",
1616
"1.1:T",
17+
"1.1:T",
18+
"1.1:S",
1719
"1.1:S",
1820
"1.2:T",
1921
"1.2:S",
@@ -45,5 +47,15 @@ describe("commitOrder", () => {
4547
constresult=validateCommitOrder(positions);
4648
expect(result).toBe(false);
4749
});
50+
it("should return false if solution is before step",()=>{
51+
constpositions=["INIT","1","1.1:S","1.1:T","1.2:T"];
52+
constresult=validateCommitOrder(positions);
53+
expect(result).toBe(false);
54+
});
55+
it("should return false if solution but no test step",()=>{
56+
constpositions=["INIT","1","1.1:S","1.2:T"];
57+
constresult=validateCommitOrder(positions);
58+
expect(result).toBe(false);
59+
});
4860
});
4961
});

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp