suyiScreen/node_modules/coffeescript-compiler/spec/Compiler.spec.js

95 lines
2.6 KiB
JavaScript

// run using jasmine-node
var Compiler = require('../Compiler.js'), path = require('path'), fs = require('fs');
var cc = new Compiler(path.join(__dirname, '../node_modules/.bin/coffee'));
var inputFile = path.join(__dirname, 'input.coffee'), outputFile = path.join(__dirname, 'out.js'), encoding = 'utf-8';
var compiled = '// Generated by CoffeeScript 1.3.3\n(function() {\n var a;\n\n a = 5;\n\n}).call(this);\n';
var bareCompiled = '// Generated by CoffeeScript 1.3.3\nvar a;\n\na = 5;\n';
describe('Memory Compiler Tests', function () {
it('Should compile input strings.', function (done) {
cc.compile('a = 5', function (status, output) {
if (status === 0) {
done();
}
});
});
it('Should bare compile input strings.', function (done) {
cc.compile('a = 5', {bare: true}, function (status, output) {
if (status === 0) {
done();
}
});
});
it('Should compile input files.', function (done) {
cc.compile(inputFile, {asFileName: true}, function (status, output) {
if (status === 0) {
done();
}
});
});
it('Should bare compile input files.', function (done) {
cc.compile(inputFile, {asFileName: true, bare: true}, function (status, output) {
if (status === 0) {
done();
}
});
});
});
describe('Output file compiler tests.', function () {
afterEach(function () {
fs.unlink(path.join(__dirname, 'out.js'));
});
it('Should compile input strings to an output file.', function (done) {
cc.compile('a = 5', {writeFile: outputFile}, function (status, output) {
if (status === 0) {
fs.readFile(outputFile, encoding, function (err, data) {
if (!err) {
done();
}
});
}
});
});
it('Should bare compile input strings to an output file.', function (done) {
cc.compile('a = 5', {bare: true, writeFile: outputFile}, function (status, output) {
if (status === 0) {
fs.readFile(outputFile, encoding, function (err, data) {
if (!err) {
done();
}
});
}
});
});
it('Should compile input files to an output file.', function (done) {
cc.compile(inputFile, {asFileName: true, writeFile: outputFile}, function (status, output) {
if (status === 0) {
fs.readFile(outputFile, encoding, function (err, data) {
if (!err) {
done();
}
});
}
});
});
it('Should bare compile input files to an output file.', function (done) {
cc.compile(inputFile, {asFileName: true, bare: true, writeFile: outputFile}, function (status, output) {
if (status === 0) {
fs.readFile(outputFile, encoding, function (err, data) {
if (!err) {
done();
}
});
}
});
});
});