~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to lib/contrib/slimmer/tests/codechunks.py

  • Committer: Steve Alexander
  • Date: 2007-03-31 20:46:51 UTC
  • mto: (3847.2.91 onezero-ui-cleanup)
  • mto: This revision was merged to the branch mainline in revision 4046.
  • Revision ID: steve.alexander@canonical.com-20070331204651-8gpspx5ya2jqbvxz
add slimmer CSS compressor to contrib.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
CSS_1 = '''
 
2
/* Comment 1 */
 
3
div#main { 
 
4
  font-family: Verdana, "Courier New"      ;
 
5
}
 
6
 
 
7
 
 
8
h2 { 
 
9
  /* Comment 2 */
 
10
  font-size: 10px;
 
11
}
 
12
'''
 
13
 
 
14
expect_CSS_1 = '''
 
15
div#main{font-family:Verdana,"Courier New"}h2{font-size:10px}
 
16
'''
 
17
 
 
18
 
 
19
#----------------------------------------------------------------------------
 
20
 
 
21
CSS_2 = '''
 
22
<style type="text/css">
 
23
div#main { 
 
24
  font-family:  Verdana, "Courier New"      ;
 
25
}
 
26
 
 
27
h2 { 
 
28
  font-size: 10px;
 
29
}
 
30
</style>
 
31
'''
 
32
 
 
33
expect_CSS_2 = '''
 
34
<style type="text/css">
 
35
div#main{font-family:Verdana,"Courier New"}h2{font-size:10px}</style>
 
36
'''
 
37
#----------------------------------------------------------------------------
 
38
CSS_3 = r'''
 
39
#centercontent {
 
40
    border:1px solid #000000;
 
41
    voice-family: "\"}\"";
 
42
    voice-family: inherit;
 
43
    margin-left: 201px;
 
44
    }
 
45
'''    
 
46
 
 
47
expect_CSS_3 = r'''
 
48
#centercontent{border:1px solid #000;voice-family: "\"}\"";voice-family:inherit;margin-left:201px}
 
49
'''    
 
50
 
 
51
#----------------------------------------------------------------------------
 
52
CSS_4 = r'''
 
53
p     {  color:#123456;   }
 
54
 
 
55
 
 
56
select {
 
57
        font-family: Verdana,Arial,Helvetica,sans-serif;
 
58
        font-size: 11px;
 
59
        color: #000000;
 
60
        /*
 
61
        background-color: #FFFFFF;
 
62
        */
 
63
}
 
64
#myDiv { float: left; background: transparent; }
 
65
'''
 
66
 
 
67
expect_CSS_4 = r'''
 
68
p{color:#123456}select{font-family:Verdana,Arial,Helvetica,sans-serif;font-size:11px;color:#000}#myDiv{float:left;background:transparent}
 
69
'''
 
70
 
 
71
#----------------------------------------------------------------------------
 
72
 
 
73
CSS_5 = r'''
 
74
/* remove this comment */
 
75
#isnotMacIE5 { display: none;  }
 
76
#isMacIE5 { display: block; background-color: #060; color: #fff; }
 
77
/* commented backslash hack v2 \*/
 
78
#isnotMacIE5 { display: block; background-color: #060; color: #fff; }
 
79
#isMacIE5 { display: none; }
 
80
/* keep this comment */
 
81
#ismozilla { state: cool; }
 
82
/* safely remove this one too */
 
83
'''
 
84
 
 
85
expect_CSS_5 = r'''
 
86
#isnotMacIE5{display:none}#isMacIE5{display:block;background-color:#060;color:#fff}/* commented backslash hack v2 \*/
 
87
#isnotMacIE5{display:block;background-color:#060;color:#fff}#isMacIE5{display:none}/* keep this comment */
 
88
#ismozilla{state:cool}
 
89
'''
 
90
 
 
91
#----------------------------------------------------------------------------
 
92
 
 
93
CSS_6 = r'''
 
94
div   a {display:block;}
 
95
'''
 
96
 
 
97
expect_CSS_6 = r'''
 
98
div a{display:block}
 
99
'''
 
100
 
 
101
#----------------------------------------------------------------------------
 
102
 
 
103
CSS_7 = r'''
 
104
/* Holly hack to cure peek-a-boo IE 6 bug*/
 
105
/* Hides from IE5-mac \*/
 
106
* html #region-content {height: 1%;}
 
107
/* End hide from IE5-mac */
 
108
'''
 
109
 
 
110
expect_CSS_7 = r'''
 
111
/* Hides from IE5-mac \*/
 
112
* html #region-content{height:1%}/* End hide from IE5-mac */
 
113
'''
 
114
 
 
115
#----------------------------------------------------------------------------
 
116
 
 
117
HTML_1='''
 
118
<img src="a.gif" width="100" width="100" height='100' border=0>
 
119
<STYLE type="text/css">
 
120
div#main {
 
121
  font-family:Verdana,   "Courier New"      ;
 
122
}
 
123
</style>
 
124
<pre>
 
125
  Here
 
126
    width="100"
 
127
    
 
128
    
 
129
</pre>
 
130
'''
 
131
   
 
132
expect_HTML_1='''
 
133
<img src="a.gif" width="100" width="100" height='100' border=0><STYLE type="text/css">
 
134
div#main{font-family:Verdana,"Courier New"}</style><pre>
 
135
  Here
 
136
    width="100"
 
137
    
 
138
    
 
139
</pre>
 
140
'''
 
141
 
 
142
 
 
143
#----------------------------------------------------------------------------
 
144
 
 
145
HTML_2='''
 
146
<a   href="x"
 
147
 width="100%" border='0'>Pointless         extra
 
148
 
 
149
space</a>
 
150
 
 
151
<!-- one line comment -->
 
152
<!-- two line
 
153
comment -->
 
154
 
 
155
<script language="Javascript">
 
156
<!-- hide this
 
157
function foo() {
 
158
    alert("Hell");
 
159
}
 
160
//-->
 
161
</script>
 
162
 
 
163
'''
 
164
   
 
165
expect_HTML_2='''
 
166
<a href="x" width="100%" border='0'>Pointless         extra
 
167
 
 
168
space</a><!-- two line
 
169
comment --><script language="Javascript"><!--
 
170
function foo(){alert("Hell");}
 
171
//--></script>
 
172
'''
 
173
 
 
174
 
 
175
#----------------------------------------------------------------------------
 
176
 
 
177
HTML_3='''
 
178
<input       value="    OK    "    >
 
179
<img   alt='    hej   '    title="  Bajs  "  width=32  >
 
180
 
 
181
<a href="x" width="100%"     border=0>Pointless         extra
 
182
 
 
183
space</a>
 
184
<img src='blank.gif'
 
185
  border='0' height='32'  alt='' width='32'>
 
186
'''
 
187
   
 
188
expect_HTML_3='''
 
189
<input value="    OK    "><img alt='    hej   ' title="  Bajs  " width=32 ><a href="x" width="100%" border=0>Pointless         extra
 
190
 
 
191
space</a><img src='blank.gif' border='0' height='32' alt='' width='32'>
 
192
'''
 
193
 
 
194
#----------------------------------------------------------------------------
 
195
 
 
196
HTML_4='''<script>
 
197
if (isMozi) {
 
198
   slides = slideml.doc.getElementsByTagNameNS("http://www.oscom.org/2003/SlideML/1.0/","slide");
 
199
}
 
200
else {
 
201
   slides = slideml.doc.getElementsByTagName("s:slide");
 
202
}
 
203
</script>'''
 
204
 
 
205
expect_HTML_4 = '''<script>if(isMozi){slides=slideml.doc.getElementsByTagNameNS("http://www.oscom.org/2003/SlideML/1.0/","slide");}else{slides=slideml.doc.getElementsByTagName("s:slide");}
 
206
</script>'''
 
207
 
 
208
 
 
209
#----------------------------------------------------------------------------
 
210
 
 
211
HTML_5='''<img src="/p_/sp" width="2" height="1" alt="" />'''
 
212
 
 
213
expect_HTML_5='''<img src="/p_/sp" width="2" height="1" alt="" />'''
 
214
 
 
215
 
 
216
#----------------------------------------------------------------------------
 
217
 
 
218
HTML_6='''
 
219
<style type="text/css"><!--
 
220
div.commentinline {
 
221
  font-family:Arial, Verdana, sans-serif;
 
222
  border-top:1px solid #cccccc;
 
223
  padding:3px 4px 4px 4px;
 
224
  margin-top:10px;
 
225
  margin-bottom:10px;
 
226
  margin-left:15px; 
 
227
}
 
228
//--></style>       
 
229
'''
 
230
 
 
231
expect_HTML_6='''
 
232
<style type="text/css"><!--
 
233
div.commentinline{font-family:Arial,Verdana,sans-serif;border-top:1px solid #ccc;padding:3px 4px 4px 4px;margin-top:10px;margin-bottom:10px;margin-left:15px}
 
234
//--></style>'''
 
235
 
 
236
#----------------------------------------------------------------------------
 
237
 
 
238
JS_1='''
 
239
init = function() {
 
240
  foo();
 
241
  bar();
 
242
}
 
243
window.onload = init;
 
244
'''
 
245
 
 
246
expect_JS_1='''
 
247
init=function(){foo();bar();}
 
248
window.onload=init;
 
249
'''
 
250
 
 
251
#----------------------------------------------------------------------------
 
252
 
 
253
JS_2='''
 
254
function econvert(s) {
 
255
    s=s.replace(/%7E/g,'~');
 
256
    s=s.replace(/%28/g,'(');
 
257
    s=s.replace(/%29/g,')');
 
258
    s=s.replace(/%20/g,' ');
 
259
    s=s.replace(/_dot_| dot |_\._|\(\.\)/gi, '.');
 
260
    s=s.replace(/_at_|~at~/gi, '@');
 
261
    return s;
 
262
}
 
263
                        
 
264
function AEHit() {
 
265
  var ss = document.getElementsByTagName("span");
 
266
  for (i=0; i< ss.length; i++) 
 
267
    if (ss[i].className=="aeh") 
 
268
      ss[i].innerHTML = econvert(ss[i].innerHTML);
 
269
}  
 
270
'''
 
271
 
 
272
expect_JS_2='''
 
273
function econvert(s){s=s.replace(/%7E/g,'~');s=s.replace(/%28/g,'(');
 
274
s=s.replace(/%29/g,')');s=s.replace(/%20/g,' ');s=s.replace(/_dot_| dot |_\._|\(\.\)/gi, '.');s=s.replace(/_at_|~at~/gi, '@');return s;}
 
275
function AEHit(){var ss=document.getElementsByTagName("span");for (i=0;i< ss.length;i++)if(ss[i].className=="aeh") 
 
276
ss[i].innerHTML=econvert(ss[i].innerHTML);}
 
277
'''
 
278
 
 
279
 
 
280
#----------------------------------------------------------------------------
 
281
 
 
282
JS_3='''
 
283
var x = " ";
 
284
x +="nothing";
 
285
x+= "something";
 
286
x+="anything";
 
287
y  =  10;
 
288
y +=1;
 
289
y+= 1;
 
290
y+=1;
 
291
 
 
292
y +=15;
 
293
y+= 15;
 
294
y+=15;
 
295
'''
 
296
 
 
297
expect_JS_3='''
 
298
var x=" ";x+="nothing";x+="something";x+="anything";
 
299
y=10;y+=1;y+=1;y+=1;
 
300
y+=15;y+=15;y+=15;
 
301
'''
 
302
 
 
303
#----------------------------------------------------------------------------
 
304
 
 
305
JS_4 ='''
 
306
this.onLoad = true;
 
307
this.onLoaded = false;
 
308
var x = true;
 
309
'''
 
310
 
 
311
expect_JS_4 ='''
 
312
this.onLoad=true;this.onLoaded=false;var x=true;
 
313
'''
 
314
 
 
315
#----------------------------------------------------------------------------
 
316
 
 
317
JS_5 ='''
 
318
if (document.getElementById("someting")) {
 
319
  cool();
 
320
} else if (document.getElementById("elsething")) {
 
321
  wicked();
 
322
} else {
 
323
  poor();
 
324
}
 
325
'''
 
326
 
 
327
expect_JS_5 ='''
 
328
if(document.getElementById("someting")){cool();}else if(document.getElementById("elsething")){wicked();}else{poor();}
 
329
'''
 
330
 
 
331
#----------------------------------------------------------------------------
 
332
 
 
333
# function foo() { alert( "foo" ); }
 
334
JS_6 ='''
 
335
bar = function () { alert( "bar" ); }
 
336
bar2 = function() { alert( "bar2" ); }
 
337
'''
 
338
 
 
339
# function foo(){alert( "foo" );}
 
340
expect_JS_6 ='''
 
341
bar=function(){alert( "bar" );}
 
342
bar2=function(){alert( "bar2" );}
 
343
'''
 
344
 
 
345
#----------------------------------------------------------------------------
 
346
 
 
347
# testing local variables inside functions
 
348
JS_7 ='''
 
349
function foobar(x,y) {
 
350
  var element1 = document.getElementById('something');
 
351
  alert(element1);
 
352
}
 
353
'''
 
354
 
 
355
# function foo(){alert( "foo" );}
 
356
expect_JS_7 ='''
 
357
function foobar(x,y) {
 
358
  var e = document.getElementById('something');
 
359
  alert(e);
 
360
}  
 
361
'''
 
362
 
 
363
#----------------------------------------------------------------------------
 
364
 
 
365
# comments within the code
 
366
JS_8 ='''
 
367
function foobar(x,y) {
 
368
  var element1 = document.getElementById('something'); // alert(element1);
 
369
  alert(element1); // this can be removed
 
370
} // end of function;
 
371
'''
 
372
 
 
373
expect_JS_8 ='''
 
374
function foobar(x,y){var element1=document.getElementById('something');alert(element1);}
 
375
'''
 
376
 
 
377
 
 
378
#----------------------------------------------------------------------------
 
379
 
 
380
 
381
JS_9 ='''
 
382
function nodeContained(innernode, outernode){
 
383
    // check if innernode is contained in outernode
 
384
    var node = innernode.parentNode;
 
385
    while (node != document) {
 
386
        if (node == outernode) {
 
387
            return true; 
 
388
        }
 
389
        node=node.parentNode;
 
390
    }
 
391
    return false;
 
392
};
 
393
'''
 
394
 
 
395
expect_JS_9 ='''
 
396
function nodeContained(innernode,outernode){var node=innernode.parentNode;while(node!=document){if(node==outernode) {return true;}
 
397
node=node.parentNode;}
 
398
return false;};
 
399
 
 
400
'''
 
401
 
 
402
#----------------------------------------------------------------------------
 
403
 
 
404
 
405
JS_10 ='''
 
406
                        // Insert P element
 
407
                        if (tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && e.keyCode == 13 && !e.shiftKey) {
 
408
                                // Insert P element instead of BR
 
409
                                if (tinyMCE.selectedInstance._insertPara(e)) {
 
410
                                        // Cancel event
 
411
                                        tinyMCE.execCommand("mceAddUndoLevel");
 
412
                                        tinyMCE.cancelEvent(e);
 
413
                                        return false;
 
414
                                }
 
415
                        }
 
416
'''
 
417
 
 
418
expect_JS_10 ='''
 
419
if(tinyMCE.isGecko && tinyMCE.settings['force_p_newlines'] && e.keyCode == 13 && !e.shiftKey){if(tinyMCE.selectedInstance._insertPara(e)) {tinyMCE.execCommand("mceAddUndoLevel");tinyMCE.cancelEvent(e);
 
420
return false;}}
 
421
'''
 
422
 
 
423
JS_11 = '''
 
424
ajax = Class.create();
 
425
ajax.prototype = {
 
426
        initialize: function(url, options){
 
427
                this.transport = this.getTransport();
 
428
                this.postBody = options.postBody || '';
 
429
                this.method = options.method || 'post';
 
430
                this.onComplete = options.onComplete || null;
 
431
                this.update = $(options.update) || null;
 
432
                this.request(url);
 
433
        },
 
434
 
 
435
        request: function(url){
 
436
                this.transport.open(this.method, url, true);
 
437
                this.transport.onreadystatechange = this.onStateChange.bind(this);
 
438
                if (this.method == 'post') {
 
439
                        this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');
 
440
                        if (this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');
 
441
                }
 
442
                this.transport.send(this.postBody);
 
443
        },
 
444
 
 
445
        onStateChange: function(){
 
446
                if (this.transport.readyState == 4 && this.transport.status == 200) {
 
447
                        if (this.onComplete) 
 
448
                                setTimeout(function(){this.onComplete(this.transport);}.bind(this), 10);
 
449
                        if (this.update)
 
450
                                setTimeout(function(){this.update.innerHTML = this.transport.responseText;}.bind(this), 10);
 
451
                        this.transport.onreadystatechange = function(){};
 
452
                }
 
453
        },
 
454
 
 
455
        getTransport: function() {
 
456
                if (window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');
 
457
                else if (window.XMLHttpRequest) return new XMLHttpRequest();
 
458
                else return false;
 
459
        }
 
460
};
 
461
'''
 
462
 
 
463
expect_JS_11 ='''
 
464
ajax=Class.create();ajax.prototype = {initialize: function(url,options){this.transport=this.getTransport();this.postBody=options.postBody || '';this.method=options.method || 'post';this.onComplete=options.onComplete || null;this.update = $(options.update) || null;this.request(url);},
 
465
request: function(url){this.transport.open(this.method, url, true);this.transport.onreadystatechange=this.onStateChange.bind(this);if(this.method=='post'){this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');if(this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');}
 
466
this.transport.send(this.postBody);},
 
467
onStateChange: function(){if(this.transport.readyState == 4 && this.transport.status == 200) {if(this.onComplete) 
 
468
setTimeout(function(){this.onComplete(this.transport);}.bind(this),10);if(this.update)
 
469
setTimeout(function(){this.update.innerHTML=this.transport.responseText;}.bind(this),10);this.transport.onreadystatechange=function(){};}},
 
470
getTransport: function(){if(window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');else if(window.XMLHttpRequest) return new XMLHttpRequest();else return false;}};
 
471
'''
 
472
expect_JS_11_hardcore ='''
 
473
ajax=Class.create();ajax.prototype = {initialize: function(_0,_1){this.transport=this.getTransport();this.postBody=_1.postBody || '';this.method=_1.method || 'post';this.onComplete=_1.onComplete || null;this.update = $(_1.update) || null;this.request(_0);},
 
474
request: function(_0){this.transport.open(this.method, _0, true);this.transport.onreadystatechange=this.onStateChange.bind(this);if(this.method=='post'){this.transport.setRequestHeader('Content-type', 'application/x-www-form-urlencoded');if(this.transport.overrideMimeType) this.transport.setRequestHeader('Connection', 'close');}
 
475
this.transport.send(this.postBody);},
 
476
onStateChange: function(){if(this.transport.readyState == 4 && this.transport.status == 200) {if(this.onComplete) 
 
477
setTimeout(function(){this.onComplete(this.transport);}.bind(this),10);if(this.update)
 
478
setTimeout(function(){this.update.innerHTML=this.transport.responseText;}.bind(this),10);this.transport.onreadystatechange=function(){};}},
 
479
getTransport: function(){if(window.ActiveXObject) return new ActiveXObject('Microsoft.XMLHTTP');else if(window.XMLHttpRequest) return new XMLHttpRequest();else return false;}};
 
480
'''
 
481
 
 
482
#----------------------------------------------------------------------------
 
483
 
 
484
JS_12='''
 
485
function foo(documentnode, nodevalue) {
 
486
    return documentnode + nodevalue;
 
487
}
 
488
'''
 
489
 
 
490
expect_JS_12='''
 
491
function foo(documentnode,nodevalue){return documentnode + nodevalue;}
 
492
'''
 
493
expect_JS_12_hardcore='''
 
494
function foo(_0,_1){return _0 + _1;}
 
495
'''
 
496
 
 
497
#----------------------------------------------------------------------------
 
498
JS_13 = '''
 
499
addEvent(window, 'load', function(){
 
500
   var editlinks = getElementsByClass("edit", document, "img");
 
501
   for (var e in editlinks) {
 
502
      foo();
 
503
   }
 
504
});
 
505
'''
 
506
 
 
507
expect_JS_13 = '''
 
508
addEvent(window, 'load', function(){var editlinks=getElementsByClass("edit", document, "img");for(var e in editlinks){foo();}});
 
509
'''
 
 
b'\\ No newline at end of file'