locale.js 1.5 KB

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