UNPKG

2.16 kBJavaScriptView Raw
1/**
2 * @license
3 * Copyright 2018 Google LLC. All Rights Reserved.
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 * =============================================================================
16 */
17import { upcastType } from './types';
18describe('upcastType', () => {
19 it('upcasts bool to bool', () => {
20 expect(upcastType('bool', 'bool')).toBe('bool');
21 });
22 it('upcasts bool/int32 to int32', () => {
23 expect(upcastType('bool', 'int32')).toBe('int32');
24 expect(upcastType('int32', 'int32')).toBe('int32');
25 });
26 it('upcasts bool/int32/float32 to float32', () => {
27 expect(upcastType('bool', 'float32')).toBe('float32');
28 expect(upcastType('int32', 'float32')).toBe('float32');
29 expect(upcastType('float32', 'float32')).toBe('float32');
30 });
31 it('upcasts bool/int32/float32/complex64 to complex64', () => {
32 expect(upcastType('bool', 'complex64')).toBe('complex64');
33 expect(upcastType('int32', 'complex64')).toBe('complex64');
34 expect(upcastType('float32', 'complex64')).toBe('complex64');
35 expect(upcastType('complex64', 'complex64')).toBe('complex64');
36 });
37 it('fails to upcast anything other than string with string', () => {
38 expect(() => upcastType('bool', 'string')).toThrowError();
39 expect(() => upcastType('int32', 'string')).toThrowError();
40 expect(() => upcastType('float32', 'string')).toThrowError();
41 expect(() => upcastType('complex64', 'string')).toThrowError();
42 // Ok upcasting string to string.
43 expect(upcastType('string', 'string')).toBe('string');
44 });
45});
46//# sourceMappingURL=types_test.js.map
\No newline at end of file