locale.js 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /**
  2. * @license Copyright (c) 2003-2016, CKSource - Frederico Knabben. All rights reserved.
  3. * For licensing, see LICENSE.md.
  4. */
  5. import Locale from 'ckeditor5/utils/locale.js';
  6. describe( 'Locale', () => {
  7. let locale;
  8. beforeEach( () => {
  9. locale = new Locale();
  10. } );
  11. describe( 'constructor', () => {
  12. it( 'sets the lang', () => {
  13. const locale = new Locale( 'pl' );
  14. expect( locale ).to.have.property( 'lang', 'pl' );
  15. } );
  16. it( 'defaults lang to en', () => {
  17. const locale = new Locale();
  18. expect( locale ).to.have.property( 'lang', 'en' );
  19. } );
  20. } );
  21. describe( 't', () => {
  22. it( 'has the context bound', () => {
  23. const t = locale.t;
  24. expect( t( 'Foo' ) ).to.equal( 'Foo' );
  25. } );
  26. it( 'interpolates 1 value', () => {
  27. const t = locale.t;
  28. expect( t( '%0 - %0', [ 'foo' ] ) ).to.equal( 'foo - foo' );
  29. } );
  30. it( 'interpolates 3 values', () => {
  31. const t = locale.t;
  32. expect( t( '%1 - %0 - %2', [ 'a', 'b', 'c' ] ) ).to.equal( 'b - a - c' );
  33. } );
  34. // Those test make sure that if %0 is really to be used, then it's going to work.
  35. // It'd be a super rare case if one would need to use %0 and at the same time interpolate something.
  36. it( 'does not interpolate placeholders if values not passed', () => {
  37. const t = locale.t;
  38. expect( t( '%1 - %0 - %2' ) ).to.equal( '%1 - %0 - %2' );
  39. } );
  40. it( 'does not interpolate those placeholders for which values has not been passed', () => {
  41. const t = locale.t;
  42. expect( t( '%1 - %0 - %2', [ 'a' ] ) ).to.equal( '%1 - a - %2' );
  43. } );
  44. } );
  45. } );