Comparing version 0.3.0 to 0.3.1
@@ -14,3 +14,3 @@ 'use strict'; | ||
var impl = function impl(to, what) { | ||
var setter = typeof to.__impl == 'function' ? to.__impl : to.prototype ? function (name, fn) { | ||
var setter = to.prototype ? function (name, fn) { | ||
to.prototype[name] = function () { | ||
@@ -17,0 +17,0 @@ return fn.apply({}, [this].concat(Array.prototype.slice.call(arguments, 0))); |
@@ -23,2 +23,6 @@ 'use strict'; | ||
var _type = require('./type'); | ||
var _type2 = _interopRequireDefault(_type); | ||
var _result = require('./result'); | ||
@@ -41,3 +45,4 @@ | ||
impl: _impl2.default, | ||
panic: _panic2.default | ||
panic: _panic2.default, | ||
type: _type2.default | ||
}; |
{ | ||
"name": "rusted", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"description": "Rust like enum, Result and Option for javascript", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -17,3 +17,5 @@ [![npm version](https://badge.fury.io/js/rusted.svg)](https://badge.fury.io/js/rusted) | ||
- [ ] static method | ||
- [ ] type alias | ||
- [ ] `trait` | ||
- [ ] `iter` | ||
- [x] type alias | ||
- [x] `panic` (not a macro) | ||
@@ -20,0 +22,0 @@ - [x] `match` |
import panic from './panic'; | ||
let impl=(to,what)=>{ | ||
let setter=typeof to.__impl=='function' | ||
? to.__impl | ||
: to.prototype | ||
let setter=to.prototype | ||
? (name,fn)=>{ | ||
@@ -8,0 +6,0 @@ to.prototype[name]=function(){ |
@@ -6,2 +6,3 @@ import Enum from './enum'; | ||
import struct from './struct'; | ||
import type from './type'; | ||
@@ -22,3 +23,4 @@ import {Result,Ok,Err} from './result'; | ||
impl, | ||
panic | ||
panic, | ||
type | ||
}; |
@@ -24,2 +24,23 @@ let expect=require('chai').expect; | ||
}); | ||
it('should throws error when non-function object was passed',()=>{ | ||
expect(()=>{ | ||
impl('Foo',{ | ||
print(self){ | ||
console.log(self); | ||
} | ||
}); | ||
}).to.throw(); | ||
}); | ||
it('should works properly for constructor',()=>{ | ||
let Person=function(name){ | ||
this.name=name; | ||
}; | ||
impl(Person,{ | ||
greet(self){ | ||
return `Hello, ${self.name}`; | ||
} | ||
}); | ||
expect((new Person('Foo')).greet()).to.equal('Hello, Foo'); | ||
}); | ||
it('should works fine for Enum',()=>{ | ||
@@ -26,0 +47,0 @@ let Foo=Enum({ |
@@ -75,2 +75,5 @@ import {expect} from 'chai'; | ||
}); | ||
it('should returns None',()=>{ | ||
expect(None.map(s=>s.length).is_none()).to.be.true; | ||
}); | ||
}); | ||
@@ -77,0 +80,0 @@ describe('#map_or',()=>{ |
@@ -53,2 +53,5 @@ let expect=require('chai').expect; | ||
}); | ||
it('should returns Err(5)',()=>{ | ||
expect(Err(5).map(n=>n*4).unwrap_err()).to.equal(5); | ||
}); | ||
}); | ||
@@ -186,2 +189,5 @@ describe('#map_err',()=>{ | ||
}); | ||
it('should unwrap value of Ok',()=>{ | ||
expect(Ok(3).expect('Testing expect')).to.equal(3); | ||
}); | ||
}); | ||
@@ -188,0 +194,0 @@ describe('#unwrap_err',()=>{ |
@@ -41,2 +41,17 @@ import {expect} from 'chai'; | ||
}); | ||
it('should works properly when constructor passed to type',()=>{ | ||
let Person=function(name){ | ||
this.name=name; | ||
}; | ||
let Foo=struct({ | ||
bar:'string', | ||
hoge:Person | ||
}); | ||
let hoge=new Person('Hoge'), | ||
foo=Foo({ | ||
bar:'bar', | ||
hoge:hoge | ||
}); | ||
expect(foo.hoge.name).to.equal('Hoge'); | ||
}); | ||
it('should throws error when some property were lacked',()=>{ | ||
@@ -43,0 +58,0 @@ let Foo=struct({ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
46940
36
1773
182