diff --git a/addon/rules/no.js b/addon/rules/no.js new file mode 100644 index 0000000..ba3356a --- /dev/null +++ b/addon/rules/no.js @@ -0,0 +1,2 @@ +import en from 'ember-cli-i18n/rules/en'; +export default en; \ No newline at end of file diff --git a/test-support/ember-cli-i18n-test.js b/test-support/ember-cli-i18n-test.js index cb96de9..6dbdc2f 100644 --- a/test-support/ember-cli-i18n-test.js +++ b/test-support/ember-cli-i18n-test.js @@ -3,6 +3,26 @@ import Ember from 'ember'; import config from '../config/environment'; +var flattenObject = function(ob) { + var toReturn = {}; + + for (var i in ob) { + if (!ob.hasOwnProperty(i)) continue; + + if ((typeof ob[i]) == 'object') { + var flatObject = flattenObject(ob[i]); + for (var x in flatObject) { + if (!flatObject.hasOwnProperty(x)) continue; + + toReturn[i + '.' + x] = flatObject[x]; + } + } else { + toReturn[i] = ob[i]; + } + } + return toReturn; +}; + if (window.QUnit) { var keys = Ember.keys; @@ -43,9 +63,12 @@ if (window.QUnit) { continue; } + currentLocale = flattenObject(currentLocale); + defaultLocale = flattenObject(defaultLocale); + for (var translationKey in defaultLocale) { assert.ok(currentLocale[translationKey], '`' + translationKey + '` should exist in the `' + knownLocales[i] + '` locale.'); } } }); -} +} \ No newline at end of file diff --git a/tests/unit/rules/no-test.js b/tests/unit/rules/no-test.js new file mode 100644 index 0000000..bb95a9f --- /dev/null +++ b/tests/unit/rules/no-test.js @@ -0,0 +1,49 @@ +import Ember from 'ember'; +import { module, test } from 'qunit'; +import rules from 'ember-cli-i18n/rules/no'; +import cldrTest from '../../helpers/cldr'; + +var result = { + one: 'one', + other: 'other' +}; + +var path = 'result'; +var countryCode = 'no'; +var ruleResults; + +module('CLDR Rules - Norwegian ('+countryCode+')'); + +test('one', function(assert) { + cldrTest(assert, 1, 'one', rules, result, path, countryCode); +}); + +test('other', function(assert) { + cldrTest(assert, 0, 'other', rules, result, path, countryCode); + cldrTest(assert, 2, 'other', rules, result, path, countryCode); +}); + +test('assertion is thrown if no valid keys exist', function(assert) { + var badResult = {foo: 'bar'}; + var count = 0; + var oldAssert = Ember.assert; + Ember.assert = function() { + count += 1; + }; + + rules(0, badResult, path, countryCode); + assert.equal(count, 1); + Ember.assert = oldAssert; +}); + +test('assertion is thrown if non-numeric value is passed ', function(assert) { + var count = 0; + var oldAssert = Ember.assert; + Ember.assert = function() { + count += 1; + }; + + rules('0', result, path, countryCode); + assert.equal(count, 1); + Ember.assert = oldAssert; +}); \ No newline at end of file