Skip to content

Commit

Permalink
adding nil to strings (with the + operator) adds an empty string.
Browse files Browse the repository at this point in the history
previously "()" was added.
  • Loading branch information
Tim Burks committed Nov 18, 2010
1 parent 89ad15d commit 3c27800
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
7 changes: 5 additions & 2 deletions objc/operator.m
Original file line number Diff line number Diff line change
Expand Up @@ -1060,7 +1060,10 @@ - (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
NSMutableString *result = [NSMutableString stringWithString:[firstArgument stringValue]];
id cursor = [cdr cdr];
while (cursor && (cursor != Nu__null)) {
[result appendString:[[[cursor car] evalWithContext:context] stringValue]];
id carValue = [[cursor car] evalWithContext:context];
if (carValue && (carValue != Nu__null)) {
[result appendString:[carValue stringValue]];
}
cursor = [cursor cdr];
}
return result;
Expand Down Expand Up @@ -1914,7 +1917,7 @@ @interface Nu_sleep_operator : NuOperator {}
@implementation Nu_sleep_operator
- (id) callWithArguments:(id)cdr context:(NSMutableDictionary *)context
{
int result = -1;
int result = -1;
if (cdr && (cdr != Nu__null)) {
int seconds = [[[cdr car] evalWithContext:context] intValue];
result = sleep(seconds);
Expand Down
5 changes: 4 additions & 1 deletion test/test_strings.nu
Original file line number Diff line number Diff line change
Expand Up @@ -150,4 +150,7 @@ END)
(then (- c (- 'a' 'A')))
(else c))))))
(set finish (mapped componentsJoinedByString:""))
(assert_equal "HELLO, WORLD" finish)))
(assert_equal "HELLO, WORLD" finish))

(- (id) testAddingNilToStrings is
(assert_equal "hello world" (+ "hello" nil " " nil "world"))))

0 comments on commit 3c27800

Please sign in to comment.