Add union types (#1417)

A union type is a compound type with 0 or more types.

Its noms serialization is UnionKind, <number-of-types>, T0, ..., TN

Its HRS is T0 | T1 | ... | TN

Towards #1311
This commit is contained in:
Erik Arvidsson
2016-05-05 15:43:11 -07:00
parent 4f6ff3480a
commit bcd8d7e172
19 changed files with 273 additions and 126 deletions

View File

@@ -13,6 +13,7 @@ import {
makeMapType,
makeSetType,
makeStructType,
makeUnionType,
stringType,
valueType,
Type,
@@ -43,6 +44,12 @@ suite('Encode human readable types', () => {
assertWriteType('Set<Number>', makeSetType(numberType));
assertWriteType('Ref<Number>', makeRefType(numberType));
assertWriteType('Map<Number, String>', makeMapType(numberType, stringType));
assertWriteType('Number | String', makeUnionType([numberType, stringType]));
assertWriteType('Bool', makeUnionType([boolType]));
assertWriteType('', makeUnionType([]));
assertWriteType('List<Number | String>', makeListType(makeUnionType([numberType, stringType])));
assertWriteType('List<>', makeListType(makeUnionType([])));
});
test('struct', () => {