Index: trunk/extensions/Narayam/tests/qunit/ext.narayam.tests.js |
— | — | @@ -87,54 +87,5 @@ |
88 | 88 | teardown(); |
89 | 89 | } ); |
90 | 90 | |
91 | | -test( '-- German transliteration and keybuffers', function() { |
92 | | - expect( 3 ); |
93 | | - setup(); |
94 | 91 | |
95 | | - // Testing keybuffer ("compose key") |
96 | | - $.narayam.setScheme( 'de' ); |
97 | | - equals( $.narayam.transliterate( '~o', '~', false ), 'ö', 'German ~o -> ö' ); |
98 | | - equals( $.narayam.transliterate( '~O', '~', false ), 'Ö', 'German ~O -> Ö' ); |
99 | | - equals( $.narayam.transliterate( '~s', '~', false ), 'ß', 'German ~s -> ß' ); |
100 | | - |
101 | | - teardown(); |
102 | | -} ); |
103 | | - |
104 | | -test( '-- Hebrew transliteration, extended keyboard', function() { |
105 | | - expect( 2 ); |
106 | | - setup(); |
107 | | - |
108 | | - // Testing extended and non-extended |
109 | | - $.narayam.setScheme( 'he-standard-2011-extonly' ); |
110 | | - equals( $.narayam.transliterate( '=', '', false ), '=', 'Hebrew non-extended = does not change' ); |
111 | | - equals( $.narayam.transliterate( '=', '', true ), '–', 'Hebrew extended = becomes en dash' ); |
112 | | - |
113 | | - teardown(); |
114 | | -} ); |
115 | | - |
116 | | -test( '-- Malayalam transliteration, cookie, zwnj, longer keybuffers', function() { |
117 | | - expect( 8 ); |
118 | | - setup(); |
119 | | - |
120 | | - $.narayam.setScheme( 'kn' ); |
121 | | - var recentSchemes = $.cookie( 'narayam-scheme' ), |
122 | | - currentSchemeRegex = new RegExp( '^kn' ); |
123 | | - ok ( currentSchemeRegex.test( recentSchemes ), 'New scheme added to the cookie' ); |
124 | | - |
125 | | - $.narayam.setScheme( 'ml' ); |
126 | | - |
127 | | - equals( $.narayam.transliterate( 'a', '', false ), 'അ', 'Malayalam a -> അ' ); |
128 | | - |
129 | | - // N.B.: There's a zwnj in the input, and no zwnj in the expected result |
130 | | - equals( $.narayam.transliterate( 'നീലa', '', false ), 'നീലഅ', 'Malayalam zwnj+a -> അ' ); |
131 | | - equals( $.narayam.transliterate( 'ൻൿh', 'nc', false ), 'ഞ്ച്', 'Malayalam nch -> ഞ്ച്' ); |
132 | | - |
133 | | - equals( $.narayam.transliterate( 'p', '', false ), 'പ്', 'Malayalam p -> പ്' ); |
134 | | - equals( $.narayam.transliterate( 'പ്a', '', false ), 'പ', 'Malayalam pa -> പ' ); |
135 | | - equals( $.narayam.transliterate( 'ക്h', '', false ), 'ഖ്', 'Malayalam kh -> ഖ്' ); |
136 | | - equals( $.narayam.transliterate( 'ഖ്a', '', false ), 'ഖ', 'Malayalam kha -> ഖ്' ); |
137 | | - |
138 | | - teardown(); |
139 | | -} ); |
140 | | - |
141 | 92 | }()); |
Index: trunk/extensions/Narayam/tests/qunit/ext.narayam.rules.tests.js |
— | — | @@ -0,0 +1,124 @@ |
| 2 | +/** |
| 3 | + * QUnit tests for Narayam typing rules |
| 4 | + * |
| 5 | + * @file |
| 6 | + * @copyright Copyright © 2012 Santhosh Thottingal |
| 7 | + * @license http://www.gnu.org/copyleft/gpl.html GNU General Public License 2.0 or later |
| 8 | + */ |
| 9 | +( function () { |
| 10 | + |
| 11 | +module( "ext.narayam.rules", QUnit.newMwEnvironment() ); |
| 12 | + |
| 13 | +function setup() { |
| 14 | + $.narayam.setup(); |
| 15 | + $.narayam.enable(); |
| 16 | +} |
| 17 | +function teardown() { |
| 18 | + // we need to disable narayam, otherwise many typing simulation based test eg: jquery.byteLimitTest will fail. |
| 19 | + $.narayam.disable(); |
| 20 | +} |
| 21 | +test( "-- Initial check", function() { |
| 22 | + expect( 1 ); |
| 23 | + ok( $.narayam, "$.narayam is defined" ); |
| 24 | +} ); |
| 25 | + |
| 26 | +// Basic sendkey-implementation |
| 27 | +typeChars = function( $input, charstr ) { |
| 28 | + var len = charstr.length; |
| 29 | + for ( var i = 0; i < len; i++ ) { |
| 30 | + // Get the key code |
| 31 | + var code = charstr.charCodeAt(i); |
| 32 | + // Trigger event and undo if prevented |
| 33 | + var event = new jQuery.Event( 'keypress', { keyCode: code, which: code, charCode: code } ); |
| 34 | + $input.trigger( event ); |
| 35 | + } |
| 36 | +}; |
| 37 | + |
| 38 | +/** |
| 39 | + * Test factory for narayamTest |
| 40 | + */ |
| 41 | +var narayamTest = function( options ) { |
| 42 | + var opt = $.extend( { |
| 43 | + description: '', // Test description |
| 44 | + $input: null, |
| 45 | + tests: [], |
| 46 | + scheme: '' // The input method name. |
| 47 | + }, options); |
| 48 | + |
| 49 | + test( opt.description, function() { |
| 50 | + expect( opt.tests.length); |
| 51 | + $.narayam.enable( ); |
| 52 | + stop(); |
| 53 | + $.narayam.setScheme( opt.scheme, function(){ |
| 54 | + opt.$input.appendTo( '#qunit-fixture' ); |
| 55 | + $.narayam.addInputs (opt.$input); |
| 56 | + $.narayam.setScheme( opt.scheme ); |
| 57 | + for ( var i= 0 ; i < opt.tests.length; i++ ) { |
| 58 | + // Simulate pressing keys for each of the sample characters |
| 59 | + typeChars( opt.$input, opt.tests[i].input ); |
| 60 | + equals( opt.$input.val(), opt.tests[i].output, opt.tests[i].description ); |
| 61 | + opt.$input.val(''); |
| 62 | + } |
| 63 | + $.narayam.disable(); |
| 64 | + start(); |
| 65 | + }); |
| 66 | + } ); |
| 67 | +}; |
| 68 | + |
| 69 | +narayamTest ( { |
| 70 | + description: 'Malayalam Transliteration test', |
| 71 | + tests: [ |
| 72 | + { input : 'ra', output : 'ര', description : 'Malayalam ra'}, |
| 73 | + { input : 'nta', output : 'ന്റ', description : 'Malayalam nta'} |
| 74 | + ], |
| 75 | + scheme : 'ml', |
| 76 | + $input: $( '<input >' ).attr( { 'id':"ml", 'type' :'text' } ) |
| 77 | +} ); |
| 78 | + |
| 79 | +narayamTest ( { |
| 80 | + description: 'Oriya Inscript test', |
| 81 | + tests : [ |
| 82 | + { input : 'ka', output : 'କୋ' } |
| 83 | + ], |
| 84 | + scheme : 'or-inscript', |
| 85 | + $input: $( '<input >' ).attr( { 'id':"or", 'type' :'text' } ) |
| 86 | +} ); |
| 87 | + |
| 88 | +narayamTest ( { |
| 89 | + description: 'Malayalam Inscript test', |
| 90 | + tests : [ |
| 91 | + { input : 'ka', output : 'കോ' } |
| 92 | + ], |
| 93 | + scheme : 'ml-inscript', |
| 94 | + $input: $( '<input >' ).attr( { 'id':"ml-inscript", 'type' :'text' } ) |
| 95 | +} ); |
| 96 | + |
| 97 | +narayamTest ( { |
| 98 | + description: 'Tamil Inscript test', |
| 99 | + tests : [ |
| 100 | + { input : 'ka', output : 'கோ', description : 'Tamil Inscript கோ' } |
| 101 | + ], |
| 102 | + scheme : 'ta-inscript', |
| 103 | + $input: $( '<input >' ).attr( { 'id':"ta-inscript", 'type' :'text' } ) |
| 104 | +} ); |
| 105 | + |
| 106 | +narayamTest ( { |
| 107 | + description: 'Amharic Transliteration test', |
| 108 | + tests : [ |
| 109 | + { input : 'ka', output : 'ካ', description : 'Amharic ka->ካ' } |
| 110 | + ], |
| 111 | + scheme : 'am', |
| 112 | + $input: $( '<input >' ).attr( { 'id':"am", 'type' :'text' } ) |
| 113 | +} ); |
| 114 | + |
| 115 | +narayamTest ( { |
| 116 | + description: 'Marathi Transliteration test', |
| 117 | + tests : [ |
| 118 | + { input : 'dny', output : 'ज्ञ्', description : 'dny for ज्ञ् in Marathi transliteration' } |
| 119 | + ], |
| 120 | + scheme : 'mr', |
| 121 | + $input: $( '<input >' ).attr( { 'id':"mr", 'type' :'text' } ) |
| 122 | +} ); |
| 123 | + |
| 124 | +teardown( ); |
| 125 | +} ( ) ); |
Property changes on: trunk/extensions/Narayam/tests/qunit/ext.narayam.rules.tests.js |
___________________________________________________________________ |
Added: svn:eol-style |
1 | 126 | + native |
Index: trunk/extensions/Narayam/resources/ext.narayam.core/ext.narayam.core.js |
— | — | @@ -439,8 +439,9 @@ |
440 | 440 | /** |
441 | 441 | * Change the current transliteration scheme |
442 | 442 | * @param name String |
| 443 | + * @param callback Function to be called when the scheme is ready/dynamically loaded.- Optional |
443 | 444 | */ |
444 | | - this.setScheme = function( name ) { |
| 445 | + this.setScheme = function( name, callback ) { |
445 | 446 | var recent = $.cookie( 'narayam-scheme' ) || []; |
446 | 447 | if ( typeof recent === "string" ) { |
447 | 448 | recent = recent.split( "," ); |
— | — | @@ -454,10 +455,12 @@ |
455 | 456 | $.cookie( 'narayam-scheme', recent, { path: '/', expires: 30 } ); |
456 | 457 | if ( name in schemes ) { |
457 | 458 | currentScheme = schemes[name]; |
| 459 | + if ( callback ) callback.call(); |
458 | 460 | } else { |
459 | 461 | // load the rules dynamically. |
460 | 462 | mw.loader.using( "ext.narayam.rules." + name, function() { |
461 | 463 | currentScheme = schemes[name]; |
| 464 | + if ( callback ) callback.call(); |
462 | 465 | } ); |
463 | 466 | } |
464 | 467 | return true; |