/Tests/Objective-J/sprintfTest.j

http://github.com/cacaodev/cappuccino · Unknown · 37 lines · 28 code · 9 blank · 0 comment · 0 complexity · cda14bf75f7b3ec788a02674907071d7 MD5 · raw file

  1. var sprintf = ObjectiveJ.sprintf;
  2. @implementation sprintfTest : OJTestCase
  3. // TODO: add many many more of these...
  4. - (void)testObjectWithPrefixAndSuffix
  5. {
  6. [self assert:@"[hello world]" equals:sprintf(@"[%@]", @"hello world")];
  7. }
  8. - (void)testDecimalWithPrefixAndSuffix
  9. {
  10. [self assert:@"[123]" equals:sprintf(@"[%d]", 123)];
  11. }
  12. - (void)testFloatWithPrefixAndSuffix
  13. {
  14. [self assert:@"[123.1234]" equals:sprintf(@"[%f]", 123.1234)];
  15. }
  16. - (void)testZeroPaddingWithWidthAndPercentEscaping
  17. {
  18. [self assert:@"099%" equals:sprintf(@"%03d%%", 99)];
  19. }
  20. - (void)testOutOfOrderExplicitFormatParameterIndexes
  21. {
  22. [self assert:@"2 > 1" equals:sprintf(@"%2$d > %1$d", 1, 2)];
  23. }
  24. - (void)testMixingImplicitAndExplicitFormatParameterIndexes
  25. {
  26. [self assert:@"a < b && b > a" equals:sprintf(@"%@ < %2$@ && %@ > %1$@", @"a", @"b")];
  27. }
  28. @end