1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>LocalStrings Tests</title> 5 <script src="http://closure-library.googlecode.com/svn/trunk/closure/goog/base.js"></script> 6 <script src="local_strings.js"></script> 7 <script> 8 goog.require('goog.testing.jsunit'); 9 </script> 10 </head> 11 <body> 12 <script> 13 14 function testGetString() { 15 var localStrings = new LocalStrings; 16 localStrings.templateData = { 17 'a': 'apple', 18 'b': 'banana' 19 }; 20 assertEquals(localStrings.getString('a'), 'apple'); 21 assertEquals(localStrings.getString('b'), 'banana'); 22 assertEquals(localStrings.getString('c'), ''); 23 } 24 25 function testGetStringF() { 26 var localStrings = new LocalStrings; 27 localStrings.templateData = { 28 'a': '$1', 29 'b': '$1$2', 30 'c': '$1$2$3', 31 'd': '$1$2$3$4$5$6$7$8$9' 32 }; 33 assertEquals(localStrings.getStringF('a', 'A'), 'A'); 34 assertEquals(localStrings.getStringF('b', 'A', 'B'), 'AB'); 35 assertEquals(localStrings.getStringF('b', 'A'), 36 'Aundefined'); 37 assertEquals(localStrings.getStringF('c', 'A', 'B', 'C'), 38 'ABC'); 39 assertEquals(localStrings.getStringF('c', 'A'), 40 'Aundefinedundefined'); 41 assertEquals(localStrings.getStringF('d', 'A', 'B', 'C', 42 'D', 'E', 'F', 'G', 'H', 'I'), 'ABCDEFGHI'); 43 assertEquals(localStrings.getStringF('e', 'A'), ''); 44 } 45 46 </script> 47 </body> 48 </html> 49