From 1cc85aad649206fa3589d0add0cb8f2afb0cce4a Mon Sep 17 00:00:00 2001 From: Trevor Burnham Date: Sun, 4 Sep 2011 13:57:09 -0400 Subject: [PATCH] Adding tests for CoffeeScript.eval --- test/eval.coffee | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 test/eval.coffee diff --git a/test/eval.coffee b/test/eval.coffee new file mode 100644 index 00000000..80dec4c5 --- /dev/null +++ b/test/eval.coffee @@ -0,0 +1,29 @@ +{Script} = require 'vm' + +test "CoffeeScript.eval runs in the global context by default", -> + global.punctuation = '!' + code = ''' + global.fhqwhgads = "global superpower#{global.punctuation}" + ''' + result = CoffeeScript.eval code + eq result, 'global superpower!' + eq fhqwhgads, 'global superpower!' + +test "CoffeeScript.eval can run in, and modify, a Script context sandbox", -> + sandbox = Script.createContext() + sandbox.foo = 'bar' + code = ''' + global.foo = 'not bar!' + ''' + result = CoffeeScript.eval code, {sandbox} + eq result, 'not bar!' + eq sandbox.foo, 'not bar!' + +test "CoffeeScript.eval can run in, but cannot modify, an ordinary object sandbox", -> + sandbox = {foo: 'bar'} + code = ''' + global.foo = 'not bar!' + ''' + result = CoffeeScript.eval code, {sandbox} + eq result, 'not bar!' + eq sandbox.foo, 'bar' \ No newline at end of file