"use strict";

var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");

var _util = require("@polkadot/util");

var _Text = _interopRequireDefault(require("./Text"));

var _Type = _interopRequireDefault(require("./Type"));

// Copyright 2017-2019 @polkadot/types authors & contributors
// This software may be modified and distributed under the terms
// of the Apache-2.0 license. See the LICENSE file for details.
describe('Type', () => {
  it('fails to cleanup invalid boxes', () => {
    expect(() => new _Type.default('Box<Proposal')).toThrow(/find closing matching/);
  });
  it('cleans up tuples with a single value', () => {
    expect(new _Type.default('(AccountId)').toString()).toEqual('AccountId');
  });
  it('does not touch tuples with multiple values', () => {
    expect(new _Type.default('(AccountId, Balance)').toString()).toEqual('(AccountId,Balance)');
  });
  it('handles nested types', () => {
    expect(new _Type.default('Box<Vec<AccountId>>').toString()).toEqual('Vec<AccountId>');
  });
  it('handles nested types (embedded)', () => {
    expect(new _Type.default('(u32, Box<Vec<AccountId>>)').toString()).toEqual('(u32,Vec<AccountId>)');
  });
  it('handles aliasses, multiples per line', () => {
    expect(new _Type.default('(Vec<u8>, AccountId, Vec<u8>)').toString()).toEqual('(Bytes,AccountId,Bytes)');
  });
  it('removes whitespaces', () => {
    expect(new _Type.default('T :: AccountId').toString()).toEqual('AccountId');
  });
  it('changes PairOf<T> -> (T, T)', () => {
    expect(new _Type.default('PairOf<T::Balance>').toString()).toEqual('(Balance,Balance)');
  });
  it('changes PairOf<T> (embedded) -> (T, T)', () => {
    expect(new _Type.default('(Vec<u8>, PairOf<T::Balance>, Vec<AccountId>)').toString()).toEqual('(Bytes,(Balance,Balance),Vec<AccountId>)');
  });
  it('changes () -> Null', () => {
    expect(new _Type.default('()').toString()).toEqual('Null');
  });
  it('has a length for the type', () => {
    expect(new _Type.default(new _Text.default(' Box<Proposal> ')).toString()).toEqual('Proposal'); // eslint-disable-line
  });
  it('unwraps compact', () => {
    expect(new _Type.default('<T::Balance as HasCompact>::Type').toString()).toEqual('Compact<Balance>');
  });
  it('handles InherentOfflineReport', () => {
    expect(new _Type.default('<T::InherentOfflineReport as InherentOfflineReport>::Inherent').toString()).toEqual('InherentOfflineReport');
  });
  it('encodes correctly via toU8a()', () => {
    const type = 'Compact<Balance>';
    expect(new _Text.default(type).toU8a()).toEqual((0, _util.u8aConcat)(new Uint8Array([type.length << 2]), (0, _util.stringToU8a)(type)));
  });
});