'use strict'; var chai = require('chai'), spies = require("chai-spies"), pp = require('../lib/preprocess'), hello = require('./lib/hello'); chai.should(); chai.use(spies); describe('newlines shall be handled in all common formats', function () { var input; it('and handle \\n (Unix) style EOLs', function () { input = "a\n" + "\n" + "b\n" + "\n" + "c"; pp.preprocess(input, {TEST: ""}).should.equal("a\nb\nc"); }); it('and handle \\r\\n (Windows) style EOLs', function () { input = "a\r\n" + "\r\n" + "b\r\n" + "\r\n" + "c"; pp.preprocess(input, {TEST: ""}).should.equal("a\r\nb\r\nc"); }); it('and handle \\r (legacy Mac) style EOLs', function () { input = "a\r" + "\r" + "b\r" + "\r" + "c"; pp.preprocess(input, {TEST: ""}).should.equal("a\rb\rc"); }); it('and replace EOL in sources with mixed style EOLs with the EOL from current OS', function () { var osEol = require('os').EOL; input = "a\r" + "\r\n" + "b\n" + "\r" + "c"; pp.preprocess(input, {TEST: ""}).should.equal("a" + osEol + "b" + osEol + "c"); }); it('and convert EOLs from included files into EOLs from target file when using @include', function () { // includenewline.txt has \n style EOLs input = "a\r" + "\r" + "b\r"; pp.preprocess(input, {srcDir: "test/fixtures/include"}).should.equal("a\r!foobar!\r\rb\r"); }); it('and convert EOLs from included files into EOLs from target file when using @include-static', function () { input = "a\r" + "\r" + "b\r"; pp.preprocess(input, {srcDir: "test/fixtures/include"}).should.equal("a\r!foobar!\r\rb\r"); }); it('and extend files and adapt all EOLs from file to be included to EOLs in target file when using @extend', function () { var helloSpy = chai.spy(hello); // extendadv.html has \r style EOLs input = "a\n\nqa\n\n\nc"; pp.preprocess(input, { srcDir: 'test/fixtures/extend', BLUE: "red", hello: helloSpy }).should.equal("a\na\n b\n red\n Hello extend!\n qa\nc\nc"); helloSpy.should.have.been.called.with('extend'); }); });