| 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 |
/** |
| 16 |
* @fileoverview Unit tests for goog.testing.i18n.asserts. |
| 17 |
*/ |
| 18 |
|
| 19 |
goog.provide('goog.testing.i18n.assertsTest'); |
| 20 |
goog.setTestOnly('goog.testing.i18n.assertsTest'); |
| 21 |
|
| 22 |
goog.require('goog.testing.ExpectedFailures'); |
| 23 |
goog.require('goog.testing.i18n.asserts'); |
| 24 |
|
| 25 |
|
| 26 |
// Add this mapping for testing only |
| 27 |
goog.testing.i18n.asserts.EXPECTED_VALUE_MAP_['mappedValue'] = 'newValue'; |
| 28 |
|
| 29 |
var expectedFailures; |
| 30 |
|
| 31 |
function setUpPage() { |
| 32 |
expectedFailures = new goog.testing.ExpectedFailures(); |
| 33 |
} |
| 34 |
|
| 35 |
function tearDown() { |
| 36 |
expectedFailures.handleTearDown(); |
| 37 |
} |
| 38 |
|
| 39 |
function testEdgeCases() { |
| 40 |
// Pass |
| 41 |
goog.testing.i18n.asserts.assertI18nEquals(null, null); |
| 42 |
goog.testing.i18n.asserts.assertI18nEquals('', ''); |
| 43 |
|
| 44 |
// Fail |
| 45 |
expectedFailures.expectFailureFor(true); |
| 46 |
try { |
| 47 |
goog.testing.i18n.asserts.assertI18nEquals(null, ''); |
| 48 |
goog.testing.i18n.asserts.assertI18nEquals(null, 'test'); |
| 49 |
goog.testing.i18n.asserts.assertI18nEquals('', null); |
| 50 |
goog.testing.i18n.asserts.assertI18nEquals('', 'test'); |
| 51 |
goog.testing.i18n.asserts.assertI18nEquals('test', null); |
| 52 |
goog.testing.i18n.asserts.assertI18nEquals('test', ''); |
| 53 |
} catch (e) { |
| 54 |
expectedFailures.handleException(e); |
| 55 |
} |
| 56 |
} |
| 57 |
|
| 58 |
function testMappingWorks() { |
| 59 |
// Real equality |
| 60 |
goog.testing.i18n.asserts.assertI18nEquals('test', 'test'); |
| 61 |
// i18n mapped equality |
| 62 |
goog.testing.i18n.asserts.assertI18nEquals('mappedValue', 'newValue'); |
| 63 |
|
| 64 |
// Negative testing |
| 65 |
expectedFailures.expectFailureFor(true); |
| 66 |
try { |
| 67 |
goog.testing.i18n.asserts.assertI18nEquals('unmappedValue', 'newValue'); |
| 68 |
} catch (e) { |
| 69 |
expectedFailures.handleException(e); |
| 70 |
} |
| 71 |
} |