USING OpenEdge.Core.Assert.

ROUTINE-LEVEL ON ERROR UNDO, THROW.

CLASS unittests.TestLongcharConversion:

  METHOD PUBLIC LONGCHAR methodWithLongcharParameter(INPUT arg AS LONGCHAR):
      RETURN arg.
  END METHOD.

  METHOD PUBLIC CHARACTER methodWithCharacterParameter(INPUT arg AS CHARACTER):
      RETURN arg.
  END METHOD.
  
  @Test.
  METHOD PUBLIC VOID test():
     DEFINE VARIABLE lc AS LONGCHAR NO-UNDO.
     DEFINE VARIABLE lcr AS LONGCHAR NO-UNDO.

     ASSIGN lc = 'qwerty'
            lcr = 'asdfqwerty'.

     // This should convert correctly
     Assert:Equals(lcr, methodWithLongcharParameter("asdfqwerty")).

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

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

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

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

     // nested mixed expression
     lcr = 'asdf' + STRING('qwerty') + 'zxcv'.
     Assert:Equals(lcr, methodWithLongcharParameter('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, methodWithLongcharParameter("a" + ch + "B" + "c" + ch2)).
     
     lcr = "a" + "b" + methodWithLongcharParameter("c" + "d" + "e") + "f" + "g".
     Assert:Equals(lcr, methodWithLongcharParameter("a" + "b" + methodWithLongcharParameter("c" + "d" + "e") + "f" + "g")).

   END METHOD.
END CLASS.