-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcompiler_test.js
54 lines (41 loc) · 1.16 KB
/
compiler_test.js
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
44
45
46
47
48
49
50
51
52
53
54
require('./exports.js')
var assert = require('assert')
var output = ocaml.compile('let a = 3')
// var json = require('../../package.json')
var header = `Generated by BUCKLESCRIPT`
/**
* @return {string|bool} return string if successful otherwise return false
* @param {*} input
*/
function test(input) {
var output = (ocaml.compile(input))
if (output && output.js_code) {
var js_code = output.js_code
if (js_code.includes(header)) {
return js_code
} else {
assert.fail(input)
}
} else {
assert.fail(input)
}
}
var fs = require('fs')
var p = require('path')
var example = p.join(__dirname, 'examples')
var files = fs.readdirSync(example)
files.forEach(function (x) {
if (x.endsWith('.ml')) {
var path = p.join(example, x)
var content = fs.readFileSync(path, 'utf8')
console.log(`testing ${path}`)
var output = test(content)
if(!output){
assert.fail(content)
}
}
})
console.log(`Testing pervasives`)
test(`print_endline "Hello world"`)
console.log(`Finished`)
// console.log(ocaml.compile(`Js.Promise.resolve 3 `))