var postcss = require('postcss');
var assert  = require('assert');

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

function test(input, expected, opts, done) {
  var result = postcss([plugin(opts)]).process(input).css;
  assert.equal(result, expected);
};

describe('postcss-each', function() {

  it('expects valid syntax', function() {
    var missedIn = function() {
      test('@each $icon foo, bar {}');
    };

    var missedVar = function() {
      test('@each in foo, bar {}');
    };

    var missedValues = function() {
      test('@each $icon in {}');
    };

    assert.throws(missedIn, /Missed "in" keyword in @each/);
    assert.throws(missedVar, /Missed variable name in @each/);
    assert.throws(missedValues, /Missed values list in @each/);
  });

  it('iterates through given values', function() {
    var input     = '@each $icon in foo, bar { .icon-$(icon) {' +
                    'background: url("$(icon).png"); } }';
    var expected  = '.icon-foo {\n    background: url("foo.png")\n}\n' +
                    '.icon-bar {\n    background: url("bar.png")\n}';
    test(input, expected);
  });

  it('iterates through one value', function() {
    var input     = '@each $icon in foo { .icon-$(icon) {' +
                    'background: url("$(icon).png"); } }';
    var expected  = '.icon-foo {\n    background: url("foo.png")\n}';
    test(input, expected);
  });

  it('respects multiple selectors', function() {
    var input     = '@each $icon in foo, bar { .icon-$(icon), .$(icon)' +
                    '{ background: url("$(icon).png"); } }';
    var expected  = '.icon-foo, .foo {\n    background: url("foo.png")\n}\n' +
                    '.icon-bar, .bar {\n    background: url("bar.png")\n}';
    test(input, expected);
  });

  it('respects multiple properties', function() {
    var input     = '@each $icon in foo, bar { .icon-$(icon) {' +
                    'background: url("$(icon).png");' +
                    'content: "$(icon)";' +
                    '}}';
    var expected  = '.icon-foo {\n    background: url("foo.png");\n' +
                                 '    content: "foo"\n}\n' +
                    '.icon-bar {\n    background: url("bar.png");\n' +
                                 '    content: "bar"\n}';
    test(input, expected);
  });

});

@@ -2277,12 +2277,392 @@
 %0A  %7D);%0A%0A
+  it('doesn%5C't replace other variables', function() %7B%0A    var input     = '@each $icon in foo, bar %7B .icon-$(icon), .$(icon)' +%0A                    '%7B background: url(%22$(bg).png%22); %7D %7D';%0A    var expected  = '.icon-foo, .foo %7B%5Cn    background: url(%22$(bg).png%22)%5Cn%7D%5Cn' +%0A                    '.icon-bar, .bar %7B%5Cn    background: url(%22$(bg).png%22)%5Cn%7D';%0A    test(input, expected);%0A  %7D);%0A%0A
 %7D);%0A

Add one more test