'use strict';

var assert = require('assert');
var estraverse = require('estraverse');
delete require.cache[require.resolve('..')];
var filter = require('..');

describe('power-assert-context-reducer-ast', function () {

    it('add parsed AST, tokens and visitor keys into output', function () {
        var input = {
            source: {
                content: 'assert(foo === bar)',
                filepath: 'test/some_test.js',
                line: 1
            },
            args: [
                {
                    value: false,
                    events: [
                        {
                            value: "FOO",
                            espath: "arguments/0/left"
                        },
                        {
                            value: "BAR",
                            espath: "arguments/0/right"
                        },
                        {
                            value: false,
                            espath: "arguments/0"
                        }
                    ]
                }
            ]
        };
        var inputClone = JSON.parse(JSON.stringify(input));
        var originalSource = input.source;

        var actual = filter(input);
        assert(actual !== input);
        assert(originalSource === input.source);
        assert.notDeepEqual(actual, input);
        assert.deepEqual(input, inputClone);

        var expected = {
            source: {
                content: 'assert(foo === bar)',
                filepath: 'test/some_test.js',
                line: 1,
                ast: '{"type":"CallExpression","callee":{"type":"Identifier","name":"assert","range":[0,6]},"arguments":[{"type":"BinaryExpression","operator":"===","left":{"type":"Identifier","name":"foo","range":[7,10]},"right":{"type":"Identifier","name":"bar","range":[15,18]},"range":[7,18]}],"range":[0,19]}',
                tokens: '[{"type":{"label":"name"},"value":"assert","range":[0,6]},{"type":{"label":"("},"range":[6,7]},{"type":{"label":"name"},"value":"foo","range":[7,10]},{"type":{"label":"==/!="},"value":"===","range":[11,14]},{"type":{"label":"name"},"value":"bar","range":[15,18]},{"type":{"label":")"},"range":[18,19]}]',
                visitorKeys: JSON.stringify(estraverse.VisitorKeys)
            },
            args: [
                {
                    value: false,
                    events: [
                        {
                            value: "FOO",
                            espath: "arguments/0/left"
                        },
                        {
                            value: "BAR",
                            espath: "arguments/0/right"
                        },
                        {
                            value: false,
                            espath: "arguments/0"
                        }
                    ]
                }
            ]
        };
        assert.deepEqual(actual, expected);
    });
});

@@ -129,22 +129,22 @@
 )%5D;%0Avar 
-filter
+reduce
  = requi
@@ -217,71 +217,23 @@
 ) %7B%0A
-%0A
     
-it('add parsed AST, tokens and visitor keys into output', 
+beforeEach(
 func
@@ -246,28 +246,29 @@
 ) %7B%0A        
-var 
+this.
 input = %7B%0A  
@@ -1025,32 +1025,271 @@
    %5D%0A        %7D;%0A
+    %7D);%0A%0A    it('new context is not deeply equal to original', function () %7B%0A        var actual = reduce(this.input);%0A        assert.notDeepEqual(actual, this.input);%0A    %7D);%0A%0A    it('original context should not be changed', function () %7B%0A
         var inpu
@@ -1323,16 +1323,21 @@
 ringify(
+this.
 input));
@@ -1349,43 +1349,130 @@
     
-var originalSource = input.source;%0A
+reduce(this.input);%0A        assert.deepEqual(this.input, inputClone);%0A    %7D);%0A%0A    it('returns new context', function () %7B
 %0A   
@@ -1493,15 +1493,20 @@
 l = 
-filter(
+reduce(this.
 inpu
@@ -1535,16 +1535,21 @@
 ual !== 
+this.
 input);%0A
@@ -1552,27 +1552,106 @@
 t);%0A    
-    assert(
+%7D);%0A%0A    it('original context reference should not be changed', function () %7B%0A        var 
 original
@@ -1658,19 +1658,22 @@
 Source =
-== 
+ this.
 input.so
@@ -1680,101 +1680,218 @@
 urce
-);%0A        assert.notDeepEqual(actual, input);%0A        assert.deepEqual(in
+;%0A        reduce(this.input);%0A        assert(originalSource === this.input.source);%0A    %7D);%0A%0A    it('add parsed AST, tokens and visitor keys into out
 put
+'
 , 
+function () %7B%0A        var actual = reduce(this.
 input
-Clone
 );%0A
-%0A
     

reorganize tests