// isnumerical - corelib subscript - by Chun
//
// Syntax: isnumerical <variable> <string>

block load
{
   es_xset _tempcore 0
   es_xexists _tempcore command isnumerical
   ifx false(_tempcore) do
   {
      es_xregcmd isnumerical corelib/isnumerical/isnumerical "Stores whether or not a string is numerical in a var"
   }
   testcase qcreate corelib isnumericaltest "Tests isnumerical"
   testcase addtest isnumericaltest isnumericaltest corelib/isnumerical/test_isnumerical "Isnumerical Corelib Command Test"
}

block isnumerical
{
   es_xset _isn_argc 0
   es_xgetargc _isn_argc
   if (server_var(_isn_argc) = 3) do
   {
      es_xset _isn_var 0
      es_xgetargv _isn_var 1
      es_xset _isn_string 0
      es_xgetargv _isn_string 2
      es_xset _tempcore 0
      es_regex match _tempcore "^-?[0-9]*\.?[0-9]*$" server_var(_isn_string)
      if (server_var(_tempcore) < 0) do
      {
         es es_xset server_var(_isn_var) 0
      }
      if (server_var(_tempcore) > 0) do
      {
         es es_xset server_var(_isn_var) 1
      }
   }
   es_xelse do
   {
      es_xdbgmsg 0 Syntax : isnumerical <variable> <string>
   }
}

block test_isnumerical
{
   profile begin isnumerical_test
   testlib begin isn1 "isnumerical test 1 - numerical string"
   es_xset _isn_testvar 0
   isnumerical _isn_testvar 32367
   testlib fail_unless _isn_testvar equalto 1
   testlib end
   testlib begin isn2 "isnumerical test 2 - non-numerical string"
   es_xset _isn_testvar 0
   isnumerical _isn_testvar wsae3425
   testlib fail_unless _isn_testvar equalto 0
   testlib end
   testlib begin isn3 "isnumerical test 3 - negative numerical string"
   es_xset _isn_testvar 0
   isnumerical _isn_testvar -3478
   testlib fail_unless _isn_testvar equalto 1
   testlib end
   testlib begin isn4 "isnumerical test 4 - decimal string"
   es_xset _isn_testvar 0
   isnumerical _isn_testvar 323.67
   testlib fail_unless _isn_testvar equalto 1
   testlib end
   testlib begin isn1 "isnumerical test 5 - negative decimal string"
   es_xset _isn_testvar 0
   isnumerical _isn_testvar -23434.1256
   testlib fail_unless _isn_testvar equalto 1
   testlib end
   profile end isnumerical_test
}