<commit_before>// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2009 Sprout Systems, Inc. and contributors.
//            Portions ©2008-2009 Apple, Inc. All rights reserved.
// License:   Licened under MIT license (see license.js)
// ==========================================================================

/*globals throws */

var content, controller, extra;

var TestObject = SC.Object.extend({
  title: "test",  
  toString: function() { return "TestObject(%@)".fmt(this.get("title")); }
});


// ..........................................................
// allowsSingleContent
// 

module("SC.ArrayController - single_case - SINGLE", {
  setup: function() {
    content = TestObject.create({ title: "FOO" });
    controller = SC.ArrayController.create({ 
      content: content, allowsSingleContent: YES
    });
  },
  
  teardown: function() {
    controller.destroy();
  }
});

test("state properties", function() {
  equals(controller.get("hasContent"), YES, 'c.hasContent');
  equals(controller.get("canRemoveContent"), YES, "c.canRemoveContent");
  equals(controller.get("canReorderContent"), NO, "c.canReorderContent");
  equals(controller.get("canAddContent"), NO, "c.canAddContent");
});

// addObject should append to end of array + notify observers on Array itself
test("addObject", function() {
  should_throw(function() {
    controller.addObject(extra);
  }, Error, "controller.addObject should throw exception");
});

test("removeObject - no destroyOnRemoval", function() {
  var callCount = 0;
  controller.set('destroyOnRemoval', NO);
  controller.addObserver('[]', function() { callCount++; });
  
  controller.removeObject(content);
  
  equals(controller.get('content'), null, 'removeObject(content) should set content to null');
  ok((callCount=1), 'should notify observer since content did not change');
  equals(controller.get('length'), 0, 'should now have length of 0');
  equals(content.isDestroyed, NO, 'content.isDestroyed should be destroyed');
});

test("removeObject - destroyOnRemoval", function() {
  controller.set('destroyOnRemoval', YES);
  SC.run(function() { controller.removeObject(content); });
  equals(content.isDestroyed, YES, 'content.isDestroyed should be destroyed');
});


test("basic array READ operations", function() {
  equals(controller.get("length"), 1, 'length should be 1');<commit_msg>Fix typo in taks commit<commit_after>// ==========================================================================
// Project:   SproutCore - JavaScript Application Framework
// Copyright: ©2006-2009 Sprout Systems, Inc. and contributors.
//            Portions ©2008-2009 Apple, Inc. All rights reserved.
// License:   Licened under MIT license (see license.js)
// ==========================================================================

/*globals should_throw */

var content, controller, extra;

var TestObject = SC.Object.extend({
  title: "test",  
  toString: function() { return "TestObject(%@)".fmt(this.get("title")); }
});


// ..........................................................
// allowsSingleContent
// 

module("SC.ArrayController - single_case - SINGLE", {
  setup: function() {
    content = TestObject.create({ title: "FOO" });
    controller = SC.ArrayController.create({ 
      content: content, allowsSingleContent: YES
    });
  },
  
  teardown: function() {
    controller.destroy();
  }
});

test("state properties", function() {
  equals(controller.get("hasContent"), YES, 'c.hasContent');
  equals(controller.get("canRemoveContent"), YES, "c.canRemoveContent");
  equals(controller.get("canReorderContent"), NO, "c.canReorderContent");
  equals(controller.get("canAddContent"), NO, "c.canAddContent");
});

// addObject should append to end of array + notify observers on Array itself
test("addObject", function() {
  should_throw(function() {
    controller.addObject(extra);
  }, Error, "controller.addObject should throw exception");
});

test("removeObject - no destroyOnRemoval", function() {
  var callCount = 0;
  controller.set('destroyOnRemoval', NO);
  controller.addObserver('[]', function() { callCount++; });
  
  controller.removeObject(content);
  
  equals(controller.get('content'), null, 'removeObject(content) should set content to null');
  equals(callCount, 1, 'should notify observer since content did not change');
  equals(controller.get('length'), 0, 'should now have length of 0');
  equals(content.isDestroyed, NO, 'content.isDestroyed should be destroyed');
});

test("removeObject - destroyOnRemoval", function() {
  controller.set('destroyOnRemoval', YES);
  SC.run(function() { controller.removeObject(content); });
  equals(content.isDestroyed, YES, 'content.isDestroyed should be destroyed');
});


test("basic array READ operations", function() {
  equals(controller.get("length"), 1, 'length should be 1');
{'fraction_non_alphanumeric': 0.22776089159067883, 'fraction_numerical': 0.008915906788247214, 'mean_word_length': 4.436123348017621, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, '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': '3313531', 'n_tokens_mistral': 1384, 'n_tokens_neox': 1306, 'n_words': 334}