Skip to content

Commit

Permalink
version 2.0.7 with support for negative, thx to @marcioendo
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiomcosta committed Jun 23, 2012
1 parent 81fa693 commit 288d782
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 36 deletions.
62 changes: 31 additions & 31 deletions Specs/moo.meio.mask.js
@@ -1,103 +1,103 @@

module('Unit Tests and some simple user emulated', {
setup: function() {
input = new Element('input', {id: 'input-id', type: 'text', maxLength: 10}).inject(document.body);
},
teardown: function(){
$('input-id').destroy();
}
setup: function() {
input = new Element('input', {id: 'input-id', type: 'text', maxLength: 10}).inject(document.body);
},
teardown: function(){
$('input-id').destroy();
}
});

test('should set the size of the input', function(){
input.meiomask('Fixed', 'Time', {autoSetSize: true});
equals(input.get('size'), 5);
input.meiomask('Fixed', 'Time', {autoSetSize: true});
equals(input.get('size'), 5);
});

test('should not set the size of the input', function(){
input.set('size', 10).meiomask('Fixed', 'Time', {autoSetSize: true});
equals(input.get('size'), 10);
input.set('size', 10).meiomask('Fixed', 'Time', {autoSetSize: true});
equals(input.get('size'), 10);
});

test('should remove the maxlength when mask is set, and reset it when mask is removed', function(){
input.meiomask('Fixed', 'Time');
equals(input.get('maxLength'), null);
input.erase('meiomask');
equals(input.get('maxLength'), 10);
input.meiomask('Fixed', 'Time');
equals(input.get('maxLength'), null);
input.erase('meiomask');
equals(input.get('maxLength'), 10);
});

test('should set properly the placeholder on the input', function(){
input.meiomask('Fixed', 'Date');
input.focus();
equals(input.value, '__/__/____');
input.meiomask('Fixed', 'Date');
input.focus();
equals(input.value, '__/__/____');
});

test('should mask the value from the input that actually haves a value', function(){
var el = new Element('input', {'type': 'text', 'value': '12122000'});
el.meiomask('Fixed', 'Date');
equals(el.value, '12/12/2000');
var el = new Element('input', {'type': 'text', 'value': '12122000'});
el.meiomask('Fixed', 'Date');
equals(el.value, '12/12/2000');
});

test('should mask a string with the fixed mask type option', function(){
equals('12121212'.meiomask('Fixed', 'Date'), '12/12/1212');
equals('12121212'.meiomask('Fixed', 'Date'), '12/12/1212');
});

test('should mask a string with the reverse.dollar mask', function(){
equals('12121212'.meiomask('reverse.dollar'), 'US$ 12,121,212.00');
equals('12121212'.meiomask('reverse.dollar'), 'US$ 12,121,212.00');
});

test('should mask a string with the reverse.dollar mask (negative)', function(){
equals('-12121212'.meiomask('reverse.dollar'), '-US$ 12,121,212.00');
});

test('should mask a string with the reverse.integer mask', function(){
equals('345678.723'.meiomask('reverse.integer'), '345.679');
equals('345678.723'.meiomask('reverse.integer'), '345.679');
});

test('should mask a string with the reverse.integer mask (negative)', function(){
equals('-345678.723'.meiomask('reverse.integer'), '-345.679');
});

test('should mask a string with the reverse.decimal mask and', function(){
equals('345678.728'.meiomask('reverse.decimal', {precision: 5, symbol: 'R$ '}), 'R$ 345.678,72800');
equals('345678.728'.meiomask('reverse.decimal', {precision: 5, symbol: 'R$ '}), 'R$ 345.678,72800');
});

test('should mask a string with the reverse.decimal mask and (negative)', function(){
equals('-345678.728'.meiomask('reverse.decimal', {precision: 5, symbol: 'R$ '}), '-R$ 345.678,72800');
});

test('should mask a string with the reverse.decimal mask', function(){
equals('345678.728'.meiomask('reverse.decimal'), '345.678,73');
equals('345678.728'.meiomask('reverse.decimal'), '345.678,73');
});

test('should mask a string with the reverse.decimal mask (negative)', function(){
equals('-345678.728'.meiomask('reverse.decimal'), '-345.678,73');
});

test('should unmask the passed string', function(){
equals('12/12/2000'.meiounmask('Fixed', 'Date'), '12122000');
equals('12/12/2000'.meiounmask('Fixed', 'Date'), '12122000');
});

test('should unmask the passed string to a float number', function(){
equals('R$ 123,12'.meiounmask('reverse.reais'), 123.12);
equals('R$ 123,12'.meiounmask('reverse.reais'), 123.12);
});

test('should unmask the passed string to a float number (negative)', function(){
equals('-R$ 123,12'.meiounmask('reverse.reais'), -123.12);
});

test('should apply a precision: 5 mask to the 0 string', function(){
equals('0'.meiomask('Reverse', 'Decimal', {precision: 5}), '0,00000');
equals('0'.meiomask('Reverse', 'Decimal', {precision: 5}), '0,00000');
});

test('should apply a precision: 5 mask to the 1 string', function(){
equals('1'.meiomask('Reverse', 'Decimal', {precision: 5}), '1,00000');
equals('1'.meiomask('Reverse', 'Decimal', {precision: 5}), '1,00000');
});

test('should apply a precision: 5 mask to the 1000 string', function(){
equals('1000'.meiomask('Reverse', 'Decimal', {precision: 5}), '1.000,00000');
equals('1000'.meiomask('Reverse', 'Decimal', {precision: 5}), '1.000,00000');
});

test('should apply a precision: 5 mask to the 0.001 string', function(){
equals('0.001'.meiomask('Reverse', 'Decimal', {precision: 5}), '0,00100');
equals('0.001'.meiomask('Reverse', 'Decimal', {precision: 5}), '0,00100');
});

8 changes: 4 additions & 4 deletions build.py
@@ -1,7 +1,8 @@
#!/usr/bin/env python

import os, re
from zipfile import ZipFile, BadZipfile
import os
import re


class Builder:

Expand Down Expand Up @@ -47,7 +48,7 @@ def add_comment(self, compressed_file):
try:
os.remove(compressed_file)
except os.error:
pass # might have been yet removed
pass # might have been yet removed
compressed_built_file = open(compressed_file, 'w+')
try:
compressed_built_file.write(re.search(r'\/\*(.*?)\*\/', ''.join(self.read_file(self.javascript_files[0][1])), re.S | re.U).group(0))
Expand Down Expand Up @@ -91,4 +92,3 @@ def build(self, file_name, files, root='Source/'):
'Meio.Mask.Regexp',
'Meio.Mask.Extras',
))

2 changes: 1 addition & 1 deletion package.yml
Expand Up @@ -22,7 +22,7 @@ sources:

author: fabiomiranda

current: 2.0.6
current: 2.0.7

docs: http://meiocodigo.com/projects/moomeiomask

Expand Down

0 comments on commit 288d782

Please sign in to comment.