asserts_test.js 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. // Copyright 2013 The Closure Library Authors. All Rights Reserved.
  2. //
  3. // Licensed under the Apache License, Version 2.0 (the "License");
  4. // you may not use this file except in compliance with the License.
  5. // You may obtain a copy of the License at
  6. //
  7. // http://www.apache.org/licenses/LICENSE-2.0
  8. //
  9. // Unless required by applicable law or agreed to in writing, software
  10. // distributed under the License is distributed on an "AS-IS" BASIS,
  11. // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. // See the License for the specific language governing permissions and
  13. // limitations under the License.
  14. /**
  15. * @fileoverview Unit tests for goog.testing.i18n.asserts.
  16. */
  17. goog.provide('goog.testing.i18n.assertsTest');
  18. goog.setTestOnly('goog.testing.i18n.assertsTest');
  19. goog.require('goog.testing.ExpectedFailures');
  20. goog.require('goog.testing.i18n.asserts');
  21. // Add this mapping for testing only
  22. goog.testing.i18n.asserts.EXPECTED_VALUE_MAP_['mappedValue'] = 'newValue';
  23. var expectedFailures = new goog.testing.ExpectedFailures();
  24. function tearDown() {
  25. expectedFailures.handleTearDown();
  26. }
  27. function testEdgeCases() {
  28. // Pass
  29. goog.testing.i18n.asserts.assertI18nEquals(null, null);
  30. goog.testing.i18n.asserts.assertI18nEquals('', '');
  31. // Fail
  32. expectedFailures.expectFailureFor(true);
  33. try {
  34. goog.testing.i18n.asserts.assertI18nEquals(null, '');
  35. goog.testing.i18n.asserts.assertI18nEquals(null, 'test');
  36. goog.testing.i18n.asserts.assertI18nEquals('', null);
  37. goog.testing.i18n.asserts.assertI18nEquals('', 'test');
  38. goog.testing.i18n.asserts.assertI18nEquals('test', null);
  39. goog.testing.i18n.asserts.assertI18nEquals('test', '');
  40. } catch (e) {
  41. expectedFailures.handleException(e);
  42. }
  43. }
  44. function testMappingWorks() {
  45. // Real equality
  46. goog.testing.i18n.asserts.assertI18nEquals('test', 'test');
  47. // i18n mapped equality
  48. goog.testing.i18n.asserts.assertI18nEquals('mappedValue', 'newValue');
  49. // Negative testing
  50. expectedFailures.expectFailureFor(true);
  51. try {
  52. goog.testing.i18n.asserts.assertI18nEquals('unmappedValue', 'newValue');
  53. } catch (e) {
  54. expectedFailures.handleException(e);
  55. }
  56. }