VFormat => PatternFormatter with added interface
* src/validate/ValidatorFormatter.js: Interface added. * src/validate/formatter/PatternFormatter.js: Renamed from ../VFormat.js. * test/validate/formatter/PatternFormatterTest.js: Renamed from ../VFormatTest.js.master
parent
a509e53a3e
commit
d6cecf1ff6
|
@ -0,0 +1,57 @@
|
|||
/**
|
||||
* Validator-formatter
|
||||
*
|
||||
* Copyright (C) 2016 LoVullo Associates, Inc.
|
||||
*
|
||||
* This file is part of liza.
|
||||
*
|
||||
* liza is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation, either version 3 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
|
||||
var Interface = require( 'easejs' ).Interface;
|
||||
|
||||
|
||||
module.exports = Interface( 'ValidatorFormatter',
|
||||
{
|
||||
/**
|
||||
* Format the given data or fail if no match is found
|
||||
*
|
||||
* If the given data matches a pattern, it will be formatted with
|
||||
* respect to the first matched pattern. Otherwise, an error will
|
||||
* be thrown indicating a validation failure.
|
||||
*
|
||||
* @param {string} data data to parse
|
||||
*
|
||||
* @return {string} formatted string, if a match is found
|
||||
*/
|
||||
'public parse': [ 'data' ],
|
||||
|
||||
|
||||
/**
|
||||
* Retrieve data that may require formatting for display
|
||||
*
|
||||
* Return formatting is optional. No formatting will be done if no pattern
|
||||
* was given when the instance was constructed.
|
||||
*
|
||||
* To ensure consistency and correctness, *any data returned by this method
|
||||
* must be reversible* --- that is, parse( retrieve( data ) ) should not
|
||||
* throw an exception.
|
||||
*
|
||||
* @param {string} data data to format for display
|
||||
*
|
||||
* @return {string} data formatted for display
|
||||
*/
|
||||
'public retrieve': [ 'data' ]
|
||||
} );
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Validator-formatter
|
||||
* Pattern-based validator-formatter
|
||||
*
|
||||
* Copyright (C) 2016 LoVullo Associates, Inc.
|
||||
*
|
||||
|
@ -20,13 +20,17 @@
|
|||
*/
|
||||
|
||||
|
||||
var Class = require( 'easejs' ).Class;
|
||||
var Class = require( 'easejs' ).Class,
|
||||
ValidatorFormatter = require( '../ValidatorFormatter' );
|
||||
|
||||
|
||||
/**
|
||||
* Data validation and formatting
|
||||
* Data validation and formatting based on patterns and their
|
||||
* replacements
|
||||
*/
|
||||
module.exports = Class( 'VFormat',
|
||||
module.exports = Class( 'VFormat' )
|
||||
.implement( ValidatorFormatter )
|
||||
.extend(
|
||||
{
|
||||
/**
|
||||
* Pattern definition
|
|
@ -1,5 +1,5 @@
|
|||
/**
|
||||
* Test validator-formatter
|
||||
* Test pattern-based validator-formatter
|
||||
*
|
||||
* Copyright (C) 2016 LoVullo Associates, Inc.
|
||||
*
|
||||
|
@ -19,8 +19,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
var liza = require( '../../' ),
|
||||
Sut = liza.validate.VFormat,
|
||||
var liza = require( '../../../' ),
|
||||
Sut = liza.validate.formatter.PatternFormatter,
|
||||
VFmt = liza.validate.ValidatorFormatter,
|
||||
Class = require( 'easejs' ).Class,
|
||||
expect = require( 'chai' ).expect,
|
||||
assert = require( 'assert' ),
|
||||
dfn = [
|
||||
|
@ -30,8 +32,15 @@ var liza = require( '../../' ),
|
|||
];
|
||||
|
||||
|
||||
describe( 'VFormat', function()
|
||||
describe( 'PatternFormatter', function()
|
||||
{
|
||||
it( 'is a ValidatorFormatter', function()
|
||||
{
|
||||
expect( Class.isA( VFmt, createSut( [] ) ) )
|
||||
.to.be.true;
|
||||
} );
|
||||
|
||||
|
||||
describe( '#parse', function()
|
||||
{
|
||||
it( 'formats string according to given definition', function()
|
Loading…
Reference in New Issue