TinTin++ Mud Client The TinTin++ message board

 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
TinTin++ Mud Client

Testing for Argument Existence in Aliases & Functions

 
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports
View previous topic :: View next topic  
Author Message
atraeyu



Joined: 12 Dec 2007
Posts: 165

PostPosted: Fri Feb 21, 2014 10:15 am    Post subject: Testing for Argument Existence in Aliases & Functions Reply with quote

If my code is correct, then it appears that testing arguments for existence is not working correctly. The last two checks are relevant for this potential bug.

Script source: https://github.com/nfarrar/TinMan/blob/master/reference/variables/check-exists.tin

Code:

#nop ./reference/variables/check-exists.tin;
/*

    Some variable and argument existence tests to ensure they work as expected.

    It appears there is a bug in TinTin 2.01 where else clauses
    will not trigger when used with variable existence tests.

    It appears that you cannot test for argument existence in aliases and
    functions in TinTin 2.01.

    RUNME: tt++ reference/variables/check-exists.tin;
*/

#if {&{MOD_LOADED}} {
    #showme {! Module has previously been loaded.  Reinitializing environment.\n};
    #class {$MOD_NAME} {kill};
};

#if {!&{MOD_LOADED}} {
    #showme {! Module has not previously been loaded.  Initializing environment.\n};
    #var {MOD_NAME} {check-exists};
    #var {MOD_PATH} {reference/variables/check-exists.tin};
    #var {MOD_LOADED} {true};
};

#nop Kill the class code and reload this file.;
#alias {reload} {
    #sys {clear};
    #read {$MOD_PATH};
};

#class {$MOD_NAME} {open};
#config {VERBOSE} {ON};
#nop +-----------------------------------------------------------------------+;
#nop |                          Start of Class                               |;
#nop +-----------------------------------------------------------------------+;

#nop Set the test variable.;
#var {this_variable_exists} {true};

#nop We'll perform checks against the variable $this_variable_does_not_exist;
#nop which has not been set and does not exist when checking for a lack of;
#nop variable existence.;

#showme {* Testing the existence of $$this_variable_exists.};
#showme {* The message is generated by the #if clause.};
#showme {* We should see a message that the variable exists.};

#if {&{this_variable_exists}} {
    #showme {> This variable exists.};
};
#else {
    #showme {> This variable does not exist.};
};

/*
    Output from this test is as expected.
*/

#showme {\n* Testing the lack of existence of $$this_variable_exists.};
#showme {* The message is generated by the #else clause.};
#showme {* We should see a message that the variable does not exist.};

#if {!&{this_variable_exists}} {
    #showme {> This variable does not exist.};
};
#else {
    #showme {> This variable exists.};
};

/*
    Output from this test is not as expected.
    The #else clause does not execute.
*/

#showme {\n* Testing the lack of existence of $$this_variable_does_not_exist.};
#showme {* The message is generated by the #if clause.};
#showme {* We should see a message that the variable does not exist.};

#if {!&{this_variable_does_not_exist}} {
    #showme {> This variable does not exist.};
};
#else {
    #showme {> This variable exists.};
};

/*
    Output from this test is as expected.
*/

#showme {\n* Testing for the existence of $$this_variable_does_not_exist.};
#showme {* The message is generated by the #else clause.};
#showme {* We should see a message that the variable does not exist.};

#if {&{this_variable_does_not_exist}} {
    #showme {> Ths variable exists.};
};
#else {
    #showme {> The variable does not exist.};
};

/*
    Output from this test is not as expected.
    The #else clause does not execute.
*/

#showme {\n* Testing for the existence of %1 in an alias. We should see two messages.};
#showme {* The first message should be generated by the #if clause and say that %1 does not exist.};
#showme {* The second message should be generated by the #else clause and say that %1 exists.};

#alias {aArgExists} {
    #if {!&{%1}} {
        #showme {> The argument %%1 does not exist.};
    };
    #else {
        #showme {> The argument %%1 exists.};
    };
};

aArgExists;
aArgExists {arg1};

/*
    Output from this test is not as expected.
    In both cases the test for the existence of %1 fails and the #else clause executes.
*/

#showme {\n* Testing for the existence of %1 in a function. We should see two messages.};
#showme {* The first message should be generated by the #if clause and say that %1 does not exist.};
#showme {* The second message should be generated by the #else clause and say that %1 exists.};

#function {fArgExists} {
    #if {!&{%1}} {
        #return {> The argument %%1 does not exist.};
    };
    #else {
        #return {> The argument %%1 exists and is set to %1\.};
    };
};

#showme {@fArgExists{}};
#showme {@fArgExists{arg1}};

/*
    Output from this test is not as expected.
    In both cases the test for the existence of %1 fails and the #else clause executes.
    Additionally, the returned string contains extraneous braces. I am not sure why.
*/

#nop +-----------------------------------------------------------------------+;
#nop |                           End of Class                                |;
#nop +-----------------------------------------------------------------------+;
#config {VERBOSE} {OFF};
#class {$MOD_NAME} {close};





The output:
Code:

* Testing the existence of $this_variable_exists.
* The message is generated by the #if clause.
* We should see a message that the variable exists.
> This variable exists.

* Testing the lack of existence of $this_variable_exists.
* The message is generated by the #else clause.
* We should see a message that the variable does not exist.

* Testing the lack of existence of $this_variable_does_not_exist.
* The message is generated by the #if clause.
* We should see a message that the variable does not exist.
> This variable does not exist.

* Testing for the existence of $this_variable_does_not_exist.
* The message is generated by the #else clause.
* We should see a message that the variable does not exist.

* Testing for the existence of %1 in an alias. We should see two messages.
* The first message should be generated by the #if clause and say that %1 does not exist.
* The second message should be generated by the #else clause and say that %1 exists.
> The argument %1 does not exist.
> The argument %1 does not exist.

* Testing for the existence of %1 in a function. We should see two messages.
* The first message should be generated by the #if clause and say that %1 does not exist.
* The second message should be generated by the #else clause and say that %1 exists.
{> The argument %1 does not exist.}{}
{> The argument %1 does not exist.}{}

Back to top
View user's profile Send private message AIM Address
Display posts from previous:   
Post new topic   Reply to topic    The TinTin++ message board Forum Index -> Bug Reports All times are GMT - 5 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads Get TinTin++ Mud Client at SourceForge.net. Fast, secure and Free Open Source software downloads
TinTin++ Homepage

Powered by phpBB © 2001, 2002 phpBB Group