<commit_before>library compiler_spec;

import '../_specs.dart';


void main() {
  describe('dte.compiler', () {
    Compiler $compile;
    DirectiveMap directives;
    Injector injector;
    Scope rootScope;

    beforeEach(module((Module module) {
      module
          ..type(TabComponent)
          ..type(PublishTypesAttrDirective)
          ..type(PaneComponent)
          ..type(SimpleTranscludeInAttachAttrDirective)
          ..type(IgnoreChildrenDirective)
          ..type(IncludeTranscludeAttrDirective)
          ..type(LocalAttrDirective)
          ..type(OneOfTwoDirectives)
          ..type(TwoOfTwoDirectives)
          ..type(MyController)
          ..type(MyParentController)
          ..type(MyChildController);
      return (Injector _injector) {
        injector = _injector;
        $compile = injector.get(Compiler);
        directives = injector.get(DirectiveMap);
        rootScope = injector.get(Scope);
      };
    }));

    it('should compile basic hello world', inject(() {
      var element = $('<div ng-bind="name"></div>');
      var template = $compile(element, directives);

      rootScope.context['name'] = 'angular';
      template(injector, element);

      expect(element.text()).toEqual('');
      rootScope.apply();
      expect(element.text()).toEqual('angular');
    }));

    it('should not throw on an empty list', inject(() {
      $compile([], directives);
    }));

    it('should compile a directive in a child', inject(() {
      var element = $('<div><div ng-bind="name"></div></div>');
      var template = $compile(element, directives);

      rootScope.context['name'] = 'angular';


      template(injector, element);

      expect(element.text()).toEqual('');
      rootScope.apply();
      expect(element.text()).toEqual('angular');
    }));

    it('should compile repeater', inject(() {
      var element = $('<div><div ng-repeat="item in items" ng-bind="item"></div></div>');
      var template = $compile(element, directives);

      rootScope.context['items'] = ['A', 'b'];
      template(injector, element);

      expect(element.text()).toEqual('');
      // TODO(deboer): Digest twice until we have dirty checking in the scope.
      rootScope.apply();
      rootScope.apply();
      expect(element.text()).toEqual('Ab');

      rootScope.context['items'] = [];
      rootScope.apply();
      expect(element.html()).toEqual('<!--ANCHOR: [ng-repeat]=item in items-->');
    }));

    it('should compile repeater with children', inject((Compiler $compile) {
      var element = $('<div><div ng-repeat="item in items"><div ng-bind="item"></div></div></div>');
      var template = $compile(element, directives);

      rootScope.context['items'] = ['A', 'b'];
      template(injector, element);

      expect(element.text()).toEqual('');
      // TODO(deboer): Digest twice until we have dirty checking in the scope.
      rootScope.apply();
      rootScope.apply();
      expect(element.text()).toEqual('Ab');
<commit_msg>chore(compiler): Fix TODO in tests<commit_after>library compiler_spec;

import '../_specs.dart';


void main() {
  describe('dte.compiler', () {
    Compiler $compile;
    DirectiveMap directives;
    Injector injector;
    Scope rootScope;

    beforeEach(module((Module module) {
      module
          ..type(TabComponent)
          ..type(PublishTypesAttrDirective)
          ..type(PaneComponent)
          ..type(SimpleTranscludeInAttachAttrDirective)
          ..type(IgnoreChildrenDirective)
          ..type(IncludeTranscludeAttrDirective)
          ..type(LocalAttrDirective)
          ..type(OneOfTwoDirectives)
          ..type(TwoOfTwoDirectives)
          ..type(MyController)
          ..type(MyParentController)
          ..type(MyChildController);
      return (Injector _injector) {
        injector = _injector;
        $compile = injector.get(Compiler);
        directives = injector.get(DirectiveMap);
        rootScope = injector.get(Scope);
      };
    }));

    it('should compile basic hello world', inject(() {
      var element = $('<div ng-bind="name"></div>');
      var template = $compile(element, directives);

      rootScope.context['name'] = 'angular';
      template(injector, element);

      expect(element.text()).toEqual('');
      rootScope.apply();
      expect(element.text()).toEqual('angular');
    }));

    it('should not throw on an empty list', inject(() {
      $compile([], directives);
    }));

    it('should compile a directive in a child', inject(() {
      var element = $('<div><div ng-bind="name"></div></div>');
      var template = $compile(element, directives);

      rootScope.context['name'] = 'angular';

      template(injector, element);

      expect(element.text()).toEqual('');
      rootScope.apply();
      expect(element.text()).toEqual('angular');
    }));

    it('should compile repeater', inject(() {
      var element = $('<div><div ng-repeat="item in items" ng-bind="item"></div></div>');
      var template = $compile(element, directives);

      rootScope.context['items'] = ['A', 'b'];
      template(injector, element);
      expect(element.text()).toEqual('');

      rootScope.apply();
      expect(element.text()).toEqual('Ab');

      rootScope.context['items'] = [];
      rootScope.apply();
      expect(element.html()).toEqual('<!--ANCHOR: [ng-repeat]=item in items-->');
    }));

    it('should compile repeater with children', inject((Compiler $compile) {
      var element = $('<div><div ng-repeat="item in items"><div ng-bind="item"></div></div></div>');
      var template = $compile(element, directives);

      rootScope.context['items'] = ['A', 'b'];
      template(injector, element);

      expect(element.text()).toEqual('');
      rootScope.apply();
      expect(element.text()).toEqual('Ab');

{'fraction_non_alphanumeric': 0.17334946422398895, 'fraction_numerical': 0.0, 'mean_word_length': 2.9207317073170733, 'pattern_counts': {'":': 0, '<': 37, '<?xml version=': 0, '>': 37, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6938435', 'n_tokens_mistral': 1654, 'n_tokens_neox': 1628, 'n_words': 328}