diff options
author | Gaurav Jain <gaurav@gauravjain.org> | 2014-04-24 12:50:00 -0400 |
---|---|---|
committer | Gaurav Jain <gaurav@gauravjain.org> | 2014-04-24 12:50:00 -0400 |
commit | f80c798a3b37ba28a61c896c62ce939e1ee0918b (patch) | |
tree | e131d254982c1d401560c8ecf50839d3e9469def /tests | |
parent | 2586a63b4796a97bf0c5549a7f708a07f716fc59 (diff) | |
parent | a5368fe16c36cb6d60eaa7985d6c1151451f8ed1 (diff) | |
download | pygments-f80c798a3b37ba28a61c896c62ce939e1ee0918b.tar.gz |
Merged birkenfeld/pygments-main into default
Diffstat (limited to 'tests')
-rw-r--r-- | tests/examplefiles/objc_example.m | 182 | ||||
-rw-r--r-- | tests/examplefiles/objc_example2.m | 27 | ||||
-rw-r--r-- | tests/test_objectiveclexer.py | 91 |
3 files changed, 254 insertions, 46 deletions
diff --git a/tests/examplefiles/objc_example.m b/tests/examplefiles/objc_example.m index f4f27170..f3f85f65 100644 --- a/tests/examplefiles/objc_example.m +++ b/tests/examplefiles/objc_example.m @@ -1,35 +1,179 @@ -#import "Somefile.h" +// Test various types of includes +#import <Foundation/Foundation.h> +# import <AppKit/AppKit.h> +#import "stdio.h" +#\ + import \ + "stdlib.h" +# /*line1*/ \ +import /* line 2 */ \ +"stdlib.h" // line 3 -@implementation ABC +// Commented out code with preprocessor +#if 0 +#define MY_NUMBER 3 +#endif -- (id)a:(B)b { - return 1; + #\ + if 1 +#define TEST_NUMBER 3 +#endif + +// Empty preprocessor +# + +// Class forward declaration +@class MyClass; + +// Empty classes +@interface EmptyClass +@end +@interface EmptyClass2 +{ +} +@end +@interface EmptyClass3 : EmptyClass2 +{ +} +@end + +// Custom class inheriting from built-in +@interface MyClass : NSObject +{ +@public + NSString *myString; + __weak NSString *_weakString; +@protected + NSTextField *_textField; +@private + NSDate *privateDate; } +// Various property aatributes +@property(copy, readwrite, nonatomic) NSString *myString; +@property(weak) NSString *weakString; +@property(retain, strong, atomic) IBOutlet NSTextField *textField; + +// Class methods ++ (void)classMethod1:(NSString *)arg; ++ (void)classMethod2:(NSString *) arg; // Test space before arg + @end -@implementation ABC +typedef id B; -- (void)xyz; +#pragma mark MyMarker +// MyClass.m +// Class extension to declare private property +@interface MyClass () +@property(retain) NSDate *privateDate; +- (void)hiddenMethod; @end -NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: - @"quattuor", @"four", @"quinque", @"five", @"sex", @"six", nil]; +// Special category +@interface MyClass (Special) +@property(retain) NSDate *specialDate; +@end +@implementation MyClass +@synthesize myString; +@synthesize privateDate; -NSString *key; -for (key in dictionary) { - NSLog(@"English: %@, Latin: %@", key, [dictionary valueForKey:key]); -} +- (id)a:(B)b { + /** + * C-style comment + */ + + // Selector keywords/types + SEL someMethod = @selector(hiddenMethod); + + // Boolean types + Boolean b1 = FALSE; + BOOL b2 = NO; + bool b3 = true; + + /** + * Number literals + */ + // Int Literal + NSNumber *n1 = @( 1 ); + // Method call + NSNumber *n2 = @( [b length] ); + // Define variable + NSNumber *n3 = @( TEST_NUMBER ); + // Arthimetic expression + NSNumber *n4 = @(1 + 2); + // From variable + int myInt = 5; + NSNumber *n5 = @(myInt); + // Nest expression + NSNumber *n6 = @(1 + (2 + 6.0)); + // Bool literal + NSNumber *n7 = @NO; + // Bool expression + NSNumber *n8 = @(YES); + // Character + NSNumber *n9 = @'a'; + // int + NSNumber *n10 = @123; + // unsigned + NSNumber *n11 = @1234U; + // long + NSNumber *n12 = @1234567890L; + // float + NSNumber *n13 = @3.14F; + // double + NSNumber *n14 = @3.14F; + + // Array literals + NSArray *arr = @[ @"1", @"2" ]; + arr = @[ @[ @"1", @"2" ], [arr lastObject] ]; + [arr lastObject]; + [@[ @"1", @"2" ] lastObject]; + + // Dictionary literals + NSDictionary *d = @{ @"key": @"value" }; + [[d allKeys] lastObject]; + [[@{ @"key": @"value" } allKeys] lastObject]; + d = @{ @"key": @{ @"key": @"value" } }; + + [self hiddenMethod]; + [b length]; + [privateDate class]; -// Literals -NSArray *a = @[ @"1", @"2" ]; + NSDictionary *dictionary = [NSDictionary dictionaryWithObjectsAndKeys: + @"1", @"one", @"2", @"two", @"3", @"three", nil]; + + NSString *key; + for (key in dictionary) { + NSLog(@"Number: %@, Word: %@", key, [dictionary valueForKey:key]); + } -NSDictionary *d = @{ @"key": @"value" }; + // Blocks + int (^myBlock)(int arg1, int arg2); + NSString *(^myName)(NSString *) = ^(NSString *value) { + return value; + }; -NSNumber *n1 = @( 1 ); -NSNumber *n2 = @( [a length] ); + return nil; +} + +- (void)hiddenMethod { + // Synchronized block + @synchronized(self) { + [myString retain]; + [myString release]; + } +} -+ (void)f1:(NSString *)s1; -+ (void)f2:(NSString *) s2; ++ (void)classMethod1:(NSString *)arg {} ++ (void)classMethod2:(NSString *) arg +{ + // Autorelease pool block + @autoreleasepool { + NSLog(@"Hello, World!"); + } +} + +@end diff --git a/tests/examplefiles/objc_example2.m b/tests/examplefiles/objc_example2.m deleted file mode 100644 index b7a5a685..00000000 --- a/tests/examplefiles/objc_example2.m +++ /dev/null @@ -1,27 +0,0 @@ -// MyClass.h -@interface MyClass : NSObject -{ - NSString *value; - NSTextField *textField; -@private - NSDate *lastModifiedDate; -} -@property(copy, readwrite) NSString *value; -@property(retain) IBOutlet NSTextField *textField; -@end - -// MyClass.m -// Class extension to declare private property -@interface MyClass () -@property(retain) NSDate *lastModifiedDate; -@end - -@implementation MyClass -@synthesize value; -@synthesize textField; -@synthesize lastModifiedDate; -// implementation continues -@end - -+ (void)f1:(NSString *)s1; -+ (void)f2:(NSString *)s2; diff --git a/tests/test_objectiveclexer.py b/tests/test_objectiveclexer.py new file mode 100644 index 00000000..46fdb6d2 --- /dev/null +++ b/tests/test_objectiveclexer.py @@ -0,0 +1,91 @@ +# -*- coding: utf-8 -*- +""" + Basic CLexer Test + ~~~~~~~~~~~~~~~~~ + + :copyright: Copyright 2006-2014 by the Pygments team, see AUTHORS. + :license: BSD, see LICENSE for details. +""" + +import unittest +import os + +from pygments.token import Token +from pygments.lexers import ObjectiveCLexer + + +class ObjectiveCLexerTest(unittest.TestCase): + + def setUp(self): + self.lexer = ObjectiveCLexer() + + def testLiteralNumberInt(self): + fragment = u'@(1);\n' + expected = [ + (Token.Text, u''), + (Token.Literal, u'@('), + (Token.Literal.Number.Integer, u'1'), + (Token.Literal, u')'), + (Token.Punctuation, u';'), + (Token.Text, u'\n'), + (Token.Text, u''), + ] + self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) + + def testLiteralNumberExpression(self): + fragment = u'@(1+2);\n' + expected = [ + (Token.Text, u''), + (Token.Literal, u'@('), + (Token.Literal.Number.Integer, u'1'), + (Token.Operator, u'+'), + (Token.Literal.Number.Integer, u'2'), + (Token.Literal, u')'), + (Token.Punctuation, u';'), + (Token.Text, u'\n'), + (Token.Text, u''), + ] + self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) + + def testLiteralNumberNestedExpression(self): + fragment = u'@(1+(2+3));\n' + expected = [ + (Token.Text, u''), + (Token.Literal, u'@('), + (Token.Literal.Number.Integer, u'1'), + (Token.Operator, u'+'), + (Token.Punctuation, u'('), + (Token.Literal.Number.Integer, u'2'), + (Token.Operator, u'+'), + (Token.Literal.Number.Integer, u'3'), + (Token.Punctuation, u')'), + (Token.Literal, u')'), + (Token.Punctuation, u';'), + (Token.Text, u'\n'), + (Token.Text, u''), + ] + self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) + + def testLiteralNumberBool(self): + fragment = u'@NO;\n' + expected = [ + (Token.Text, u''), + (Token.Literal.Number, u'@NO'), + (Token.Punctuation, u';'), + (Token.Text, u'\n'), + (Token.Text, u''), + ] + self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) + + def testLieralNumberBoolExpression(self): + fragment = u'@(YES);\n' + expected = [ + (Token.Text, u''), + (Token.Literal, u'@('), + (Token.Name.Builtin, u'YES'), + (Token.Literal, u')'), + (Token.Punctuation, u';'), + (Token.Text, u'\n'), + (Token.Text, u''), + ] + self.assertEqual(expected, list(self.lexer.get_tokens(fragment))) |