var postcss = require('postcss');
var expect  = require('chai').expect;

var vars = require('../');

var test = function (input, output, opts) {
    expect(postcss(vars(opts)).process(input).css).to.eql(output);
};

describe('postcss-simple-vars', function () {

    it('replaces variables in values', function () {
        test('$size: 10px;\na { width: $size; height: $size }',
             'a { width: 10px; height: 10px }');
    });

    it('allows dashes and digits in variable name', function () {
        test('$a-b_10: 1;\na { one: $a-b_10 a$(a-b_10) }', 'a { one: 1 a1 }');
    });

    it('needs space before variable', function () {
        test('$size: 10px; a { width: one-$size }', 'a { width: one-$size }');
    });

    it('has second syntax for varibles', function () {
        test('$size: 10; a { width: $(size)px }', 'a { width: 10px }');
    });

    it('replaces variables in selector', function () {
        test('$name: a; $name $(name)b { }', 'a ab { }');
    });

    it('replaces variables in at-rule params', function () {
        test('$name: a; @atrule $name $(name)b { }', '@atrule a ab { }');
    });

    it('parses at-rule without params', function () {
        test('@atrule{}', '@atrule{}');
    });

    it('overrides variables', function () {
        test('$var: 1; a{ one: $var } b{ $var: 2; two: $var } c{ two: $var }',
             'a{ one: 1 } b{ two: 2 } c{ two: 2 }');
    });

    it('throws an error on unknown variable', function () {
        expect(function () {
            test('a { width: $size }');
        }).to.throw('<css input>:1:5: Undefined variable $size');
    });

    it('allows to silent errors', function () {
        test('a { width: $size }', 'a { width: $size }', { silent: true });
    });

    it('gets variables from options', function () {
        test('a { width: $one }', 'a { width: 1 }', { variables: { one: 1 } });
    });

    it('cans get variables only from option', function () {
        test('$one: 2; $two: 2; a { one: $one }',
             '$one: 2; $two: 2; a { one: 1 }',
             { only: { one: 1 } });
    });

    it('works with false value', function () {
        test('a { zero: $zero }', 'a { zero: 0 }', { variables: { zero: 0 } });
    });

    it('do not remove first symbol', function () {
        test('a { a: 1 $a }', 'a { a: 1 1 }', { variables: { a: 1 } });
    });

});

@@ -338,17 +338,16 @@
 10px;%5Cna
- 
 %7B width:
@@ -387,17 +387,16 @@
       'a
- 
 %7B width:
@@ -523,17 +523,16 @@
 0: 1;%5Cna
- 
 %7B one: $
@@ -555,17 +555,16 @@
 ) %7D', 'a
- 
 %7B one: 1
@@ -666,33 +666,32 @@
 ; a %7B width: one
--
 $size %7D', 'a %7B w
@@ -699,17 +699,16 @@
 dth: one
--
 $size %7D'
@@ -711,32 +711,164 @@
 e %7D');%0A    %7D);%0A%0A
+    it('does not remove first symbol', function () %7B%0A        test('a%7B a: 1 $a %7D', 'a%7B a: 1 1 %7D', %7B variables: %7B a: 1 %7D %7D);%0A    %7D);%0A%0A
     it('has seco
@@ -1641,33 +1641,32 @@
          test('a
- 
 %7B width: $size %7D
@@ -1708,9 +1708,9 @@
 %3E:1:
-5
+4
 : Un
@@ -1799,33 +1799,32 @@
 %0A        test('a
- 
 %7B width: $size %7D
@@ -1820,33 +1820,32 @@
 th: $size %7D', 'a
- 
 %7B width: $size %7D
@@ -1942,17 +1942,16 @@
  test('a
- 
 %7B width:
@@ -1954,33 +1954,32 @@
 dth: $one %7D', 'a
- 
 %7B width: 1 %7D', %7B
@@ -2103,25 +2103,24 @@
 ; $two: 2; a
- 
 %7B one: $one 
@@ -2156,17 +2156,16 @@
 wo: 2; a
- 
 %7B one: 1
@@ -2276,17 +2276,16 @@
  test('a
- 
 %7B zero: 
@@ -2296,17 +2296,16 @@
 o %7D', 'a
- 
 %7B zero: 
@@ -2352,140 +2352,8 @@
 );%0A%0A
-    it('do not remove first symbol', function () %7B%0A        test('a %7B a: 1 $a %7D', 'a %7B a: 1 1 %7D', %7B variables: %7B a: 1 %7D %7D);%0A    %7D);%0A%0A
 %7D);%0A

Clean up tests