/**
 * @file test for formatters of non-html content (js, css)
 * @author nighca<nighca@live.cn>
 */

var formatters = require('../../lib/other-formatter');
var parse = require('../../lib/parse');

var indent = function (opt) {
    var repeat = function (str, num) {
        return Array.prototype.join.call({length: num + 1}, str);
    };

    return repeat(opt['indent-char'] === 'tab' ? '\t' : repeat(' ', opt['indent-size']), opt.level);
};

var trim = function (content) {
    return content.replace(/(^([\s\t]*\n)+)|((\n[\s\t]*)+$)/g, '');
};

describe('formatter', function () {

    describe('for script', function () {
        var scriptFormatter = formatters.script;

        it('should be a function', function () {
            expect(typeof scriptFormatter).toBe('function');
        });

        it('should format jvascript', function () {
            var node = parse('<script>var a=0;\nvar b=1;</script>').querySelector('script');
            var newContent = scriptFormatter(node.childNodes[0].textContent, node,
                {
                    'level': 0,
                    'indent-char': 'space',
                    'indent-size': 4
                },
                {
                    indent: indent,
                    trim: trim
                }
            );

            expect(typeof newContent).toBe('string');
        });
    });

    describe('for style', function () {
        var styleFormatter = formatters.style;

        it('should be a function', function () {
            expect(typeof styleFormatter).toBe('function');
        });

        it('should format css', function () {
            var node = parse('<style>body{margin:0;}</style>').querySelector('style');
            var newContent = styleFormatter(node.childNodes[0].textContent, node,
                {
                    'level': 0,
                    'indent-char': 'space',
                    'indent-size': 4
                },
                {
                    indent: indent,
                    trim: trim
                }
            );

            expect(typeof newContent).toBe('string');
        });
    });

});

@@ -443,20 +443,37 @@
 %7D;%0A%0Avar 
-trim
+removeBlankLineAround
  = funct
@@ -564,27 +564,25 @@
 %7D;%0A%0A
-describe('f
+var testF
 ormatter
 ', f
@@ -577,18 +577,18 @@
 ormatter
-',
+ =
  functio
@@ -962,36 +962,33 @@
             var 
-newC
+c
 ontent = scriptF
@@ -984,24 +984,8 @@
 t = 
-scriptFormatter(
 node
@@ -1002,39 +1002,33 @@
 s%5B0%5D.textContent
-, node,
+;
 %0A               
@@ -1016,35 +1016,41 @@
 nt;%0A            
-   
+var opt =
  %7B%0A             
@@ -1044,36 +1044,32 @@
                 
- 
-   
 'level': 0,%0A    
@@ -1056,36 +1056,32 @@
     'level': 0,%0A
-    
                 
@@ -1112,36 +1112,32 @@
                 
-    
 'indent-size': 4
@@ -1141,37 +1141,356 @@
 : 4%0A            
-    %7D
+%7D;%0A            var indentContent = function (content) %7B%0A                opt.level++;%0A%0A                return content.split('%5Cn').map(function (line) %7B%0A                    return line ? (indent(opt) + line) : line;%0A                %7D).join('%5Cn');%0A            %7D;%0A%0A            var newContent = scriptFormatter(content, node, opt
 ,%0A              
@@ -1519,32 +1519,39 @@
   indent: indent
+Content
 ,%0A              
@@ -1554,36 +1554,53 @@
           trim: 
-trim
+removeBlankLineAround
 %0A               
@@ -2044,36 +2044,33 @@
             var 
-newC
+c
 ontent = styleFo
@@ -2066,23 +2066,8 @@
 t = 
-styleFormatter(
 node
@@ -2092,23 +2092,17 @@
 tContent
-, node,
+;
 %0A       
@@ -2098,35 +2098,41 @@
 nt;%0A            
-   
+var opt =
  %7B%0A             
@@ -2126,36 +2126,32 @@
                 
-  
-  
 'level': 0,%0A    
@@ -2138,36 +2138,32 @@
     'level': 0,%0A
-    
                 
@@ -2194,36 +2194,32 @@
                 
-    
 'indent-size': 4
@@ -2231,21 +2231,339 @@
         
-    %7D
+%7D;%0A            var indentContent = function (content) %7B%0A                opt.level++;%0A%0A                return content.split('%5Cn').map(function (line) %7B%0A                    return line ? (indent(opt) + line) : line;%0A                %7D).join('%5Cn');%0A            %7D;%0A%0A            var newContent = styleFormatter(content, node, opt
 ,%0A      
@@ -2608,16 +2608,23 @@
 : indent
+Content
 ,%0A      
@@ -2643,20 +2643,37 @@
   trim: 
-trim
+removeBlankLineAround
 %0A       
@@ -2775,11 +2775,49 @@
   %7D);%0A%0A%7D
+;%0A%0Adescribe('formatter', testFormatter
 );%0A

debug test case for other-formatter