From 8609543ad0fb2820d5b8ca77e03af65973fd0f6c Mon Sep 17 00:00:00 2001 From: Ian Riley Date: Tue, 26 May 2015 17:00:31 -0700 Subject: [PATCH] refactor (test/facade): Ts'ify test/facade Translate AtScript in test/facade to TypeScript --- modules/angular2/test/facade/async_spec.js | 61 ---------- modules/angular2/test/facade/async_spec.ts | 65 ++++++++++ .../angular2/test/facade/collection_spec.js | 112 ------------------ .../angular2/test/facade/collection_spec.ts | 101 ++++++++++++++++ modules/angular2/test/facade/lang_spec.js | 60 ---------- modules/angular2/test/facade/lang_spec.ts | 54 +++++++++ 6 files changed, 220 insertions(+), 233 deletions(-) delete mode 100644 modules/angular2/test/facade/async_spec.js create mode 100644 modules/angular2/test/facade/async_spec.ts delete mode 100644 modules/angular2/test/facade/collection_spec.js create mode 100644 modules/angular2/test/facade/collection_spec.ts delete mode 100644 modules/angular2/test/facade/lang_spec.js create mode 100644 modules/angular2/test/facade/lang_spec.ts diff --git a/modules/angular2/test/facade/async_spec.js b/modules/angular2/test/facade/async_spec.js deleted file mode 100644 index f1af69cd6e..0000000000 --- a/modules/angular2/test/facade/async_spec.js +++ /dev/null @@ -1,61 +0,0 @@ -import {describe, it, expect, beforeEach, ddescribe, iit, xit, el, - SpyObject, AsyncTestCompleter, inject, IS_DARTIUM} from 'angular2/test_lib'; - -import {ObservableWrapper, EventEmitter, PromiseWrapper} from 'angular2/src/facade/async'; - -export function main() { - describe('EventEmitter', () => { - var emitter:EventEmitter; - - beforeEach(() => { - emitter = new EventEmitter(); - }); - - it("should call the next callback", inject([AsyncTestCompleter], (async) => { - ObservableWrapper.subscribe(emitter, (value) => { - expect(value).toEqual(99); - async.done(); - }); - - ObservableWrapper.callNext(emitter, 99); - })); - - it("should call the throw callback", inject([AsyncTestCompleter], (async) => { - ObservableWrapper.subscribe(emitter, (_) => {}, (error) => { - expect(error).toEqual("Boom"); - async.done(); - }); - ObservableWrapper.callThrow(emitter, "Boom"); - })); - - it("should work when no throw callback is provided", inject([AsyncTestCompleter], (async) => { - ObservableWrapper.subscribe(emitter, (_) => {}, (_) => { - async.done(); - }); - ObservableWrapper.callThrow(emitter, "Boom"); - })); - - it("should call the return callback", inject([AsyncTestCompleter], (async) => { - ObservableWrapper.subscribe(emitter, (_) => {}, (_) => {}, () => { - async.done(); - }); - - ObservableWrapper.callReturn(emitter); - })); - - it("should subscribe to the wrapper asynchronously", () => { - var called = false; - ObservableWrapper.subscribe(emitter, (value) => { - called = true; - }); - - ObservableWrapper.callNext(emitter, 99); - expect(called).toBe(false); - }); - - //TODO: vsavkin: add tests cases - //should call dispose on the subscription if generator returns {done:true} - //should call dispose on the subscription on throw - //should call dispose on the subscription on return - }); -} \ No newline at end of file diff --git a/modules/angular2/test/facade/async_spec.ts b/modules/angular2/test/facade/async_spec.ts new file mode 100644 index 0000000000..15aec817b4 --- /dev/null +++ b/modules/angular2/test/facade/async_spec.ts @@ -0,0 +1,65 @@ +import { + describe, + it, + expect, + beforeEach, + ddescribe, + iit, + xit, + el, + SpyObject, + AsyncTestCompleter, + inject, + IS_DARTIUM +} from 'angular2/test_lib'; + +import {ObservableWrapper, EventEmitter, PromiseWrapper} from 'angular2/src/facade/async'; + +export function main() { + describe('EventEmitter', () => { + var emitter: EventEmitter; + + beforeEach(() => { emitter = new EventEmitter(); }); + + it("should call the next callback", inject([AsyncTestCompleter], (async) => { + ObservableWrapper.subscribe(emitter, (value) => { + expect(value).toEqual(99); + async.done(); + }); + + ObservableWrapper.callNext(emitter, 99); + })); + + it("should call the throw callback", inject([AsyncTestCompleter], (async) => { + ObservableWrapper.subscribe(emitter, (_) => {}, (error) => { + expect(error).toEqual("Boom"); + async.done(); + }); + ObservableWrapper.callThrow(emitter, "Boom"); + })); + + it("should work when no throw callback is provided", inject([AsyncTestCompleter], (async) => { + ObservableWrapper.subscribe(emitter, (_) => {}, (_) => { async.done(); }); + ObservableWrapper.callThrow(emitter, "Boom"); + })); + + it("should call the return callback", inject([AsyncTestCompleter], (async) => { + ObservableWrapper.subscribe(emitter, (_) => {}, (_) => {}, () => { async.done(); }); + + ObservableWrapper.callReturn(emitter); + })); + + it("should subscribe to the wrapper asynchronously", () => { + var called = false; + ObservableWrapper.subscribe(emitter, (value) => { called = true; }); + + ObservableWrapper.callNext(emitter, 99); + expect(called).toBe(false); + }); + + // TODO: vsavkin: add tests cases + // should call dispose on the subscription if generator returns {done:true} + // should call dispose on the subscription on throw + // should call dispose on the subscription on return + }); +} \ No newline at end of file diff --git a/modules/angular2/test/facade/collection_spec.js b/modules/angular2/test/facade/collection_spec.js deleted file mode 100644 index 3dd20cf45d..0000000000 --- a/modules/angular2/test/facade/collection_spec.js +++ /dev/null @@ -1,112 +0,0 @@ -import {describe, it, expect, beforeEach, ddescribe, iit, xit} - from 'angular2/test_lib'; - -import {List, ListWrapper, StringMap, StringMapWrapper} from 'angular2/src/facade/collection'; - -export function main() { - describe('ListWrapper', () => { - var l: List; - - describe('splice', () => { - it('should remove sublist of given length and return it', () => { - var list = [1, 2, 3, 4, 5, 6]; - expect(ListWrapper.splice(list, 1, 3)).toEqual([2, 3, 4]); - expect(list).toEqual([1, 5, 6]); - }); - - it('should support negative start', () => { - var list = [1, 2, 3, 4, 5, 6]; - expect(ListWrapper.splice(list, -5, 3)).toEqual([2, 3, 4]); - expect(list).toEqual([1, 5, 6]); - }); - }); - - describe('fill', () => { - beforeEach(() => { - l = [1, 2, 3, 4]; - }); - - it('should fill the whole list if neither start nor end are specified', () => { - ListWrapper.fill(l, 9); - expect(l).toEqual([9, 9, 9, 9]); - }); - - it('should fill up to the end if end is not specified', () => { - ListWrapper.fill(l, 9, 1); - expect(l).toEqual([1, 9, 9, 9]); - }); - - it('should support negative start', () => { - ListWrapper.fill(l, 9, -1); - expect(l).toEqual([1, 2, 3, 9]); - }); - - it('should support negative end', () => { - ListWrapper.fill(l, 9, -2, -1); - expect(l).toEqual([1, 2, 9, 4]); - }); - }); - - describe('slice', () => { - beforeEach(() => { - l = [1, 2, 3, 4]; - }); - - it('should return the whole list if neither start nor end are specified', () => { - expect(ListWrapper.slice(l)).toEqual([1, 2, 3, 4]); - }); - - it('should return up to the end if end is not specified', () => { - expect(ListWrapper.slice(l, 1)).toEqual([2, 3, 4]); - }); - - it('should support negative start', () => { - expect(ListWrapper.slice(l, -1)).toEqual([4]); - }); - - it('should support negative end', () => { - expect(ListWrapper.slice(l, -3, -1)).toEqual([2, 3]); - }); - }); - }); - - describe('StringMapWrapper', () => { - describe('equals', () => { - it('should return true when comparing empty maps', () => { - expect(StringMapWrapper.equals({}, {})).toBe(true); - }); - - it('should return true when comparing the same map', () => { - var m1 = {'a': 1, 'b': 2, 'c': 3}; - expect(StringMapWrapper.equals(m1, m1)).toBe(true); - }); - - it('should return true when comparing different maps with the same keys and values', () => { - var m1 = {'a': 1, 'b': 2, 'c': 3}; - var m2 = {'a': 1, 'b': 2, 'c': 3}; - expect(StringMapWrapper.equals(m1, m2)).toBe(true); - }); - - it('should return false when comparing maps with different numbers of keys', () => { - var m1 = {'a': 1, 'b': 2, 'c': 3}; - var m2 = {'a': 1, 'b': 2, 'c': 3, 'd': 4}; - expect(StringMapWrapper.equals(m1, m2)).toBe(false); - expect(StringMapWrapper.equals(m2, m1)).toBe(false); - }); - - it('should return false when comparing maps with different keys', () => { - var m1 = {'a': 1, 'b': 2, 'c': 3}; - var m2 = {'a': 1, 'b': 2, 'CC': 3}; - expect(StringMapWrapper.equals(m1, m2)).toBe(false); - expect(StringMapWrapper.equals(m2, m1)).toBe(false); - }); - - it('should return false when comparing maps with different values', () => { - var m1 = {'a': 1, 'b': 2, 'c': 3}; - var m2 = {'a': 1, 'b': 20, 'c': 3}; - expect(StringMapWrapper.equals(m1, m2)).toBe(false); - expect(StringMapWrapper.equals(m2, m1)).toBe(false); - }); - }); - }); -} diff --git a/modules/angular2/test/facade/collection_spec.ts b/modules/angular2/test/facade/collection_spec.ts new file mode 100644 index 0000000000..e9d121378f --- /dev/null +++ b/modules/angular2/test/facade/collection_spec.ts @@ -0,0 +1,101 @@ +import {describe, it, expect, beforeEach, ddescribe, iit, xit} from 'angular2/test_lib'; + +import {List, ListWrapper, StringMap, StringMapWrapper} from 'angular2/src/facade/collection'; + +export function main() { + describe('ListWrapper', () => { + var l: List; + + describe('splice', () => { + it('should remove sublist of given length and return it', () => { + var list = [1, 2, 3, 4, 5, 6]; + expect(ListWrapper.splice(list, 1, 3)).toEqual([2, 3, 4]); + expect(list).toEqual([1, 5, 6]); + }); + + it('should support negative start', () => { + var list = [1, 2, 3, 4, 5, 6]; + expect(ListWrapper.splice(list, -5, 3)).toEqual([2, 3, 4]); + expect(list).toEqual([1, 5, 6]); + }); + }); + + describe('fill', () => { + beforeEach(() => { l = [1, 2, 3, 4]; }); + + it('should fill the whole list if neither start nor end are specified', () => { + ListWrapper.fill(l, 9); + expect(l).toEqual([9, 9, 9, 9]); + }); + + it('should fill up to the end if end is not specified', () => { + ListWrapper.fill(l, 9, 1); + expect(l).toEqual([1, 9, 9, 9]); + }); + + it('should support negative start', () => { + ListWrapper.fill(l, 9, -1); + expect(l).toEqual([1, 2, 3, 9]); + }); + + it('should support negative end', () => { + ListWrapper.fill(l, 9, -2, -1); + expect(l).toEqual([1, 2, 9, 4]); + }); + }); + + describe('slice', () => { + beforeEach(() => { l = [1, 2, 3, 4]; }); + + it('should return the whole list if neither start nor end are specified', + () => { expect(ListWrapper.slice(l)).toEqual([1, 2, 3, 4]); }); + + it('should return up to the end if end is not specified', + () => { expect(ListWrapper.slice(l, 1)).toEqual([2, 3, 4]); }); + + it('should support negative start', () => { expect(ListWrapper.slice(l, -1)).toEqual([4]); }); + + it('should support negative end', + () => { expect(ListWrapper.slice(l, -3, -1)).toEqual([2, 3]); }); + }); + }); + + describe('StringMapWrapper', () => { + describe('equals', () => { + it('should return true when comparing empty maps', + () => { expect(StringMapWrapper.equals({}, {})).toBe(true); }); + + it('should return true when comparing the same map', () => { + var m1 = {'a': 1, 'b': 2, 'c': 3}; + expect(StringMapWrapper.equals(m1, m1)).toBe(true); + }); + + it('should return true when comparing different maps with the same keys and values', () => { + var m1 = {'a': 1, 'b': 2, 'c': 3}; + var m2 = {'a': 1, 'b': 2, 'c': 3}; + expect(StringMapWrapper.equals(m1, m2)).toBe(true); + }); + + it('should return false when comparing maps with different numbers of keys', () => { + var m1 = {'a': 1, 'b': 2, 'c': 3}; + var m2 = {'a': 1, 'b': 2, 'c': 3, 'd': 4}; + expect(StringMapWrapper.equals(m1, m2)).toBe(false); + expect(StringMapWrapper.equals(m2, m1)).toBe(false); + }); + + it('should return false when comparing maps with different keys', () => { + var m1 = {'a': 1, 'b': 2, 'c': 3}; + var m2 = {'a': 1, 'b': 2, 'CC': 3}; + expect(StringMapWrapper.equals(m1, m2)).toBe(false); + expect(StringMapWrapper.equals(m2, m1)).toBe(false); + }); + + it('should return false when comparing maps with different values', () => { + var m1 = {'a': 1, 'b': 2, 'c': 3}; + var m2 = {'a': 1, 'b': 20, 'c': 3}; + expect(StringMapWrapper.equals(m1, m2)).toBe(false); + expect(StringMapWrapper.equals(m2, m1)).toBe(false); + }); + }); + }); +} diff --git a/modules/angular2/test/facade/lang_spec.js b/modules/angular2/test/facade/lang_spec.js deleted file mode 100644 index 2da41d15a1..0000000000 --- a/modules/angular2/test/facade/lang_spec.js +++ /dev/null @@ -1,60 +0,0 @@ -import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib'; - -import {ListWrapper} from 'angular2/src/facade/collection'; -import {isPresent, RegExpWrapper, RegExpMatcherWrapper, StringWrapper, CONST_EXPR} from 'angular2/src/facade/lang'; - -export function main() { - describe('RegExp', () => { - it('should expose the index for each match', () => { - var re = RegExpWrapper.create('(!)'); - var matcher = RegExpWrapper.matcher(re, '0!23!567!!'); - var indexes = []; - var m; - - while (isPresent(m = RegExpMatcherWrapper.next(matcher))) { - ListWrapper.push(indexes, m.index); - expect(m[0]).toEqual('!'); - expect(m[1]).toEqual('!'); - expect(m.length).toBe(2); - } - - expect(indexes).toEqual([1, 4, 8, 9]); - }); - - it('should whether the regular expression has a match in the string', () => { - var barRe = RegExpWrapper.create('bar'); - - expect(RegExpWrapper.test(barRe, 'bar')).toEqual(true); - expect(RegExpWrapper.test(barRe, 'foo')).toEqual(false); - }); - }); - - describe('const', () => { - it('should support const expressions both in TS and Dart', () => { - const numbers = CONST_EXPR([1, 2, 3]); - expect(numbers).toEqual([1, 2, 3]); - }) - }); - - describe('String', () => { - var upper, lower; - - beforeEach(() => { - upper = 'SOMETHING' - lower = 'something'; - }); - - it('should upper case a string', () => { - var str = StringWrapper.toUpperCase(lower); - - expect(str).toEqual(upper); - }); - - it('should lower case a string', () => { - var str = StringWrapper.toLowerCase(upper); - - expect(str).toEqual(lower); - }); - }); - -} diff --git a/modules/angular2/test/facade/lang_spec.ts b/modules/angular2/test/facade/lang_spec.ts new file mode 100644 index 0000000000..fd7cc3d975 --- /dev/null +++ b/modules/angular2/test/facade/lang_spec.ts @@ -0,0 +1,54 @@ +import {describe, it, expect, beforeEach, ddescribe, iit, xit, el} from 'angular2/test_lib'; + +import {ListWrapper} from 'angular2/src/facade/collection'; +import { + isPresent, + RegExpWrapper, + RegExpMatcherWrapper, + StringWrapper, + CONST_EXPR +} from 'angular2/src/facade/lang'; + +export function main() { + describe('RegExp', () => {it('should expose the index for each match', () => { + var re = RegExpWrapper.create('(!)'); + var matcher = RegExpWrapper.matcher(re, '0!23!567!!'); + var indexes = []; + var m; + + while (isPresent(m = RegExpMatcherWrapper.next(matcher))) { + ListWrapper.push(indexes, m.index); + expect(m[0]).toEqual('!'); + expect(m[1]).toEqual('!'); + expect(m.length).toBe(2); + } + + expect(indexes).toEqual([1, 4, 8, 9]); + })}); + + describe('const', () => {it('should support const expressions both in TS and Dart', () => { + const numbers = CONST_EXPR([1, 2, 3]); + expect(numbers).toEqual([1, 2, 3]); + })}); + + describe('String', () => { + var upper, lower; + + beforeEach(() => { + upper = 'SOMETHING'; + lower = 'something'; + }); + + it('should upper case a string', () => { + var str = StringWrapper.toUpperCase(lower); + + expect(str).toEqual(upper); + }); + + it('should lower case a string', () => { + var str = StringWrapper.toLowerCase(upper); + + expect(str).toEqual(lower); + }); + }); +}