Skip to content

Commit

Permalink
Create test-packer.py
Browse files Browse the repository at this point in the history
test packer part of python jsbeautifier
  • Loading branch information
swan46 committed Apr 23, 2018
1 parent df72b52 commit 63013ff
Showing 1 changed file with 31 additions and 0 deletions.
31 changes: 31 additions & 0 deletions python/jsbeautifier/tests/test-packer.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
import sys
import jsbeautifier

opts = jsbeautifier.default_options()
opts.eol = "\n"
global fails
fails = 0


def test_str(str, expected):
global fails;
res = jsbeautifier.beautify(str,opts)
if(res == expected):
print "."
return True;
else:
print "___got:" + res + "\n___expected:" + expected +"\n"
fails = fails + 1
return False;

str = "eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('2 0=\"4 3!\";2 1=0.5(/b/6);a.9(\"8\").7=1;',12,12,'str|n|var|W3Schools|Visit|search|i|innerHTML|demo|getElementById|document|w3Schools'.split('|'),0,{}))"
expected = "var str = \"Visit W3Schools!\";\nvar n = str.search(/w3Schools/i);\ndocument.getElementById(\"demo\").innerHTML = n;"

res = test_str(str, expected)

str = "a=b;\r\nwhile(1){\ng=h;{return'\\w+'};break;eval(function(p,a,c,k,e,d){e=function(c){return c.toString(36)};if(!''.replace(/^/,String)){while(c--){d[c.toString(a)]=k[c]||c.toString(a)}k=[function(e){return d[e]}];e=function(){return'\\w+'};c=1};while(c--){if(k[c]){p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c])}}return p}('$(5).4(3(){$(\'.1\').0(2);$(\'.6\').0(d);$(\'.7\').0(b);$(\'.a\').0(8);$(\'.9\').0(c)});',14,14,'html|r5e57|8080|function|ready|document|r1655|rc15b|8888|r39b0|r6ae9|3128|65309|80'.split('|'),0,{}))c=abx;"
expected = "a = b;\nwhile (1) {\n g = h; {\n return '\w+'\n };\n break;\n $(document).ready(function() {\n $('.r5e57').html(8080);\n $('.r1655').html(80);\n $('.rc15b').html(3128);\n $('.r6ae9').html(8888);\n $('.r39b0').html(65309)\n });\n c = abx;"

res = test_str(str, expected)
if (fails == 0):
print "OK"

0 comments on commit 63013ff

Please sign in to comment.