mirror of
https://github.com/jashkenas/coffeescript.git
synced 2026-02-18 19:34:27 -05:00
node conversion finished, narwhal removed.
This commit is contained in:
24
test/fixtures/execution/test_existence.coffee
vendored
24
test/fixtures/execution/test_existence.coffee
vendored
@@ -1,8 +1,8 @@
|
||||
print(if my_special_variable? then false else true)
|
||||
puts(if my_special_variable? then false else true)
|
||||
|
||||
my_special_variable: false
|
||||
|
||||
print(if my_special_variable? then true else false)
|
||||
puts(if my_special_variable? then true else false)
|
||||
|
||||
|
||||
# Existential assignment.
|
||||
@@ -12,7 +12,7 @@ a: null
|
||||
a ?= 10
|
||||
b ?= 10
|
||||
|
||||
print a is 10 and b is 10
|
||||
puts a is 10 and b is 10
|
||||
|
||||
|
||||
# The existential operator.
|
||||
@@ -20,7 +20,7 @@ print a is 10 and b is 10
|
||||
z: null
|
||||
x: z ? "EX"
|
||||
|
||||
print z is null and x is "EX"
|
||||
puts z is null and x is "EX"
|
||||
|
||||
|
||||
# Only evaluate once.
|
||||
@@ -30,7 +30,7 @@ get_next_node: ->
|
||||
throw "up" if counter
|
||||
counter++
|
||||
|
||||
print(if get_next_node()? then true else false)
|
||||
puts(if get_next_node()? then true else false)
|
||||
|
||||
|
||||
# Existence chains, soaking up undefined properties:
|
||||
@@ -39,17 +39,17 @@ obj: {
|
||||
prop: "hello"
|
||||
}
|
||||
|
||||
print obj?.prop is "hello"
|
||||
puts obj?.prop is "hello"
|
||||
|
||||
print obj?.prop?.non?.existent?.property is undefined
|
||||
puts obj?.prop?.non?.existent?.property is undefined
|
||||
|
||||
|
||||
# Soaks and caches method calls as well.
|
||||
|
||||
arr: ["--", "----"]
|
||||
|
||||
print arr.pop()?.length is 4
|
||||
print arr.pop()?.length is 2
|
||||
print arr.pop()?.length is undefined
|
||||
print arr[0]?.length is undefined
|
||||
print arr.pop()?.length?.non?.existent()?.property is undefined
|
||||
puts arr.pop()?.length is 4
|
||||
puts arr.pop()?.length is 2
|
||||
puts arr.pop()?.length is undefined
|
||||
puts arr[0]?.length is undefined
|
||||
puts arr.pop()?.length?.non?.existent()?.property is undefined
|
||||
|
||||
Reference in New Issue
Block a user