mirror of
https://github.com/jimeh/dotify.git
synced 2026-02-19 10:06:39 +00:00
Add tests for has-argument and parse-argument functions
This commit is contained in:
51
test/lib/arguments-test.sh
Executable file
51
test/lib/arguments-test.sh
Executable file
@@ -0,0 +1,51 @@
|
||||
#! /usr/bin/env bash
|
||||
source "../assert.sh"
|
||||
|
||||
source "../../src/lib/arguments.sh"
|
||||
|
||||
|
||||
#
|
||||
# has-argument()
|
||||
#
|
||||
|
||||
# Returns 1 when it does not have argument.
|
||||
assert_raises 'has-argument help h -v -f --debug' 1
|
||||
|
||||
# Returns 0 when any form of the argument is present.
|
||||
assert_raises 'has-argument help h -v --help' 0
|
||||
assert_raises 'has-argument help h -v --help=wtf' 0
|
||||
assert_raises 'has-argument help h -v -h' 0
|
||||
assert_raises 'has-argument help h -v -h=wtf' 0
|
||||
|
||||
assert_end "has-argument()"
|
||||
|
||||
|
||||
#
|
||||
# parse-argument()
|
||||
#
|
||||
|
||||
# Echos nothing and returns 1 when argument is not present.
|
||||
assert 'parse-argument file f -v --debug' ""
|
||||
assert_raises 'parse-argument file f -v --debug' 1
|
||||
|
||||
# echos value of argument and returns 0 when any form of argument is present.
|
||||
assert 'parse-argument file f -v --file foo/bar.txt' "foo/bar.txt"
|
||||
assert_raises 'parse-argument file f -v --file foo/bar.txt' 0
|
||||
assert 'parse-argument file f -v --file=foo/bar.txt' "foo/bar.txt"
|
||||
assert_raises 'parse-argument file f -v --file=foo/bar.txt' 0
|
||||
assert 'parse-argument file f -v -f foo/bar.txt' "foo/bar.txt"
|
||||
assert_raises 'parse-argument file f -v -f foo/bar.txt' 0
|
||||
assert 'parse-argument file f -v -f=foo/bar.txt' "foo/bar.txt"
|
||||
assert_raises 'parse-argument file f -v -f=foo/bar.txt' 0
|
||||
|
||||
# Value with a space.
|
||||
assert 'parse-argument file f -v --file foo\ bar.txt' "foo bar.txt"
|
||||
assert 'parse-argument file f -v --file "foo bar.txt"' "foo bar.txt"
|
||||
assert "parse-argument file f -v --file 'foo bar.txt'" "foo bar.txt"
|
||||
|
||||
assert 'parse-argument file f -v --file=foo\ bar.txt' "foo bar.txt"
|
||||
assert 'parse-argument file f -v --file="foo bar.txt"' "foo bar.txt"
|
||||
assert "parse-argument file f -v --file='foo bar.txt'" "foo bar.txt"
|
||||
|
||||
|
||||
assert_end "parse-argument()"
|
||||
Reference in New Issue
Block a user