From: <cr...@us...> - 2009-02-02 12:22:02
|
Revision: 4980 http://jnode.svn.sourceforge.net/jnode/?rev=4980&view=rev Author: crawley Date: 2009-02-02 11:53:36 +0000 (Mon, 02 Feb 2009) Log Message: ----------- Implement ${param=word} and ${param:=word} Modified Paths: -------------- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml Modified: trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java =================================================================== --- trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-02-02 11:00:56 UTC (rev 4979) +++ trunk/shell/src/shell/org/jnode/shell/bjorne/BjorneContext.java 2009-02-02 11:53:36 UTC (rev 4980) @@ -729,9 +729,6 @@ break; } // Extract the word - if (i >= sb.length()) { - throw new ShellSyntaxException("bad substitution"); - } word = sb.substring(i); } String value = variable(parameter); @@ -760,6 +757,20 @@ } else { return value; } + case EQUALS: + if (value == null) { + setVariable(parameter, word); + return word; + } else { + return value; + } + case COLONEQUALS: + if (value == null || value.length() == 0) { + setVariable(parameter, word); + return word; + } else { + return value; + } default: throw new ShellFailureException("not implemented"); } Modified: trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml =================================================================== --- trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-02-02 11:00:56 UTC (rev 4979) +++ trunk/shell/src/test/org/jnode/test/shell/bjorne/bjorne-shell-tests.xml 2009-02-02 11:53:36 UTC (rev 4980) @@ -157,6 +157,12 @@ echo A - dog is ${A-dog} echo B - dog is ${B-dog} echo X - dog is ${X-dog} + echo A :- null is ${A:-} + echo B :- null is ${B:-} + echo X :- null is ${X:-} + echo A - null is ${A-} + echo B - null is ${B-} + echo X - null is ${X-} </script> <output>A is cat A is cat @@ -173,6 +179,12 @@ A - dog is cat B - dog is X - dog is dog +A :- null is cat +B :- null is +X :- null is +A - null is cat +B - null is +X - null is </output> <rc>0</rc> </testSpec> @@ -227,4 +239,101 @@ </error> <rc>1</rc> </testSpec> + <testSpec> + <title>${..?..} expansions #4</title> + <command>test</command> + <runMode>AS_SCRIPT</runMode> + <script>#!bjorne + A=cat + B= + echo A :? null is ${A:?} + echo B :? null is ${B:?} + echo X :? null is ${X:?} + </script> + <output>A :? null is cat +</output> + <error>B is unset or null +</error> + <rc>1</rc> + </testSpec> + <testSpec> + <title>${..?..} expansions #5</title> + <command>test</command> + <runMode>AS_SCRIPT</runMode> + <script>#!bjorne + A=cat + B= + echo A :? null is ${A:?} + echo X :? null is ${X:?} + </script> + <output>A :? null is cat +</output> + <error>X is unset or null +</error> + <rc>1</rc> + </testSpec> + <testSpec> + <title>${..?..} expansions #6</title> + <command>test</command> + <runMode>AS_SCRIPT</runMode> + <script>#!bjorne + A=cat + B= + echo A ? null is ${A?} + echo B ? null is ${B?} + echo X ? null is ${X?} + </script> + <output>A ? null is cat +B ? null is +</output> + <error>X is unset +</error> + <rc>1</rc> + </testSpec> + <testSpec> + <title>${..=..} expansions</title> + <command>test</command> + <runMode>AS_SCRIPT</runMode> + <script>#!bjorne + A=cat + B= + echo A := dog is ${A:=dog} + echo $A + echo B := dog is ${B:=dog} + echo $B + echo X := dog is ${X:=dog} + echo $X + </script> + <output>A := dog is cat +cat +B := dog is dog +dog +X := dog is dog +dog +</output> + <rc>0</rc> + </testSpec> + <testSpec> + <title>${..=..} expansions #2</title> + <command>test</command> + <runMode>AS_SCRIPT</runMode> + <script>#!bjorne + A=cat + B= + echo A = dog is ${A=dog} + echo $A + echo B = dog is ${B=dog} + echo $B + echo X = dog is ${X=dog} + echo $X + </script> + <output>A = dog is cat +cat +B = dog is + +X = dog is dog +dog +</output> + <rc>0</rc> + </testSpec> </testSpecs> \ No newline at end of file This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site. |