refactor(i18n): remove circular dep
This commit is contained in:
38
modules/@angular/compiler/test/i18n/digest_spec.ts
Normal file
38
modules/@angular/compiler/test/i18n/digest_spec.ts
Normal file
@ -0,0 +1,38 @@
|
||||
/**
|
||||
* @license
|
||||
* Copyright Google Inc. All Rights Reserved.
|
||||
*
|
||||
* Use of this source code is governed by an MIT-style license that can be
|
||||
* found in the LICENSE file at https://angular.io/license
|
||||
*/
|
||||
|
||||
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||
import {strHash} from '../../src/i18n/digest';
|
||||
|
||||
export function main(): void {
|
||||
describe('strHash', () => {
|
||||
it('should return a hash value', () => {
|
||||
// https://github.com/google/closure-library/blob/1fb19a857b96b74e6523f3e9d33080baf25be046/closure/goog/string/string_test.js#L1115
|
||||
expectHash('', 0);
|
||||
expectHash('foo', 101574);
|
||||
expectHash('\uAAAAfoo', 1301670364);
|
||||
expectHash('a', 92567585, 5);
|
||||
expectHash('a', 2869595232, 6);
|
||||
expectHash('a', 3058106369, 7);
|
||||
expectHash('a', 312017024, 8);
|
||||
expectHash('a', 2929737728, 1024);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
function expectHash(text: string, decimal: number, repeat: number = 1) {
|
||||
let acc = text;
|
||||
for (let i = 1; i < repeat; i++) {
|
||||
acc += text;
|
||||
}
|
||||
|
||||
const hash = strHash(acc);
|
||||
expect(typeof(hash)).toEqual('string');
|
||||
expect(hash.length > 0).toBe(true);
|
||||
expect(parseInt(hash, 16)).toEqual(decimal);
|
||||
}
|
@ -8,9 +8,9 @@
|
||||
|
||||
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {digestMessage, serializeNodes as serializeI18nNodes} from '../../src/i18n/digest';
|
||||
import {extractMessages, mergeTranslations} from '../../src/i18n/extractor_merger';
|
||||
import * as i18n from '../../src/i18n/i18n_ast';
|
||||
import {digestMessage, serializeNodes as serializeI18nNodes} from '../../src/i18n/message_bundle';
|
||||
import {TranslationBundle} from '../../src/i18n/translation_bundle';
|
||||
import * as html from '../../src/ml_parser/ast';
|
||||
import {HtmlParser} from '../../src/ml_parser/html_parser';
|
||||
|
@ -10,7 +10,7 @@ import {extractMessages} from '@angular/compiler/src/i18n/extractor_merger';
|
||||
import {Message} from '@angular/compiler/src/i18n/i18n_ast';
|
||||
import {ddescribe, describe, expect, iit, it} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {serializeNodes} from '../../src/i18n/message_bundle';
|
||||
import {serializeNodes} from '../../src/i18n/digest';
|
||||
import {HtmlParser} from '../../src/ml_parser/html_parser';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG} from '../../src/ml_parser/interpolation_config';
|
||||
|
||||
|
@ -10,7 +10,8 @@ import * as i18n from '@angular/compiler/src/i18n/i18n_ast';
|
||||
import {Serializer} from '@angular/compiler/src/i18n/serializers/serializer';
|
||||
import {beforeEach, ddescribe, describe, expect, iit, inject, it, xdescribe, xit} from '@angular/core/testing/testing_internal';
|
||||
|
||||
import {MessageBundle, serializeNodes, strHash} from '../../src/i18n/message_bundle';
|
||||
import {serializeNodes} from '../../src/i18n/digest';
|
||||
import {MessageBundle} from '../../src/i18n/message_bundle';
|
||||
import {HtmlParser} from '../../src/ml_parser/html_parser';
|
||||
import {DEFAULT_INTERPOLATION_CONFIG} from '../../src/ml_parser/interpolation_config';
|
||||
|
||||
@ -39,20 +40,6 @@ export function main(): void {
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('strHash', () => {
|
||||
it('should return a hash value', () => {
|
||||
// https://github.com/google/closure-library/blob/1fb19a857b96b74e6523f3e9d33080baf25be046/closure/goog/string/string_test.js#L1115
|
||||
expectHash('', 0);
|
||||
expectHash('foo', 101574);
|
||||
expectHash('\uAAAAfoo', 1301670364);
|
||||
expectHash('a', 92567585, 5);
|
||||
expectHash('a', 2869595232, 6);
|
||||
expectHash('a', 3058106369, 7);
|
||||
expectHash('a', 312017024, 8);
|
||||
expectHash('a', 2929737728, 1024);
|
||||
});
|
||||
});
|
||||
});
|
||||
}
|
||||
|
||||
@ -68,16 +55,4 @@ class _TestSerializer implements Serializer {
|
||||
|
||||
function humanizeMessages(catalog: MessageBundle): string[] {
|
||||
return catalog.write(new _TestSerializer()).split('//');
|
||||
}
|
||||
|
||||
function expectHash(text: string, decimal: number, repeat: number = 1) {
|
||||
let acc = text;
|
||||
for (let i = 1; i < repeat; i++) {
|
||||
acc += text;
|
||||
}
|
||||
|
||||
const hash = strHash(acc);
|
||||
expect(typeof(hash)).toEqual('string');
|
||||
expect(hash.length > 0).toBe(true);
|
||||
expect(parseInt(hash, 16)).toEqual(decimal);
|
||||
}
|
Reference in New Issue
Block a user