Comparing version 0.4.4 to 0.4.5
@@ -39,4 +39,2 @@ 'use strict'; | ||
var Enum = {}; | ||
Object.keys(variants).forEach(function (variant) { | ||
@@ -46,3 +44,3 @@ var data = variants[variant]; | ||
if (data === null) { | ||
Object.defineProperty(Enum, variant, { | ||
Object.defineProperty(EnumValue, variant, { | ||
get: function get() { | ||
@@ -56,3 +54,3 @@ return new EnumValue(variant); | ||
} else { | ||
Object.defineProperty(Enum, variant, { | ||
Object.defineProperty(EnumValue, variant, { | ||
value: function value(_value) { | ||
@@ -76,14 +74,5 @@ var _check_type = (0, _util.check_type)(data, _value); | ||
Object.defineProperty(Enum, 'prototype', { | ||
get: function get() { | ||
return EnumValue.prototype; | ||
}, | ||
enumerable: false, | ||
configurable: false | ||
}); | ||
return Enum; | ||
return EnumValue; | ||
}; | ||
exports.default = factory; |
{ | ||
"name": "rusted", | ||
"version": "0.4.4", | ||
"version": "0.4.5", | ||
"description": "Rust like enum, Result and Option for javascript", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -20,3 +20,3 @@ [![npm version](https://badge.fury.io/js/rusted.svg)](https://badge.fury.io/js/rusted) | ||
+ [ ] tuple struct | ||
+ [ ] unit struct | ||
+ [x] unit struct | ||
- [x] `impl` | ||
@@ -23,0 +23,0 @@ - [x] static method (associated function) |
@@ -29,4 +29,2 @@ import panic from './panic'; | ||
let Enum={}; | ||
Object.keys(variants).forEach((variant)=>{ | ||
@@ -36,3 +34,3 @@ let data=variants[variant]; | ||
if(data===null){ | ||
Object.defineProperty(Enum,variant,{ | ||
Object.defineProperty(EnumValue,variant,{ | ||
get(){ | ||
@@ -45,3 +43,3 @@ return new EnumValue(variant); | ||
}else{ | ||
Object.defineProperty(Enum,variant,{ | ||
Object.defineProperty(EnumValue,variant,{ | ||
value(value){ | ||
@@ -60,13 +58,5 @@ let {match,expected,actual}=check_type(data,value); | ||
Object.defineProperty(Enum,'prototype',{ | ||
get(){ | ||
return EnumValue.prototype; | ||
}, | ||
enumerable:false, | ||
configurable:false | ||
}); | ||
return Enum; | ||
return EnumValue; | ||
}; | ||
export default factory; |
var expect=require('chai').expect; | ||
import Enum from '../src/enum'; | ||
import {check_type} from '../src/util'; | ||
describe('enum.js',function(){ | ||
describe('#Enum',function(){ | ||
it('should returns Enum factory object',function(){ | ||
expect(Enum({})).to.be.an('object'); | ||
it('should returns Enum',function(){ | ||
expect(Enum({})).to.be.an('function'); | ||
}); | ||
}); | ||
describe('Enum factory object returned by factory',function(){ | ||
describe('Enum returned by factory',function(){ | ||
it('should be used as type',()=>{ | ||
let Foo=Enum({ | ||
Hoge:null | ||
}), | ||
Bar=Enum({ | ||
Hoge:null | ||
}); | ||
expect(check_type(Foo,Foo.Hoge).match) | ||
.to.be.true; | ||
expect(check_type(Foo,Bar.Hoge).match) | ||
.to.be.false; | ||
}); | ||
it('should includes passed variants name',function(){ | ||
@@ -13,0 +26,0 @@ var e=Enum({ |
@@ -9,2 +9,4 @@ import {expect} from 'chai'; | ||
import Enum from '../src/enum'; | ||
describe('struct.js',()=>{ | ||
@@ -113,2 +115,5 @@ describe('#factory',()=>{ | ||
}); | ||
let SomeEnum=Enum({ | ||
Foo:null | ||
}); | ||
let Foo=struct({ | ||
@@ -118,3 +123,4 @@ bar:'any', | ||
fuga:Array, | ||
piyo:OtherStruct | ||
piyo:OtherStruct, | ||
some:SomeEnum | ||
}); | ||
@@ -130,3 +136,4 @@ let foo; | ||
y:2 | ||
}) | ||
}), | ||
some:SomeEnum.Foo | ||
}); | ||
@@ -133,0 +140,0 @@ }).not.to.throw(); |
65551
2197