sanitize.js 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. /* global describe, it */
  6. 'use strict';
  7. const sanitize = require( '../../tasks/dev/utils/sanitize' );
  8. const chai = require( 'chai' );
  9. const expect = chai.expect;
  10. describe( 'utils', () => {
  11. describe( 'sanitize', () => {
  12. describe( 'appendPeriodIfMissing', () => {
  13. it( 'should be defined', () => expect( sanitize.appendPeriodIfMissing ).to.be.a( 'function' ) );
  14. it( 'should trim whitespace/new lines to empty string', () => {
  15. // jscs: disable validateQuoteMarks
  16. const sanitized = sanitize.appendPeriodIfMissing( "\n\t\r " );
  17. expect( sanitized ).to.equal( '' );
  18. } );
  19. it( 'should add period at the end if missing ', () => {
  20. const sanitized = sanitize.appendPeriodIfMissing( 'sometext' );
  21. expect( sanitized ).to.equal( 'sometext.' );
  22. } );
  23. it( 'should not add period at the end if present', () => {
  24. const sanitized = sanitize.appendPeriodIfMissing( 'sometext.' );
  25. expect( sanitized ).to.equal( 'sometext.' );
  26. } );
  27. it( 'should leave empty string as is', () => {
  28. const sanitized = sanitize.appendPeriodIfMissing( '' );
  29. expect( sanitized ).to.equal( '' );
  30. } );
  31. it( 'should return empty string when invoked with empty string', () => {
  32. expect( sanitize.appendPeriodIfMissing( '' ) ).to.equal( '' );
  33. } );
  34. } );
  35. } );
  36. } );