-
-
Notifications
You must be signed in to change notification settings - Fork 178
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes #230
- Loading branch information
Showing
5 changed files
with
98 additions
and
27 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,20 @@ | ||
import { cloneMethod } from '../../symbols'; | ||
import { CommandWrapper } from './CommandWrapper'; | ||
|
||
/** @hidden */ | ||
export class CommandsIterable<Model extends object, Real, RunResult> | ||
implements Iterable<CommandWrapper<Model, Real, RunResult>> { | ||
private lastErrorDetectedStr: string = ''; | ||
constructor(readonly commands: CommandWrapper<Model, Real, RunResult>[]) {} | ||
[Symbol.iterator](): Iterator<CommandWrapper<Model, Real, RunResult>> { | ||
for (let idx = 0; idx !== this.commands.length; ++idx) { | ||
this.commands[idx].hasRan = false; | ||
} | ||
return this.commands[Symbol.iterator](); | ||
} | ||
errorDetected() { | ||
this.lastErrorDetectedStr = this.commands | ||
[cloneMethod]() { | ||
return new CommandsIterable(this.commands.map(c => c.clone())); | ||
} | ||
toString(): string { | ||
return this.commands | ||
.filter(c => c.hasRan) | ||
.map(c => c.toString()) | ||
.join(','); | ||
} | ||
toString(): string { | ||
return this.lastErrorDetectedStr; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
import * as assert from 'assert'; | ||
import * as fc from '../../../../../lib/fast-check'; | ||
|
||
import { CommandWrapper } from '../../../../../src/check/model/commands/CommandWrapper'; | ||
import { CommandsIterable } from '../../../../../src/check/model/commands/CommandsIterable'; | ||
import { Command } from '../../../../../src/check/model/command/Command'; | ||
import { cloneMethod } from '../../../../../src/check/symbols'; | ||
|
||
type Model = {}; | ||
type Real = {}; | ||
|
||
const buildAlreadyRanCommands = (runFlags: boolean[]) => { | ||
return runFlags.map((hasRun, idx) => { | ||
const cmd = new class implements Command<Model, Real> { | ||
check = (m: Readonly<Model>) => true; | ||
run = (m: Model, r: Real) => {}; | ||
toString = () => String(idx); | ||
}(); | ||
const wrapper = new CommandWrapper(cmd); | ||
if (hasRun) { | ||
wrapper.run({}, {}); | ||
} | ||
return wrapper; | ||
}); | ||
}; | ||
|
||
describe('CommandsIterable', () => { | ||
it('Should not reset hasRun flag on iteration', () => | ||
fc.assert( | ||
fc.property(fc.array(fc.boolean()), runFlags => { | ||
const commands = [...new CommandsIterable(buildAlreadyRanCommands(runFlags))]; | ||
for (let idx = 0; idx !== runFlags.length; ++idx) { | ||
assert.equal(commands[idx].hasRan, runFlags[idx]); | ||
} | ||
}) | ||
)); | ||
it('Should not reset hasRun flag on the original iterable on clone', () => | ||
fc.assert( | ||
fc.property(fc.array(fc.boolean()), runFlags => { | ||
const originalIterable = new CommandsIterable(buildAlreadyRanCommands(runFlags)); | ||
originalIterable[cloneMethod](); | ||
const commands = [...originalIterable]; | ||
for (let idx = 0; idx !== runFlags.length; ++idx) { | ||
assert.equal(commands[idx].hasRan, runFlags[idx]); | ||
} | ||
}) | ||
)); | ||
it('Should reset hasRun flag for the clone on clone', () => | ||
fc.assert( | ||
fc.property(fc.array(fc.boolean()), runFlags => { | ||
const commands = [...new CommandsIterable(buildAlreadyRanCommands(runFlags))[cloneMethod]()]; | ||
for (let idx = 0; idx !== runFlags.length; ++idx) { | ||
assert.ok(!commands[idx].hasRan); | ||
} | ||
}) | ||
)); | ||
it('Should only print ran commands', () => | ||
fc.assert( | ||
fc.property(fc.array(fc.boolean()), runFlags => { | ||
const commandsIterable = new CommandsIterable(buildAlreadyRanCommands(runFlags)); | ||
const expectedToString = runFlags | ||
.map((hasRan, idx) => (hasRan ? String(idx) : '')) | ||
.filter(s => s !== '') | ||
.join(','); | ||
assert.equal(commandsIterable.toString(), expectedToString); | ||
}) | ||
)); | ||
}); |