blob: 27fc273b7a3dc48cce13122367a1c0f5fcf6a23f (
plain)
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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
/*
Please use git log for copyright holder and year information
This file is part of libbash.
libbash is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
(at your option) any later version.
libbash is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with libbash. If not, see <http://www.gnu.org/licenses/>.
*/
gunit java_libbash;
variable_reference:
"$asdf" -> (VAR_REF asdf)
"${asdf}" -> (VAR_REF asdf)
"${asdf:-foo}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING foo)))
"${asdf:-=}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING =)))
"${asdf:+=}" -> (VAR_REF (USE_ALTERNATE_WHEN_UNSET_OR_NULL asdf (STRING =)))
"${asdf:==}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING =)))
"${asdf:-public_html}" -> (VAR_REF (USE_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING public_html)))
"${asdf='foo'}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET asdf (STRING 'foo')))
"${asdf:=}" -> (VAR_REF (ASSIGN_DEFAULT_WHEN_UNSET_OR_NULL asdf (STRING EMPTY_EXPANSION_VALUE)))
"${bar:7}" -> (VAR_REF (OFFSET bar 7))
"${bar: -10}" -> (VAR_REF (OFFSET bar (MINUS_SIGN 10)))
"${bar:(-10 + 5)}" -> (VAR_REF (OFFSET bar (+ (MINUS_SIGN 10) 5)))
"${foo:5:2}" -> (VAR_REF (OFFSET foo 5 2))
"${foo::2}" -> (VAR_REF (OFFSET foo 0 2))
"${foo:$((5)):$((2))}" -> (VAR_REF (OFFSET foo 5 2))
"${!asdf*}" -> (VAR_REF (! asdf *))
"${!asdf@}" -> (VAR_REF (! asdf @))
"${!asdf[*]}" -> (VAR_REF (LIST_EXPAND asdf *))
"${!asdf[@]}" -> (VAR_REF (LIST_EXPAND asdf @))
"${#foo}" -> (VAR_REF (# foo))
"${foo#bar}" -> (VAR_REF (LAZY_REMOVE_AT_START foo (STRING bar)))
"${fo*o#bar}" FAIL
"${fo@o#bar}" FAIL
"${foo##bar}" -> (VAR_REF (REPLACE_AT_START foo (STRING bar)))
"${foo%bar}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING bar)))
"${foo%%bar}" -> (VAR_REF (REPLACE_AT_END foo (STRING bar)))
"${foo%; *}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING ; MATCH_ALL)))
"${foo%/}" -> (VAR_REF (LAZY_REMOVE_AT_END foo (STRING /)))
"${1%& <><<;
();&&|<<<<<()*}" -> (VAR_REF (LAZY_REMOVE_AT_END 1 (STRING & < > << ;
( ) ; && | <<< << ( ) MATCH_ALL)))
"${this/is/pattern}"->(VAR_REF (REPLACE_FIRST this (STRING is) (STRING pattern)))
//Test positional/special parameters
"$1" -> (VAR_REF 1)
"$@" -> (VAR_REF @)
"$*" -> (VAR_REF *)
"${@}" -> (VAR_REF @)
"${#}" -> (VAR_REF #)
"$#" -> (VAR_REF #)
"${!foo}" -> (VAR_REF (VAR_REF foo))
"${!#}" -> (VAR_REF (VAR_REF #))
"${3}" -> (VAR_REF 3)
"$?" -> (VAR_REF ?)
"$_" -> (VAR_REF _)
"${_}" -> (VAR_REF _)
"$$" -> (VAR_REF $)
"${$}" -> (VAR_REF $)
"${PV//./_}" -> (VAR_REF (REPLACE_ALL PV (STRING .) (STRING _)))
"${PV// }" -> (VAR_REF (REPLACE_ALL PV (STRING )))
"${PV//[-._]/}" -> (VAR_REF (REPLACE_ALL PV (STRING (MATCH_ANY - . _)) (STRING EMPTY_EXPANSION_VALUE)))
"${PV/${pattern}/${replace}}" -> (VAR_REF (REPLACE_FIRST PV (STRING (VAR_REF pattern)) (STRING $ { replace })))
"${PV/#foo/bar}" -> (VAR_REF (REPLACE_AT_START PV (STRING foo) (STRING bar)))
"${PV/%foo/bar}" -> (VAR_REF (REPLACE_AT_END PV (STRING foo) (STRING bar)))
"${PN/%spaces /more }" -> (VAR_REF (REPLACE_AT_END PN (STRING spaces ) (STRING more )))
"${PN/wrong#/#correct}" -> (VAR_REF (REPLACE_FIRST PN (STRING wrong #) (STRING # correct)))
"${a/b/\}c}" -> (VAR_REF (REPLACE_FIRST a (STRING b) (STRING \ } c)))
"${a/b/a\}c}" -> (VAR_REF (REPLACE_FIRST a (STRING b) (STRING a \ } c)))
"${#var}" -> (VAR_REF (# var))
"${#var[@]}" -> (VAR_REF (# (var ARRAY_SIZE)))
"${#var[*]}" -> (VAR_REF (# (var ARRAY_SIZE)))
"${#@}" -> (VAR_REF (# @))
"${#*}" -> (VAR_REF (# *))
"${##}" -> (VAR_REF (# #))
"${#$}" -> (VAR_REF (# $))
variable_definition_atom:
"MY_PN=${PN/asterisk-}" -> (= MY_PN (STRING (VAR_REF (REPLACE_FIRST PN (STRING asterisk -)))))
"MY_PN=1abc" -> (= MY_PN (STRING 1 abc))
|