Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/javascript/lib/core.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import io from './core/erlang_compat/io';
import binary from './core/erlang_compat/binary';
import unicode from './core/erlang_compat/unicode';
import Store from './core/store';
import math from './core/erlang_compat/math';

class Integer {}
class Float {}
Expand Down Expand Up @@ -51,5 +52,6 @@ export default {
io,
binary,
unicode,
elixir_config
elixir_config,
math
};
16 changes: 15 additions & 1 deletion src/javascript/lib/core/erlang_compat/erlang.js
Original file line number Diff line number Diff line change
Expand Up @@ -360,6 +360,19 @@ function node() {
return Symbol.for('nonode@nohost');
}

function nodes(arg = []) {
const nodeTypes = Array.isArray(arg) ? arg : [arg];
const nodesFound = [];

for (const nodeType of nodeTypes) {
if (nodeType === Symbol.for('this')) {
nodesFound.push(Symbol.for('nonode@nohost'));
console.log(nodesFound);
}
}
return nodesFound;
}

function self() {
return selfPID;
}
Expand Down Expand Up @@ -458,5 +471,6 @@ export default {
error,
exit,
raise,
list_to_binary
list_to_binary,
nodes
};
7 changes: 7 additions & 0 deletions src/javascript/lib/core/erlang_compat/math.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
function log2(x) {
return Math.log2(x);
}

export default {
log2
};
20 changes: 20 additions & 0 deletions src/javascript/tests/core/erlang_compat/erlang_spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -95,3 +95,23 @@ test('list_subtraction', t => {
t.deepEqual(Core.erlang.list_subtraction([1, 2, 3], [1, 2, 3]), []);
t.deepEqual(Core.erlang.list_subtraction([1, 2, 3], [1, 2]), [3]);
});

test('node', t => {
t.deepEqual(Core.erlang.node(), Symbol.for('nonode@nohost'));
});

test('nodes/0', t => {
t.deepEqual(Core.erlang.nodes(), []);
});

test('nodes/1', t => {
t.deepEqual(Core.erlang.nodes(Symbol.for('this')), [
Symbol.for('nonode@nohost')
]);

t.deepEqual(Core.erlang.nodes([Symbol.for('this')]), [
Symbol.for('nonode@nohost')
]);

t.deepEqual(Core.erlang.nodes([Symbol.for('connected')]), []);
});
13 changes: 13 additions & 0 deletions src/javascript/tests/core/erlang_compat/math_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import test from 'ava';
import Core from '../../../lib/core';

test('log2/1', t => {
let result = Core.math.log2(1);
t.is(result, 0);

result = Core.math.log2(2);
t.is(result, 1);

result = Core.math.log2(4);
t.is(result, 2);
});