"use strict";
const assert = require('assert');
const jsc = require('jsverify');

const jscCommands = require('../src/jscCommands');

describe('jscCommands', function() {
    it('should be able to return an unshrinkable test', async function() {
        function FailureCommand() {
            this.check = (model) => true;
            this.run = (state, model) => false;
        }
        const commands = [jscCommands.command(FailureCommand)];
        const result = await jsc.check(jscCommands.forall(jscCommands.commands(...commands)), {quiet: true});
        
        // result.counterexample contains two items:
        // - the generated seed
        // - the faulty array of commands
        assert.notEqual(result, true, 'should fails');
        assert.equal(result.counterexample[1].length, 1, 'only one command in counterexample');
        assert.ok(result.counterexample[1][0].command instanceof FailureCommand, 'failure command in counterexample');
    });
});

@@ -179,57 +179,101 @@
     
-it('should be able to return an unshrinkable test
+describe('failure', function() %7B%0D%0A        it('should shrink to empty array for failing warmup
 ', a
@@ -283,32 +283,36 @@
 c function() %7B%0D%0A
+    
         function
@@ -328,24 +328,28 @@
 ommand() %7B%0D%0A
+    
             
@@ -387,24 +387,28 @@
             
+    
 this.run = (
@@ -444,11 +444,19 @@
     
-%7D%0D%0A
+    %7D%0D%0A    
     
@@ -520,24 +520,28 @@
 %5D;%0D%0A        
+ 
+   
 const result
@@ -578,16 +578,38 @@
 .forall(
+%0D%0A                    
 jscComma
@@ -637,10 +637,92 @@
 nds)
-)
 ,
+%0D%0A                    () =%3E %7Bthrow %22failure%22;%7D%0D%0A                ),%0D%0A               
  %7Bqu
@@ -743,18 +743,26 @@
         
-%0D%0A
+    %0D%0A    
         
@@ -807,32 +807,36 @@
 items:%0D%0A        
+    
 // - the generat
@@ -844,32 +844,36 @@
 d seed%0D%0A        
+   
+ 
 // - the faulty 
@@ -891,16 +891,20 @@
 mmands%0D%0A
+    
         
@@ -947,24 +947,1391 @@
 d fails');%0D%0A
+            assert.equal(result.counterexample%5B1%5D.length, 0, 'no command in counterexample');%0D%0A        %7D);%0D%0A        it('should shrink to empty array for failing teardown', async function() %7B%0D%0A            function FailureCommand() %7B%0D%0A                this.check = (model) =%3E true;%0D%0A                this.run = (state, model) =%3E false;%0D%0A            %7D%0D%0A            const commands = %5BjscCommands.command(FailureCommand)%5D;%0D%0A            const result = await jsc.check(jscCommands.forall(%0D%0A                    jscCommands.commands(...commands),%0D%0A                    () =%3E new Object(%7Bstate: %7B%7D, model: %7B%7D%7D),%0D%0A                    () =%3E %7Bthrow %22failure%22;%7D%0D%0A                ),%0D%0A                %7Bquiet: true%7D);%0D%0A            %0D%0A            assert.notEqual(result, true, 'should fails');%0D%0A            assert.equal(result.counterexample%5B1%5D.length, 0, 'no command in counterexample');%0D%0A        %7D);%0D%0A        it('should be able to return an unshrinkable test', async function() %7B%0D%0A            function FailureCommand() %7B%0D%0A                this.check = (model) =%3E true;%0D%0A                this.run = (state, model) =%3E false;%0D%0A            %7D%0D%0A            const commands = %5BjscCommands.command(FailureCommand)%5D;%0D%0A            const result = await jsc.check(jscCommands.forall(jscCommands.commands(...commands)), %7Bquiet: true%7D);%0D%0A%0D%0A            assert.notEqual(result, true, 'should fails');%0D%0A    
         asse
@@ -2407,32 +2407,36 @@
 nterexample');%0D%0A
+    
         assert.o
@@ -2535,24 +2535,37 @@
 example');%0D%0A
+        %7D);%0D%0A
     %7D);%0D%0A%7D);

add tests on failing warmup/teardown