var assert = require('assert');
var string = require('../src/renderer/string.js');
var constants = require('../src/util/constants.js');

describe('string.js', function() {
  describe('isTooLong()', function() {
    it('should return true when a string is too long', function() {
      assert.equal(true, string.isTooLong(constants.MAX_STRING_LENGTH + 1));
    });

    it('should return false when a string is not too long', function() {
      assert.equal(false, string.isTooLong(''.length));
      assert.equal(false, string.isTooLong('a'.length));
      assert.equal(false, string.isTooLong(constants.MAX_STRING_LENGTH));
    });
  });

  describe('getLengthInCrossPlatform()', function() {
    it('should return zero when a string is nothing', function() {
      var str = '';
      assert.equal(0, string.getLengthInCrossPlatform(str));
    });

    it('should return string length when a space', function() {
      var str = ' ';
      assert.equal(1, string.getLengthInCrossPlatform(str));

      str = '   ';
      assert.equal(3, string.getLengthInCrossPlatform(str));
    });

    it('should return string length when an alphabet', function() {
      var str = 'a';
      assert.equal(1, string.getLengthInCrossPlatform(str));

      str = 'xyz';
      assert.equal(3, string.getLengthInCrossPlatform(str));
    });

    it('should return string length when Japanese', function() {
      var str = 'あ';
      assert.equal(1, string.getLengthInCrossPlatform(str));

      str = '朝昼夜';
      assert.equal(3, string.getLengthInCrossPlatform(str));
    });

    it('should return string length when LF', function() {
      var str = '\n';
      assert.equal(1, string.getLengthInCrossPlatform(str));

      str = '\n\n\n';
      assert.equal(3, string.getLengthInCrossPlatform(str));
    });

    it('should return string length when CRLF', function() {
      var str = '\r\n';
      assert.equal(1, string.getLengthInCrossPlatform(str));

      str = '\r\n\r\n\r\n';
      assert.equal(3, string.getLengthInCrossPlatform(str));
    });

    it('should return string length when TAB', function() {
      var str = '\t';
      assert.equal(1, string.getLengthInCrossPlatform(str));

      str = '\t\t\t';
      assert.equal(3, string.getLengthInCrossPlatform(str));
    });

    it('should return string length when various strings', function() {
      var str = '1\na\nあ\n \n\t\n';
      assert.equal(10, string.getLengthInCrossPlatform(str));

      str = '1\r\na\r\nあ\r\n \r\n\t\r\n';
      assert.equal(10, string.getLengthInCrossPlatform(str));
    });
  });
});

@@ -758,28 +758,8 @@
 ) %7B%0A
-      var str = '';%0A
     
@@ -800,35 +800,34 @@
 InCrossPlatform(
-str
+''
 ));%0A    %7D);%0A%0A   
@@ -891,29 +891,8 @@
 ) %7B%0A
-      var str = ' ';%0A
     
@@ -945,33 +945,13 @@
 orm(
-str));%0A%0A      str = '   '
+' '))
 ;%0A  
@@ -994,35 +994,37 @@
 InCrossPlatform(
-str
+'   '
 ));%0A    %7D);%0A%0A   
@@ -1092,29 +1092,8 @@
 ) %7B%0A
-      var str = 'a';%0A
     
@@ -1146,33 +1146,13 @@
 orm(
-str));%0A%0A      str = 'xyz'
+'a'))
 ;%0A  
@@ -1195,35 +1195,37 @@
 InCrossPlatform(
-str
+'xyz'
 ));%0A    %7D);%0A%0A   
@@ -1290,29 +1290,8 @@
 ) %7B%0A
-      var str = '%E3%81%82';%0A
     
@@ -1344,34 +1344,14 @@
 orm(
-str
+'%E3%81%82'
 ));
-%0A%0A      str = '%E6%9C%9D%E6%98%BC%E5%A4%9C';
 %0A   
@@ -1393,35 +1393,37 @@
 InCrossPlatform(
-str
+'%E6%9C%9D%E6%98%BC%E5%A4%9C'
 ));%0A    %7D);%0A%0A   
@@ -1482,30 +1482,8 @@
 ) %7B%0A
-      var str = '%5Cn';%0A
     
@@ -1536,36 +1536,14 @@
 orm(
-str));%0A%0A      str = '%5Cn%5Cn
+'
 %5Cn'
+))
 ;%0A  
@@ -1586,35 +1586,40 @@
 InCrossPlatform(
-str
+'%5Cn%5Cn%5Cn'
 ));%0A    %7D);%0A%0A   
@@ -1680,32 +1680,8 @@
 ) %7B%0A
-      var str = '%5Cr%5Cn';%0A
     
@@ -1734,42 +1734,16 @@
 orm(
-str));%0A%0A      str = '%5Cr%5Cn%5Cr%5Cn%5Cr%5Cn'
+'%5Cr%5Cn'))
 ;%0A  
@@ -1786,35 +1786,46 @@
 InCrossPlatform(
-str
+'%5Cr%5Cn%5Cr%5Cn%5Cr%5Cn'
 ));%0A    %7D);%0A%0A   
@@ -1885,30 +1885,8 @@
 ) %7B%0A
-      var str = '%5Ct';%0A
     
@@ -1939,36 +1939,14 @@
 orm(
-str));%0A%0A      str = '%5Ct%5Ct%5Ct'
+'%5Ct'))
 ;%0A  
@@ -1989,35 +1989,40 @@
 InCrossPlatform(
-str
+'%5Ct%5Ct%5Ct'
 ));%0A    %7D);%0A%0A   
@@ -2094,44 +2094,8 @@
 ) %7B%0A
-      var str = '1%5Cna%5Cn%E3%81%82%5Cn %5Cn%5Ct%5Cn';%0A
     
@@ -2149,56 +2149,28 @@
 orm(
-str));%0A%0A      str = 
 '1%5C
-r%5C
 na%5C
-r%5C
 n%E3%81%82%5C
-r%5C
 n 
-%5Cr
 %5Cn%5Ct%5C
-r%5C
 n'
+))
 ;%0A  
@@ -2222,19 +2222,44 @@
 latform(
-str
+'1%5Cr%5Cna%5Cr%5Cn%E3%81%82%5Cr%5Cn %5Cr%5Cn%5Ct%5Cr%5Cn'
 ));%0A    

Remove an unused variable