Skip to content

Instantly share code, notes, and snippets.

@jimfleming
Created July 2, 2014 19:34
Show Gist options
  • Save jimfleming/f51b8d837e548c6e35da to your computer and use it in GitHub Desktop.
Save jimfleming/f51b8d837e548c6e35da to your computer and use it in GitHub Desktop.
diff --git a/tests/rewrite.js b/tests/rewrite.js
index e6c85a0..5a6db87 100644
--- a/tests/rewrite.js
+++ b/tests/rewrite.js
@@ -8,6 +8,33 @@ var libPath = process.env.JSFMT_COV ? 'lib-cov' : 'lib';
var jsfmt = require('../' + libPath + '/index');
describe('jsfmt.rewrite', function() {
+
+ it('should test multiline BlockStatement rewrite' ,function() {
+ var js = ['var x=true;', 'var y=false;',
+ 'x=1, y=2, z=3;',
+ 'function f() {', '}',
+ 'function g() {', '}',
+ 'if (x)', 'f();',
+ 'x || f();',
+ 'if (x) {', 'f();',
+ '} else {', 'g();',
+ '}'].join('\n');
+
+ var result = ['var x=true;', 'var y=false;',
+ 'x=1;',
+ 'y=2;',
+ 'z=3;',
+ 'function f() {', '}',
+ 'function g() {', '}',
+ 'if (x)', 'f();',
+ 'x || f();',
+ 'if (x) {', 'f();',
+ '} else {', 'g();',
+ '}'].join('\n');
+
+ jsfmt.rewrite(js, 'a,b,c; -> a;b;c;').toString().should.eql(result);
+ });
+
it('should test basic rewrite', function() {
jsfmt.rewrite('_.each(a, b)', '_.each(a, b) -> a.forEach(b)')
.toString().should.eql('a.forEach(b)');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment