Changeset 55

Show
Ignore:
Timestamp:
03/10/08 12:46:31 (4 years ago)
Author:
flithm
Message:

Update parseTo and parseFrom

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/tango/scrapple/text/convert/parseFrom.d

    r47 r55  
    313313    return ((c <= '\r' && c >= '\a') || c == '\"' || c == '\'' || c == '\\'); 
    314314} 
    315 // Warning: this DOES NOT check c is escapable 
     315// Throws on unsupported escape sequences; however this should never actually happen within parseFrom. 
    316316private char replaceEscapableChar (char c) { 
    317     static char[char] escCharsRev;  // reversed escChars 
    318     static bool escCharsRevFilled;  // will be initialised false 
    319      
    320     if (!escCharsRevFilled) {   // only do this once 
    321         // map of all supported escape sequences 
    322         escCharsRev = ['"' : '"', '\'' : '\'', 
    323                        '\\' : '\\', '\a' : 'a', 
    324                        '\b' : 'b', '\f' : 'f', 
    325                        '\n' : 'n', '\r' : 'r', 
    326                        '\t' : 't', '\v' : 'v']; 
    327         escCharsRevFilled = true; 
    328     } 
    329      
    330     return escCharsRev[c]; 
    331 
    332  
    333 debug (UnitTest) unittest { 
    334     // all utility functions should be well-enough used not to need testing 
     317    // This code was generated: 
     318    if (c <= '\v') { 
     319        if (c <= '\b') { 
     320            if (c == '\a') { 
     321                return 'a'; 
     322            } else if (c == '\b') { 
     323                return 'b'; 
     324            } 
     325        } else { 
     326            if (c == '\t') { 
     327                return 't'; 
     328            } else if (c == '\n') { 
     329                return 'n'; 
     330            } else if (c == '\v') { 
     331                return 'v'; 
     332            } 
     333        } 
     334    } else { 
     335        if (c <= '\r') { 
     336            if (c == '\f') { 
     337                return 'f'; 
     338            } else if (c == '\r') { 
     339                return 'r'; 
     340            } 
     341        } else { 
     342            if (c == '\"') { 
     343                return '\"'; 
     344            } else if (c == '\'') { 
     345                return '\''; 
     346            } else if (c == '\\') { 
     347                return '\\'; 
     348            } 
     349        } 
     350    } 
     351     
     352    // if we haven't returned: 
     353    throw new IllegalArgumentException ("Character is not escapable (internal parseFrom error)"); 
     354
     355 
     356debug (UnitTest) { 
     357    import tango.io.Console; 
     358     
     359    unittest { 
     360        Cout ("Running unittest: parseFrom ...").flush; 
     361         
     362        assert (parseFrom!(char[]) ("\a\b\t\n\v\f\r\"\'\\") == "\"\\a\\b\\t\\n\\v\\f\\r\\\"\\\'\\\\\""); 
     363         
     364        Cout (" complete").newline; 
     365    } 
    335366} 
    336367//END Utility funcs 
  • trunk/tango/scrapple/text/convert/parseTo.d

    r49 r55  
    442442private char replaceEscapedChar (char c) 
    443443{ 
    444     static char[char] escChars; 
    445     static bool escCharsFilled; // will be initialised false 
    446      
    447     if (!escCharsFilled) { 
    448         // map of all supported escape sequences (cannot be static?) 
    449         escChars = ['"'  : '"', '\'' : '\'', 
    450                     '\\' : '\\', 'a' : '\a', 
    451                     'b'  : '\b', 'f' : '\f', 
    452                     'n'  : '\n', 'r' : '\r', 
    453                     't'  : '\t', 'v' : '\v']; 
    454         escCharsFilled = true; 
    455     } 
    456      
    457     char* r = c in escChars; 
    458     if (r != null) return *r; 
    459     else throw new ParseException ("Invalid escape sequence: \\"~c); 
     444    // This code was generated: 
     445    if (c <= 'b') { 
     446        if (c <= '\'') { 
     447            if (c == '\"') { 
     448                return '\"'; 
     449            } else if (c == '\'') { 
     450                return '\''; 
     451            } 
     452        } else { 
     453            if (c == '\\') { 
     454                return '\\'; 
     455            } else if (c == 'a') { 
     456                return '\a'; 
     457            } else if (c == 'b') { 
     458                return '\b'; 
     459            } 
     460        } 
     461    } else { 
     462        if (c <= 'n') { 
     463            if (c == 'f') { 
     464                return '\f'; 
     465            } else if (c == 'n') { 
     466                return '\n'; 
     467            } 
     468        } else { 
     469            if (c == 'r') { 
     470                return '\r'; 
     471            } else if (c == 't') { 
     472                return '\t'; 
     473            } else if (c == 'v') { 
     474                return '\v'; 
     475            } 
     476        } 
     477    } 
     478     
     479    // if we haven't returned: 
     480    throw new ParseException ("Invalid escape sequence: \\"~c); 
    460481} 
    461482 
     
    484505} 
    485506 
    486 debug (UnitTest) unittest { 
    487     // all utility functions should be well-enough used not to need testing 
     507debug (UnitTest) { 
     508    import tango.io.Console; 
     509     
     510    unittest { 
     511        Cout ("Running unittest: parseTo ...").flush; 
     512         
     513        assert (parseTo!(char[]) ("\"\\a\\b\\t\\n\\v\\f\\r\\\"\\\'\\\\\"") == "\a\b\t\n\v\f\r\"\'\\"); 
     514         
     515        Cout (" complete").newline; 
     516    } 
    488517} 
    489518//END Utility funcs 
  • trunk/tests/dsss.conf

    r47 r55  
    77[shakematrix.d] 
    88[unittests.d] 
    9 buildflags=-I.. -debug=UnitTest -unittest 
     9buildflags=-I.. -debug -debug=UnitTest -C-unittest 
  • trunk/tests/unittests.d

    r47 r55  
    1010 * It indiscriminately imports all modules in tango.scrapple so that any with unittests have their 
    1111 * tests compiled in. 
     12 * 
     13 * BIG FAT WARNING: If you have scrapple installed in a global import directory, the modules will 
     14 * probably get imported from there, and hence will likely not reflect your latest versions! 
     15 * 
     16 * To double-check your unittests actually run, make them print a message or test with an 
     17 * assert(false) expression. 
    1218 *************************************************************************************************/ 
    1319module unittests; 
     20 
     21// Should import all modules. Last updated using r54 code. 
     22// Some lines are commented out due to link errors. 
    1423 
    1524import tango.scrapple.io.filter.RawCoutFilter; 
     
    1827import tango.scrapple.net.http.HttpMultipart; 
    1928import tango.scrapple.protocol.PlainTextProtocol; 
    20 /+ No unittest and link errors: 
    21 import tango.scrapple.sys.win32.Registry; +/ 
     29//import tango.scrapple.sys.win32.Registry; link errors 
    2230import tango.scrapple.text.convert.parseFrom; 
    2331import tango.scrapple.text.convert.parseTo; 
     
    2533import tango.scrapple.thread.Message; 
    2634import tango.scrapple.thread.ThreadPool; 
    27 import tango.scrapple.util.uuid.Generators; 
    28 import tango.scrapple.util.uuid.NameBased; 
    29 import tango.scrapple.util.uuid.Random; 
    30 import tango.scrapple.util.uuid.Uuid2; 
    31 import tango.scrapple.util.uuid.Uuid3; 
     35import tango.scrapple.util.uuid.ipc.AutoSemaphore; 
     36import tango.scrapple.util.uuid.ipc.Common; 
     37import tango.scrapple.util.uuid.ipc.IpcObject; 
     38import tango.scrapple.util.uuid.ipc.MappableFile; 
     39import tango.scrapple.util.uuid.ipc.MappedRegion; 
     40import tango.scrapple.util.uuid.ipc.MemoryMappable; 
     41import tango.scrapple.util.uuid.ipc.NamedSemaphore; 
     42//import tango.scrapple.util.uuid.ipc.SharedMemoryObject; link errors 
     43//import tango.scrapple.util.uuid.sys.Mac;  pragma(lib,...) 
     44import tango.scrapple.util.uuid.sys.SysString; 
     45import tango.scrapple.util.uuid.NameUuidGen; 
     46//import tango.scrapple.util.uuid.NativeUuidGen;  pragma(lib,...) 
     47import tango.scrapple.util.uuid.RandomUuidGen; 
     48import tango.scrapple.util.uuid.TimeUuidGen; 
     49import tango.scrapple.util.uuid.UnitTestUtil; 
    3250import tango.scrapple.util.uuid.Uuid; 
    3351import tango.scrapple.util.Arguments; 
     
    3553import tango.scrapple.util.Test; 
    3654 
    37 import tango.io.Console;       // for success message 
     55import tango.io.Console;        // for success message 
     56 
     57bool unittestsRun = false;      // check the test here, at least, actually gets run 
    3858 
    3959// This should be an executable: 
    4060void main() { 
    4161    // If execution reaches here, unittests were succesful: 
    42     Cout ("All scrapple unittests passed!").newline; 
     62    if (unittestsRun) Cout ("All scrapple unittests passed! (presuming they were run)").newline; 
    4363} 
     64 
     65debug (UnitTest) unittest { 
     66    Cout ("Unittests are being run...").newline; 
     67    unittestsRun = true; 
     68    assert (parseTo!(char[]) ("\"\\a\\b\\t\\n\\v\\f\\r\\\"\\\'\\\\\"") == "\a\b\t\n\v\f\r\"\'\\"); 
     69    assert (parseFrom!(char[]) ("\a\b\t\n\v\f\r\"\'\\") == "\"\\a\\b\\t\\n\\v\\f\\r\\\"\\\'\\\\\""); 
     70}