separated rmtrail function into its own tool and added test
parent
3ffb150207
commit
8b8c7e8533
|
@ -0,0 +1,54 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Copyright (C) 2010 Mike Gerwitz
|
||||
#
|
||||
# This file is part of ease.js.
|
||||
#
|
||||
# ease.js is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU Lesser General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program 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 Lesser General Public License
|
||||
# for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# #
|
||||
|
||||
PATH_TOOLS=$( dirname "$0" )/../tools
|
||||
|
||||
# string to remove trailing commas from
|
||||
TEST_DATA=$( echo '[a,b,]{a,b,}[
|
||||
a,
|
||||
b,
|
||||
]{
|
||||
a,
|
||||
b,
|
||||
}' \
|
||||
| $PATH_TOOLS/rmtrail
|
||||
)
|
||||
|
||||
# expected result
|
||||
TEST_CMP='[a,b]{a,b}[
|
||||
a,
|
||||
b
|
||||
]{
|
||||
a,
|
||||
b
|
||||
}'
|
||||
|
||||
# perform the assertion
|
||||
if [ ! "$TEST_DATA" == "$TEST_CMP" ]; then
|
||||
echo "rmtrail failed"
|
||||
echo "< expected"
|
||||
echo "> given"
|
||||
|
||||
diff <( echo "$TEST_CMP" ) <( echo "$TEST_DATA" )
|
||||
exit 1
|
||||
fi
|
||||
|
||||
exit 0
|
||||
|
|
@ -23,6 +23,7 @@ PATH_LIB="$PATH_TOOLS/../lib"
|
|||
MODULE_EXT='js'
|
||||
TPL_PATH="$PATH_TOOLS/combine.tpl"
|
||||
TPL_VAR='/**{CONTENT}**/'
|
||||
RMTRAIL="$PATH_TOOLS/rmtrail"
|
||||
|
||||
# order matters
|
||||
CAT_MODULES="util class interface"
|
||||
|
@ -60,38 +61,6 @@ tpl_footer()
|
|||
}"
|
||||
}
|
||||
|
||||
##
|
||||
# Removes trailing commas from array and object declarations (certain browsers,
|
||||
# such as earlier versions of IE, do not parse trailing commas correctly)
|
||||
#
|
||||
# This is a very simple (dumb) system. It does not check to ensure we're not
|
||||
# replacing text inside a string, nor is it 100% certain we're in an array or
|
||||
# object declaration. However, until such an implementation is needed, I'd like
|
||||
# to keep it as simple (and fast) as possible. The below implementation is
|
||||
# suitable for our needs.
|
||||
##
|
||||
rmtrail()
|
||||
{
|
||||
cat - \
|
||||
| sed -n '
|
||||
# copy first line to hold buffer
|
||||
1h
|
||||
|
||||
# if not the first line, append to hold buffer
|
||||
1!H
|
||||
|
||||
# if last line, process
|
||||
$ {
|
||||
# pull from hold and perform replacement
|
||||
g
|
||||
s/,\(\s*[]}]\)/\1/g
|
||||
|
||||
# print result
|
||||
p
|
||||
}
|
||||
'
|
||||
}
|
||||
|
||||
# ensure we can locate our template (should be in the /tools dir)
|
||||
if [ ! -f "$TPL_PATH" ]; then
|
||||
echo "Error: combine.tpl not found ($TPL_PATH)"
|
||||
|
@ -117,7 +86,7 @@ for module in $CAT_MODULES; do
|
|||
echo "{"
|
||||
|
||||
# add the module, removing trailing commas
|
||||
cat $filename | rmtrail
|
||||
cat $filename | $RMTRAIL
|
||||
|
||||
echo "} )( exports['$module'] = {} );"
|
||||
done
|
||||
|
|
|
@ -0,0 +1,51 @@
|
|||
#!/bin/bash
|
||||
#
|
||||
# Removes trailing commas from array and object declarations (certain browsers,
|
||||
# such as earlier versions of IE, do not parse trailing commas correctly)
|
||||
#
|
||||
# This is a very simple (dumb) system. It does not check to ensure we're not
|
||||
# replacing text inside a string, nor is it 100% certain we're in an array or
|
||||
# object declaration. However, until such an implementation is needed, I'd like
|
||||
# to keep it as simple (and fast) as possible. The below implementation is
|
||||
# suitable for our needs.
|
||||
#
|
||||
# Copyright (C) 2010 Mike Gerwitz
|
||||
#
|
||||
# This file is part of ease.js.
|
||||
#
|
||||
# ease.js is free software: you can redistribute it and/or modify it under the
|
||||
# terms of the GNU Lesser General Public License as published by the Free
|
||||
# Software Foundation, either version 3 of the License, or (at your option)
|
||||
# any later version.
|
||||
#
|
||||
# This program 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 Lesser General Public License
|
||||
# for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU Lesser General Public License
|
||||
# along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
# #
|
||||
|
||||
# read from stdin
|
||||
cat - \
|
||||
| sed -n '
|
||||
# copy first line to hold buffer
|
||||
1h
|
||||
|
||||
# if not the first line, append to hold buffer
|
||||
1!H
|
||||
|
||||
# if last line, process
|
||||
$ {
|
||||
# pull from hold and perform replacement
|
||||
g
|
||||
s/,\(\s*[]}]\)/\1/g
|
||||
|
||||
# print result
|
||||
p
|
||||
}
|
||||
'
|
||||
|
||||
exit 0
|
||||
|
Loading…
Reference in New Issue