<commit_before>Components.utils.import("resource://gtranslate/GoogleTranslate.js");

function test_mozPrefs() {
   do_check_true(GoogleTranslate.mozPrefs instanceof Ci.nsIPrefService);
}

function test_langConf() {
   do_check_eq(typeof(GoogleTranslate.langConf), "object");
   do_check_eq(typeof(GoogleTranslate.langConf.availableLangs_from), "string");
   do_check_eq(typeof(GoogleTranslate.langConf.availableLangs_to), "string");
   do_check_eq(typeof(GoogleTranslate.langConf.langDict), "object");
}

function test_prefs() {
   do_check_true(GoogleTranslate.prefs instanceof Ci.nsIPrefBranch);
   do_check_eq(GoogleTranslate.prefs.getCharPref("from"), "auto");

   var getDefaultTo = GoogleTranslate.getDefaultTo;
   GoogleTranslate.getDefaultTo = function() { return "en"; };
   do_check_eq(GoogleTranslate.prefs.getCharPref("to"), "en");
   GoogleTranslate.getDefaultTo = getDefaultTo;

   do_check_true(GoogleTranslate.prefs.getBoolPref("detectpagelang"));
}

function test_getGoogleUrl() {
    let langFrom = "en", langTo = "fr", text = "project", url;
    url = GoogleTranslate.getGoogleUrl("api", langFrom, langTo, text);
    do_check_eq(url,
                "http://ajax.googleapis.com/ajax/services/language/translate" +
                "?v=1.0&format=text&langpair=en%7Cfr&q=project");
}<commit_msg>add tests for setLangPair and getLangPair, and complete the getGoogleUrl tests<commit_after>Components.utils.import("resource://gtranslate/GoogleTranslate.js");

function test_mozPrefs() {
   do_check_true(GoogleTranslate.mozPrefs instanceof Ci.nsIPrefService);
}

function test_langConf() {
   do_check_eq(typeof(GoogleTranslate.langConf), "object");
   do_check_eq(typeof(GoogleTranslate.langConf.availableLangs_from), "string");
   do_check_eq(typeof(GoogleTranslate.langConf.availableLangs_to), "string");
   do_check_eq(typeof(GoogleTranslate.langConf.langDict), "object");
}

function test_prefs() {
   do_check_true(GoogleTranslate.prefs instanceof Ci.nsIPrefBranch);
   do_check_eq(GoogleTranslate.prefs.getCharPref("from"), "auto");

   var getDefaultTo = GoogleTranslate.getDefaultTo;
   GoogleTranslate.getDefaultTo = function() { return "en"; };
   do_check_eq(GoogleTranslate.prefs.getCharPref("to"), "en");
   GoogleTranslate.getDefaultTo = getDefaultTo;

   do_check_true(GoogleTranslate.prefs.getBoolPref("detectpagelang"));
}

function test_setLangPair() {
    let from = GoogleTranslate.prefs.getCharPref("from");
    let to = GoogleTranslate.prefs.getCharPref("to");

    GoogleTranslate.setLangPair("fr", "en");

    do_check_eq(GoogleTranslate.prefs.getCharPref("from"), "fr");
    do_check_eq(GoogleTranslate.prefs.getCharPref("to"), "en");

    GoogleTranslate.prefs.setCharPref("from", from);
    GoogleTranslate.prefs.setCharPref("to", to);
}

function test_getLangPair() {
    let from = GoogleTranslate.prefs.getCharPref("from");
    let to = GoogleTranslate.prefs.getCharPref("to");

    GoogleTranslate.prefs.setCharPref("from", "fr");
    GoogleTranslate.prefs.setCharPref("to", "en");

    let pair = GoogleTranslate.getLangPair();

    do_check_eq(pair[0], "fr");
    do_check_eq(pair[1], "en");

    GoogleTranslate.prefs.setCharPref("from", from);
    GoogleTranslate.prefs.setCharPref("to", to);
}

function test_getGoogleUrl() {
    let langFrom = "en", langTo = "fr", text = "project", url;
    url = GoogleTranslate.getGoogleUrl("api", langFrom, langTo, text);
    do_check_eq(url,
                "http://ajax.googleapis.com/ajax/services/language/translate" +
                "?v=1.0&format=text&langpair=en%7Cfr&q=project");
    url = GoogleTranslate.getGoogleUrl("page", langFrom, langTo, text);
    do_check_eq(url,
                "http://translate.google.com/#en%7Cfr%7Cproject");
    url = GoogleTranslate.getGoogleUrl("dict", langFrom, langTo, text);
    do_check_eq(url,
                "http://www.google.com/dictionary?langpair=en%7Cfr&q=project");
}
{'fraction_non_alphanumeric': 0.14289366053169733, 'fraction_numerical': 0.0028118609406952966, 'mean_word_length': 5.311290322580645, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 1, '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': '6519860', 'n_tokens_mistral': 1311, 'n_tokens_neox': 1295, 'n_words': 171}