<commit_before>'use strict';

import assert from 'assert';

import { MessageContext } from '../../src/intl/context';

describe('Formatting messages:', function(){
  let ctx, args, errs;

  before(function() {
    ctx = new MessageContext('en-US');
    ctx.addMessages([
      'key1 = Value 1',
      'key2 = Value 2',
      '  [a] A2',
      '  [b] B2',
      'key3 = Value 3',
      '  [a] A3',
      ' *[b] B3',
      'key4 =',
      '  [a] A4',
      ' *[b] B4',
      'key5 =',
      '  [a] A5',
      '  [b] B5',
    ].join('\n'));
  });

  beforeEach(function() {
    errs = [];
  });

  it('uses the value when no traits are defined', function(){
    const msg = ctx.messages.get('key1');
    const val = ctx.format(msg, args, errs);
    assert.equal(val, 'Value 1');
    assert.deepEqual(errs, []);
  });

  it('uses the value even if traits are defined', function(){
    const msg = ctx.messages.get('key2');
    const val = ctx.format(msg, args, errs);
    assert.equal(val, 'Value 2');
    assert.deepEqual(errs, []);
  });

  it('uses the value even if one trait is marked as default', function(){
    const msg = ctx.messages.get('key3');
    const val = ctx.format(msg, args, errs);
    assert.equal(val, 'Value 3');
    assert.deepEqual(errs, []);
  });

  it('uses the default trait if there is no value', function(){
    const msg = ctx.messages.get('key4');
    const val = ctx.format(msg, args, errs);
    assert.equal(val, 'B4');
    assert.deepEqual(errs, []);
  });

  it('returns null if there is no value and no default', function(){
    const msg = ctx.messages.get('key5');
    const val = ctx.format(msg, args, errs);
    assert.strictEqual(val, null);
    assert.deepEqual(errs, []);
  });

});<commit_msg>test formatting trait values<commit_after>'use strict';

import assert from 'assert';

import { MessageContext } from '../../src/intl/context';

describe('Formatting values', function(){
  let ctx, args, errs;

  before(function() {
    ctx = new MessageContext('en-US');
    ctx.addMessages([
      'key1 = Value 1',
      'key2 = Value 2',
      '  [a] A2',
      '  [b] B2',
      'key3 = Value 3',
      '  [a] A3',
      ' *[b] B3',
      'key4 =',
      '  [a] A4',
      ' *[b] B4',
      'key5 =',
      '  [a] A5',
      '  [b] B5',
    ].join('\n'));
  });

  beforeEach(function() {
    errs = [];
  });

  it('uses the value when no traits are defined', function(){
    const msg = ctx.messages.get('key1');
    const val = ctx.format(msg, args, errs);
    assert.equal(val, 'Value 1');
    assert.deepEqual(errs, []);
  });

  it('uses the value even if traits are defined', function(){
    const msg = ctx.messages.get('key2');
    const val = ctx.format(msg, args, errs);
    assert.equal(val, 'Value 2');
    assert.deepEqual(errs, []);
  });

  it('uses the value even if one trait is marked as default', function(){
    const msg = ctx.messages.get('key3');
    const val = ctx.format(msg, args, errs);
    assert.equal(val, 'Value 3');
    assert.deepEqual(errs, []);
  });

  it('uses the default trait if there is no value', function(){
    const msg = ctx.messages.get('key4');
    const val = ctx.format(msg, args, errs);
    assert.equal(val, 'B4');
    assert.deepEqual(errs, []);
  });

  it('returns null if there is no value and no default', function(){
    const msg = ctx.messages.get('key5');
    const val = ctx.format(msg, args, errs);
    assert.strictEqual(val, null);
    assert.deepEqual(errs, []);
  });

  it('allows to pass traits directly to ctx.format', function(){
    const msg = ctx.messages.get('key2');
    const vals = msg.traits.map(
      trait => ctx.format(trait, args, errs)
    );
    assert.deepEqual(vals, ['A2', 'B2']);
    assert.deepEqual(errs, []);
  });

});
{'fraction_non_alphanumeric': 0.18811617372768452, 'fraction_numerical': 0.014122035704769519, 'mean_word_length': 2.7804632426988922, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 4, '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': '2454192', 'n_tokens_mistral': 1323, 'n_tokens_neox': 1292, 'n_words': 347}