BLOCK-LEVEL ON ERROR UNDO, THROW.

USING OpenEdge.Core.Assert.

/**
 * Convert CHARACTER to  LONGCHAR
 */
FUNCTION CLc RETURNS LONGCHAR
   (INPUT c AS CHARACTER):

   RETURN c.
END FUNCTION.

/**
 * Return LONGCHAR argument unchanged
 */
FUNCTION Lc RETURNS LONGCHAR
   (INPUT c AS LONGCHAR):

   RETURN c.
END FUNCTION.

/**
 * Concat CHARACTER with LONGCHAR, return LONGCHAR
 */
FUNCTION CLcLc RETURNS LONGCHAR
   (INPUT c AS CHARACTER,
    INPUT lc AS LONGCHAR):

   RETURN c + lc.
END FUNCTION.

@Test.
PROCEDURE test1:
   DEFINE VARIABLE lc AS LONGCHAR NO-UNDO.
   DEFINE VARIABLE lcr AS LONGCHAR NO-UNDO.
   
   ASSIGN lc = 'qwerty'
          lcr = 'asdfqwerty'.
   Assert:Equals(lcr, CLcLc('asdf', lc)).
   Assert:Equals(lcr, CLcLc('asdf', 'qwerty')).

   Assert:Equals(lcr, Lc("asdf" + "qwerty")).

   lcr = "asdf".
   Assert:Equals(lcr, Lc("asdf")).
   
   lcr = "asdfqwerty".
   
   // And this parameter converts to CHARACTER instead of LONGCHAR
   Assert:Equals(lcr, Lc("asdf" + "qwerty")).
   Assert:Equals(lcr, Lc("asdf" + lc)).
   
   Assert:Equals(lc, Lc(lc)).

   lcr = "a'sdf" + 'qwe"rty'.
   Assert:Equals(lcr, Lc("a'sdf" + 'qwe"rty')).

   lcr = 'as"df' + "qwe'rty".
   Assert:Equals(lcr, Lc('as"df' + "qwe'rty")).

   lcr = 'as"df' + 'qwe"rty'.
   Assert:Equals(lcr, Lc('as"df' + 'qwe"rty')).
   
   // Now three arguments
   lcr = 'as"df' + 'qwe"rty' + "third arg".
   Assert:Equals(lcr, Lc('as"df' + 'qwe"rty' + "third arg")).

   // nested mixed expression
   lcr = 'asdf' + STRING('qwerty') + 'zxcv'.
   Assert:Equals(lcr, Lc('asdf' + STRING('qwerty') + 'zxcv')).
   
   DEFINE VARIABLE ch AS CHARACTER NO-UNDO.
   DEFINE VARIABLE ch2 AS CHARACTER NO-UNDO.
   
   lcr = "a" + ch + "B" + "c" + ch2.
   Assert:Equals(lcr, Lc("a" + ch + "B" + "c" + ch2)).
   
   lcr = "a" + "b" + Lc("c" + "d" + "e") + "f" + "g".
   Assert:Equals(lcr, Lc("a" + "b" + Lc("c" + "d" + "e") + "f" + "g")).

END.


