diff --git a/src/validate/formatter/EchoFormatter.js b/src/validate/formatter/EchoFormatter.js new file mode 100644 index 0000000..4e6a44f --- /dev/null +++ b/src/validate/formatter/EchoFormatter.js @@ -0,0 +1,60 @@ +/** + * Echo 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 . + */ + +var Class = require( 'easejs' ).Class, + ValidatorFormatter = require( '../ValidatorFormatter' ); + + +/** + * Echos its input + * + * This formatter does nothing; it is intended to be used as a base + * for mixing in other formatters, or for a formatting noop. + */ +module.exports = Class( 'EchoFormatter' ) + .implement( ValidatorFormatter ) + .extend( +{ + /** + * Echo given data + * + * @param {string} data data to echo + * + * @return {string} DATA + */ + 'virtual public parse': function( data ) + { + return data; + }, + + + /** + * Echo given data + * + * @param {string} data data to echo + * + * @return {string} DATA + */ + 'virtual public retrieve': function( data ) + { + return data; + } +} ); diff --git a/test/validate/formatter/EchoFormatterTest.js b/test/validate/formatter/EchoFormatterTest.js new file mode 100644 index 0000000..01133de --- /dev/null +++ b/test/validate/formatter/EchoFormatterTest.js @@ -0,0 +1,65 @@ +/** + * Tests echo list 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 . + */ + + +var liza = require( '../../../' ), + Sut = liza.validate.formatter.EchoFormatter, + testValidate = require( './common' ).testValidate, + expect = require( 'chai' ).expect; + + +describe( 'EchoListFormatter', function() +{ + testValidate( Sut(), { + "": [ "" ], + "foo": [ "foo" ], + " 123 ": [ " 123 " ], + } ); + + + describe( 'as a supertype', function() + { + it( 'permits overriding #parse', function() + { + var expected = 'parsed'; + + expect( + Sut.extend( + { + 'override parse': function( _ ) { return expected; } + } )().parse( 'foo' ) + ).to.equal( expected ); + } ); + + + it( 'permits overriding #retrieve', function() + { + var expected = 'retrieved'; + + expect( + Sut.extend( + { + 'override retrieve': function( _ ) { return expected; } + } )().retrieve( 'foo' ) + ).to.equal( expected ); + } ); + } ); +} ); \ No newline at end of file