Index: src/OFList.m ================================================================== --- src/OFList.m +++ src/OFList.m @@ -12,10 +12,12 @@ #include "config.h" #include "assert.h" #import "OFList.h" +#import "OFString.h" +#import "OFAutoreleasePool.h" #import "OFExceptions.h" #import "macros.h" @implementation OFList + list @@ -254,10 +256,34 @@ OF_HASH_FINALIZE(hash); return hash; } + +- (OFString*)description +{ + OFMutableString *ret = [OFMutableString stringWithString: @"["]; + OFAutoreleasePool *pool; + of_list_object_t *iter; + + pool = [[OFAutoreleasePool alloc] init]; + + for (iter = firstListObject; iter != NULL; iter = iter->next) { + [ret appendString: [iter->object description]]; + + if (iter->next != NULL) + [ret appendString: @", "]; + + [pool releaseObjects]; + } + + [ret appendString: @"]"]; + + [pool release]; + + return ret; +} - (int)countByEnumeratingWithState: (of_fast_enumeration_state_t*)state objects: (id*)objects count: (int)count_ { Index: tests/OFListTests.m ================================================================== --- tests/OFListTests.m +++ tests/OFListTests.m @@ -77,10 +77,13 @@ [[list firstListObject]->next->object isEqual: strings[1]] && [[list lastListObject]->object isEqual: strings[2]]) TEST(@"-[isEqual:]", [list isEqual: [[list copy] autorelease]]) + TEST(@"-[description]", + [[list description] isEqual: @"[Foo, Bar, Baz]"]) + TEST(@"-[objectEnumerator]", (enumerator = [list objectEnumerator])) loe = [list firstListObject]; i = 0; ok = YES;