Skip to content
This repository has been archived by the owner on Dec 9, 2020. It is now read-only.

Commit

Permalink
Merge pull request KosmicTask#21 from balthisar/improve-errors
Browse files Browse the repository at this point in the history
Breakpoint Delegate rework (part of improve errors)
  • Loading branch information
shysaur committed Feb 16, 2015
2 parents 5629358 + 2938fb0 commit 7b01cdf
Show file tree
Hide file tree
Showing 13 changed files with 304 additions and 75 deletions.
4 changes: 3 additions & 1 deletion Applications/MGSFragariaView/AppDelegate.h
Expand Up @@ -9,8 +9,10 @@
//

#import <Cocoa/Cocoa.h>
#import "MGSBreakpointDelegate.h"

@interface AppDelegate : NSObject <NSApplicationDelegate>

@interface AppDelegate : NSObject <NSApplicationDelegate, MGSBreakpointDelegate>

@end

48 changes: 37 additions & 11 deletions Applications/MGSFragariaView/AppDelegate.m
Expand Up @@ -35,7 +35,9 @@ @interface AppDelegate ()
#pragma mark - IMPLEMENTATION


@implementation AppDelegate
@implementation AppDelegate {
NSArray *_breakPoints;
}


#pragma mark - Initialization and Setup
Expand Down Expand Up @@ -100,14 +102,38 @@ - (void)textDidChange:(NSNotification *)notification


/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
breakpointsForFile:
breakpointsForView:
*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
- (NSSet*) breakpointsForView:(id)sender
{
#pragma unused(sender)
return [NSSet setWithArray:_breakPoints];
}

/*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*
toggleBreakpointForView:onLine
*–––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––––*/
- (NSSet*) breakpointsForFile:(NSString*)file
- (void)toggleBreakpointForView:(id)sender onLine:(int)line;
{
#pragma unused(file)
NSLog(@"%@", @"I'm the breakpoints delegate.");
//return [NSSet setWithArray:@[@(6)]];
return nil;
#pragma unused(sender)
if ([_breakPoints containsObject:@(line)])
{
_breakPoints = [_breakPoints filteredArrayUsingPredicate:[NSPredicate predicateWithBlock:^BOOL(id evaluatedObject, NSDictionary *bindings) {
return ![evaluatedObject isEqualToValue:@(line)];
}]];
}
else
{
if (_breakPoints)
{
_breakPoints = [_breakPoints arrayByAddingObject:@(line)];
}
else
{
_breakPoints = @[@(line)];
}
}

}


Expand Down Expand Up @@ -192,7 +218,7 @@ - (NSArray *)makeSyntaxErrors
@"character" : @(3),
@"length" : @(5),
@"hidden" : @(YES),
@"warningLevel" : @(kMGSErrorError)
@"warningLevel" : @(kMGSErrorCategoryError)
}];

SMLSyntaxError *error2 = [[SMLSyntaxError alloc] initWithDictionary:@{
Expand All @@ -201,7 +227,7 @@ - (NSArray *)makeSyntaxErrors
@"character" : @(12),
@"length" : @(7),
@"hidden" : @(NO),
@"warningLevel" : @(kMGSErrorAccess)
@"warningLevel" : @(kMGSErrorCategoryAccess)
}];

SMLSyntaxError *error3 = [[SMLSyntaxError alloc] init];
Expand All @@ -210,10 +236,10 @@ - (NSArray *)makeSyntaxErrors
error3.character = 1;
error3.length = 2;
error3.hideWarning = NO;
error3.warningStyle = kMGSErrorConfig;
error3.warningStyle = kMGSErrorCategoryConfig;

SMLSyntaxError *error4 = [SMLSyntaxError new];
error4.description = @"This error will be hidden.";
error4.description = @"This error will not be hidden.";
error4.line = 10;
error4.character = 12;
error4.length = 7;
Expand Down
5 changes: 5 additions & 0 deletions Fragaria.xcodeproj/project.pbxproj
Expand Up @@ -87,6 +87,7 @@
ABE25D0A1635CA7C00F23718 /* MGSFragariaPrefsViewController.h in Headers */ = {isa = PBXBuildFile; fileRef = ABE25D081635CA7C00F23718 /* MGSFragariaPrefsViewController.h */; settings = {ATTRIBUTES = (Public, ); }; };
ABE25D0B1635CA7C00F23718 /* MGSFragariaPrefsViewController.m in Sources */ = {isa = PBXBuildFile; fileRef = ABE25D091635CA7C00F23718 /* MGSFragariaPrefsViewController.m */; };
ABF28AF014C075D400ECAD48 /* NSScanner+Fragaria.m in Sources */ = {isa = PBXBuildFile; fileRef = ABF28AEE14C075D400ECAD48 /* NSScanner+Fragaria.m */; };
D0AB50F01A91CDC200A6DF58 /* SMLSyntaxErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = D0AB50EF1A91CDC200A6DF58 /* SMLSyntaxErrorTests.m */; };
D0C145C71A85F2C900DDE90A /* SMLTextView+MGSDragging.m in Sources */ = {isa = PBXBuildFile; fileRef = D0C145C31A85E1FD00DDE90A /* SMLTextView+MGSDragging.m */; };
D0C146521A87196200DDE90A /* AppDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = D0C146511A87196200DDE90A /* AppDelegate.m */; };
D0C146541A87196200DDE90A /* main.m in Sources */ = {isa = PBXBuildFile; fileRef = D0C146531A87196200DDE90A /* main.m */; };
Expand Down Expand Up @@ -257,6 +258,7 @@
ABE25D091635CA7C00F23718 /* MGSFragariaPrefsViewController.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = MGSFragariaPrefsViewController.m; sourceTree = "<group>"; };
ABF28AEE14C075D400ECAD48 /* NSScanner+Fragaria.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; lineEnding = 0; path = "NSScanner+Fragaria.m"; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.objc; };
ABF28AEF14C075D400ECAD48 /* NSScanner+Fragaria.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "NSScanner+Fragaria.h"; sourceTree = "<group>"; };
D0AB50EF1A91CDC200A6DF58 /* SMLSyntaxErrorTests.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SMLSyntaxErrorTests.m; sourceTree = "<group>"; };
D0C145C21A85E1FD00DDE90A /* SMLTextView+MGSDragging.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "SMLTextView+MGSDragging.h"; sourceTree = "<group>"; };
D0C145C31A85E1FD00DDE90A /* SMLTextView+MGSDragging.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "SMLTextView+MGSDragging.m"; sourceTree = "<group>"; };
D0C1464C1A87196200DDE90A /* MGSFragariaView.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = MGSFragariaView.app; sourceTree = BUILT_PRODUCTS_DIR; };
Expand Down Expand Up @@ -659,6 +661,7 @@
isa = PBXGroup;
children = (
D0E521071A90E307005CB80B /* MGSSyntaxErrorControllerTests.m */,
D0AB50EF1A91CDC200A6DF58 /* SMLSyntaxErrorTests.m */,
D0E5210F1A90E34F005CB80B /* Supporting Files */,
);
path = "MGSFragaria Tests";
Expand Down Expand Up @@ -999,6 +1002,7 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
D0AB50F01A91CDC200A6DF58 /* SMLSyntaxErrorTests.m in Sources */,
D0E5211A1A90E399005CB80B /* MGSSyntaxErrorControllerTests.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down Expand Up @@ -1655,6 +1659,7 @@
D0E521191A90E34F005CB80B /* Release */,
);
defaultConfigurationIsVisible = 0;
defaultConfigurationName = Release;
};
/* End XCConfigurationList section */
};
Expand Down
37 changes: 35 additions & 2 deletions MGSBreakpointDelegate.h
Expand Up @@ -8,9 +8,42 @@

#import <Foundation/Foundation.h>

/**
* The <MGSBreakpointDelegate> protocol specifies methods for delegates
* to adopt in order to receive breakpoint-related messages from Fragaria.
**/
@protocol MGSBreakpointDelegate <NSObject>

- (void) toggleBreakpointForFile:(NSString*)file onLine:(int)line;
- (NSSet*) breakpointsForFile:(NSString*)file;

@optional

/**
* This message is sent to a delegate when Fragaria requests
* a set of line numbers containing breakpoints.
* @param sender The object sending the message, and is a reference to the Fragaria instance.
* @return A set if NSNumber indicating the line numbers that have breakpoints.
**/
- (NSSet*) breakpointsForView:(id)sender;


/**
* This message is sent to a delegate when Fragaria indicates
* that a request to toggle a breakpoint was made.
* @param sender The object sending the message, and is a reference to the Fragaria instance.
@ @param line The line number for which the request was made.
**/
- (void) toggleBreakpointForView:(id)sender onLine:(int)line;


/**
* @deprecated Use breakpointsForView: instead.
**/
- (NSSet*) breakpointsForFile:(NSString*)file __deprecated_msg("Use breakpointsForView: instead.");


/**
* @deprecated Use toggleBreakpointForView:onLine: instead.
**/
- (void) toggleBreakpointForFile:(NSString*)file onLine:(int)line __deprecated_msg("Use toggleBreakpointForView:onLine: instead.");

@end
32 changes: 16 additions & 16 deletions MGSFragaria Tests/MGSSyntaxErrorControllerTests.m
Expand Up @@ -29,39 +29,39 @@ - (void)setUp
@"description" : @"Sample error 1.",
@"line" : @(4),
@"hidden" : @(NO),
@"warningLevel" : @(kMGSErrorAccess)
@"warningLevel" : @(kMGSErrorCategoryAccess)
}],

[SMLSyntaxError errorWithDictionary:@{
@"description" : @"Sample error 2.",
@"line" : @(4),
@"hidden" : @(YES),
@"warningLevel" : @(kMGSErrorPanic)
@"warningLevel" : @(kMGSErrorCategoryPanic)
}],
[SMLSyntaxError errorWithDictionary:@{
@"description" : @"Sample error 3.",
@"line" : @(37),
@"hidden" : @(NO),
@"warningLevel" : @(kMGSErrorDocument)
@"warningLevel" : @(kMGSErrorCategoryDocument)
}],
[SMLSyntaxError errorWithDictionary:@{
@"description" : @"Sample error 4.",
@"line" : @(37),
@"hidden" : @(NO),
@"warningLevel" : @(kMGSErrorDocument)
@"warningLevel" : @(kMGSErrorCategoryDocument)
}],
[NSString stringWithFormat:@"%@", @"I don't belong here."],
[SMLSyntaxError errorWithDictionary:@{
@"description" : @"Sample error 5.",
@"line" : @(189),
@"hidden" : @(NO),
@"warningLevel" : @(kMGSErrorError)
@"warningLevel" : @(kMGSErrorCategoryError)
}],
[SMLSyntaxError errorWithDictionary:@{
@"description" : @"Sample error 6.",
@"line" : @(212),
@"hidden" : @(YES),
@"warningLevel" : @(kMGSErrorPanic)
@"warningLevel" : @(kMGSErrorCategoryPanic)
}],
];
}
Expand All @@ -71,7 +71,7 @@ - (void)tearDown
[super tearDown];
}

- (void)testLinesWithErrorsInArray
- (void)test_linesWithErrorsInArray
{
NSArray *result = [[MGSSyntaxErrorController linesWithErrorsInArray:self.syntaxErrors] sortedArrayUsingSelector:@selector(compare:)];
NSArray *expects = @[@(4), @(37), @(189)];
Expand All @@ -81,7 +81,7 @@ - (void)testLinesWithErrorsInArray



- (void)testErrorCountForLine
- (void)test_errorCountForLine
{
NSInteger result4 = [MGSSyntaxErrorController errorCountForLine:4 inArray:self.syntaxErrors];
NSInteger result37 = [MGSSyntaxErrorController errorCountForLine:37 inArray:self.syntaxErrors];
Expand All @@ -92,20 +92,20 @@ - (void)testErrorCountForLine
}


- (void)testErrorForLine
- (void)test_errorForLine
{
// We should get kMGSErrorAccess, because the other error is hidden.
MGSErrorType result4 = [[MGSSyntaxErrorController errorForLine:4 inArray:self.syntaxErrors] warningLevel];
float result4 = [[MGSSyntaxErrorController errorForLine:4 inArray:self.syntaxErrors] warningLevel];

// We should get @"Sample error 3." because error level is the same, and this is the first one.
NSString *result37 = [[MGSSyntaxErrorController errorForLine:37 inArray:self.syntaxErrors] description];

XCTAssert(result4 == kMGSErrorAccess && [result37 isEqualToString:@"Sample error 3."]);
XCTAssert(result4 == kMGSErrorCategoryAccess && [result37 isEqualToString:@"Sample error 3."]);

}


- (void)testErrorsForLine
- (void)test_errorsForLine
{
SMLSyntaxError *testContent = [[MGSSyntaxErrorController errorsForLine:4 inArray:self.syntaxErrors] objectAtIndex:0];
NSInteger testQuantity = [[MGSSyntaxErrorController errorsForLine:37 inArray:self.syntaxErrors] count];
Expand All @@ -114,15 +114,15 @@ - (void)testErrorsForLine
}


- (void)testNonHiddenErrorsInArray
- (void)test_nonHiddenErrorsInArray
{
NSInteger testQuantity = [[MGSSyntaxErrorController nonHiddenErrorsInArray:self.syntaxErrors] count];

XCTAssert(testQuantity == 4);
}


- (void)testSanitizedErrorsInArray
- (void)test_sanitizedErrorsInArray
{
BOOL pass = YES;
for (id object in [MGSSyntaxErrorController sanitizedErrorsInArray:self.syntaxErrors])
Expand All @@ -137,7 +137,7 @@ - (void)testSanitizedErrorsInArray
}


- (void)testErrorDecorationsInArray
- (void)test_errorDecorationsInArray
{
NSDictionary *resultDict = [MGSSyntaxErrorController errorDecorationsInArray:self.syntaxErrors];
NSImage *image = [resultDict objectForKey:@(189)];
Expand All @@ -150,7 +150,7 @@ - (void)testErrorDecorationsInArray
}


- (void)testErrorDecorationsInArraySize
- (void)test_errorDecorationsInArraySize
{
NSDictionary *resultDict = [MGSSyntaxErrorController errorDecorationsInArray:self.syntaxErrors size:NSMakeSize(123.0, 119.4)];
NSImage *image = [resultDict objectForKey:@(4)];
Expand Down

0 comments on commit 7b01cdf

Please sign in to comment.