From a768f167cfaee16249fe0683e699277e10e79444 Mon Sep 17 00:00:00 2001 From: Jeremy Banks Date: Mon, 3 Oct 2011 21:57:33 -0400 Subject: [PATCH] Improved tests for #1627. --- test/assignment.coffee | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/test/assignment.coffee b/test/assignment.coffee index 5e9cf382..ce16ce4b 100644 --- a/test/assignment.coffee +++ b/test/assignment.coffee @@ -277,17 +277,21 @@ test "existential assignment", -> eq nonce, c test "#1627: prohibit conditional assignment of undefined variables", -> - nonce = {} + throws (-> CoffeeScript.compile "x ?= 10"), null, "prohibit (x ?= 10)" + throws (-> CoffeeScript.compile "x ||= 10"), null, "prohibit (x ||= 10)" + throws (-> CoffeeScript.compile "x or= 10"), null, "prohibit (x or= 10)" + throws (-> CoffeeScript.compile "do -> x ?= 10"), null, "prohibit (do -> x ?= 10)" + throws (-> CoffeeScript.compile "do -> x ||= 10"), null, "prohibit (do -> x ||= 10)" + throws (-> CoffeeScript.compile "do -> x or= 10"), null, "prohibit (do -> x or= 10)" + doesNotThrow (-> CoffeeScript.compile "x = null; x ?= 10"), "allow (x = null; x ?= 10)" + doesNotThrow (-> CoffeeScript.compile "x = null; x ||= 10"), "allow (x = null; x ||= 10)" + doesNotThrow (-> CoffeeScript.compile "x = null; x or= 10"), "allow (x = null; x or= 10)" + doesNotThrow (-> CoffeeScript.compile "x = null; do -> x ?= 10"), "allow (x = null; do -> x ?= 10)" + doesNotThrow (-> CoffeeScript.compile "x = null; do -> x ||= 10"), "allow (x = null; do -> x ||= 10)" + doesNotThrow (-> CoffeeScript.compile "x = null; do -> x or= 10"), "allow (x = null; do -> x or= 10)" - eq nonce, (try CoffeeScript.compile "x ?= 10"; false catch e then nonce), "prohibit (x ?= 10)" - eq nonce, (try CoffeeScript.compile("x = null; x ?= 10"); nonce), "allow (x = null; x ?= 10)" - eq nonce, (try CoffeeScript.compile("x = null; (-> x ?= 10)()"); nonce), "allow (x = null; (-> x ?= 10)())" - eq nonce, (try CoffeeScript.compile "x ||= 10"; false catch e then nonce), "prohibit (x ||= 10)" - eq nonce, (try CoffeeScript.compile("x = null; x ||= 10"); nonce), "allow (x = null; x ||= 10)" - eq nonce, (try CoffeeScript.compile("x = null; (-> x ||= 10)()"); nonce), "allow (x = null; (-> x ||= 10)())" - eq nonce, (try CoffeeScript.compile "x or= 10"; false catch e then nonce), "prohibit (x or= 10)" - eq nonce, (try CoffeeScript.compile("x = null; x or= 10"); nonce), "allow (x = null; x or= 10)" - eq nonce, (try CoffeeScript.compile("x = null; (-> x or= 10)()"); nonce), "allow (x = null; (-> x or= 10)())" + throws (-> CoffeeScript.compile "-> -> -> x ?= 10"), null, "prohibit (-> -> -> x ?= 10)" + doesNotThrow (-> CoffeeScript.compile "x = null; -> -> -> x ?= 10"), "allow (x = null; -> -> -> x ?= 10)" test "#1348, #1216: existential assignment compilation", -> nonce = {}