UNPKG

amie

Version:

Amalgamation Made Insanely Easy. A tool to easily amalgamate stuff!

92 lines (85 loc) 3.66 kB
'use strict'; const path = require('path'); const amie = require('../../'); const should = require('should'); describe('Include path', function() { describe('Successes', function() { describe('From real file', function() { it('should properly amalgamate', function(done) { amie({ input: path.join(__dirname, 'cpp', 'main.cpp'), includePaths: [ path.join(__dirname, 'cpp', 'inc') ] }, (err, result) => { should.not.exist(err); should.exist(result); result.should.be.a.String(); result.should.equal('#ifndef FILE_HH_\n#define FILE_HH_\n\n#endif // FILE_HH_\n\n\nint main(int ac, char**av)\n{\n return 0;\n}\n'); done(); }); }); it('should prioritize earlier include paths', function(done) { amie({ input: path.join(__dirname, 'cpp', 'main.cpp'), includePaths: [ path.join(__dirname, 'cpp', 'inc2'), path.join(__dirname, 'cpp', 'inc') ] }, (err, result) => { should.not.exist(err); should.exist(result); result.should.be.a.String(); result.should.equal('#ifndef FILE2_HH_\n#define FILE2_HH_\n\n#endif // FILE2_HH_\n\n\nint main(int ac, char**av)\n{\n return 0;\n}\n'); done(); }); }); it('should prioritize source directory', function(done) { amie({ input: path.join(__dirname, 'cpp', 'main2.cpp'), includePaths: [ path.join(__dirname, 'cpp', 'inc2'), path.join(__dirname, 'cpp', 'inc') ] }, (err, result) => { should.not.exist(err); should.exist(result); result.should.be.a.String(); result.should.equal('// This is file2 from cpp\n\n\n// This is main2.cpp\n'); done(); }); }); }); describe('From string input', function() { it('should properly amalgamate', function(done) { amie({ input: '#include "file.hh"\n#include "file.hh"', fromString: true, includePaths: [ path.join(__dirname, 'cpp', 'inc') ] }, (err, result) => { should.not.exist(err); should.exist(result); result.should.be.a.String(); result.should.equal('#ifndef FILE_HH_\n#define FILE_HH_\n\n#endif // FILE_HH_\n\n#ifndef FILE_HH_\n#define FILE_HH_\n\n#endif // FILE_HH_\n'); done(); }); }); }); }); describe('Errors', function() { describe('From real file', function() { it('should error if include is not found', function(done) { amie({ input: path.join(__dirname, 'cpp', 'main.cpp') }, (err, result) => { should.exist(err); should.not.exist(result); err.message.should.equal('Unable to find file \'file.hh\''); done(); }); }); }); }); });