Changeset 9
- Timestamp:
- 10/21/05 17:19:22 (3 years ago)
- Files:
-
- jsolait/trunk/jsolait/jsolait.js (modified) (2 diffs)
- jsolait/trunk/jsolait/lib/codecs.js (modified) (1 diff)
- jsolait/trunk/jsolait/lib/lang.js (modified) (15 diffs)
- jsolait/trunk/jsolait/lib/sets.js (modified) (2 diffs)
- jsolait/trunk/jsolait/lib/testing.js (modified) (16 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
jsolait/trunk/jsolait/jsolait.js
r8 r9 560 560 561 561 specifier([...]-items are optional): 562 "% (key)[flag][sign][min][percision]typeOfValue"562 "%[(key)][flag][sign][min][percision]typeOfValue" 563 563 564 564 (key) If specified the 1st argument is treated as an object/associative array and the formating values … … 758 758 } 759 759 return out.join('\n'); 760 } 760 }; 761 761 762 762 ///Tests the module. jsolait/trunk/jsolait/lib/codecs.js
r5 r9 157 157 158 158 /** 159 Decodes a URI using decodeURI .159 Decodes a URI using decodeURIComponent. 160 160 **/ 161 161 String.prototype.decode_uri=function(){ 162 return decodeURI (this);162 return decodeURIComponent(this); 163 163 }; 164 164 165 165 /** 166 Encodes a URI using encodeURI .166 Encodes a URI using encodeURIComponent. 167 167 **/ 168 168 String.prototype.encode_uri=function(){ 169 return encodeURI (this);169 return encodeURIComponent(this); 170 170 }; 171 171 }); jsolait/trunk/jsolait/lib/lang.js
r8 r9 20 20 21 21 /** 22 Module providing language services like tokenizing JavaScript code 23 or converting JavaScript objects to and from JSON (see json.org). 24 To customize JSON serialization of Objects just overwrite the toJSON method in your class. 22 Module providing language services like tokenizing and parsing JavaScript code. 23 25 24 @creator Jan-Klaas Kollhof 26 25 @created 2004-03-14 … … 305 304 } 306 305 }; 307 308 309 310 306 }); 311 312 313 314 mod.ModuleNode=Class(function(publ,supr){ 315 publ.__init__=function(script){ 316 this.script=script; 317 }; 318 319 publ.parse=function(){ 320 321 }; 322 }); 323 324 307 325 308 mod.CodeNode=Class(function(publ,supr){ 326 309 publ.__init__=function(){ … … 603 586 604 587 this.currentNode.version = tkn.value.slice(1,-1); 605 this.currentNode.d ocumentation = this.getDocumentation();588 this.currentNode.description = this.getDocumentation(); 606 589 607 590 tkn=this.nextNonWhiteSpaceExpect(','); … … 667 650 668 651 publ.parseStatement_mod=function(tkn){ 669 return this.parseStatement_publProp(tkn); 652 if(this.currentNode instanceof mod.ModuleNode){ 653 return this.parseStatement_publProp(tkn); 654 }else{ 655 tkn = this.parseExpression(tkn); 656 return this.parseEndOfStatement(tkn); 657 } 670 658 }; 671 659 … … 687 675 this.currentNode = this.currentNode.addPublic(new mod.MethodNode()); 688 676 this.currentNode.name = name; 689 this.currentNode.d ocumentation = this.getDocumentation();677 this.currentNode.description = this.getDocumentation(); 690 678 tkn = this.parseExpression_function(tkn); 691 679 break; … … 693 681 this.currentNode = this.currentNode.addPublic(new mod.ClassNode()); 694 682 this.currentNode.name = name; 695 this.currentNode.d ocumentation = this.getDocumentation();683 this.currentNode.description = this.getDocumentation(); 696 684 tkn = this.parseExpression_Class(tkn); 697 685 break; … … 699 687 this.currentNode = this.currentNode.addPublic(new mod.PropertyNode()); 700 688 this.currentNode.name = name; 701 this.currentNode.d ocumentation = this.getDocumentation();689 this.currentNode.description = this.getDocumentation(); 702 690 tkn = this.parseExpression(tkn); 703 691 } … … 705 693 this.currentNode = this.currentNode.addPublic(new mod.PropertyNode()); 706 694 this.currentNode.name = name; 707 this.currentNode.d ocumentation = this.getDocumentation();695 this.currentNode.description = this.getDocumentation(); 708 696 } 709 697 … … 1075 1063 pprint('<module>',4); 1076 1064 pprint('<name>'+n.name+'</name>'); 1077 pprint('<d ocumentation>', 4);1078 pprint(n.d ocumentation);1079 pprint('</d ocumentation>', -4);1065 pprint('<description>', 4); 1066 pprint(n.description); 1067 pprint('</description>', -4); 1080 1068 pprint('<dependencies>'+n.dependencies+'</dependencies>'); 1081 1069 … … 1089 1077 pprint('<name>'+n.name+'</name>'); 1090 1078 1091 pprint('<d ocumentation>', 4);1092 pprint(n.d ocumentation);1093 pprint('</d ocumentation>', -4);1079 pprint('<description>', 4); 1080 pprint(n.description); 1081 pprint('</description>', -4); 1094 1082 1095 1083 this.printPublics(n); … … 1146 1134 pprint('<property>',4); 1147 1135 pprint('<name>' + n.name + '</name>'); 1148 pprint('<d ocumentation>', 4);1149 pprint(n.d ocumentation);1150 pprint('</d ocumentation>', -4);1136 pprint('<description>', 4); 1137 pprint(n.description); 1138 pprint('</description>', -4); 1151 1139 pprint('</property>',-4); 1152 1140 … … 1156 1144 pprint('<method>',4); 1157 1145 pprint('<name>' + n.name + '(' + n.parameters.join(', ') + ')</name>'); 1158 pprint('<d ocumentation>', 4);1159 pprint(n.d ocumentation);1160 pprint('</d ocumentation>', -4);1146 pprint('<description>', 4); 1147 pprint(n.description); 1148 pprint('</description>', -4); 1161 1149 pprint('</method>',-4); 1162 1150 }; … … 1166 1154 mod.__main__=function(){ 1167 1155 //var s='switch(a){\n case "as":\n\na=2;\nbreak;case "df":\nbreak; } a.'; 1168 var it =imprt('iter'); 1156 var it=imprt('iter'); 1157 var c= imprt('codecs'); 1158 1169 1159 var filenames= ['jsolait.js', 1170 1160 'lib/codecs.js', … … 1186 1176 fname=jsolait.baseURI + '/' + fname; 1187 1177 var s = jsolait.loadURI(fname); 1178 print(s.encode('uri')); 1188 1179 1189 1180 var p = new mod.Parser(s, gn); … … 1193 1184 }catch(e){ 1194 1185 var l=p.getPosition(); 1195 throw fname.slice('file://'.length) + '(' + (l[0] ) + ',' +l[1] + ') ' + e + ' near:\n' + p._working.slice(0,200);1186 throw new mod.Exception(fname.slice('file://'.length) + '(' + (l[0] ) + ',' +l[1] + ') ' + e + ' near:\n' + p._working.slice(0,200)); 1196 1187 } 1197 1188 }); jsolait/trunk/jsolait/lib/sets.js
r8 r9 335 335 print(testing.test(function(){ 336 336 testing.assertEquals("checking %s | %s".format(s1, s2), 337 new mod.Set("0123456789"), s1.union(s2)) 337 new mod.Set("0123456789"), s1.union(s2)); 338 338 339 339 testing.assertEquals("checking %s | %s".format(s2, s1), … … 357 357 testing.assertEquals("checking %s ^ %s".format(s2, s1), 358 358 new mod.Set("012789"),s2.symmDifference(s1)); 359 })) 359 })); 360 360 }; 361 361 }); jsolait/trunk/jsolait/lib/testing.js
r8 r9 50 50 publ.__init__=function(testScope){ 51 51 this.testScope=testScope; 52 } 52 }; 53 53 54 54 publ.run=function(){ … … 65 65 this.endTime=(new Date()).getTime(); 66 66 this.duration=this.endTime-this.startTime; 67 } 67 }; 68 68 69 69 publ.report=function(){ … … 73 73 return "Test completed in %s ms".format(this.duration); 74 74 } 75 } 75 }; 76 76 77 77 publ.startTime; … … 91 91 this.comment = comment; 92 92 supr.__init__.call(this, "%s failed: %s".format(comment, failMsg)); 93 } 93 }; 94 94 }); 95 95 … … 104 104 throw new mod.AssertFailed(comment, failMsg===undefined ? "Expected true but found: %s".format(value) : failMsg); 105 105 } 106 } 106 }; 107 107 108 108 mod.assertTrue=function(comment, value){ … … 112 112 } 113 113 mod.assert(comment, value===true, "Expected true but found: %s".format(value)); 114 } 114 }; 115 115 116 116 mod.assertFalse=function(comment, value){ … … 120 120 } 121 121 mod.assert(comment, value===false, "Expected false but found: %s".format(value)); 122 } 122 }; 123 123 124 124 mod.assertEquals=function(comment, value1, value2){ … … 133 133 mod.assert(comment, value1 === value2, "Expected %s === %s.".format(value1, value2)); 134 134 } 135 } 135 }; 136 136 137 137 mod.assertNotEquals=function(comment, value1, value2){ … … 146 146 mod.assert(comment, value1 !== value2, "Expected %s !== %s.".format(value1, value2)); 147 147 } 148 } 148 }; 149 149 150 150 mod.assertNull=function(comment, value){ … … 154 154 } 155 155 mod.assert(comment, value===null, "Expected %s === null.".format(value)); 156 } 156 }; 157 157 158 158 mod.assertNotNull=function(comment, value){ … … 162 162 } 163 163 mod.assert(comment, value !==null, "Expected %s !== null.".format(value)); 164 } 164 }; 165 165 166 166 mod.assertUndefined=function(comment, value){ … … 170 170 } 171 171 mod.assert(comment, value===undefined, "Expected %s === undefined.".format(value)); 172 } 172 }; 173 173 174 174 mod.assertNotUndefined=function(comment, value){ … … 178 178 } 179 179 mod.assert(comment, value!==undefined, "Expected %s !== undefined".format(value)); 180 } 180 }; 181 181 182 182 mod.assertNaN=function(comment, value){ … … 186 186 } 187 187 mod.assert(comment, isNaN(value)===true, "Expected %s === NaN.".format(value)); 188 } 188 }; 189 189 190 190 mod.assertNotNaN=function(comment, value){ … … 194 194 } 195 195 mod.assert(comment, isNaN(value)!==true, "Expected %s !== NaN".format(value)); 196 } 196 }; 197 197 198 198 mod.fail=function(){ 199 199 200 } 200 }; 201 201 202 202 mod.objectKeys=function(obj){ … … 231 231 mod.assertNotEquals(mod,{}); 232 232 })); 233 } 233 }; 234 234 }); 235 235
