File: disect_argument_spec.lua

package info (click to toggle)
lua-cliargs 3.0.2-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 388 kB
  • sloc: sh: 118; javascript: 14; makefile: 5
file content (37 lines) | stat: -rw-r--r-- 1,338 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
dofile("spec/spec_helper.lua")
local disect_argument = require('cliargs.utils.disect_argument')

describe("utils::disect_argument", function()
  local function assert_disect(pattern, expected)
    it("works with '" .. pattern .. "'", function()
      local symbol, key, value, negated = disect_argument(pattern)

      assert.equal(symbol, expected[1])
      assert.equal(key, expected[2])
      assert.equal(value, expected[3])
      assert.equal(negated, expected[4])
    end)
  end

  -- flags
  assert_disect("", { nil, nil, nil, false })
  assert_disect("-q", { '-', 'q', nil, false })
  assert_disect("--quiet", { '--', 'quiet', nil, false })

  -- -- -- -- flag negation
  assert_disect("--no-quiet", { '--', 'quiet', nil, true })
  assert_disect("--no-q", { '--', 'q', nil, true })

  -- -- options
  assert_disect("-v=VALUE", { '-', 'v', 'VALUE', false })
  assert_disect("--value=VALUE", { '--', 'value', 'VALUE', false })
  assert_disect('--value=with whitespace', { '--', 'value', 'with whitespace', false })

  -- -- end-of-options indicator
  assert_disect('--', { '--', nil, nil, false })

  -- -- values
  assert_disect('value', { nil, nil, 'value', false })
  assert_disect('/path/to/something', { nil, nil, '/path/to/something', false })
  assert_disect('oops-look-at--me', { nil, nil, 'oops-look-at--me', false })
end)