/**
 *  Test number formatting with formats with Credit/Debit sign.
 */
USING OpenEdge.Core.Assert.

ROUTINE-LEVEL ON ERROR UNDO, THROW.

CLASS unittests.base.numeric.NumericFormattingCRDBTest:

   @Before.
   METHOD PUBLIC VOID BeforeClass():
     SESSION:SET-NUMERIC-FORMAT(",",".").
   END METHOD.

   @Test.
   METHOD PUBLIC VOID TestCRDB():
      test( 123.45, ">>9.99CR", "123.45  ").
      test(-123.45, ">>9.99CR", "123.45CR").
      test( 123.45, ">>9.99DB", "123.45  ").
      test(-123.45, ">>9.99DB", "123.45DB").
      test( 123.45, ">>9.99DR", "123.45  ").
      test(-123.45, ">>9.99DR", "123.45DR").
      test(-123.45, ">>9.99cr", "123.45cr").
      test(-123.45, ">>9.99dR", "123.45dR").
      test(-123.45, ">>9.99Dr", "123.45Dr").
      test(-123.45, "->>9.99CR", "-123.45CR").
      test(-123.45, "+>>9.99DB", "-123.45DB").
      test(-123.45, ">>9.99+CR", "123.45-CR").
      test(-123.45, "(>>9.99)DB", "(123.45)DB").
      test(0, ">>9.99CR", "  0.00  ").
      
      test(123.45, ">>9.99+CR", "123.45+CR").
      test(123.45, ">>9.99-CR", "123.45 CR").
      test(123.45, "(>>9.99)DB", " 123.45 DB").      
   END METHOD.

   /**
    * Verify that DR/DB/DR Cannot be used for space reuse.
    */
   @Test.
   METHOD PUBLIC VOID TestCRDBSignReuse():
      DEFINE VARIABLE rc AS CHARACTER NO-UNDO.
      rc = STRING(12345.456, ">>>9.99<CR") NO-ERROR.
      Assert:Equals(74, ERROR-STATUS:GET-NUMBER(1)).
   END METHOD.

   /**
    * Execute the test, compare result with the expected value.
    */
   METHOD PRIVATE VOID test(INPUT v AS DECIMAL, INPUT fmt AS CHARACTER, INPUT expectedResult AS CHARACTER):
      DEFINE VARIABLE rc AS CHARACTER NO-UNDO.
      rc = STRING(v, fmt).
      Assert:Equals(expectedResult, rc).
      Assert:Equals(LENGTH(expectedResult), LENGTH(rc)).
   END METHOD.
END CLASS.
