<commit_before>module("jsAspect.around");

(function() {
    
    test("jsAspect.inject: 'around' advice, 'prototypeMethods' pointcut", function() {
        function Object() {
        }

        Object.prototype.identity = function(x) {
            return x;
        };
        
        Object.prototype.minusOne = function(x) {
            return x - 1;
        };
        
        jsAspect.inject(Object, jsAspect.POINTCUT.PROTOTYPE_METHODS, jsAspect.JOIN_POINT.AROUND,
            function aroundCallback(func, x) {
                return 2 * func(x);
            }
        );

        var obj = new Object();
        
        equal(obj.identity(3), 6, "'around' advice has been applied to 'identity'");
        equal(obj.minusOne(3), 4, "'around' advice has been applied to 'minusOne'");
    });

    test("jsAspect.inject: 'around' advice, 'prototypeMethods' pointcut, multiple arguments in the method", function() {
        function Object() {
        }

        Object.prototype.sum = function() {
            var args = [].slice.call(arguments, 0);
            
            return args.reduce(function(accumulated, current){
                return accumulated + current;
            });
        };

        jsAspect.inject(Object, jsAspect.POINTCUT.PROTOTYPE_METHODS, jsAspect.JOIN_POINT.AROUND,
            function aroundCallback(func) {
                var args = [].slice.call(arguments, 1),
                    sum = func.apply(this, args);

                return (sum > 10) ? sum : 0;
            }
        );

        var obj = new Object();
        
        equal(obj.sum(1, 2, 3), 0, "'around' advice has been applied to 'sum'");
        equal(obj.sum(1, 2, 3, 4, 5), 15, "'around' advice has been applied to 'sum'");
    });
    
    test("jsAspect.inject: 'around' advice, 'prototypeMethods' pointcut: 'this' has the correct value", function() {
        var obj = new Object();

        function Object() {
        }

        Object.prototype.identity = function(x) {
            equal(obj, this, "'this' is correct in 'identity'");
            return x;
        };
        
        Object.prototype.minusOne = function(x) {
            equal(obj, this, "'this' is correct in 'minusOne'");
            return x - 1;
        };
        
        jsAspect.inject(Object, jsAspect.POINTCUT.PROTOTYPE_METHODS, jsAspect.JOIN_POINT.AROUND,
            function aroundCallback(func, x) {
                equal(obj, this, "'this' is correct in advice 1");
                return 2 * func(x);
            }
        );
        jsAspect.inject(Object, jsAspect.POINTCUT.PROTOTYPE_METHODS, jsAspect.JOIN_POINT.AROUND,
            function aroundCallback(func, x) {
                equal(obj, this, "'this' is correct in advice 2");
                return 3 * func(x);
            }
        );
        jsAspect.inject(Object, jsAspect.POINTCUT.PROTOTYPE_METHODS, jsAspect.JOIN_POINT.AROUND,
            function aroundCallback(func, x) {
                equal(obj, this, "'this' is correct in advice 3");
                return 4 * func(x);
            }
        );

        equal(obj.identity(3), 72, "'around' advice has been applied to 'identity'");
        equal(obj.minusOne(3), 48, "'around' advice has been applied to 'minusOne'");
    });
    
    test("jsAspect.inject: 'around' advice, 'self' pointcut", function() {
        function Object() {
        }
      Object.prototype.identity = function(x) {
            return x;
        };

        var obj = new Object();
        
        obj.multiplyByTwo = function(x) {
            return 2 * x;
        };
        
        jsAspect.inject(obj, jsAspect.POINTCUT.METHODS, jsAspect.JOIN_POINT.AROUND,
            function aroundCallback(func, x) {
                return func(x) - 1;
            }
        );

        equal(obj.identity(5), 5, "'around' advice has not been applied to 'identity'");
        equal(obj.multiplyByTwo(3), 5, "'around' advice has been applied to 'multiplyByTwo'");
    });
})();<commit_msg>Formatted the test for 'around' properly<commit_after>module("jsAspect.around");

(function() {

  test("jsAspect.inject: 'around' advice, 'prototypeMethods' pointcut", function() {
    function Target() {
    }

    Target.prototype.identity = function(x) {
      return x;
    };

    Target.prototype.minusOne = function(x) {
      return x - 1;
    };

    jsAspect.inject(Target, jsAspect.POINTCUT.PROTOTYPE_METHODS, jsAspect.JOIN_POINT.AROUND,
      function aroundCallback(func, x) {
        return 2 * func(x);
      }
    );

    var obj = new Target();

    equal(obj.identity(3), 6, "'around' advice has been applied to 'identity'");
    equal(obj.minusOne(3), 4, "'around' advice has been applied to 'minusOne'");
  });

  test("jsAspect.inject: 'around' advice, 'prototypeMethods' pointcut, multiple arguments in the method", function() {
    function Target() {
    }

    Target.prototype.sum = function() {
      var args = [].slice.call(arguments, 0);

      return args.reduce(function(accumulated, current){
        return accumulated + current;
      });
    };

    jsAspect.inject(Target, jsAspect.POINTCUT.PROTOTYPE_METHODS, jsAspect.JOIN_POINT.AROUND,
      function aroundCallback(func) {
        var args = [].slice.call(arguments, 1),
          sum = func.apply(this, args);

        return (sum > 10) ? sum : 0;
      }
    );

    var obj = new Target();

    equal(obj.sum(1, 2, 3), 0, "'around' advice has been applied to 'sum'");
    equal(obj.sum(1, 2, 3, 4, 5), 15, "'around' advice has been applied to 'sum'");
  });

  test("jsAspect.inject: 'around' advice, 'prototypeMethods' pointcut: 'this' has the correct value", function() {
    var obj = new Target();

    function Target() {
    }

    Target.prototype.identity = function(x) {
      equal(obj, this, "'this' is correct in 'identity'");
      return x;
    };

    Target.prototype.minusOne = function(x) {
      equal(obj, this, "'this' is correct in 'minusOne'");
      return x - 1;
    };

    jsAspect.inject(Target, jsAspect.POINTCUT.PROTOTYPE_METHODS, jsAspect.JOIN_POINT.AROUND,
      function aroundCallback(func, x) {
        equal(obj, this, "'this' is correct in advice 1");
        return 2 * func(x);
      }
    );
    jsAspect.inject(Target, jsAspect.POINTCUT.PROTOTYPE_METHODS, jsAspect.JOIN_POINT.AROUND,
      function aroundCallback(func, x) {
        equal(obj, this, "'this' is correct in advice 2");
        return 3 * func(x);
      }
    );
    jsAspect.inject(Target, jsAspect.POINTCUT.PROTOTYPE_METHODS, jsAspect.JOIN_POINT.AROUND,
      function aroundCallback(func, x) {
        equal(obj, this, "'this' is correct in advice 3");
        return 4 * func(x);
      }
    );

    equal(obj.identity(3), 72, "'around' advice has been applied to 'identity'");
    equal(obj.minusOne(3), 48, "'around' advice has been applied to 'minusOne'");
  });

  test("jsAspect.inject: 'around' advice, 'self' pointcut", function() {
    function Target() {
    }

    Target.prototype.identity = function(x) {
      return x;
    };

    var obj = new Target();

    obj.multiplyByTwo = function(x) {
      return 2 * x;
    };

    jsAspect.inject(obj, jsAspect.POINTCUT.METHODS, jsAspect.JOIN_POINT.AROUND,
      function aroundCallback(func, x) {
        return func(x) - 1;
      }
    );

    equal(obj.identity(5), 5, "'around' advice has not been applied to 'identity'");
    equal(obj.multiplyByTwo(3), 5, "'around' advice has been applied to 'multiplyByTwo'");
  });
})();
{'fraction_non_alphanumeric': 0.13643659711075443, 'fraction_numerical': 0.010968432316746924, 'mean_word_length': 2.2664919178680645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4969207', 'n_tokens_mistral': 2400, 'n_tokens_neox': 2270, 'n_words': 561}