forked from elixirscript/elixirscript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathkernel.spec.js
More file actions
91 lines (73 loc) · 3.16 KB
/
Copy pathkernel.spec.js
File metadata and controls
91 lines (73 loc) · 3.16 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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
var Erlang = require('../lib/erlang');
var Kernel = require('../lib/kernel');
var expect = require('chai').expect;
describe('Kernel', function(){
describe('match?', function(){
it('match numbers', function(){
expect(Kernel.match__qmark__(1, 1)).to.equal(true);
expect(Kernel.match__qmark__(1.0, 1)).to.equal(true);
expect(Kernel.match__qmark__(2, 1)).to.equal(false);
expect(Kernel.match__qmark__(2, 1 + 1)).to.equal(true);
let a;
expect(Kernel.match__qmark__(a, 1 + 1)).to.equal(true);
expect(Kernel.match__qmark__(undefined, 1 + 1)).to.equal(true);
})
it('match strings', function(){
expect(Kernel.match__qmark__("", "")).to.equal(true);
expect(Kernel.match__qmark__('', "")).to.equal(true);
expect(Kernel.match__qmark__("Hello", "Hell")).to.equal(false);
expect(Kernel.match__qmark__("Hello", "Hell" + "o")).to.equal(true);
})
it('match atoms', function(){
expect(Kernel.match__qmark__(Erlang.atom("test"), Erlang.atom("test"))).to.equal(true);
expect(Kernel.match__qmark__(Erlang.atom("test"), Erlang.atom("notest"))).to.equal(false);
})
it('match tuples', function(){
expect(Kernel.match__qmark__(Erlang.tuple(1, 2, 3), Erlang.tuple(1, 2, 3))).to.equal(true);
expect(Kernel.match__qmark__(Erlang.tuple(1, undefined, 3), Erlang.tuple(1, 2, 3))).to.equal(true);
expect(Kernel.match__qmark__(Erlang.tuple(1, 2, 3), Erlang.tuple(1, 2))).to.equal(false);
})
it('match list', function(){
expect(Kernel.match__qmark__([1, 2, 3], [1, 2, 3])).to.equal(true);
expect(Kernel.match__qmark__([1, undefined, 3], [1, 2, 3])).to.equal(true);
expect(Kernel.match__qmark__([1, 2, 3], [1, 2])).to.equal(false);
})
it('match map', function(){
expect(Kernel.match__qmark__({a: 1, b: 2}, {a: 1, b: 2})).to.equal(true);
expect(Kernel.match__qmark__({a: 1}, {a: 1, b: 2})).to.equal(true);
expect(Kernel.match__qmark__({a: undefined}, {a: 1, b: 2})).to.equal(true);
expect(Kernel.match__qmark__({c: 1}, {a: 1, b: 2})).to.equal(false);
expect(Kernel.match__qmark__({c: undefined}, {a: 1, b: 2})).to.equal(false);
})
it('match numbers with guards', function(){
expect(Kernel.match__qmark__(1, 1, () => Kernel.is_number(1))).to.equal(true);
})
})
describe('defmodule', function(){
it('must create a module', function(){
let Hello = {}
let hello = Kernel.defmodule(Erlang.list(Erlang.atom("Hello")), function(__MODULE__){
return {
world: function(){ return 0; }
}
}, Hello);
expect(Hello).to.equal(hello);
expect(Hello.world()).to.equal(0);
})
it('must create inner modules correctly', function(){
let Foo = {}
Kernel.defmodule(Erlang.list(Erlang.atom("Foo")), function(__MODULE__){
Kernel.defmodule(Erlang.list(Erlang.atom("Foo"), Erlang.atom("Bar")), function(__MODULE__){
return {
baz: function(){ return 0; }
}
}, Foo);
return {
world: function(){ return 0; }
}
}, Foo);
expect(Foo.Bar.baz()).to.equal(0);
expect(Foo.world()).to.equal(0);
})
})
})