Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Add qunit tests

Importing the tests from MediaWiki gerrit

Change-Id: I2aec075b5ea04f927e2ee0a0e747334ba9efb4a0
  • Loading branch information...
commit fc28cfeb3befbcc421bf9c3b20a9f68b6cde7625 1 parent 41499db
@santhoshtr santhoshtr authored amire80 committed
View
4 .gitmodules
@@ -0,0 +1,4 @@
+[submodule "libs/qunit"]
+ path = libs/qunit
+ url = git://github.com/jquery/qunit.git
+
View
9,404 libs/jquery.js
9,404 additions, 0 deletions not shown
1  libs/qunit
@@ -0,0 +1 @@
+Subproject commit dbd005333d23dc1b248a3b6d17f32ab2b2396c66
View
36 test/index.html
@@ -0,0 +1,36 @@
+<!DOCTYPE html>
+<html lang="en" dir="ltr">
+<head>
+<meta charset="utf-8">
+<title>jQuery ULS Test Suite</title>
+
+<!-- External libs -->
+<script src="../libs/jquery.js"></script>
+
+<!-- Source of our libs -->
+<script src="../src/jquery.uls.data.js"></script>
+<script src="../src/jquery.uls.data.utils.js"></script>
+<script src="../src/jquery.uls.lcd.js"></script>
+<script src="../src/jquery.uls.languagefilter.js"></script>
+<script src="../src/jquery.uls.regionfilter.js"></script>
+<script src="../src/jquery.uls.core.js"></script>
+
+<!-- Test framework -->
+<link rel="stylesheet" href="../libs/qunit/qunit/qunit.css">
+<script src="../libs/qunit/qunit/qunit.js"></script>
+
+<!-- Test config -->
+<script>
+ QUnit.config.requireExpects = true;
+</script>
+
+<!-- Test Suite -->
+<script src="jquery.uls.test.js"></script>
+
+</head>
+<body>
+ <div id="qunit"></div>
+ <div id="qunit-fixture"></div>
+</body>
+</html>
+
View
158 test/jquery.uls.test.js
@@ -0,0 +1,158 @@
+/**
+ * QUnit tests for ULS.
+ *
+ * Copyright (C) 2012 Alolita Sharma, Amir Aharoni, Arun Ganesh, Brandon Harris,
+ * Niklas Laxström, Pau Giner, Santhosh Thottingal, Siebrand Mazeland and other
+ * contributors. See CREDITS for a list.
+ *
+ * UniversalLanguageSelector is dual licensed GPLv2 or later and MIT. You don't
+ * have to do anything special to choose one license or the other and you don't
+ * have to notify anyone which license you are using. You are free to use
+ * UniversalLanguageSelector in commercial projects as long as the copyright
+ * header is left intact. See files GPL-LICENSE and MIT-LICENSE for details.
+ *
+ */
+( function ( $ ) {
+ 'use strict';
+
+ module( 'jquery.uls' );
+
+ /*
+ * Runs over all script codes mentioned in langdb and checks whether
+ * they belong to the 'Other' group.
+ */
+ var orphanScripts = function () {
+ var result = [];
+
+ for ( var language in $.uls.data.languages ) {
+ var script = $.uls.data.script( language );
+ if ( $.uls.data.groupOfScript( script ) === 'Other' ) {
+ result.push( script );
+ }
+ }
+
+ return result;
+ };
+
+ /*
+ * Runs over all script codes mentioned in langdb and checks whether
+ * they have something that looks like an autonym.
+ */
+ var languagesWithoutAutonym = function () {
+ var result = [];
+
+ for ( var language in $.uls.data.languages ) {
+ if ( typeof $.uls.data.autonym( language ) !== 'string' ) {
+ result.push( language );
+ }
+ }
+
+ return result;
+ };
+
+ test( "-- Initial check", 1, function ( assert ) {
+ assert.ok( $.fn.uls, "$.fn.uls is defined" );
+ } );
+
+ test( "-- $.uls.data testing", 25, function ( assert ) {
+
+ assert.strictEqual( $.uls.data.autonyms()['he'], 'עברית', 'Correct autonym is returned for Hebrew using autonyms().' );
+
+ // This test assumes that we don't want any scripts to be in the 'Other'
+ // group. Actually, this may become wrong some day.
+ assert.deepEqual( orphanScripts(), [], 'All scripts belong to script groups.' );
+ assert.deepEqual( languagesWithoutAutonym(), [], 'All languages have autonyms.' );
+
+ assert.strictEqual(
+ $.uls.data.groupOfScript( 'Beng' ),
+ 'SouthAsian',
+ 'Bengali script belongs to the SouthAsian group.'
+ );
+ assert.strictEqual(
+ $.uls.data.scriptGroupOfLanguage( 'iu' ),
+ 'NativeAmerican',
+ 'The script of the Inupiaq language belongs to the NativeAmerican group.'
+ );
+
+ assert.strictEqual( $.uls.data.script( 'ii' ), 'Yiii', 'Correct script of the Yi language was selected' );
+ assert.deepEqual( $.uls.data.regions( 'lzz' ), [
+ 'EU', 'ME'
+ ], 'Correct regions of the Laz language were selected' );
+ assert.strictEqual( $.uls.data.regions( 'no-such-language' ), 'UNKNOWN', "The region of an invalid language is 'UNKNOWN'" );
+
+ var allLanguagesByRegionAndScript = $.uls.data.allLanguagesByRegionAndScript();
+ assert.deepEqual( allLanguagesByRegionAndScript['4']['AS']['SouthEastAsian']['Bugi'], [
+ 'bug'
+ ], 'All languages in the Buginese script in Asia were selected' );
+
+ assert.deepEqual( $.uls.data.languagesInRegion( "PA" ),
+ [
+ "ace", "bi", "ch", "en-gb", "en", "fj", "haw", "hif-latn", "hif", "ho", "jv",
+ "mh", "mi", "na", "niu", "pih", "pis", "pt", "rtm", "sm", "tet",
+ "to", "tpi", "ty", "wls"
+ ],
+ "languages of region PA are selected correctly" );
+ assert.deepEqual( $.uls.data.languagesInRegions( ["AM", "WW"] ),
+ [
+ "akz", "arn", "aro", "ase", "avk", "ay", "cho", "chr", "chy", "cr-cans", "cr-latn",
+ "cr", "en-ca", "en", "eo", "es-419", "es-formal", "es", "esu", "fr", "gcf", "gn",
+ "guc", "haw", "ht", "ia", "ie", "ik", "ike-cans", "ike-latn", "io", "iu", "jam",
+ "jbo", "kgp", "kl", "lad", "lfn", "mfe", "mic", "mus", "nah", "nl-informal", "nl",
+ "nov", "nv", "pap", "pdc", "pdt", "ppl", "pt-br", "pt", "qu", "qug", "rap", "sei",
+ "simple", "srn", "tokipona", "vo", "yi", "yrl", "yua"
+ ],
+ "languages of regions AM and WW are selected correctly"
+ );
+
+ assert.deepEqual( $.uls.data.languagesInScript( 'Knda' ), [
+ "kn", "tcy"
+ ], "languages in script Knda are selected correctly" );
+ assert.deepEqual( $.uls.data.languagesInScripts( ['Geor', 'Armn'] ),
+ ["hy", "ka", "xmf"],
+ "languages in scripts Geor and Armn are selected correctly"
+ );
+
+ assert.deepEqual( $.uls.data.regionsInGroup( 3 ), [
+ "EU", "ME", "AF"
+ ], "regions in group 2 are selected correctly" );
+ assert.deepEqual( $.uls.data.regionsInGroup( 2 ), [
+ "AM"
+ ], "regions in group 2 are selected correctly" );
+ assert.deepEqual( $.uls.data.regionsInGroup( 1 ), [
+ "WW"
+ ], "regions in group 1 are selected correctly" );
+
+ var languagesByScriptInAM = $.uls.data.languagesByScriptInRegion( "AM" );
+ assert.deepEqual( languagesByScriptInAM['Cans'], [
+ "cr-cans", "cr", "ike-cans", "iu"
+ ], "correct languages in Cans in AM selected" );
+
+ assert.strictEqual( $.uls.data.autonym( 'pa' ), 'ਪੰਜਾਬੀ', 'Correct autonym of the Punjabi language was selected' );
+
+ var languagesByScriptGroupInEMEA = $.uls.data.languagesByScriptGroupInRegions( $.uls.data.regionsInGroup( 3 ) );
+ assert.deepEqual( languagesByScriptGroupInEMEA['WestCaucasian'], [
+ 'hy', 'ka', 'xmf'
+ ], 'Correct languages in WestCaucasian script group in EMEA selected' );
+
+ var allLanguagesByScriptGroup = $.uls.data.allLanguagesByScriptGroup();
+ assert.deepEqual( allLanguagesByScriptGroup['Greek'], [
+ 'el', 'grc', 'pnt', 'ruq-grek', 'tsd'
+ ], 'All languages in the Greek script found' );
+
+ assert.deepEqual( $.uls.data.allRegions(), [
+ "WW", "AM", "EU", "ME", "AF", "AS", "PA"
+ ], "All regions found" );
+
+ // autonyms: gn: avañe'ẽ, de: deutsch, hu: magyar, fi: suomi
+ assert.deepEqual( ['de', 'fi', 'gn', 'hu'].sort( $.uls.data.sortByAutonym ), [
+ 'gn', 'de', 'hu', 'fi'
+ ], 'Languages are correctly sorted by autonym' );
+
+ assert.strictEqual( $.uls.data.isRtl( "te" ), false, "Telugu language is not RTL" );
+ assert.strictEqual( $.uls.data.isRtl( "dv" ), true, "Divehi language is RTL" );
+
+ assert.ok( $.inArray( "sah", $.uls.data.languagesInTerritory( "RU" ) )
+ > -1, "Sakha language is spoken in Russia" );
+ } );
+
+}( jQuery ) );
Please sign in to comment.
Something went wrong with that request. Please try again.