Revision control

1
/* This Source Code Form is subject to the terms of the Mozilla Public
2
* License, v. 2.0. If a copy of the MPL was not distributed with this
3
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
4
5
import Foundation
6
@testable import Client
7
import UIKit
8
9
import XCTest
10
11
class DefaultSearchPrefsTests: XCTestCase {
12
13
func testParsing() {
14
// setup the list json
15
let searchPrefs = DefaultSearchPrefs(with: Bundle.main.resourceURL!.appendingPathComponent("SearchPlugins").appendingPathComponent("list.json"))!
16
17
// setup the most popular locales
18
let us = (lang: ["en-US", "en"], region: "US", resultList: ["google-b-1-m", "bing", "amazondotcom", "ddg", "twitter", "wikipedia"], resultDefault: "google-b-m")
19
let england = (lang: ["en-GB", "en"], region: "GB", resultList: ["google-b-m", "bing", "amazon-co-uk", "ddg", "qwant", "twitter", "wikipedia"], resultDefault: "google-b-m")
20
let france = (lang: ["fr-FR", "fr"], region: "FR", resultList: ["google-b-m", "bing", "ddg", "qwant", "twitter", "wikipedia-fr"], resultDefault: "google-b-m")
21
let japan = (lang: ["ja-JP", "ja"], region: "JP", resultList: ["google-b-m", "amazon-jp", "bing", "twitter-ja", "wikipedia-ja", "yahoo-jp"], resultDefault: "google-b-m")
22
let canada = (lang: ["en-CA", "en"], region: "CA", resultList: ["google-b-m", "bing", "amazondotcom", "ddg", "twitter", "wikipedia"], resultDefault: "google-b-m")
23
let russia = (lang: ["ru-RU", "ru"], region: "RU", resultList: ["google-b-m", "yandex-ru", "twitter", "wikipedia-ru"], resultDefault: "Яндекс")
24
let taiwan = (lang: ["zh-TW", "zh"], region: "TW", resultList: ["google-b-m", "bing", "ddg", "wikipedia-zh-TW"], resultDefault: "google-b-m")
25
let china = (lang: ["zh-hans-CN", "zh-CN", "zh"], region: "CN", resultList: ["google-b-m", "baidu", "bing", "wikipedia-zh-CN"], resultDefault: "百度")
26
let germany = (lang: ["de-DE", "de"], region: "DE", resultList: ["google-b-m", "bing", "amazon-de", "ddg", "qwant", "twitter", "wikipedia-de"], resultDefault: "google-b-m")
27
let southAfrica = (lang: ["en-SA", "en"], region: "SA", resultList: ["google-b-m", "bing", "amazondotcom", "ddg", "twitter", "wikipedia"], resultDefault: "google-b-m")
28
let testLocales = [us, england, france, japan, canada, russia, taiwan, china, germany, southAfrica]
29
30
// run tests
31
testLocales.forEach { locale in
32
XCTAssertEqual(searchPrefs.searchDefault(for: locale.lang, and: locale.region), locale.resultDefault, "incorrect for \(locale.lang) and \(locale.region)")
33
XCTAssertEqual(searchPrefs.visibleDefaultEngines(for: locale.lang, and: locale.region), locale.resultList)
34
}
35
}
36
}