Index: trunk/extensions/Narayam/tests/qunit/ext.narayam.tests.js |
— | — | @@ -11,21 +11,31 @@ |
12 | 12 | |
13 | 13 | module( "ext.narayam", QUnit.newMwEnvironment() ); |
14 | 14 | |
15 | | -// A language that definitely has input methods |
16 | | -mw.config.set( { wgUserLanguage: "ml" } ); |
17 | | - |
18 | 15 | function setup() { |
19 | 16 | $.narayam.setup(); |
20 | 17 | $.narayam.enable(); |
21 | 18 | } |
| 19 | + |
22 | 20 | function teardown() { |
23 | | - // we need to disable narayam, otherwise many typing simulation based test eg: jquery.byteLimitTest will fail. |
| 21 | + // We need to disable narayam, otherwise many typing simulation based |
| 22 | + // tests, like jquery.byteLimitTest, will fail. |
24 | 23 | $.narayam.disable(); |
25 | 24 | } |
| 25 | + |
26 | 26 | test( "-- Initial check", function() { |
27 | | - expect( 1 ); |
| 27 | + expect( 2 ); |
28 | 28 | |
| 29 | + // Clean up before testing initialization |
| 30 | + teardown(); |
| 31 | + // Delete state cookie |
| 32 | + $.cookie( 'narayam-enabled', null ); |
| 33 | + |
| 34 | + setup(); |
29 | 35 | ok( $.narayam, "$.narayam is defined" ); |
| 36 | + equals( $.narayam.enabled(), mw.config.get( 'wgNarayamEnabledByDefault' ), 'Initial state of Narayam matches the configuration' ); |
| 37 | + |
| 38 | + // Init empty cookie of recent schemes |
| 39 | + $.cookie( 'narayam-scheme', '', { path: '/', expires: 30 } ); |
30 | 40 | } ); |
31 | 41 | |
32 | 42 | test( "-- Initialization functions", function() { |
— | — | @@ -77,4 +87,54 @@ |
78 | 88 | teardown(); |
79 | 89 | } ); |
80 | 90 | |
| 91 | +test( '-- German transliteration and keybuffers', function() { |
| 92 | + expect( 3 ); |
| 93 | + setup(); |
| 94 | + |
| 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 | + |
81 | 141 | }()); |