Sha256: 3eda4ce3f57ddda6e87015be1e6cc1f6ab88231581d78242e91f59b7f954ff70

Contents?: true

Size: 1.37 KB

Versions: 10

Compression:

Stored size: 1.37 KB

Contents

# Array Literals
# --------------

# * Array Literals
# * Splats in Array Literals

# TODO: add indexing and method invocation tests: [1][0] is 1, [].toString()

test "trailing commas", ->
  trailingComma = [1, 2, 3,]
  ok (trailingComma[0] is 1) and (trailingComma[2] is 3) and (trailingComma.length is 3)

  trailingComma = [
    1, 2, 3,
    4, 5, 6
    7, 8, 9,
  ]
  (sum = (sum or 0) + n) for n in trailingComma

  a = [((x) -> x), ((x) -> x * x)]
  ok a.length is 2

test "incorrect indentation without commas", ->
  result = [['a']
   {b: 'c'}]
  ok result[0][0] is 'a'
  ok result[1]['b'] is 'c'


# Splats in Array Literals

test "array splat expansions with assignments", ->
  nums = [1, 2, 3]
  list = [a = 0, nums..., b = 4]
  eq 0, a
  eq 4, b
  arrayEq [0,1,2,3,4], list


test "mixed shorthand objects in array lists", ->

  arr = [
    a:1
    'b'
    c:1
  ]
  ok arr.length is 3
  ok arr[2].c is 1

  arr = [b: 1, a: 2, 100]
  eq arr[1], 100

  arr = [a:0, b:1, (1 + 1)]
  eq arr[1], 2

  arr = [a:1, 'a', b:1, 'b']
  eq arr.length, 4
  eq arr[2].b, 1
  eq arr[3], 'b'


test "array splats with nested arrays", ->
  nonce = {}
  a = [nonce]
  list = [1, 2, a...]
  eq list[0], 1
  eq list[2], nonce

  a = [[nonce]]
  list = [1, 2, a...]
  arrayEq list, [1, 2, [nonce]]

test "#1274: `[] = a()` compiles to `false` instead of `a()`", ->
  a = false
  fn = -> a = true
  [] = fn()
  ok a

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
guard-mthaml-0.4.0 vendor/coffeescript/coffeescript/tests/cases/arrays.coffee
guard-mthaml-0.3.1 vendor/coffeescript/coffeescript/tests/cases/arrays.coffee
guard-mthaml-0.3.0 vendor/coffeescript/coffeescript/tests/cases/arrays.coffee
guard-mthaml-0.2.5 vendor/coffeescript/coffeescript/tests/cases/arrays.coffee
guard-mthaml-0.2.4 vendor/coffeescript/coffeescript/tests/cases/arrays.coffee
guard-mthaml-0.2.3 vendor/coffeescript/coffeescript/tests/cases/arrays.coffee
guard-mthaml-0.2.2 vendor/coffeescript/coffeescript/tests/cases/arrays.coffee
guard-mthaml-0.2.1 vendor/coffeescript/coffeescript/tests/cases/arrays.coffee
guard-mthaml-0.2.0 vendor/coffeescript/coffeescript/tests/cases/arrays.coffee
guard-mthaml-0.1.0 vendor/coffeescript/coffeescript/tests/cases/arrays.coffee