-
Notifications
You must be signed in to change notification settings - Fork 35
/
Copy pathnodetest.js
39 lines (30 loc) · 1.09 KB
/
nodetest.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
// minimal sanity test to verify usage of Ruby2JS under Node
const assert = require('assert');
const Ruby2JS = require('../docs/src/demo/ruby2js.js');
function to_js(string, options={}) {
return Ruby2JS.convert(string, options).toString()
}
assert.strictEqual(
to_js('foo = 1'),
'var foo = 1');
assert.strictEqual(
to_js('foo = 1', {eslevel: 2015}),
'let foo = 1');
assert.strictEqual(
to_js('foo.empty?', {filters: ['functions']}),
'foo.length == 0');
assert.strictEqual(
to_js('1 => foo'),
'var foo = 1');
let ast = Ruby2JS.convert('String', {file: 'a.rb'}).ast
assert.strictEqual(ast.constructor, Ruby2JS.AST.Node)
assert.strictEqual(ast.type, "const")
assert.strictEqual(ast.children.length, 2)
assert.strictEqual(ast.children[0], Ruby2JS.nil)
assert.strictEqual(ast.children[1], "String")
let sourcemap = Ruby2JS.convert('a=1', {file: 'a.rb'}).sourcemap
assert.strictEqual(sourcemap.version, 3)
assert.strictEqual(sourcemap.file, 'a.rb')
assert.strictEqual(sourcemap.sources.length, 1)
assert.strictEqual(sourcemap.sources[0], 'a.rb')
assert.strictEqual(sourcemap.mappings, 'AAAAA,QAAE')