test_unicode.js (2635B)
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 // This file tests the unicode functions that we have added 6 7 const LATIN1_AE = "\xc6"; // "Æ" 8 const LATIN1_ae = "\xe6"; // "æ" 9 10 add_task(async function setup() { 11 getOpenedDatabase().createTable("test", "id INTEGER PRIMARY KEY, name TEXT"); 12 13 var stmt = createStatement("INSERT INTO test (name, id) VALUES (?1, ?2)"); 14 stmt.bindByIndex(0, LATIN1_AE); 15 stmt.bindByIndex(1, 1); 16 stmt.execute(); 17 stmt.bindByIndex(0, "A"); 18 stmt.bindByIndex(1, 2); 19 stmt.execute(); 20 stmt.bindByIndex(0, "b"); 21 stmt.bindByIndex(1, 3); 22 stmt.execute(); 23 stmt.bindByIndex(0, LATIN1_ae); 24 stmt.bindByIndex(1, 4); 25 stmt.execute(); 26 stmt.finalize(); 27 28 registerCleanupFunction(cleanup); 29 }); 30 31 add_task(async function test_upper_ascii() { 32 var stmt = createStatement( 33 "SELECT name, id FROM test WHERE name = upper('a')" 34 ); 35 Assert.ok(stmt.executeStep()); 36 Assert.equal("A", stmt.getString(0)); 37 Assert.equal(2, stmt.getInt32(1)); 38 stmt.reset(); 39 stmt.finalize(); 40 }); 41 42 add_task(async function test_upper_non_ascii() { 43 var stmt = createStatement( 44 "SELECT name, id FROM test WHERE name = upper(?1)" 45 ); 46 stmt.bindByIndex(0, LATIN1_ae); 47 Assert.ok(stmt.executeStep()); 48 Assert.equal(LATIN1_AE, stmt.getString(0)); 49 Assert.equal(1, stmt.getInt32(1)); 50 stmt.reset(); 51 stmt.finalize(); 52 }); 53 54 add_task(async function test_lower_ascii() { 55 var stmt = createStatement( 56 "SELECT name, id FROM test WHERE name = lower('B')" 57 ); 58 Assert.ok(stmt.executeStep()); 59 Assert.equal("b", stmt.getString(0)); 60 Assert.equal(3, stmt.getInt32(1)); 61 stmt.reset(); 62 stmt.finalize(); 63 }); 64 65 add_task(async function test_lower_non_ascii() { 66 var stmt = createStatement( 67 "SELECT name, id FROM test WHERE name = lower(?1)" 68 ); 69 stmt.bindByIndex(0, LATIN1_AE); 70 Assert.ok(stmt.executeStep()); 71 Assert.equal(LATIN1_ae, stmt.getString(0)); 72 Assert.equal(4, stmt.getInt32(1)); 73 stmt.reset(); 74 stmt.finalize(); 75 }); 76 77 add_task(async function test_like_search_different() { 78 var stmt = createStatement("SELECT COUNT(*) FROM test WHERE name LIKE ?1"); 79 stmt.bindByIndex(0, LATIN1_AE); 80 Assert.ok(stmt.executeStep()); 81 Assert.equal(2, stmt.getInt32(0)); 82 stmt.finalize(); 83 }); 84 85 add_task(async function test_like_search_same() { 86 var stmt = createStatement("SELECT COUNT(*) FROM test WHERE name LIKE ?1"); 87 stmt.bindByIndex(0, LATIN1_ae); 88 Assert.ok(stmt.executeStep()); 89 Assert.equal(2, stmt.getInt32(0)); 90 stmt.finalize(); 91 });