new TypeTool()

Description

Facilitate working with arbitrary types.

Currently supports a Python-like repr() method. Better output for built-in container types is the primary goal.

Some built-in types (e.g., Map, Set), do not have good string representations when showing up in error messages. While user classes can provide a toString() method, sometimes they may not be available. To help with this situation, this class provides a registration system to extend support.

The addReprFunc method can allow users to register their own.

Migrating equality testing out of TestCase is a future goal.

It was originally designed for testing, but there can be use cases such as human readable logging as well.

Details

<p><a href="https://github.com/nexushoratio/userscripts/issues/344">(#344)</a> WIP</p>

Methods


getType( item ) → {string}

Description

Attempt to get the type of item.

This is NOT equivalent to the built-in typeof operator. Hence, results are explicitly NOT lower-cased in order to reduce chances of conflicts.

Parameters
Name Type Description
item object

Item to inspect.

Returns

The likely type of item.

Details

repr( item ) → {string}

Description

Returns a string representation of the item using the registration system.

Parameters
Name Type Description
item object

Anything.

Returns

String version of item.

Details

getReprFunc( item ) → {NexusHoratio.xunit.TypeTool~ReprFunc}

Description

Find a ReprFunc for the given item.

Parameters
Name Type Description
item object

Item of interest.

Returns

Function for this item.

Details

addReprFunc( type, func )

Parameters
Name Type Description
type string

Type of interest.

func NexusHoratio.xunit.TypeTool~ReprFunc

Function for this type.

Details

reprString( item ) → {string}

Parameters
Name Type Description
item string

String to wrap.

Returns

Wrapped version of item.


reprArray( array ) → {string}

Parameters
Name Type Description
array Array.<object>

Array of anything.

Returns

String version of item.


reprObject( obj ) → {string}

Parameters
Name Type Description
obj object

Any object.

Returns

String version of obj.


reprMap( map ) → {string}

Parameters
Name Type Description
map Map.<object, object>

Any Map.

Returns

String version of map.


reprSet( set ) → {string}

Parameters
Name Type Description
set Set.<object>

Any Set.

Returns

String version of set.

Type Definitions


ReprFunc( item ) → {string}

Parameters
Name Type Description
item object

Anything.

Returns

String version of item.

Details
function