church booleans, but this needs some more work

-- Modeling Opetopes
-- here is Eric's editor: http://sma.epfl.ch/~finster/opetope/opetope.html
--
-- Note: Kock et al. use a similar scheme, where
--          - dots    <-->   lines
--          - spheres <-->   dots
--          - lines disappear
--          -                spheres appear

-- Note: In Eric's new work (at IAS) there are no
--       dots any more, instead he uses 'external cards', so
--          - (external) cards   <-->  lines
--          - space between stacked cards <--> external cards
--          - lines disappear
--          -                (regular) cards appear

import "../src/LangPrelude.prg" (maybeM)
import "../tests/Nat.prg"

##bounds backchain 10

-- GLOBAL TODOs
----------------

-- Naming: Seems essential for identifying things Hor(Name), Ver(Tree)
--         Name can be Label, then Niches (= sequences of opetope names).
--         the latter arise from the composition rule.
--         Note: don't store names in Stacks, that kills alpha
--               conversion. Instead names should be pushed into nodes
--               'singleton style' from outside: (node :: Tree (Hor `g))

-- Morphisms: given an opetope and a pointer to one of its cards
--            extract the opetope of that face (do we need a label
--            space to reliably find it?). This must be a type
--            function, with an algorithm accompanying it to extract
--            the face proper.

-- Composition: grafting of trees to external cards, but only if the
--              morphisms (faces) match. lower-dim stuff is unaffected.

-- Swapping: given a proof of equality between two niches, provide an
--           operation to swap them, replacing old faces by new ones,
--           FGL-style (functional graph library), just note that
--           certain morphisms are gone, others appeared.

-- References: a disciplined way of saying "I am an identical node to that guy",
--             by corollary these always obtain the same names.
--             a topologist would say 'surgery' (http://en.wikipedia.org/wiki/Surgery_theory)
--             We get a new Tree flavour, Ref, at least one up, followed by
--             naturals to index a node in a subtree.
--             At this point we are doing algebraic topology, and dealing with
--             closed manifolds, so that we can do homology etc. on them.
--             In logic this corresponds to relations, satisfiability.

-- Quoting: So far we have only dealt with data, i.e. quoted (inert) syntax.
--          we need a way to convert this syntax to code (e.g. at some stage),
--          to obtain semantics. We can have the usual splicing game.
--          Lisp does this with sexprs and macros.
--          The code needs then be executed (run, decreasing stage), when
--          it becomes active, and we can observe the manifestation of its
--          semantics. The reduction system could go along the lines of the
--          (typed) LambdaGraph.

-- NbE: I fully believe we can use this technique to reduce opetopic terms
--      to normal form. ('many syntax', 'one semantics' adjunction:
--                       http://www.logicmatters.net/resources/pdfs/Galois.pdf)

-- TODO: these three must be LeftLists
--
kind Trees = NoTree | Pre (Tree d) Trees deriving syntax (ts) List(NoTree, Pre)

data ZoomCompley :: Tree e ~> Tree f ~> * where
  Nily :: ZoomCompley a a
  Consy :: Stack a b -> ZoomCompley b c -> ZoomCompley a c
 deriving List(cply)

data ZoomComplex :: Trees ~> * where
  Nilx :: ZoomComplex [()tr]ts
  Endx :: Stack a b -> ZoomComplex [a, b]ts
  Consx :: Stack a b -> ZoomComplex [b; c]ts -> ZoomComplex [a, b; c]ts
 deriving syntax (cplx) List(Nilx, Consx) Item(Endx)

data Dir :: *2 where
  Hor :: Dir
  Ver :: Dir

-- define the Tree kind, a rose tree
-- note: we may need a two-level kind, since we need to track disjointness
--       of subtrees
-- todo: later we may want to have a label kind parameter too

data Tree :: Dir ~> *1 where
  Unit :: Tree Ver
  Ni :: Tree Hor
  Fork :: Tree d ~> Tree Hor ~> Tree Hor
 deriving syntax (tr) List(Ni, Fork) Unit(Unit)

-- make it singleton

data Tree' :: Tree d ~> * where
  In :: Tree' ()tr
  Fork :: treelike head -> Tree' tail -> Tree' [head; tail]tr
  Done :: Tree' []tr
 deriving syntax (ar) List(Done, Fork) Unit(In) -- "arbre"
-- http://www.papoulipoesique.com/wp-content/uploads/2013/06/arbre.jpg

-- define a proposition for subtrees
-- to be checked: TakeHead must ensure that all the node is consumed

prop Subtree :: Tree d ~> Tree e ~> * where
  UnitSub :: Subtree ()tr tr
  BothNil :: Subtree []tr []tr
  TakeHead :: Subtree head head' -> Subtree tail tail' -> Subtree [head; tail]tr [head'; tail']tr

-- TODO: separate the notions of Niche / Frame / Cell
kind Volume = FramedHollow | FilledCell
kind Diagram = Closed Volume | OpenNiche
-- should be a parameter to Stack

-- now we can stack cards (these are zooms in Kock et al. parlance)

data Stack :: Tree d ~> Tree e ~> * where
  Corolla :: Corolla tr => Tree' tr -> Stack tr ()tr

  -- TODO: needed?
  --Expand :: (Subtree consumed tr, {nodeValence consumed} `Equal` {nodeValence tr}) => Stack consumed prod -> Stack tr prod

  -- add another target face to a web
  Target :: ({nodes tr} `Equal` {nodeValence out}) => Stack tr out -> Stack tr out

  -- the following three grab a node (and possibly its offsprings) and incorporate it into a single card
  NodeDone :: Stack []tr [()tr]tr
  Pick :: {- EntireNode => -} Stack head prodhead -> Stack tail prodtail -> Stack [head; tail]tr [prodhead; prodtail]tr
  Exclude :: {- EntireNode => -} Stack tail prod -> Stack [()tr; tail]tr prod
  -- TODO: maybe just specify a subtree (Tree') and that's it

  On :: (Subtree tr' tr, Pointers 1t at out) => Stack tr' out' -> Stack tr out -> Tree' at -> Stack tr {graft out' at out}

  -- building niches (pasting diagrams)
  -- TODO: these must produce a composite labelled Hor
  NicheDone :: Stack ()tr []tr
  Niche :: Stack tr out -> Stack tr [out]tr
  Also :: Pointers 1t at tr
       => Tree' at -> Stack tr' out' -> Stack tr out -> Stack {extgraft tr' at tr} [out'; out]tr

  -- put a frame around a niche
  Frame :: (Corolla out, {nodes tr}  `Equal` {nodeValence out}) => Stack tr out -> Stack tr out

 deriving syntax(z) Record(NicheDone, Also) Item(Target)

stop = ({}z)z

-- this is bogus, just make it compile again...
up :: Reference tr => Stack ()tr tr -> Stack ()tr [tr]tr
up inner = ({()ar=inner}z)z

-- it remains to define corollas

-- TODO: one could say {nodes tr} == 1
prop Corolla :: Tree d ~> * where
  None' :: Corolla []tr
  One' :: Corolla tail -> Corolla [()tr; tail]tr

--  o   --->  |
--  |         |

lolliCell :: Stack []tr ()tr
lolliCell = Corolla Done

--  |         |
--  o   --->  |
--  |         |

dolliCell :: Stack [()tr]tr ()tr
dolliCell = Corolla $ Fork In Done

--              |
--  [o]   --->  o
--   |          |

lolliFrame :: Stack []tr [()tr]tr
lolliFrame = Target NodeDone

--   |          |
--  [o]   --->  o
--   |          |

dolliFrame :: Stack [()tr]tr [()tr]tr
dolliFrame = Target (Exclude NodeDone)

--   |          |
--   |          o
-- [[o]]  --->  |
--   |          o
--   |          |

stacked :: Stack [()tr]tr [[()tr]tr]tr
stacked = (dolliFrame `On` dolliFrame) (In `Fork` Done)

--   |
--  [|]   --->  o
--   |          |

crossed :: Stack ()tr []tr
crossed = stop

-- we can now join things
--
dolliForever = [dolliFrame; dolliForever]cply
nopetope = [crossed, lolliFrame; dolliForever]cply

-- back to unit as fast as possible...
--
stopetope = [crossed, lolliFrame, dolliCell]cply
neverstopetope = [crossed, lolliFrame, dolliCell; neverstopetope]cply
stopetope' = [crossed, lolliFrame; (dolliCell)cplx]cplx
stopetope'' = [crossed, lolliFrame, dolliCell]cplx

--   |          o
-- [[|]]  --->  |
--   |          o
--   |          |

drossed :: Stack ()tr [[]tr]tr
drossed = up stop

-- ################################
-- ############  Niches ###########
-- ################################

--  |          +
--  |          |

-- this is a niche, but assume to be a frame
niche0 :: Stack ()tr []tr
niche0 = {}z

--  |           |
-- [|]          +
--  |           |

-- this is a niche, but assume to be a frame
niche1 :: Stack ()tr [[]tr]tr
niche1 = {()ar=stop; {}z}z

--  |         o   o
-- [|]  --->   \ /
-- [|]          +
--  |           |

-- this is a niche, but assume to be a frame
niche2 :: Stack ()tr [[]tr, []tr]tr
niche2 = {()ar=stop; niche1}z

--                |
--  |         o   o
-- [o]  --->   \ /
-- [|]          +
--  |           |

niche10 :: Stack [()tr]tr [[()tr]tr, []tr]tr
niche10 = {()ar=Exclude NodeDone; Niche stop}z

-- ################################
-- ############  Frames ###########
-- ################################

--   |              |
--  /|\         o   o
-- |[o]|  --->   \ /
-- |[|]|          o
--  \|/           |
--   |

cyclops :: Stack [()tr]tr [[()tr]tr, []tr]tr
cyclops = (niche10)z

-- Stacking, Valence, Affine subtree, Substitute at an affine position

-- counting Units in a tree

valence :: Tree d ~> Nat
{valence []tr} = 0t
{valence [head; tail]tr} = {plus {valence head} {valence tail}}
{valence ()tr} = 1t

-- counting siblings of a tree

nodeValence :: Tree d ~> Nat
{nodeValence []tr} = 0t
{nodeValence [head; tail]tr} = (1+{nodeValence tail})t

-- counting nodes in a tree

nodes :: Tree d ~> Nat
{nodes ()tr} = t
{nodes []tr} = 1t
{nodes [head; tail]tr} = {plus {nodes head} {nodes tail}}

-- nodeValenceAt: given a (multi)pointer, determine the node valences at those positions
--               WHERE     IN
nodeValenceAt :: Tree d ~> Tree e ~> Nat
{nodeValenceAt ()tr tree} = {nodeValence tree}
{nodeValenceAt []tr []tr} = 0t
{nodeValenceAt [head'; tail']tr [head; tail]tr} = {plus {nodeValenceAt head' head} {nodeValenceAt tail' tail}}

-- a pointer is a valence-1 subtree of a tree
-- it is used to mark a unit in a tree where substitution will occur
--
prop Pointers :: Nat ~> Tree d ~> Tree e ~> * where
  Finger :: Pointers 1t ()tr ()tr
  Finished :: Pointers 0t []tr []tr
  ThisWay :: Pointers 1t head' head -> Pointers n tail' tail -> Pointers (1+n)t [head'; tail']tr [head; tail]tr
  ElseWhere :: Pointers n tail' tail -> Pointers n [[]tr; tail']tr [head; tail]tr

-- http://en.wikipedia.org/wiki/Grafting
--
-- graft WHAT      WHERE     IN
graft :: Tree d ~> Tree e ~> Tree f ~> Tree f
{graft what ()tr ()tr} = what
{graft what []tr tr} = tr
{graft what [head'; tail']tr [head; tail]tr} = [{graft what head' head}; {graft what tail' tail}]tr

-- extgraft: extend and graft
--
extgraft :: Tree what ~> Tree wher ~> Tree tree ~> Tree tree'
{extgraft what ()tr ()tr} = what
{extgraft what []tr ()tr} = ()tr
{extgraft what [head; tail]tr ()tr} = {extgrafthor what [head; tail]tr}
{extgraft what []tr []tr} = []tr
{extgraft what []tr [head; tail]tr} = [head; tail]tr
{extgraft what [head'; tail']tr [head; tail]tr} = [{extgraft what head' head}; {extgraft what tail' tail}]tr

-- helper:
extgrafthor :: Tree what ~> Tree Hor ~> Tree Hor
{extgrafthor what []tr} = []tr
{extgrafthor what [head; tail]tr} = [{extgraft what head ()tr}; {extgrafthor what tail}]tr

{- NOTE: we have an Omega bug here:

prompt> :norm {graft []tr ()tr ()tr}
Normalizes to:
  []tr

prompt> :kind []tr
[]tr :: Tree Hor  = []tr

prompt> :kind {graft []tr ()tr ()tr}
{graft []tr ()tr ()tr} :: Tree Ver  = {graft []tr ()tr ()tr}

... BUT: Hor /= Ver :-(
-}

-- substitution: replace a pointed node (of valence n) in a tree with an
-- other tree of (valence n) -- TODO

-- HERE IS A NICE RESEARCH QUESTION:
-- is it possible to "proof search" a Zoom?
-- i.e.
{-

class ZoomLike (int :: Tree) (out :: Tree) where
  zoom :: (Nodes int ~ Valence out) => Zoom int out

-}

prop Reference :: Tree Hor ~> * where
  Stop :: Reference []tr
  Up :: Reference tr -> Reference [tr]tr
 deriving Nat(d) -- de Bruijn index

prop Teleport :: Tree Hor ~> * where
  Gate :: Teleport [()tr]tr
  Tele :: Teleport tr -> Teleport [tr]tr
 deriving Nat(sk) -- skips

{-

0
|   |
1   L  (lambda node)
|   |
2   1  (how many skips)
 \ /
  o
  |
  B  (binds here)
  |

Encodes \x.xx

-}

r2 = 2d
t1 = 1sk

lamX_XX = addBinder $ [r2, t1]ar

prop BindsUp :: Nat ~> Tree Hor ~> * where
  LastSkip :: BindsUp 1t [()tr]tr
  MoreSkip :: Teleport tr -> BindsUp n tr -> BindsUp (1+n)t [tr]tr
  -- prove Application node
  HeadBindsUp :: Nat' n -> BindsUp (1+n)t head -> BindsUp n [head; tail]tr
  TailBindsUp :: BindsUp n [head; tail]tr -> BindsUp n [nonempty, head; tail]tr

-- TODO: make sure that something teleports here
addBinder :: BindsUp 1t tr => Tree' tr -> Tree' [tr]tr
addBinder term = [term]ar

testB :: BindsUp 0t [[[[]tr]tr]tr,[()tr]tr]tr -> Tree' [[[[]tr]tr]tr,[()tr]tr]tr
testB ev = [r2, 0sk]ar
testB' = testB (TailBindsUp (HeadBindsUp 0v (LastSkip)))

testC :: BindsUp 0t [[[[[]tr]tr]tr,[[()tr]tr]tr]tr]tr -> Tree' [[[[[]tr]tr]tr,[[()tr]tr]tr]tr]tr
testC ev = lamX_XX
testC' = testC (HeadBindsUp 0v (TailBindsUp (HeadBindsUp 1v (MoreSkip 0sk LastSkip))))

--TODO: prop Lambda :: Tree Hor ~> * where

{-
The slogan is: binder nodes do not count as result nodes:
 - just consider the next node upstream
 - incoming (external) cards, when identified to a binder do not count as inputs to application
 - incoming (external) cards, when identified to an (iterated) application become pattern matching (sigma).

In the end all identifications have a semantics (hopefully!), when the counting rules are ensured.

-}

-- Now some fun stuff

data LC :: (k ~> *) ~> * where
  Var :: tf a -> LC tf
  App :: LC tf -> LC tf -> LC tf
  Lam :: tf a -> LC tf -> LC tf
  LetRec :: tf a -> LC tf -> LC tf -> LC tf
 deriving syntax (lc) Applicative(Var, App, Lam, LetRec)

alamX_XX = (\x->x x)lc

kind Dict key value = Dempty | Dextend (Dict key value) key value deriving LeftRecord(dict)

-- Contexts map keys to some value
--
data Context :: (key ~> *) ~> (value ~> *) ~> Dict key value ~> * where
  Empty :: Context key value {}dict
  Extend :: Context key value dict -> key k -> value v -> Context key value {dict; k = v}dict
 deriving LeftRecord(ctx)

-- DeBrujn levels as keys
--
dictSize :: Dict key value ~> Nat
{dictSize {}dict} = 0t
{dictSize {pre; k = v}dict} = (1+{dictSize pre})t

data DeBrujnContext :: (value ~> *) ~> Dict Nat value ~> * where
  DeBrujnEmpty :: DeBrujnContext value {}dict
  DeBrujnExtend :: DeBrujnContext value dict -> value v -> DeBrujnContext value {dict; {dictSize dict} = v}dict
 deriving LeftList(dtx)

getDeBruijnIndex :: Dict key value ~> value ~> Nat ~> Nat
{getDeBruijnIndex {pre; k = v}dict v acc} = acc
{getDeBruijnIndex {pre; k = v'}dict v acc} = {getDeBruijnIndex pre v (1+acc)t}

lookUpDeBruijn :: DeBrujnContext Label dict -> Label l -> Nat' acc -> Maybe (Nat' {getDeBruijnIndex dict l acc})
lookUpDeBruijn []dtx _ _ = Nothing
lookUpDeBruijn [pre; known]dtx lab acc = case sameLabel known lab of
                                         R _ -> lookUpDeBruijn pre lab (1+acc)t
                                         L Eq -> Just acc

monad maybeM

toDeBruijn :: DeBrujnContext Label dict -> LC Label -> Maybe (LC Nat')
toDeBruijn ctx (Var a) = do idx <- lookUpDeBruijn ctx a 0t
                            return $ Var idx
toDeBruijn ctx (Lam l a) = do a' <- toDeBruijn [ctx; l]dtx a
                              return $ Lam 0t a'
toDeBruijn ctx (App f a) = do f' <- toDeBruijn ctx f
                              a' <- toDeBruijn ctx a
                              return $ App f' a'

pattern Let n v exp = App (Lam n v) exp

-- fun with church encoding

true = (\t f->t)lc
false = (\t f->f)lc

-- church 'if'
chif = (\v iftrue iffalse->v iftrue iffalse)lc

chtest = (chif true false true)lc -- will not do what you expect
--chtest' = ($chif $true $false $true)lc -- not ready yet!


QtScript: updated to use the macro PBOOL

/*

  Qt5xHb - bibliotecas de ligao entre Harbour/xHarbour e Qt Framework 5

  Copyright (C) 2012-2017 Marcos Antonio Gambeta <marcosgambeta@uol.com.br>

*/

#include "hbclass.ch"

#ifndef QT5XHB_NO_REQUESTS
REQUEST QSCRIPTENGINE
REQUEST QVARIANT
#endif

CLASS QScriptEngineAgent

   DATA pointer
   DATA class_flags INIT 0
   DATA self_destruction INIT .F.

   METHOD new
   METHOD delete
   METHOD contextPop
   METHOD contextPush
   METHOD engine
   METHOD exceptionCatch
   METHOD exceptionThrow
   METHOD extension
   METHOD functionEntry
   METHOD functionExit
   METHOD positionChange
   METHOD scriptLoad
   METHOD scriptUnload
   METHOD supportsExtension

   METHOD newFrom
   METHOD newFromObject
   METHOD newFromPointer
   METHOD selfDestruction
   METHOD setSelfDestruction

   DESTRUCTOR destroyObject

END CLASS

PROCEDURE destroyObject () CLASS QScriptEngineAgent
   IF ::self_destruction
      ::delete()
   ENDIF
RETURN

#pragma BEGINDUMP

#include <Qt>

#ifndef __XHARBOUR__
#include <QScriptEngineAgent>
#endif

#include "qt5xhb_common.h"
#include "qt5xhb_clsid.h"
#include "qt5xhb_utils.h"

#ifdef __XHARBOUR__
#include <QScriptEngineAgent>
#endif

/*
QScriptEngineAgent(QScriptEngine * engine)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_NEW )
{
  QScriptEngine * par1 = (QScriptEngine *) _qt5xhb_itemGetPtr(1);
  QScriptEngineAgent * o = new QScriptEngineAgent ( par1 );
  _qt5xhb_storePointerAndFlag( o, false );
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_DELETE )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) hb_itemGetPtr( hb_objSendMsg( hb_stackSelfItem(), "POINTER", 0 ) );
  if( obj )
  {
    delete obj;
    obj = NULL;
    PHB_ITEM self = hb_stackSelfItem();
    PHB_ITEM ptr = hb_itemPutPtr( NULL, NULL );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void contextPop()
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_CONTEXTPOP )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->contextPop (  );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void contextPush()
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_CONTEXTPUSH )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->contextPush (  );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
QScriptEngine * engine() const
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_ENGINE )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QScriptEngine * ptr = obj->engine (  );
    _qt5xhb_createReturnClass ( ptr, "QSCRIPTENGINE" );
  }
}

/*
virtual void exceptionCatch(qint64 scriptId, const QScriptValue & exception)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_EXCEPTIONCATCH )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QScriptValue * par2 = (QScriptValue *) _qt5xhb_itemGetPtr(2);
    obj->exceptionCatch ( (qint64) hb_parni(1), *par2 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void exceptionThrow(qint64 scriptId, const QScriptValue & exception, bool hasHandler)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_EXCEPTIONTHROW )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QScriptValue * par2 = (QScriptValue *) _qt5xhb_itemGetPtr(2);
    obj->exceptionThrow ( (qint64) hb_parni(1), *par2, PBOOL(3) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual QVariant extension(Extension extension, const QVariant & argument = QVariant())
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_EXTENSION )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int par1 = hb_parni(1);
    QVariant par2 = ISNIL(2)? QVariant() : *(QVariant *) _qt5xhb_itemGetPtr(2);
    QVariant * ptr = new QVariant( obj->extension (  (QScriptEngineAgent::Extension) par1, par2 ) );
    _qt5xhb_createReturnClass ( ptr, "QVARIANT", true );
  }
}

/*
virtual void functionEntry(qint64 scriptId)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_FUNCTIONENTRY )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->functionEntry ( (qint64) hb_parni(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void functionExit(qint64 scriptId, const QScriptValue & returnValue)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_FUNCTIONEXIT )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QScriptValue * par2 = (QScriptValue *) _qt5xhb_itemGetPtr(2);
    obj->functionExit ( (qint64) hb_parni(1), *par2 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void positionChange(qint64 scriptId, int lineNumber, int columnNumber)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_POSITIONCHANGE )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->positionChange ( (qint64) hb_parni(1), (int) hb_parni(2), (int) hb_parni(3) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void scriptLoad(qint64 id, const QString & program, const QString & fileName, int baseLineNumber)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_SCRIPTLOAD )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->scriptLoad ( (qint64) hb_parni(1), PQSTRING(2), PQSTRING(3), (int) hb_parni(4) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void scriptUnload(qint64 id)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_SCRIPTUNLOAD )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->scriptUnload ( (qint64) hb_parni(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual bool supportsExtension(Extension extension) const
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_SUPPORTSEXTENSION )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int par1 = hb_parni(1);
    hb_retl( obj->supportsExtension (  (QScriptEngineAgent::Extension) par1 ) );
  }
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_NEWFROM )
{
  PHB_ITEM self = hb_stackSelfItem();
  if( hb_pcount() == 1 && ISOBJECT(1) )
  {
    PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_objSendMsg( hb_param(1, HB_IT_OBJECT ), "POINTER", 0 ) ) );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
    PHB_ITEM des = hb_itemPutL( NULL, false );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  else if( hb_pcount() == 1 && ISPOINTER(1) )
  {
    PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_param(1, HB_IT_POINTER ) ) );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
    PHB_ITEM des = hb_itemPutL( NULL, false );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  hb_itemReturn( self );
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_NEWFROMOBJECT )
{
  HB_FUNC_EXEC( QSCRIPTENGINEAGENT_NEWFROM );
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_NEWFROMPOINTER )
{
  HB_FUNC_EXEC( QSCRIPTENGINEAGENT_NEWFROM );
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_SELFDESTRUCTION )
{
  hb_retl( (bool) hb_itemGetL( hb_objSendMsg( hb_stackSelfItem(), "SELF_DESTRUCTION", 0 ) ) );
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_SETSELFDESTRUCTION )
{
  PHB_ITEM self = hb_stackSelfItem();
  if( hb_pcount() == 1 && ISLOG(1) )
  {
    PHB_ITEM des = hb_itemPutL( NULL, hb_parl(1) );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  hb_itemReturn( self );
}

#pragma ENDDUMP

/*

  Qt5xHb - bibliotecas de ligao entre Harbour/xHarbour e Qt Framework 5

  Copyright (C) 2012-2017 Marcos Antonio Gambeta <marcosgambeta@uol.com.br>

*/

#include "hbclass.ch"

#ifndef QT5XHB_NO_REQUESTS
REQUEST QSCRIPTENGINE
REQUEST QVARIANT
#endif

CLASS QScriptEngineAgent

   DATA pointer
   DATA class_flags INIT 0
   DATA self_destruction INIT .F.

   METHOD new
   METHOD delete
   METHOD contextPop
   METHOD contextPush
   METHOD engine
   METHOD exceptionCatch
   METHOD exceptionThrow
   METHOD extension
   METHOD functionEntry
   METHOD functionExit
   METHOD positionChange
   METHOD scriptLoad
   METHOD scriptUnload
   METHOD supportsExtension

   METHOD newFrom
   METHOD newFromObject
   METHOD newFromPointer
   METHOD selfDestruction
   METHOD setSelfDestruction

   DESTRUCTOR destroyObject

END CLASS

PROCEDURE destroyObject () CLASS QScriptEngineAgent
   IF ::self_destruction
      ::delete()
   ENDIF
RETURN

#pragma BEGINDUMP

#include <Qt>

#ifndef __XHARBOUR__
#include <QScriptEngineAgent>
#endif

#include "qt5xhb_common.h"
#include "qt5xhb_clsid.h"
#include "qt5xhb_utils.h"

#ifdef __XHARBOUR__
#include <QScriptEngineAgent>
#endif

/*
QScriptEngineAgent(QScriptEngine * engine)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_NEW )
{
  QScriptEngine * par1 = (QScriptEngine *) _qt5xhb_itemGetPtr(1);
  QScriptEngineAgent * o = new QScriptEngineAgent ( par1 );
  _qt5xhb_storePointerAndFlag( o, false );
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_DELETE )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) hb_itemGetPtr( hb_objSendMsg( hb_stackSelfItem(), "POINTER", 0 ) );
  if( obj )
  {
    delete obj;
    obj = NULL;
    PHB_ITEM self = hb_stackSelfItem();
    PHB_ITEM ptr = hb_itemPutPtr( NULL, NULL );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void contextPop()
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_CONTEXTPOP )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->contextPop (  );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void contextPush()
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_CONTEXTPUSH )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->contextPush (  );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
QScriptEngine * engine() const
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_ENGINE )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QScriptEngine * ptr = obj->engine (  );
    _qt5xhb_createReturnClass ( ptr, "QSCRIPTENGINE" );
  }
}

/*
virtual void exceptionCatch(qint64 scriptId, const QScriptValue & exception)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_EXCEPTIONCATCH )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QScriptValue * par2 = (QScriptValue *) _qt5xhb_itemGetPtr(2);
    obj->exceptionCatch ( (qint64) hb_parni(1), *par2 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void exceptionThrow(qint64 scriptId, const QScriptValue & exception, bool hasHandler)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_EXCEPTIONTHROW )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QScriptValue * par2 = (QScriptValue *) _qt5xhb_itemGetPtr(2);
    obj->exceptionThrow ( (qint64) hb_parni(1), *par2, (bool) hb_parl(3) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual QVariant extension(Extension extension, const QVariant & argument = QVariant())
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_EXTENSION )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int par1 = hb_parni(1);
    QVariant par2 = ISNIL(2)? QVariant() : *(QVariant *) _qt5xhb_itemGetPtr(2);
    QVariant * ptr = new QVariant( obj->extension (  (QScriptEngineAgent::Extension) par1, par2 ) );
    _qt5xhb_createReturnClass ( ptr, "QVARIANT", true );
  }
}

/*
virtual void functionEntry(qint64 scriptId)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_FUNCTIONENTRY )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->functionEntry ( (qint64) hb_parni(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void functionExit(qint64 scriptId, const QScriptValue & returnValue)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_FUNCTIONEXIT )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    QScriptValue * par2 = (QScriptValue *) _qt5xhb_itemGetPtr(2);
    obj->functionExit ( (qint64) hb_parni(1), *par2 );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void positionChange(qint64 scriptId, int lineNumber, int columnNumber)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_POSITIONCHANGE )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->positionChange ( (qint64) hb_parni(1), (int) hb_parni(2), (int) hb_parni(3) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void scriptLoad(qint64 id, const QString & program, const QString & fileName, int baseLineNumber)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_SCRIPTLOAD )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->scriptLoad ( (qint64) hb_parni(1), PQSTRING(2), PQSTRING(3), (int) hb_parni(4) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual void scriptUnload(qint64 id)
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_SCRIPTUNLOAD )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    obj->scriptUnload ( (qint64) hb_parni(1) );
  }
  hb_itemReturn( hb_stackSelfItem() );
}

/*
virtual bool supportsExtension(Extension extension) const
*/
HB_FUNC_STATIC( QSCRIPTENGINEAGENT_SUPPORTSEXTENSION )
{
  QScriptEngineAgent * obj = (QScriptEngineAgent *) _qt5xhb_itemGetPtrStackSelfItem();
  if( obj )
  {
    int par1 = hb_parni(1);
    hb_retl( obj->supportsExtension (  (QScriptEngineAgent::Extension) par1 ) );
  }
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_NEWFROM )
{
  PHB_ITEM self = hb_stackSelfItem();
  if( hb_pcount() == 1 && ISOBJECT(1) )
  {
    PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_objSendMsg( hb_param(1, HB_IT_OBJECT ), "POINTER", 0 ) ) );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
    PHB_ITEM des = hb_itemPutL( NULL, false );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  else if( hb_pcount() == 1 && ISPOINTER(1) )
  {
    PHB_ITEM ptr = hb_itemPutPtr( NULL, (void *) hb_itemGetPtr( hb_param(1, HB_IT_POINTER ) ) );
    hb_objSendMsg( self, "_pointer", 1, ptr );
    hb_itemRelease( ptr );
    PHB_ITEM des = hb_itemPutL( NULL, false );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  hb_itemReturn( self );
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_NEWFROMOBJECT )
{
  HB_FUNC_EXEC( QSCRIPTENGINEAGENT_NEWFROM );
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_NEWFROMPOINTER )
{
  HB_FUNC_EXEC( QSCRIPTENGINEAGENT_NEWFROM );
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_SELFDESTRUCTION )
{
  hb_retl( (bool) hb_itemGetL( hb_objSendMsg( hb_stackSelfItem(), "SELF_DESTRUCTION", 0 ) ) );
}

HB_FUNC_STATIC( QSCRIPTENGINEAGENT_SETSELFDESTRUCTION )
{
  PHB_ITEM self = hb_stackSelfItem();
  if( hb_pcount() == 1 && ISLOG(1) )
  {
    PHB_ITEM des = hb_itemPutL( NULL, hb_parl(1) );
    hb_objSendMsg( self, "_self_destruction", 1, des );
    hb_itemRelease( des );
  }
  hb_itemReturn( self );
}

#pragma ENDDUMP


[Runtime tests] Added string comparison tests for https://github.com/X-Sharp/XSharpPublic/issues/601

//
// Copyright (c) XSharp B.V.  All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
//
USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text
USING XUnit

#pragma warnings(165, off)  // unassigned variables
#pragma warnings(219, off)  // assigned but not used

// Array tests are not working correctly yet with the current build
BEGIN NAMESPACE XSharp.VO.Tests

	CLASS StringTests

		[Fact, Trait("Category", "String")];
		METHOD MoreStringTests() AS VOID
			Assert.Equal("          ", Transform("", "@R XXXXXXXXXX")        )
			Assert.Equal("Italia    ", Transform("Italia", "@R XXXXXXXXXX")  )
			Assert.Equal("ITALIA    ", Transform("Italia", "@! XXXXXXXXXX")  )
			Assert.Equal("Italia    ", Transform("Italia", "XXXXXXXXXX")     )
			Assert.Equal("1234512345", Transform("1234512345", "XXXXXXXXXX") )
			Assert.Equal("1234"      , Transform("1234", "XX99") )
			Assert.Equal("ITALIA"    , Transform("Italia", "@!") )

			LOCAL c AS STRING
			c := "Not nil!"
			Assert.False(c == NIL)
			Assert.True(c != NIL)
			LOCAL u AS STRING
			u := "Not nil!"
			Assert.False(c == NIL)
			Assert.True(c != NIL)
		RETURN

		[Fact, Trait("Category", "StringEq")];
		METHOD StringEquality() AS VOID
			LOCAL c1,c2 AS STRING
			LOCAL u1,u2 AS USUAL
			LOCAL exact AS LOGIC
			u1 := c1 := "TESTLONG"
			u2 := c2 := "TEST"
			exact := SetExact( FALSE )

			Assert.Equal(TRUE, c1 = c2)
			Assert.Equal(TRUE, c1 != c2)

			Assert.Equal(TRUE, u1 = u2)
			Assert.Equal(FALSE, u1 != u2)

			SetExact( exact )
		RETURN

		[Fact, Trait("Category", "Str")];
		METHOD StrTests() AS VOID
			LOCAL deci,thou,digit,decimal,fixed_,digitfixed AS USUAL
			deci := SetDecimalSep(Asc("."))
			thou := SetThousandSep(Asc(","))
			digit := SetDigit(6)
			decimal := SetDecimal(3)
			fixed_ := SetFixed(FALSE)
			digitfixed := SetDigitFixed(FALSE)

			Assert.Equal( "     1.2"			, Str(1.2) )
			Assert.Equal( "    12.3"			, Str(12.3) )
			Assert.Equal( "    12.34"			, Str(12.34) )
			Assert.Equal( "   123.456"			, Str(123.456) )
			Assert.Equal( "  1234.567"			, Str(1234.567) )
			Assert.Equal( "  1234.5678"			, Str(1234.5678) )
			Assert.Equal( "  1234.5679012345"	, Str(1234.5679012345) )
			Assert.Equal( "123456.78901234568"	, Str(123456.78901234567) )
			Assert.Equal( "999999" , Str(999999) )
			Assert.Equal( "******" , Str(1000000) )

			Assert.Equal( "0.0" , Transform(0 , "9.9") )
			Assert.Equal( "1.0" , Transform(1 , "9.9") )
			Assert.Equal( "*.*" , Transform(-1 , "9.9") )
			SetDecimalSep(Asc(","))
			SetThousandSep(Asc("."))
			Assert.Equal( " 0,00" , Transform(0 , "99.99") )
			Assert.Equal( " 1,00" , Transform(1 , "99.99") )
			Assert.Equal( "-1,00" , Transform(-1 , "99.99") )

			Assert.Equal( "  0,00" , Transform(0 , "999.99") )
			Assert.Equal( "  0,0" , Transform(0 , "999.9") )
			Assert.Equal( " 0,0" , Transform(0 , "99.9") )

			SetFixed(TRUE)
			SetDigit(5)
			Assert.Equal("  123" , Str(123))
			Assert.Equal("123" , Str(123 , -1))
			Assert.Equal("123" , Str(123 , 3))
			Assert.Equal("-123" , Str(-123 , 4))
			Assert.Equal("-123" , Str(-123 , -1))
			Assert.Equal(" -123" , Str(-123))
			Assert.Equal(" 123" , Str(123 , 4))
			Assert.Equal("**" , Str(123 , 2))
			SetDigit(10)
			Assert.Equal(" 123456789" , Str(123456789))
			Assert.Equal("**********" , Str(12345678901))

			SetFixed(FALSE)
			SetDigit(5)
			Assert.Equal("  123" , Str(123))
			Assert.Equal("123" , Str(123 , -1))
			Assert.Equal("123" , Str(123 , 3))
			Assert.Equal("-123" , Str(-123 , 4))
			Assert.Equal("-123" , Str(-123 , -1))
			Assert.Equal(" -123" , Str(-123))
			Assert.Equal(" 123" , Str(123 , 4))
			Assert.Equal("**" , Str(123 , 2))
			SetDigit(10)
			Assert.Equal(" 123456789" , Str(123456789))
			Assert.Equal("**********" , Str(12345678901))

			SetDecimal(2)
			SetDecimalSep(Asc(","))
			SetThousandSep(Asc("."))
			Assert.Equal( "**",    Str(1.23 , 2 , 1) )
			Assert.Equal( "1,2",   Str(1.2 , 3) )
			Assert.Equal( "123",   Str(123.456 , 3) )

			Assert.Equal( "123",   Str(123.4567 , 3 , 1) )
			Assert.Equal( "123,",  Str(123.4567 , 4 , 2) )
			Assert.Equal( "123,4", Str(123.4567 , 5 , 3) )
			Assert.Equal( "****" , Str(123.4567 , 4 , 3) )
			Assert.Equal( "*****", Str(123.4567 , 5 , 4) )

			Assert.Equal( "***",   Str(-123.4567 , 3 , 1) )
			Assert.Equal( "-123",  Str(-123.4567 , 4 , 2) )
			Assert.Equal( "-123,", Str(-123.4567 , 5 , 3) )
			Assert.Equal( "****" , Str(-123.4567 , 4 , 3) )
			Assert.Equal( "*****", Str(-123.4567 , 5 , 4) )

			Assert.Equal( "0,0",   Str(0.0 , -1) )
			Assert.Equal( "0,1",   Str(0.1 , -1) )
			Assert.Equal( "-0,1",  Str(-0.1 , -1) )
			Assert.Equal( "0,000",   Str(0.0 , -1 , 3) )
			Assert.Equal( "0,100",   Str(0.1 , -1 , 3) )
			Assert.Equal( "-0,100",  Str(-0.1 , -1 , 3) )

			Assert.Equal( "  123"	, Str(FloatFormat(123 , 5, 0)) )
			Assert.Equal( "   123"	, Str(FloatFormat(123 , 6, 0)) )
			Assert.Equal( " 123,5"	, Str(FloatFormat(123.456 , 6, 1) ) )
			Assert.Equal( "123,46"	, Str(FloatFormat(123.456 , 6, 2) ) )
			Assert.Equal( " 123,46"	, Str(FloatFormat(123.456 , 7, 2) ) )

			SetDecimalSep(deci)
			SetThousandSep(thou)
			SetDigit(digit)
			SetDecimal(decimal)
			SetFixed(fixed_)
			SetDigitFixed(digitfixed)
		RETURN

		[Fact, Trait("Category", "Str")];
		METHOD Str_With_SetFixed_TRUE() AS VOID

		   SetDecimalSep(Asc("."))
		   SetThousandSep(Asc(","))
		   SetDecimal(3)
		   SetDigit(12)

		   SetFixed(TRUE)
		   SetDigitFixed(TRUE)

		   Assert.Equal( Str(12.34)            		, "          12.340")
		   Assert.Equal( Str1(12.34)          		, "          12.340")
		   Assert.Equal( Str(123.456)         		, "         123.456")
		   Assert.Equal( Str1(123.456)       		, "         123.456")
		   Assert.Equal( Str(1230.4567)         	, "        1230.457")
		   Assert.Equal( Str1(1230.4567)        	, "        1230.457")
		   Assert.Equal( Str(100000001234.4567)		, "100000001234.457")
		   Assert.Equal( Str1(100000001234.4567)	, "100000001234.457")
		   Assert.Equal( Str(1000000001234.4567)	, "****************")
		   Assert.True ( Str1(1000000001234.4567):StartsWith("********"))
		   Assert.Equal( Str(12.3)              	, "          12.300")
		   Assert.Equal( Str1(12.3)            		, "          12.300")
		   Assert.Equal( Str(12.34567)        	 	, "          12.346")
		   Assert.Equal( Str1(12.34567)        		, "          12.346")
		   Assert.Equal( Str(12.34 , 10, 2)    		, "     12.34")
		   Assert.Equal( Str(12.34 , 5, 2)     		, "12.34")
		   Assert.Equal( Str(12.34 , 4, 2)     		, "12.3")
		   Assert.Equal( Str(12.34 , 4, 1)     		, "12.3")
		   Assert.Equal( Str(12.34 , 2, 1)     		, "**")
		   Assert.Equal( Str3(12.34 , 10, 2)   		, "     12.34")
		   Assert.Equal( Str3(12.34 , 5, 2)    		, "12.34")
		   Assert.Equal( Str3(12.34 , 4, 2)     	, "12.3")
		   Assert.Equal( Str3(12.34 , 4, 1)     	, "12.3")
		   Assert.Equal( Str3(12.34 , 2, 1)    		, "**")
		   Assert.Equal( Str(-12.34)            	, "         -12.340")
		   Assert.Equal( Str1(-12.34)           	, "         -12.340")
		   Assert.Equal( Str(-12.3456)         		, "         -12.346")
		   Assert.Equal( Str1(-12.3456)         	, "         -12.346")
		   Assert.Equal( Str(-12.34 , 10, 2)    	, "    -12.34")
		   Assert.Equal( Str(-12.34 , 5, 2)     	, "-12.3")	 //VO wrong: -2.34
		   Assert.Equal( Str(-12.34 , 4, 2)     	, "-12.")    // VO wrong: -12.
		   Assert.Equal( Str(-12.34 , 4, 1)     	, "-12.")    //VO wrong: -2.3
	       Assert.Equal( Str(-12.34 , 4, 0)     	, " -12")    //VO wrong: -2.3
		   Assert.Equal( Str(-12.34 , 2, 1)     	, "**")

		   SetDigit(8)
		   SetDecimal(2)
		   SetDecimalSep(Asc(","))
		   SetThousandSep(Asc("."))

		   Assert.Equal( Str(123456789.1)	, "***********")
		   Assert.True(Str1(123456789.1):StartsWith("*****"))
		   Assert.Equal( Str(12345678.1)	, "12345678,10")
		   Assert.Equal(Str1(12345678.1)	, "12345678,10")
		   Assert.Equal( Str(1234567.1)		, " 1234567,10")
		   Assert.Equal(Str1(1234567.1)		, " 1234567,10")
		   Assert.Equal( Str(123456.1)		, "  123456,10")
		   Assert.Equal(Str1(123456.1)		, "  123456,10")

		RETURN

		[Fact, Trait("Category", "Str")];
		METHOD Str_With_SetFixed_FALSE() AS VOID

		   SetDecimalSep(Asc("."))
		   SetThousandSep(Asc(","))
		   SetDecimal(3)
		   SetDigit(12)

		   SetFixed(FALSE)
		   SetDigitFixed(FALSE)

		   Assert.Equal( Str(12.34)            		, "          12.34")
		   Assert.Equal( Str1(12.34)          		, "          12.34")
		   Assert.Equal( Str(123.456)         		, "         123.456")
		   Assert.Equal( Str1(123.456)				, "         123.456")
		   Assert.Equal( Str(1230.4567)         	, "        1230.4567")
		   Assert.Equal( Str1(1230.4567)        	, "        1230.4567")
		   Assert.Equal( Str(100000001234.4567)		, "100000001234.4567")
		   Assert.Equal( Str1(100000001234.4567)	, "100000001234.4567")
		   Assert.Equal( Str(1000000001234.4567)	, "*****************")
//		   Assert.Equal( Str1(1000000001234.4567)	, "*****************")
		   Assert.True(  Str1(1000000001234.4567):StartsWith("*")) // it's really impossible to replicate completely VO's insane behavior
		   Assert.Equal( Str(12.3)              	, "          12.3")
		   Assert.Equal( Str1(12.3)            		, "          12.3")
		   Assert.Equal( Str(12.34567)         		, "          12.34567")
		   Assert.Equal( Str1(12.34567)        		, "          12.34567")
		   Assert.Equal( Str(12.34 , 10, 2)    		, "     12.34")
		   Assert.Equal( Str(12.34 , 5, 2)     		, "12.34")
		   Assert.Equal( Str(12.34 , 4, 2)     		, "12.3") // VO returns 12.3
		   Assert.Equal( Str(12.34 , 4, 1)     		, "12.3")
		   Assert.Equal( Str(12.34 , 2, 1)     		, "**")
		   Assert.Equal( Str3(12.34 , 10, 2)   		, "     12.34")
		   Assert.Equal( Str3(12.34 , 5, 2)    		, "12.34")
		   Assert.Equal( Str3(12.34 , 4, 2)     	, "12.3")   // VO 12.3
		   Assert.Equal( Str3(12.34 , 4, 1)     	, "12.3")
		   Assert.Equal( Str3(12.34 , 2, 1)    		, "**")
		   Assert.Equal( Str(-12.34)            	, "         -12.34")
		   Assert.Equal( Str1(-12.34)           	, "         -12.34")
		   Assert.Equal( Str(-12.3456)         		, "         -12.3456")
		   Assert.Equal( Str1(-12.3456)         	, "         -12.3456")
		   Assert.Equal( Str(-12.34 , 10, 2)    	, "    -12.34")
		   Assert.Equal( Str(-12.34 , 5, 2)     	, "-12.3")	 //VO: -2.34
		   Assert.Equal( Str(-12.34 , 4, 2)     	, "-12.")    // VO
		   Assert.Equal( Str(-12.34 , 4, 1)     	, "-12.")    //VO: -2.3
		   Assert.Equal( Str(-12.34 , 2, 1)     	, "**")

		   SetDigit(8)
		   SetDecimal(2)

		   Assert.True( Str(123456789.1):StartsWith("*"))
		   Assert.True(Str1(123456789.1):StartsWith("*"))

		   Assert.Equal( "12.34" , Str(12.34 , -1))
		   Assert.Equal( "12.3400" , Str(12.34 , -1 , 4))
		   Assert.Equal( "1.1" , Str(1.1 , -1 , 1))

            [Fact, Trait("Category", "Str")];
		    METHOD Pad_Test() AS VOID
                LOCAL u AS USUAL
                Assert.Equal(Space(10), PadR(u,10))
                Assert.Equal(Space(10), Pad(u,10))
                Assert.Equal(Space(10), PadC(u,10))
                Assert.Equal(Space(10), PadL(u,10))
                u := "a"
                Assert.Equal("a         ", PadR(u,10))
                Assert.Equal("a         ", Pad(u,10))
                Assert.Equal("    a     ", PadC(u,10))
                Assert.Equal("----a-----", PadC(u,10,"-"))
                Assert.Equal("         a", PadL(u,10))
                u := 1
                Assert.Equal("1         ", PadR(u,10))
                Assert.Equal("1         ", Pad(u,10))
                Assert.Equal("    1     ", PadC(u,10))
                Assert.Equal("====1=====", PadC(u,10,"="))
                Assert.Equal("         1", PadL(u,10))
                u := 1.23
                SetDecimalSep(Asc("."))
                Assert.Equal("1.23      ", PadR(u,10))
                Assert.Equal("1.23      ", Pad(u,10))
                Assert.Equal("   1.23   ", PadC(u,10))
                Assert.Equal("...1.23...", PadC(u,10,"."))
                Assert.Equal("      1.23", PadL(u,10))

#pragma options ("vo13" , on)
            [Fact, Trait("Category", "Str")];
		    METHOD StringComparison_WINDOWS_notEXACT() AS VOID
				LOCAL u1,u2 AS USUAL
				LOCAL s1,s2 AS USUAL
				LOCAL c,e,vo13 AS USUAL
				vo13 := XSharp.RuntimeState.CompilerOptionVO13
				XSharp.RuntimeState.CompilerOptionVO13 := TRUE
				c := SetCollation(#WINDOWS)
				e := SetExact(FALSE)

				u1 := "AB"
				u2 := "A"
				s1 := u1
				s2 := u2

				Assert.True ( "AB" = "A"  )
				Assert.False( "A" = "AB"  )
				Assert.True ( u1 = u2     )
				Assert.False( u2 = u1     )
				Assert.True ( s1 = s2     )
				Assert.False( s2 = s1     )

				Assert.True ( "AB" >= "A" )
				Assert.True ( "AB" <= "A" )
				Assert.True ( u1 >= u2    )
				Assert.True ( u1 <= u2    )
				Assert.True ( s1 >= s2    )
				Assert.True ( s1 <= s2    )

				Assert.False( "AB" > "A"  )
				Assert.False( "AB" < "A"  )
				Assert.False( u1 > u2     )
				Assert.False( u1 < u2     )
				Assert.False( s1 > s2     )
				Assert.False( s1 < s2     )

				SetCollation(c)
				SetExact(e)

				XSharp.RuntimeState.CompilerOptionVO13 := vo13

            [Fact, Trait("Category", "Str")];
		    METHOD StringComparison_CLIPPER_notEXACT() AS VOID
				LOCAL u1,u2 AS USUAL
				LOCAL s1,s2 AS USUAL
				LOCAL c,e,vo13 AS USUAL
				vo13 := XSharp.RuntimeState.CompilerOptionVO13
				XSharp.RuntimeState.CompilerOptionVO13 := TRUE
				c := SetCollation(#CLIPPER)
				e := SetExact(FALSE)

				u1 := "AB"
				u2 := "A"
				s1 := u1
				s2 := u2

				Assert.True ( "AB" = "A"  )
				Assert.False( "A" = "AB"  )
				Assert.True ( u1 = u2     )
				Assert.False( u2 = u1     )
				Assert.True ( s1 = s2     )
				Assert.False( s2 = s1     )

				Assert.True ( "AB" >= "A" )
				Assert.True ( "AB" <= "A" )
				Assert.True ( u1 >= u2    )
				Assert.True ( u1 <= u2    )
				Assert.True ( s1 >= s2    )
				Assert.True ( s1 <= s2    )

				Assert.False( "AB" > "A"  )
				Assert.False( "AB" < "A"  )
				Assert.False( u1 > u2     )
				Assert.False( u1 < u2     )
				Assert.False( s1 > s2     )
				Assert.False( s1 < s2     )

				SetCollation(c)
				SetExact(e)

				XSharp.RuntimeState.CompilerOptionVO13 := vo13

            [Fact, Trait("Category", "Str")];
		    METHOD StringComparison_WINDOWS_EXACT() AS VOID
				LOCAL u1,u2 AS USUAL
				LOCAL s1,s2 AS USUAL
				LOCAL c,e,vo13 AS USUAL
				vo13 := XSharp.RuntimeState.CompilerOptionVO13
				XSharp.RuntimeState.CompilerOptionVO13 := TRUE
				c := SetCollation(#WINDOWS)
				e := SetExact(TRUE)

				u1 := "AB"
				u2 := "A"
				s1 := u1
				s2 := u2

				Assert.False( "AB" = "A"  )
				Assert.False( "A" = "AB"  )
				Assert.False( u1 = u2     )
				Assert.False( u2 = u1     )
				Assert.False( s1 = s2     )
				Assert.False( s2 = s1     )

				Assert.True ( "AB" >= "A" )
				Assert.False( "AB" <= "A" )
				Assert.True ( u1 >= u2    )
				Assert.False( u1 <= u2    )
				Assert.True ( s1 >= s2    )
				Assert.False( s1 <= s2    )

				Assert.True ( "AB" > "A"  )
				Assert.False( "AB" < "A"  )
				Assert.True ( u1 > u2     )
				Assert.False( u1 < u2     )
				Assert.True ( s1 > s2     )
				Assert.False( s1 < s2     )

				SetCollation(c)
				SetExact(e)

				XSharp.RuntimeState.CompilerOptionVO13 := vo13

            [Fact, Trait("Category", "Str")];
		    METHOD StringComparison_CLIPPER_EXACT() AS VOID
				LOCAL u1,u2 AS USUAL
				LOCAL s1,s2 AS USUAL
				LOCAL c,e,vo13 AS USUAL
				vo13 := XSharp.RuntimeState.CompilerOptionVO13
				XSharp.RuntimeState.CompilerOptionVO13 := TRUE
				c := SetCollation(#CLIPPER)
				e := SetExact(TRUE)

				u1 := "AB"
				u2 := "A"
				s1 := u1
				s2 := u2

				Assert.False( "AB" = "A"  )
				Assert.False( "A" = "AB"  )
				Assert.False( u1 = u2     )
				Assert.False( u2 = u1     )
				Assert.False( s1 = s2     )
				Assert.False( s2 = s1     )

				Assert.True ( "AB" >= "A" )
				Assert.False( "AB" <= "A" )
				Assert.True ( u1 >= u2    )
				Assert.False( u1 <= u2    )
				Assert.True ( s1 >= s2    )
				Assert.False( s1 <= s2    )

				Assert.True ( "AB" > "A"  )
				Assert.False( "AB" < "A"  )
				Assert.True ( u1 > u2     )
				Assert.False( u1 < u2     )
				Assert.True ( s1 > s2     )
				Assert.False( s1 < s2     )

				SetCollation(c)
				SetExact(e)

				XSharp.RuntimeState.CompilerOptionVO13 := vo13

#pragma options ("vo13" , default)

	END CLASS

END NAMESPACE

//
// Copyright (c) XSharp B.V.  All Rights Reserved.
// Licensed under the Apache License, Version 2.0.
// See License.txt in the project root for license information.
//
USING System
USING System.Collections.Generic
USING System.Linq
USING System.Text
USING XUnit

#pragma warnings(165, off)  // unassigned variables
#pragma warnings(219, off)  // assigned but not used

// Array tests are not working correctly yet with the current build
BEGIN NAMESPACE XSharp.VO.Tests

	CLASS StringTests

		[Fact, Trait("Category", "String")];
		METHOD MoreStringTests() AS VOID
			Assert.Equal("          ", Transform("", "@R XXXXXXXXXX")        )
			Assert.Equal("Italia    ", Transform("Italia", "@R XXXXXXXXXX")  )
			Assert.Equal("ITALIA    ", Transform("Italia", "@! XXXXXXXXXX")  )
			Assert.Equal("Italia    ", Transform("Italia", "XXXXXXXXXX")     )
			Assert.Equal("1234512345", Transform("1234512345", "XXXXXXXXXX") )
			Assert.Equal("1234"      , Transform("1234", "XX99") )
			Assert.Equal("ITALIA"    , Transform("Italia", "@!") )

			LOCAL c AS STRING
			c := "Not nil!"
			Assert.False(c == NIL)
			Assert.True(c != NIL)
			LOCAL u AS STRING
			u := "Not nil!"
			Assert.False(c == NIL)
			Assert.True(c != NIL)
		RETURN

		[Fact, Trait("Category", "StringEq")];
		METHOD StringEquality() AS VOID
			LOCAL c1,c2 AS STRING
			LOCAL u1,u2 AS USUAL
			LOCAL exact AS LOGIC
			u1 := c1 := "TESTLONG"
			u2 := c2 := "TEST"
			exact := SetExact( FALSE )

			Assert.Equal(TRUE, c1 = c2)
			Assert.Equal(TRUE, c1 != c2)

			Assert.Equal(TRUE, u1 = u2)
			Assert.Equal(FALSE, u1 != u2)

			SetExact( exact )
		RETURN

		[Fact, Trait("Category", "Str")];
		METHOD StrTests() AS VOID
			LOCAL deci,thou,digit,decimal,fixed_,digitfixed AS USUAL
			deci := SetDecimalSep(Asc("."))
			thou := SetThousandSep(Asc(","))
			digit := SetDigit(6)
			decimal := SetDecimal(3)
			fixed_ := SetFixed(FALSE)
			digitfixed := SetDigitFixed(FALSE)

			Assert.Equal( "     1.2"			, Str(1.2) )
			Assert.Equal( "    12.3"			, Str(12.3) )
			Assert.Equal( "    12.34"			, Str(12.34) )
			Assert.Equal( "   123.456"			, Str(123.456) )
			Assert.Equal( "  1234.567"			, Str(1234.567) )
			Assert.Equal( "  1234.5678"			, Str(1234.5678) )
			Assert.Equal( "  1234.5679012345"	, Str(1234.5679012345) )
			Assert.Equal( "123456.78901234568"	, Str(123456.78901234567) )
			Assert.Equal( "999999" , Str(999999) )
			Assert.Equal( "******" , Str(1000000) )

			Assert.Equal( "0.0" , Transform(0 , "9.9") )
			Assert.Equal( "1.0" , Transform(1 , "9.9") )
			Assert.Equal( "*.*" , Transform(-1 , "9.9") )
			SetDecimalSep(Asc(","))
			SetThousandSep(Asc("."))
			Assert.Equal( " 0,00" , Transform(0 , "99.99") )
			Assert.Equal( " 1,00" , Transform(1 , "99.99") )
			Assert.Equal( "-1,00" , Transform(-1 , "99.99") )

			Assert.Equal( "  0,00" , Transform(0 , "999.99") )
			Assert.Equal( "  0,0" , Transform(0 , "999.9") )
			Assert.Equal( " 0,0" , Transform(0 , "99.9") )

			SetFixed(TRUE)
			SetDigit(5)
			Assert.Equal("  123" , Str(123))
			Assert.Equal("123" , Str(123 , -1))
			Assert.Equal("123" , Str(123 , 3))
			Assert.Equal("-123" , Str(-123 , 4))
			Assert.Equal("-123" , Str(-123 , -1))
			Assert.Equal(" -123" , Str(-123))
			Assert.Equal(" 123" , Str(123 , 4))
			Assert.Equal("**" , Str(123 , 2))
			SetDigit(10)
			Assert.Equal(" 123456789" , Str(123456789))
			Assert.Equal("**********" , Str(12345678901))

			SetFixed(FALSE)
			SetDigit(5)
			Assert.Equal("  123" , Str(123))
			Assert.Equal("123" , Str(123 , -1))
			Assert.Equal("123" , Str(123 , 3))
			Assert.Equal("-123" , Str(-123 , 4))
			Assert.Equal("-123" , Str(-123 , -1))
			Assert.Equal(" -123" , Str(-123))
			Assert.Equal(" 123" , Str(123 , 4))
			Assert.Equal("**" , Str(123 , 2))
			SetDigit(10)
			Assert.Equal(" 123456789" , Str(123456789))
			Assert.Equal("**********" , Str(12345678901))

			SetDecimal(2)
			SetDecimalSep(Asc(","))
			SetThousandSep(Asc("."))
			Assert.Equal( "**",    Str(1.23 , 2 , 1) )
			Assert.Equal( "1,2",   Str(1.2 , 3) )
			Assert.Equal( "123",   Str(123.456 , 3) )

			Assert.Equal( "123",   Str(123.4567 , 3 , 1) )
			Assert.Equal( "123,",  Str(123.4567 , 4 , 2) )
			Assert.Equal( "123,4", Str(123.4567 , 5 , 3) )
			Assert.Equal( "****" , Str(123.4567 , 4 , 3) )
			Assert.Equal( "*****", Str(123.4567 , 5 , 4) )

			Assert.Equal( "***",   Str(-123.4567 , 3 , 1) )
			Assert.Equal( "-123",  Str(-123.4567 , 4 , 2) )
			Assert.Equal( "-123,", Str(-123.4567 , 5 , 3) )
			Assert.Equal( "****" , Str(-123.4567 , 4 , 3) )
			Assert.Equal( "*****", Str(-123.4567 , 5 , 4) )

			Assert.Equal( "0,0",   Str(0.0 , -1) )
			Assert.Equal( "0,1",   Str(0.1 , -1) )
			Assert.Equal( "-0,1",  Str(-0.1 , -1) )
			Assert.Equal( "0,000",   Str(0.0 , -1 , 3) )
			Assert.Equal( "0,100",   Str(0.1 , -1 , 3) )
			Assert.Equal( "-0,100",  Str(-0.1 , -1 , 3) )

			Assert.Equal( "  123"	, Str(FloatFormat(123 , 5, 0)) )
			Assert.Equal( "   123"	, Str(FloatFormat(123 , 6, 0)) )
			Assert.Equal( " 123,5"	, Str(FloatFormat(123.456 , 6, 1) ) )
			Assert.Equal( "123,46"	, Str(FloatFormat(123.456 , 6, 2) ) )
			Assert.Equal( " 123,46"	, Str(FloatFormat(123.456 , 7, 2) ) )

			SetDecimalSep(deci)
			SetThousandSep(thou)
			SetDigit(digit)
			SetDecimal(decimal)
			SetFixed(fixed_)
			SetDigitFixed(digitfixed)
		RETURN

		[Fact, Trait("Category", "Str")];
		METHOD Str_With_SetFixed_TRUE() AS VOID

		   SetDecimalSep(Asc("."))
		   SetThousandSep(Asc(","))
		   SetDecimal(3)
		   SetDigit(12)

		   SetFixed(TRUE)
		   SetDigitFixed(TRUE)

		   Assert.Equal( Str(12.34)            		, "          12.340")
		   Assert.Equal( Str1(12.34)          		, "          12.340")
		   Assert.Equal( Str(123.456)         		, "         123.456")
		   Assert.Equal( Str1(123.456)       		, "         123.456")
		   Assert.Equal( Str(1230.4567)         	, "        1230.457")
		   Assert.Equal( Str1(1230.4567)        	, "        1230.457")
		   Assert.Equal( Str(100000001234.4567)		, "100000001234.457")
		   Assert.Equal( Str1(100000001234.4567)	, "100000001234.457")
		   Assert.Equal( Str(1000000001234.4567)	, "****************")
		   Assert.True ( Str1(1000000001234.4567):StartsWith("********"))
		   Assert.Equal( Str(12.3)              	, "          12.300")
		   Assert.Equal( Str1(12.3)            		, "          12.300")
		   Assert.Equal( Str(12.34567)        	 	, "          12.346")
		   Assert.Equal( Str1(12.34567)        		, "          12.346")
		   Assert.Equal( Str(12.34 , 10, 2)    		, "     12.34")
		   Assert.Equal( Str(12.34 , 5, 2)     		, "12.34")
		   Assert.Equal( Str(12.34 , 4, 2)     		, "12.3")
		   Assert.Equal( Str(12.34 , 4, 1)     		, "12.3")
		   Assert.Equal( Str(12.34 , 2, 1)     		, "**")
		   Assert.Equal( Str3(12.34 , 10, 2)   		, "     12.34")
		   Assert.Equal( Str3(12.34 , 5, 2)    		, "12.34")
		   Assert.Equal( Str3(12.34 , 4, 2)     	, "12.3")
		   Assert.Equal( Str3(12.34 , 4, 1)     	, "12.3")
		   Assert.Equal( Str3(12.34 , 2, 1)    		, "**")
		   Assert.Equal( Str(-12.34)            	, "         -12.340")
		   Assert.Equal( Str1(-12.34)           	, "         -12.340")
		   Assert.Equal( Str(-12.3456)         		, "         -12.346")
		   Assert.Equal( Str1(-12.3456)         	, "         -12.346")
		   Assert.Equal( Str(-12.34 , 10, 2)    	, "    -12.34")
		   Assert.Equal( Str(-12.34 , 5, 2)     	, "-12.3")	 //VO wrong: -2.34
		   Assert.Equal( Str(-12.34 , 4, 2)     	, "-12.")    // VO wrong: -12.
		   Assert.Equal( Str(-12.34 , 4, 1)     	, "-12.")    //VO wrong: -2.3
	       Assert.Equal( Str(-12.34 , 4, 0)     	, " -12")    //VO wrong: -2.3
		   Assert.Equal( Str(-12.34 , 2, 1)     	, "**")

		   SetDigit(8)
		   SetDecimal(2)
		   SetDecimalSep(Asc(","))
		   SetThousandSep(Asc("."))

		   Assert.Equal( Str(123456789.1)	, "***********")
		   Assert.True(Str1(123456789.1):StartsWith("*****"))
		   Assert.Equal( Str(12345678.1)	, "12345678,10")
		   Assert.Equal(Str1(12345678.1)	, "12345678,10")
		   Assert.Equal( Str(1234567.1)		, " 1234567,10")
		   Assert.Equal(Str1(1234567.1)		, " 1234567,10")
		   Assert.Equal( Str(123456.1)		, "  123456,10")
		   Assert.Equal(Str1(123456.1)		, "  123456,10")

		RETURN

		[Fact, Trait("Category", "Str")];
		METHOD Str_With_SetFixed_FALSE() AS VOID

		   SetDecimalSep(Asc("."))
		   SetThousandSep(Asc(","))
		   SetDecimal(3)
		   SetDigit(12)

		   SetFixed(FALSE)
		   SetDigitFixed(FALSE)

		   Assert.Equal( Str(12.34)            		, "          12.34")
		   Assert.Equal( Str1(12.34)          		, "          12.34")
		   Assert.Equal( Str(123.456)         		, "         123.456")
		   Assert.Equal( Str1(123.456)				, "         123.456")
		   Assert.Equal( Str(1230.4567)         	, "        1230.4567")
		   Assert.Equal( Str1(1230.4567)        	, "        1230.4567")
		   Assert.Equal( Str(100000001234.4567)		, "100000001234.4567")
		   Assert.Equal( Str1(100000001234.4567)	, "100000001234.4567")
		   Assert.Equal( Str(1000000001234.4567)	, "*****************")
//		   Assert.Equal( Str1(1000000001234.4567)	, "*****************")
		   Assert.True(  Str1(1000000001234.4567):StartsWith("*")) // it's really impossible to replicate completely VO's insane behavior
		   Assert.Equal( Str(12.3)              	, "          12.3")
		   Assert.Equal( Str1(12.3)            		, "          12.3")
		   Assert.Equal( Str(12.34567)         		, "          12.34567")
		   Assert.Equal( Str1(12.34567)        		, "          12.34567")
		   Assert.Equal( Str(12.34 , 10, 2)    		, "     12.34")
		   Assert.Equal( Str(12.34 , 5, 2)     		, "12.34")
		   Assert.Equal( Str(12.34 , 4, 2)     		, "12.3") // VO returns 12.3
		   Assert.Equal( Str(12.34 , 4, 1)     		, "12.3")
		   Assert.Equal( Str(12.34 , 2, 1)     		, "**")
		   Assert.Equal( Str3(12.34 , 10, 2)   		, "     12.34")
		   Assert.Equal( Str3(12.34 , 5, 2)    		, "12.34")
		   Assert.Equal( Str3(12.34 , 4, 2)     	, "12.3")   // VO 12.3
		   Assert.Equal( Str3(12.34 , 4, 1)     	, "12.3")
		   Assert.Equal( Str3(12.34 , 2, 1)    		, "**")
		   Assert.Equal( Str(-12.34)            	, "         -12.34")
		   Assert.Equal( Str1(-12.34)           	, "         -12.34")
		   Assert.Equal( Str(-12.3456)         		, "         -12.3456")
		   Assert.Equal( Str1(-12.3456)         	, "         -12.3456")
		   Assert.Equal( Str(-12.34 , 10, 2)    	, "    -12.34")
		   Assert.Equal( Str(-12.34 , 5, 2)     	, "-12.3")	 //VO: -2.34
		   Assert.Equal( Str(-12.34 , 4, 2)     	, "-12.")    // VO
		   Assert.Equal( Str(-12.34 , 4, 1)     	, "-12.")    //VO: -2.3
		   Assert.Equal( Str(-12.34 , 2, 1)     	, "**")

		   SetDigit(8)
		   SetDecimal(2)

		   Assert.True( Str(123456789.1):StartsWith("*"))
		   Assert.True(Str1(123456789.1):StartsWith("*"))

		   Assert.Equal( "12.34" , Str(12.34 , -1))
		   Assert.Equal( "12.3400" , Str(12.34 , -1 , 4))
		   Assert.Equal( "1.1" , Str(1.1 , -1 , 1))

            [Fact, Trait("Category", "Str")];
		    METHOD Pad_Test() AS VOID
                LOCAL u AS USUAL
                Assert.Equal(Space(10), PadR(u,10))
                Assert.Equal(Space(10), Pad(u,10))
                Assert.Equal(Space(10), PadC(u,10))
                Assert.Equal(Space(10), PadL(u,10))
                u := "a"
                Assert.Equal("a         ", PadR(u,10))
                Assert.Equal("a         ", Pad(u,10))
                Assert.Equal("    a     ", PadC(u,10))
                Assert.Equal("----a-----", PadC(u,10,"-"))
                Assert.Equal("         a", PadL(u,10))
                u := 1
                Assert.Equal("1         ", PadR(u,10))
                Assert.Equal("1         ", Pad(u,10))
                Assert.Equal("    1     ", PadC(u,10))
                Assert.Equal("====1=====", PadC(u,10,"="))
                Assert.Equal("         1", PadL(u,10))
                u := 1.23
                SetDecimalSep(Asc("."))
                Assert.Equal("1.23      ", PadR(u,10))
                Assert.Equal("1.23      ", Pad(u,10))
                Assert.Equal("   1.23   ", PadC(u,10))
                Assert.Equal("...1.23...", PadC(u,10,"."))
                Assert.Equal("      1.23", PadL(u,10))

	END CLASS

END NAMESPACE


prepare testcase for issue 67

prepare testcase for issue 67

import "LangPrelude.prg"

prop Free :: Tag ~> Row Tag * ~> * where
  Klar :: Free t {}r
  Mehr :: DiffLabel t t' -> Free t r -> Free t {t'=a;r}r
 deriving List(f)

notMentionedIn :: Label a -> Record sh -> Maybe (Free a sh)
notMentionedIn l {} = Just $ Klar
notMentionedIn l {m=v; r} = do
                            diff <- case sameLabel l m of
                                    R x -> Just x
      	      	      	      	    _ -> Nothing
                            r' <- notMentionedIn l r
                            return $ Mehr diff r'
                       where monad maybeM

Just test1 = `a `notMentionedIn` {`g=7, `h='a'}

##test "`a occurs in head position"
  Just test2 = `a `notMentionedIn` {`g=7, `a='a'}

##test "`a occurs in second position"
  Just test3 = `a `notMentionedIn` {`a=7, `b='b'}

data Environment :: Row Tag * ~> * where
  Empty :: Environment {}r
  Extend :: Free t s => Label t -> a -> Environment s -> Environment {t=a;s}r
 deriving Record(e)

verifyEnv :: Record sh -> Maybe (Environment sh)
verifyEnv {} = Just {}e
verifyEnv {l=v; r} = do
                     l' <- l `notMentionedIn` r
                     r' <- verifyEnv r
                     return {l=v; r'}e
                 where monad maybeM

Just test4 = verifyEnv {`g=7, `a='a', `h="hey"}

##test "`g occurs twice"
  Just test5 = verifyEnv {`g=7, `a='a', `g="2"}

testThatItReconstructs :: Environment sh -> Environment sh
testThatItReconstructs {}e = {}e
testThatItReconstructs {l=v; r}e = Extend l v r

test6 = testThatItReconstructs test4

##test "this should pass --> issue 67"
  test7 = {`a=4, `b='a', `c="what?"}e

##test "this should not pass, refutable, because label `a is duplicated"
  test8 = {`a=4, `b='a', `a="what?"}e