<commit_before>require File.dirname(__FILE__) + '/../test_helper'

class MessageTest < Test::Unit::TestCase
  fixtures :messages, :users

  # This needs to be updated when new fixtures are added
  # or removed.
  def test_check_message_count
    assert_equal 2, Message.count
  end

  def test_check_empty_message_fails
    message = Message.new
    assert !message.valid?
    assert message.errors.invalid?(:title)
    assert message.errors.invalid?(:body)
    assert message.errors.invalid?(:sent_on)
    assert true, message.message_read
  end
  
  def test_validating_msgs
    message = messages(:one)
    assert message.valid?
    massage = messages(:two)
    assert message.valid?
  end
  
  def test_invalid_send_recipient
    message = messages(:one)
    message.sender = nil
    message.recipient = nil
    assert !message.valid?
  end
end<commit_msg>utf-8 wide-char testing of message title - this will come in useful for other things e.g. k/v pairs<commit_after>require File.dirname(__FILE__) + '/../test_helper'

class MessageTest < Test::Unit::TestCase
  fixtures :messages, :users

  EURO = "\xe2\x82\xac" #euro symbol

  # This needs to be updated when new fixtures are added
  # or removed.
  def test_check_message_count
    assert_equal 2, Message.count
  end

  def test_check_empty_message_fails
    message = Message.new
    assert !message.valid?
    assert message.errors.invalid?(:title)
    assert message.errors.invalid?(:body)
    assert message.errors.invalid?(:sent_on)
    assert true, message.message_read
  end
  
  def test_validating_msgs
    message = messages(:one)
    assert message.valid?
    massage = messages(:two)
    assert message.valid?
  end
  
  def test_invalid_send_recipient
    message = messages(:one)
    message.sender = nil
    message.recipient = nil
    assert !message.valid?
  end

  def test_utf8_roundtrip
    (1..255).each do |i|
      assert_message_ok('c', i)
      assert_message_ok(EURO, i)
    end
  end

  def test_length_oversize
    assert_raise(ActiveRecord::RecordInvalid) { make_message('c', 256).save! }
    assert_raise(ActiveRecord::RecordInvalid) { make_message(EURO, 256).save! }
  end

  def make_message(char, count)
    message = messages(:one)
    message.title = char * count
    return message
  end

  def assert_message_ok(char, count)
    message = make_message(char, count)
    assert message.save!
    response = message.class.find(message.id) # stand by for some über-generalisation...
    assert_equal char * count, response.title, "message with #{count} #{char} chars (i.e. #{char.length*count} bytes) fails"
  end

end
{'fraction_non_alphanumeric': 0.09609494640122511, 'fraction_numerical': 0.006508422664624809, 'mean_word_length': 3.5443478260869563, 'pattern_counts': {'":': 0, '<': 5, '<?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': '1277553', 'n_tokens_mistral': 839, 'n_tokens_neox': 812, 'n_words': 211}