Skip to content

Commit efd4487

Browse files
committed
Implement hasBeenRun flag in SingleLineAssertion to prevent modification after execution
1 parent 7f8c143 commit efd4487

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

internal/assertions/single_line_assertion.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,13 +20,17 @@ type SingleLineAssertion struct {
2020
// should stay on the same line after the assertion is run
2121
// Most probably because the next assertion will run on the same line
2222
StayOnSameLine bool
23+
24+
hasBeenRun bool
2325
}
2426

2527
func (a SingleLineAssertion) Inspect() string {
2628
return fmt.Sprintf("SingleLineAssertion (%q)", a.ExpectedOutput)
2729
}
2830

2931
func (a SingleLineAssertion) Run(screenState screen_state.ScreenState, startRowIndex int) (processedRowCount int, err *AssertionError) {
32+
a.hasBeenRun = true
33+
3034
if a.ExpectedOutput == "" && len(a.FallbackPatterns) == 0 {
3135
panic("CodeCrafters Internal Error: ExpectedOutput or fallbackPatterns must be provided")
3236
}
@@ -61,6 +65,11 @@ func (a SingleLineAssertion) Run(screenState screen_state.ScreenState, startRowI
6165
ErrorRowIndex: startRowIndex,
6266
Message: "Didn't find expected line.\n" + detailedErrorMessage,
6367
}
68+
} else if a.hasBeenRun {
69+
return 0, &AssertionError{
70+
ErrorRowIndex: startRowIndex,
71+
Message: "A previous line should not be modified.\n" + detailedErrorMessage,
72+
}
6473
} else {
6574
return 0, &AssertionError{
6675
ErrorRowIndex: startRowIndex,

0 commit comments

Comments
 (0)