'use strict';

require('chai').should();

var StringStream = require('./utils/string-stream');
var parse = require('../lib/parse');

describe('parse()', function () {
  it('should return a promise for a list of hosts', function (done) {
    parse(new StringStream(['127.0.0.1 localhost'])).then(function (hosts) {
      hosts.should.be.an('array');
      hosts.should.have.length(1);
      hosts.should.include('localhost');
      done();
    });
  });
  it('should ignore comments and whitespaces', function (done) {
    var stream = new StringStream([
      ' 127.0.0.1  h1     ',
      '#127.0.0.1  h2',
      ' 127.0.0.1 # h3',
      ' 127.0.0.1  h4  #comment'
    ]);
    parse(stream).then(function (hosts) {
      hosts.should.have.length(2);
      hosts.should.not.include('h2');
      hosts.should.not.include('h3');
      done();
    });
  });
  it('should parse IPv4 and IPv6 addresses', function (done) {
    var stream = new StringStream([
      '127.0.0.1  h1',
      '::1    h2'
    ]);
    parse(stream).then(function (hosts) {
      hosts.should.have.length(2);
      hosts.should.include('h1');
      hosts.should.include('h2');
      done();
    });
  });
  it('should always return a promise for an array', function (done) {
    parse(new StringStream([])).then(function (hosts) {
      hosts.should.be.an('array');
      hosts.should.have.length(0);
      done();
    });
  });
});

@@ -23,16 +23,55 @@
 ('chai')
+%0A  .use(require('chai-as-promised'))%0A  
 .should(
@@ -257,36 +257,32 @@
 , function (
-done
 ) %7B%0A    
 parse(new St
@@ -261,32 +261,39 @@
 nction () %7B%0A    
+return 
 parse(new String
@@ -328,52 +328,23 @@
 '%5D))
-.then(function (hosts) %7B
 %0A      
-hosts
 .should.
 be.a
@@ -331,32 +331,43 @@
 )%0A      .should.
+eventually.
 be.an('array');%0A
@@ -364,35 +364,26 @@
 'array')
-;
 %0A      
-hosts.shoul
+.an
 d.have.l
@@ -390,35 +390,26 @@
 ength(1)
-;
 %0A      
-hosts.shoul
+.an
 d.includ
@@ -424,38 +424,16 @@
 host');%0A
-      done();%0A    %7D);%0A
   %7D);%0A  
@@ -479,36 +479,32 @@
 ces', function (
-done
 ) %7B%0A    var stre
@@ -642,32 +642,39 @@
 nt'%0A    %5D);%0A    
+return 
 parse(stream).th
@@ -674,52 +674,23 @@
 eam)
-.then(function (hosts) %7B
 %0A      
-hosts
 .should.
 have
@@ -677,32 +677,43 @@
 )%0A      .should.
+eventually.
 have.length(2);%0A
@@ -710,35 +710,26 @@
 ength(2)
-;
 %0A      
-hosts.shoul
+.an
 d.not.in
@@ -739,35 +739,26 @@
 de('h2')
-;
 %0A      
-hosts.shoul
+.an
 d.not.in
@@ -774,36 +774,14 @@
 ');%0A
-      done();%0A  
   %7D);%0A
-  %7D);%0A
   it
@@ -823,36 +823,32 @@
 ses', function (
-done
 ) %7B%0A    var stre
@@ -920,24 +920,31 @@
     %5D);%0A    
+return 
 parse(stream
@@ -948,52 +948,23 @@
 eam)
-.then(function (hosts) %7B
 %0A      
-hosts
 .should.
 have
@@ -951,32 +951,43 @@
 )%0A      .should.
+eventually.
 have.length(2);%0A
@@ -984,35 +984,26 @@
 ength(2)
-;
 %0A      
-hosts.shoul
+.an
 d.includ
@@ -1009,35 +1009,26 @@
 de('h1')
-;
 %0A      
-hosts.shoul
+.an
 d.includ
@@ -1036,38 +1036,16 @@
 ('h2');%0A
-      done();%0A    %7D);%0A
   %7D);%0A  
@@ -1108,20 +1108,16 @@
 on (
-done
 ) %7B%0A    
 pars
@@ -1112,16 +1112,23 @@
 ) %7B%0A    
+return 
 parse(ne
@@ -1150,52 +1150,23 @@
 %5B%5D))
-.then(function (hosts) %7B
 %0A      
-hosts
 .should.
 be.a
@@ -1161,16 +1161,27 @@
 .should.
+eventually.
 be.an('a
@@ -1190,27 +1190,18 @@
 ay')
-;
 %0A      
-hosts.shoul
+.an
 d.ha
@@ -1218,30 +1218,8 @@
 0);%0A
-      done();%0A    %7D);%0A
   %7D)

use chai-as-promised in existing tests