<commit_before>import Ember from 'ember-metal'; // ES6TODO Ember.STRINGS
import { ENV } from 'ember-environment';
import { loc } from '../../../system/string';

let oldString;

QUnit.module('EmberStringUtils.loc', {
  beforeEach() {
    oldString = Ember.STRINGS;
    Ember.STRINGS = {
      '_Hello World': 'Bonjour le monde',
      '_Hello %@': 'Bonjour %@',
      '_Hello %@ %@': 'Bonjour %@ %@',
      '_Hello %@# %@#': 'Bonjour %@2 %@1'
    };
  },

  afterEach() {
    Ember.STRINGS = oldString;
  }
});

if (!ENV.EXTEND_PROTOTYPES.String) {
  QUnit.test('String.prototype.loc is not available without EXTEND_PROTOTYPES', function(assert) {
    assert.ok('undefined' === typeof String.prototype.loc, 'String.prototype helper disabled');
  });
}

function test(given, args, expected, description) {
  QUnit.test(description, function(assert) {
    assert.equal(loc(given, args), expected);
    if (ENV.EXTEND_PROTOTYPES.String) {
      assert.equal(given.loc(...args), expected);
    }
  });
}

test('_Hello World',    [],              'Bonjour le monde', `loc('_Hello World') => 'Bonjour le monde'`);
test('_Hello %@ %@',    ['John', 'Doe'], 'Bonjour <NAME>', `loc('_Hello %@ %@', ['John', 'Doe']) => 'Bonjour John Doe'`);
test('_Hello %@# %@#',  ['John', 'Doe'], 'Bonjour Doe John', `loc('_Hello %@# %@#', ['John', 'Doe']) => 'Bonjour Doe John'`);
test('_Not In Strings', [],              '_Not In Strings',  `loc('_Not In Strings') => '_Not In Strings'`);

QUnit.test('works with argument form', function(assert) {
  assert.equal(loc('_Hello %@', 'John'), 'Bonjour John');
  assert.equal(loc('_Hello %@ %@', ['John'], 'Doe'), 'Bonjour [John] Doe');<commit_msg>Don't use Ember global for testing `loc`<commit_after>import { ENV } from 'ember-environment';
import { loc } from '../../../system/string';
import { setStrings, getStrings } from '../../../string_registry';


let oldString;

QUnit.module('EmberStringUtils.loc', {
  beforeEach() {
    oldString = getStrings();
    setStrings({
      '_Hello World': 'Bonjour le monde',
      '_Hello %@': 'Bonjour %@',
      '_Hello %@ %@': 'Bonjour %@ %@',
      '_Hello %@# %@#': 'Bonjour %@2 %@1'
    });
  },

  afterEach() {
    setStrings(oldString);
  }
});

if (!ENV.EXTEND_PROTOTYPES.String) {
  QUnit.test('String.prototype.loc is not available without EXTEND_PROTOTYPES', function(assert) {
    assert.ok('undefined' === typeof String.prototype.loc, 'String.prototype helper disabled');
  });
}

function test(given, args, expected, description) {
  QUnit.test(description, function(assert) {
    assert.equal(loc(given, args), expected);
    if (ENV.EXTEND_PROTOTYPES.String) {
      assert.equal(given.loc(...args), expected);
    }
  });
}

test('_Hello World',    [],              'Bonjour le monde', `loc('_Hello World') => 'Bonjour le monde'`);
test('_Hello %@ %@',    ['John', 'Doe'], 'Bonjour <NAME>', `loc('_Hello %@ %@', ['John', 'Doe']) => 'Bonjour <NAME>'`);
test('_Hello %@# %@#',  ['John', 'Doe'], 'Bonjour Doe John', `loc('_Hello %@# %@#', ['John', 'Doe']) => 'Bonjour Doe John'`);
test('_Not In Strings', [],              '_Not In Strings',  `loc('_Not In Strings') => '_Not In Strings'`);

QUnit.test('works with argument form', function(assert) {
  assert.equal(loc('_Hello %@', 'John'), 'Bonjour John');
  assert.equal(loc('_Hello %@ %@', ['John'], 'Doe'), 'Bonjour [John] Doe');
{'fraction_non_alphanumeric': 0.223081499107674, 'fraction_numerical': 0.00148720999405116, 'mean_word_length': 3.8809869375907113, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 14, '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': '3222843', 'n_tokens_mistral': 1187, 'n_tokens_neox': 1177, 'n_words': 254}