Sha256: 2f51cc0824ad443bfa6f415509151ca046e24e409b259d57f101576bf3a6004e

Contents?: true

Size: 1.31 KB

Versions: 10

Compression:

Stored size: 1.31 KB

Contents

# Option Parser
# -------------

# TODO: refactor option parser tests

# Ensure that the OptionParser handles arguments correctly.
return unless require?
{OptionParser} = require './../lib/coffee-script/optparse'

opt = new OptionParser [
  ['-r', '--required [DIR]',  'desc required']
  ['-o', '--optional',        'desc optional']
  ['-l', '--list [FILES*]',   'desc list']
]

test "basic arguments", ->
  args = ['one', 'two', 'three', '-r', 'dir']
  result = opt.parse args
  arrayEq args, result.arguments
  eq undefined, result.required

test "boolean and parameterised options", ->
  result = opt.parse ['--optional', '-r', 'folder', 'one', 'two']
  ok result.optional
  eq 'folder', result.required
  arrayEq ['one', 'two'], result.arguments

test "list options", ->
  result = opt.parse ['-l', 'one.txt', '-l', 'two.txt', 'three']
  arrayEq ['one.txt', 'two.txt'], result.list
  arrayEq ['three'], result.arguments

test "-- and interesting combinations", ->
  result = opt.parse ['-o','-r','a','-r','b','-o','--','-a','b','--c','d']
  arrayEq ['-a', 'b', '--c', 'd'], result.arguments
  ok result.optional
  eq 'b', result.required

  args = ['--','-o','a','-r','c','-o','--','-a','arg0','-b','arg1']
  result = opt.parse args
  eq undefined, result.optional
  eq undefined, result.required
  arrayEq args[1..], result.arguments

Version data entries

10 entries across 10 versions & 1 rubygems

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