forked from josdejong/mathjs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcli.test.js
More file actions
43 lines (37 loc) · 1.11 KB
/
cli.test.js
File metadata and controls
43 lines (37 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
// Only use native node.js API's and references to ./lib here, this file is not transpiled!
const assert = require('assert')
const path = require('path')
const cp = require('child_process')
function run (args, done) {
cp.exec('node bin/cli.js ' + args, function (e, r) {
done(e, r.replace(/\n$/g, ''))
})
}
describe('command line interface', function () {
it('should sum numbers', function (done) {
run('"1+1"', function (e, result) {
assert.strictEqual(result, '2')
done()
})
})
it('should multiply matrices', function (done) {
run('"[1,2] * [3,4]"', function (e, result) {
assert.strictEqual(result, '11')
done()
})
})
it('should thow error', function (done) {
run('"y=x"', function (e, result) {
assert.strictEqual(/^Error/g.test(e.toString()), true)
done()
})
})
it('should interpret scripts', function (done) {
const path1 = path.join(__dirname, 'script1')
const path2 = path.join(__dirname, 'script2')
run('"' + path1 + '" "' + path2 + '"', function (e, result) {
assert.strictEqual(result, '2\n8\n')
done()
})
})
})