// Copyright (c) 2014, the Dart project authors.  Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.

import 'package:expect/expect.dart';
import "package:async_helper/async_helper.dart";
import 'package:compiler/implementation/types/types.dart'
    show ContainerTypeMask, TypeMask;
    
import 'memory_compiler.dart';
import 'compiler_helper.dart' show findElement;
import 'type_mask_test_helper.dart';

const TEST = const {
  'main.dart' : r'''
import 'dart:typed_data';

var myList = new Float32List(42);
var myOtherList = new Uint8List(32);

main() {
  var a = new Float32List(9);
  return myList[0] + myOtherList[0];
}
'''};

void main() {
  var compiler = compilerFor(TEST);
  asyncTest(() => compiler.run(Uri.parse('memory:main.dart')).then((_) {
    var typesInferrer = compiler.typesTask.typesInferrer;

    checkType(String name, type, length) {
      var element = findElement(compiler, name);
      TypeMask mask = typesInferrer.getTypeOfElement(element);
      Expect.isTrue(mask.isContainer);
      ContainerTypeMask container = mask;
      Expect.equals(type, simplify(container.elementType, compiler), name);
      Expect.equals(container.length, length);
    }

    checkType('myList', compiler.typesTask.numType, 42);
    checkType('myOtherList', compiler.typesTask.uint31Type, 32);
  }));
}

Add a test for inferring the length of typed data lists.
Add a test for inferring the length of typed data lists.

BUG=
R=floitsch@google.com

Review URL: https://codereview.chromium.org//424663003

git-svn-id: c93d8a2297af3b929165606efe145742a534bc71@38722 260f80e4-7a28-3924-810f-c04153c831b5
