Skip to content

Commit

Permalink
YES and NO are now bools and as a result appear as bools in property …
Browse files Browse the repository at this point in the history
…lists.
  • Loading branch information
timburks committed Mar 21, 2013
1 parent e673cdb commit 7da8bf6
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 34 deletions.
4 changes: 2 additions & 2 deletions objc/Nu.m
Expand Up @@ -8990,8 +8990,8 @@ void load_builtins(NuSymbolTable *symbolTable)
{
[(NuSymbol *) [symbolTable symbolWithString:@"t"] setValue:[symbolTable symbolWithString:@"t"]];
[(NuSymbol *) [symbolTable symbolWithString:@"nil"] setValue:Nu__null];
[(NuSymbol *) [symbolTable symbolWithString:@"YES"] setValue:[NSNumber numberWithInt:1]];
[(NuSymbol *) [symbolTable symbolWithString:@"NO"] setValue:[NSNumber numberWithInt:0]];
[(NuSymbol *) [symbolTable symbolWithString:@"YES"] setValue:[NSNumber numberWithBool:YES]];
[(NuSymbol *) [symbolTable symbolWithString:@"NO"] setValue:[NSNumber numberWithBool:NO]];

install(@"car", Nu_car_operator);
install(@"cdr", Nu_cdr_operator);
Expand Down
71 changes: 39 additions & 32 deletions test/test_numbers.nu
Expand Up @@ -4,35 +4,42 @@
;; Copyright (c) 2007 Tim Burks, Radtastical Inc.

(class TestNumbers is NuTestCase

(- testTimes is
(set sum 0)
(10 times:
(do (i) (set sum (+ sum i))))
(assert_equal 45 sum))

(- testDownTo is
(set firstValue nil)
(set lastValue nil)
(set sum 0)
(10 downTo:5 do:
(do (i)
(set sum (+ sum i))
(unless firstValue (set firstValue i))
(set lastValue i)))
(assert_equal 45 sum)
(assert_equal 10 firstValue)
(assert_equal 5 lastValue))

(- testUpTo is
(set firstValue nil)
(set lastValue nil)
(set sum 0)
(5 upTo:10 do:
(do (i)
(set sum (+ sum i))
(unless firstValue (set firstValue i))
(set lastValue i)))
(assert_equal 45 sum)
(assert_equal 5 firstValue)
(assert_equal 10 lastValue)))

(- testTimes is
(set sum 0)
(10 times:
(do (i) (set sum (+ sum i))))
(assert_equal 45 sum))

(- testDownTo is
(set firstValue nil)
(set lastValue nil)
(set sum 0)
(10 downTo:5 do:
(do (i)
(set sum (+ sum i))
(unless firstValue (set firstValue i))
(set lastValue i)))
(assert_equal 45 sum)
(assert_equal 10 firstValue)
(assert_equal 5 lastValue))

(- testUpTo is
(set firstValue nil)
(set lastValue nil)
(set sum 0)
(5 upTo:10 do:
(do (i)
(set sum (+ sum i))
(unless firstValue (set firstValue i))
(set lastValue i)))
(assert_equal 45 sum)
(assert_equal 5 firstValue)
(assert_equal 10 lastValue))

(- testBooleans is
;; YES and NO should be bools and should show up as bools in property lists
(assert_equal ((NSNumber numberWithBool:YES) class) (YES class))
(assert_equal ((NSNumber numberWithBool:NO) class) (NO class))
(assert (/<true\/>/ findInString: (NSString stringWithData:((dict x:YES) XMLPropertyListRepresentation) encoding:NSUTF8StringEncoding)))
(assert (/<false\/>/ findInString: (NSString stringWithData:((dict x:NO) XMLPropertyListRepresentation) encoding:NSUTF8StringEncoding)))))

0 comments on commit 7da8bf6

Please sign in to comment.