'use strict'

var fs = require('fs')
var path = require('path')

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

var themePlugin = require('../index')

var CSS_INPUT_FILE = __dirname + '/css/test.css'

function normalizeString (string) {
  return string.split('\n').map(line => line.trim()).join('')
}

function realpath (filePath) {
  return fs.realpathSync(path.join(__dirname, filePath))
}

describe('postcss-theme', function () {
  let cssOutput

  it('runs successfully', function () {
    return postcss([
      themePlugin({
        themePath: __dirname + '/css/themes/default'
      })
    ])
    .process(fs.readFileSync(CSS_INPUT_FILE), { from: CSS_INPUT_FILE, to: path.basename(CSS_INPUT_FILE) })
    .then(function (result) {
      cssOutput = result.css
    })
  })

  it('produces the expected output', () => {
    expect(normalizeString(cssOutput)).to.equal(normalizeString(`
      @value black, white from "${realpath('./css/themes/default/colors.css')}";

      .test-1 {
        composes: no-borders from "${realpath('./css/themes/default/base-styles.css')}";
        color: black;
      }

      .test-2 {
        color: white;
      }
    `))
  })
})

@@ -268,16 +268,21 @@
 n string
+%0A    
 .split('
@@ -289,33 +289,72 @@
 %5Cn')
-.map(line =%3E line.trim())
+%0A    .map(function (line) %7B%0A      return line.trim()%0A    %7D)%0A    
 .joi

Fix test for Node 0.12