#!/bin/sh
#
# Test cases for nedit syntax highlighting.
# All these contructs are syntactically correct bash.
# So far it's only a bug list, not a complete test suite.
#
# Released under the same license as NEdit itself.
#
# Volker Kuhlmann
#   31 Dec 2003
#   13 Jan 2004


# Case 1a
# nedit 5.4, builtin sh patterns
# Bug 1:
# The matching backtick isn't found, causing massive highlighting corruption
# for possibly pages full of text.
# Bug 2:
# A backtick inside a comment is taken as an active one.
# (Bug 2 can be used as damage control for bug 1.)
arg="`for n in \"$@\"; do printf \"%s\n\" \"$n\"; done \
    | sed -e 's,[][(){}<>         \`\"'\''|\\?\!$&*~;^#],\\\&,g' \
    | tr '\\n' ' '`"
#` # this commented-out backtick makes nedit's syntax highlighting happy

# Case 1b
arg=`for n in \"$@\"; do printf \"%s\n\" \"$n\"; done \
    | sed -e 's,[][(){}<>         \`\"'\''|\\?\!$&*~;^#],\\\&,g' \
    | tr '\\n' ' '`
#` # this commented-out backtick makes nedit's syntax highlighting happy

# Case 1c
arg=(`for n in \"$@\"; do printf \"%s\n\" \"$n\"; done \
    | sed -e 's,[][(){}<>         \`\"'\''|\\?\!$&*~;^#],\\\&,g' \
    | tr '\\n' ' '`)
#` # this commented-out backtick makes nedit's syntax highlighting happy


# Case 2
# nedit 5.4, builtin sh patterns
# Bug 1:
# Quoting around $var has wrong colours
# Bug 2:
# The doublequotes are messed up badly in the $(..) case
# Bug 3:
# The 2 echos have different colour
var="A B C"
arg="`echo \""$var"\"; echo xyz`"
#` # this commented-out backtick makes nedit's syntax highlighting happy
arg="$(echo \""$var"\"; echo xyz)"
#" # this commented-out doublequote makes nedit's syntax highlighting happy


# Case 3
# nedit 5.4, builtin sh patterns
# Bug 1:
# The first ";;" have different colour
case "$arg" in
    debug|d)
    	debug=1; shift;;
    aaa)
    	shift ;;
    imgmask)
	checkarg2 "$@"; IMGMASK="$2"; shift 2;;
esac


# Case 4
# Massive highlighting corruption by not recognising matching backticks.
    killall()
    {
	# NB: ps ax should give an error on System V, so we try it first!
	pid="`ps ax 2>/dev/null | $AWK \"\
		/[\/ (]$2[ )]/	{print \\$1;}
		/[\/ ]$2\$/	{print \\$1;}\"`"
	if test -z "$pid"; then
            local bn=`basename $2`
	    pid="`ps -e 2>/dev/null | $AWK \"/ $bn[ ]*\$/ {print \\$1;}\"`"
        fi
	test "$pid" && kill $1 $pid; return
    }
#` this comments prevents the backtick highlighting bug from spreading past
# here





exit $?
Should be implemented when time permits:

From: Thorsten Haude, yoo  vranx.de
Subject: Re: Bugs in sh patterns
Date: Thu, 1 Jan 2004 22:34:14 +0100
To: discuss@nedit.org

Well, since you already put some work in the error demonstration
files, why not write them in a way so that they are this initial file?
For example, you write:
- - - Schnipp - - -
# Bug 1:
# The matching backtick isn't found, causing massive highlighting corruption
# for possibly pages full of text.
arg="`for n in \"$@\"; do printf \"%s\n\" \"$n\"; done \
    | sed -e 's,[][(){}<>	  \`\"'\''|\\?\!$&*~;^#],\\\&,g' \
    | tr '\\n' ' '`"
- - - Schnapp - - -

This could be written as:
- - - Schnipp - - -
#   Test case #1: Double quotes within doublequoted backticks
#   The initial 'arg=' must be of type 'assignment'
#   First and last double quote must be of type 'double quoted string'.
#   The '\"' combos must be of type 'dq command sub escape'
#   The rest must be of type 'dq command sub'
arg="`echo \"Hallo World\"`"
- - - Schnapp - - -

Written in this way, it serves as both a specification and a test,
done visually by the user.
