fixbraces 0.9.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +18 -0
- data/.rspec +2 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +56 -0
- data/Rakefile +14 -0
- data/bin/fixbraces +36 -0
- data/features/cli.feature +13 -0
- data/features/fixbraces.feature +22 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/AppDelegate.h +13 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/AppDelegate.m +44 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/Default-568h@2x.png +0 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/Default.png +0 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/Default@2x.png +0 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/DetailViewController.h +18 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/DetailViewController.m +49 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/FixbracesTestProject-Info.plist +50 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/FixbracesTestProject-Prefix.pch +14 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/MasterViewController.h +12 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/MasterViewController.m +111 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/en.lproj/InfoPlist.strings +2 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/en.lproj/MainStoryboard.storyboard +103 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject/main.m +16 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProject.xcodeproj/project.pbxproj +468 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProjectTests/FixbracesTestProjectTests-Info.plist +22 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProjectTests/FixbracesTestProjectTests.h +11 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProjectTests/FixbracesTestProjectTests.m +30 -0
- data/features/fixtures/FixbracesTestProject/FixbracesTestProjectTests/en.lproj/InfoPlist.strings +2 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/AppDelegate.h +13 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/AppDelegate.m +38 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/Default-568h@2x.png +0 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/Default.png +0 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/Default@2x.png +0 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/DetailViewController.h +17 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/DetailViewController.m +45 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/FixbracesTestProject-Info.plist +50 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/FixbracesTestProject-Prefix.pch +14 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/MasterViewController.h +10 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/MasterViewController.m +99 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/en.lproj/InfoPlist.strings +2 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/en.lproj/MainStoryboard.storyboard +103 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject/main.m +15 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProject.xcodeproj/project.pbxproj +468 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProjectTests/FixbracesTestProjectTests-Info.plist +22 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProjectTests/FixbracesTestProjectTests.h +11 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProjectTests/FixbracesTestProjectTests.m +27 -0
- data/features/fixtures/FixbracesTestProjectExpected/FixbracesTestProjectTests/en.lproj/InfoPlist.strings +2 -0
- data/features/step_definitions/cli_steps.rb +7 -0
- data/features/step_definitions/fixbraces_steps.rb +55 -0
- data/features/step_definitions/touch +0 -0
- data/features/support/env.rb +16 -0
- data/fixbraces.gemspec +28 -0
- data/lib/fixbraces/version.rb +3 -0
- data/lib/fixbraces.rb +25 -0
- data/spec/fixbraces_spec.rb +67 -0
- data/spec/fixtures/expected/AppDelegate.h +13 -0
- data/spec/fixtures/expected/AppDelegate.m +38 -0
- data/spec/fixtures/expected/MasterViewController.h +10 -0
- data/spec/fixtures/expected/MasterViewController.m +99 -0
- data/spec/fixtures/input/AppDelegate.h +13 -0
- data/spec/fixtures/input/AppDelegate.m +44 -0
- data/spec/fixtures/input/MasterViewController.h +12 -0
- data/spec/fixtures/input/MasterViewController.m +111 -0
- data/spec/fixtures/sample_text.rb +112 -0
- metadata +234 -0
data/lib/fixbraces.rb
ADDED
@@ -0,0 +1,25 @@
|
|
1
|
+
require "fixbraces/version"
|
2
|
+
require "tempfile"
|
3
|
+
|
4
|
+
module Fixbraces
|
5
|
+
def Fixbraces.fixbraces(text)
|
6
|
+
# Move the opening brace to the same line as the opening clause
|
7
|
+
partial_result = text.gsub(/\n[ \t]*\{[ \t]*$/, " {")
|
8
|
+
|
9
|
+
# If there are a pair of braces on their own line move them both up to the
|
10
|
+
# same line as the opening line
|
11
|
+
partial_result.gsub(/\n[\s]*\{\}[\s]*$/, " {}")
|
12
|
+
end
|
13
|
+
|
14
|
+
def Fixbraces.process_file(file)
|
15
|
+
temp_file = Tempfile.new "fixbraces"
|
16
|
+
File.open(file, "r") do |f|
|
17
|
+
contents = f.read
|
18
|
+
new_contents = fixbraces contents
|
19
|
+
temp_file.write new_contents
|
20
|
+
end
|
21
|
+
temp_file.close
|
22
|
+
FileUtils.cp temp_file.path, file
|
23
|
+
temp_file.unlink
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,67 @@
|
|
1
|
+
require 'fixbraces'
|
2
|
+
require_relative './fixtures/sample_text'
|
3
|
+
|
4
|
+
describe Fixbraces do
|
5
|
+
let(:split_braces) { "- (void)someMethod\n{ \n return;\n}" }
|
6
|
+
let(:corrected_split_braces) { "- (void)someMethod {\n return;\n}" }
|
7
|
+
let(:paired_braces) { "@interface SomeClass ()\n{} \n@end" }
|
8
|
+
let(:corrected_paired_braces) { "@interface SomeClass () {}\n@end" }
|
9
|
+
let(:input) { SampleText::INPUT }
|
10
|
+
let(:expected) { SampleText::EXPECTED }
|
11
|
+
|
12
|
+
describe "#fixbraces" do
|
13
|
+
it "correctly puts the opening brace on the same line" do
|
14
|
+
expect(Fixbraces.fixbraces split_braces).to eq corrected_split_braces
|
15
|
+
end
|
16
|
+
|
17
|
+
it "correctly puts paired empty braces on the opening line" do
|
18
|
+
expect(Fixbraces.fixbraces paired_braces).to eq corrected_paired_braces
|
19
|
+
end
|
20
|
+
|
21
|
+
it "correctly puts paired empty braces on the opening line" do
|
22
|
+
expect(Fixbraces.fixbraces paired_braces).to eq corrected_paired_braces
|
23
|
+
end
|
24
|
+
|
25
|
+
it "operates on strings with more than one correction to make" do
|
26
|
+
expect(Fixbraces.fixbraces input).to eq expected
|
27
|
+
end
|
28
|
+
|
29
|
+
it "doesn't change text that is correctly formatted" do
|
30
|
+
expect(Fixbraces.fixbraces corrected_split_braces).to eq corrected_split_braces
|
31
|
+
expect(Fixbraces.fixbraces corrected_paired_braces).to eq corrected_paired_braces
|
32
|
+
end
|
33
|
+
end
|
34
|
+
|
35
|
+
describe "#process_file" do
|
36
|
+
before(:each) do
|
37
|
+
tests_dir = Dir.pwd + "/tmp/spec/"
|
38
|
+
|
39
|
+
if File.exists? tests_dir
|
40
|
+
FileUtils.rm_rf tests_dir
|
41
|
+
end
|
42
|
+
|
43
|
+
FileUtils.mkdir_p tests_dir
|
44
|
+
|
45
|
+
FileUtils.cp_r Dir.pwd + "/spec/fixtures/input/.", tests_dir
|
46
|
+
end
|
47
|
+
|
48
|
+
after(:each) do
|
49
|
+
tests_dir = Dir.pwd + "/tmp/spec/"
|
50
|
+
|
51
|
+
if File.exists? tests_dir
|
52
|
+
FileUtils.rm_rf tests_dir
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
it "manages to update multiple files" do
|
57
|
+
files = Dir.glob Dir.pwd + "/tmp/spec/*.{h,m}"
|
58
|
+
files.each do |f|
|
59
|
+
Fixbraces.process_file f
|
60
|
+
end
|
61
|
+
|
62
|
+
result = `diff -r --brief #{Dir.pwd + "/tmp/spec/"} #{Dir.pwd + "/spec/fixtures/expected/"}`
|
63
|
+
expect(result).to eq ""
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
//
|
2
|
+
// AppDelegate.m
|
3
|
+
// FixbracesTestProject
|
4
|
+
//
|
5
|
+
//
|
6
|
+
|
7
|
+
#import "AppDelegate.h"
|
8
|
+
|
9
|
+
@implementation AppDelegate
|
10
|
+
|
11
|
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
|
12
|
+
// Override point for customization after application launch.
|
13
|
+
return YES;
|
14
|
+
}
|
15
|
+
|
16
|
+
- (void)applicationWillResignActive:(UIApplication *)application {
|
17
|
+
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
18
|
+
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
19
|
+
}
|
20
|
+
|
21
|
+
- (void)applicationDidEnterBackground:(UIApplication *)application {
|
22
|
+
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
23
|
+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
24
|
+
}
|
25
|
+
|
26
|
+
- (void)applicationWillEnterForeground:(UIApplication *)application {
|
27
|
+
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
28
|
+
}
|
29
|
+
|
30
|
+
- (void)applicationDidBecomeActive:(UIApplication *)application {
|
31
|
+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
32
|
+
}
|
33
|
+
|
34
|
+
- (void)applicationWillTerminate:(UIApplication *)application {
|
35
|
+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
36
|
+
}
|
37
|
+
|
38
|
+
@end
|
@@ -0,0 +1,99 @@
|
|
1
|
+
//
|
2
|
+
// MasterViewController.m
|
3
|
+
// FixbracesTestProject
|
4
|
+
//
|
5
|
+
//
|
6
|
+
|
7
|
+
#import "MasterViewController.h"
|
8
|
+
|
9
|
+
#import "DetailViewController.h"
|
10
|
+
|
11
|
+
@interface MasterViewController () {
|
12
|
+
NSMutableArray *_objects;
|
13
|
+
}
|
14
|
+
@end
|
15
|
+
|
16
|
+
@implementation MasterViewController
|
17
|
+
|
18
|
+
- (void)awakeFromNib {
|
19
|
+
[super awakeFromNib];
|
20
|
+
}
|
21
|
+
|
22
|
+
- (void)viewDidLoad {
|
23
|
+
[super viewDidLoad];
|
24
|
+
// Do any additional setup after loading the view, typically from a nib.
|
25
|
+
self.navigationItem.leftBarButtonItem = self.editButtonItem;
|
26
|
+
|
27
|
+
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
|
28
|
+
self.navigationItem.rightBarButtonItem = addButton;
|
29
|
+
}
|
30
|
+
|
31
|
+
- (void)didReceiveMemoryWarning {
|
32
|
+
[super didReceiveMemoryWarning];
|
33
|
+
// Dispose of any resources that can be recreated.
|
34
|
+
}
|
35
|
+
|
36
|
+
- (void)insertNewObject:(id)sender {
|
37
|
+
if (!_objects) {
|
38
|
+
_objects = [[NSMutableArray alloc] init];
|
39
|
+
}
|
40
|
+
[_objects insertObject:[NSDate date] atIndex:0];
|
41
|
+
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
|
42
|
+
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
|
43
|
+
}
|
44
|
+
|
45
|
+
#pragma mark - Table View
|
46
|
+
|
47
|
+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView {
|
48
|
+
return 1;
|
49
|
+
}
|
50
|
+
|
51
|
+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {
|
52
|
+
return _objects.count;
|
53
|
+
}
|
54
|
+
|
55
|
+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
|
56
|
+
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
|
57
|
+
|
58
|
+
NSDate *object = _objects[indexPath.row];
|
59
|
+
cell.textLabel.text = [object description];
|
60
|
+
return cell;
|
61
|
+
}
|
62
|
+
|
63
|
+
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath {
|
64
|
+
// Return NO if you do not want the specified item to be editable.
|
65
|
+
return YES;
|
66
|
+
}
|
67
|
+
|
68
|
+
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath {
|
69
|
+
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
70
|
+
[_objects removeObjectAtIndex:indexPath.row];
|
71
|
+
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
72
|
+
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
73
|
+
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
|
74
|
+
}
|
75
|
+
}
|
76
|
+
|
77
|
+
/*
|
78
|
+
// Override to support rearranging the table view.
|
79
|
+
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath {
|
80
|
+
}
|
81
|
+
*/
|
82
|
+
|
83
|
+
/*
|
84
|
+
// Override to support conditional rearranging of the table view.
|
85
|
+
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath {
|
86
|
+
// Return NO if you do not want the item to be re-orderable.
|
87
|
+
return YES;
|
88
|
+
}
|
89
|
+
*/
|
90
|
+
|
91
|
+
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
|
92
|
+
if ([[segue identifier] isEqualToString:@"showDetail"]) {
|
93
|
+
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
|
94
|
+
NSDate *object = _objects[indexPath.row];
|
95
|
+
[[segue destinationViewController] setDetailItem:object];
|
96
|
+
}
|
97
|
+
}
|
98
|
+
|
99
|
+
@end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
//
|
2
|
+
// AppDelegate.m
|
3
|
+
// FixbracesTestProject
|
4
|
+
//
|
5
|
+
//
|
6
|
+
|
7
|
+
#import "AppDelegate.h"
|
8
|
+
|
9
|
+
@implementation AppDelegate
|
10
|
+
|
11
|
+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
|
12
|
+
{
|
13
|
+
// Override point for customization after application launch.
|
14
|
+
return YES;
|
15
|
+
}
|
16
|
+
|
17
|
+
- (void)applicationWillResignActive:(UIApplication *)application
|
18
|
+
{
|
19
|
+
// Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
|
20
|
+
// Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
|
21
|
+
}
|
22
|
+
|
23
|
+
- (void)applicationDidEnterBackground:(UIApplication *)application
|
24
|
+
{
|
25
|
+
// Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
|
26
|
+
// If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
|
27
|
+
}
|
28
|
+
|
29
|
+
- (void)applicationWillEnterForeground:(UIApplication *)application
|
30
|
+
{
|
31
|
+
// Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
|
32
|
+
}
|
33
|
+
|
34
|
+
- (void)applicationDidBecomeActive:(UIApplication *)application
|
35
|
+
{
|
36
|
+
// Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
|
37
|
+
}
|
38
|
+
|
39
|
+
- (void)applicationWillTerminate:(UIApplication *)application
|
40
|
+
{
|
41
|
+
// Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
|
42
|
+
}
|
43
|
+
|
44
|
+
@end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
//
|
2
|
+
// MasterViewController.m
|
3
|
+
// FixbracesTestProject
|
4
|
+
//
|
5
|
+
//
|
6
|
+
|
7
|
+
#import "MasterViewController.h"
|
8
|
+
|
9
|
+
#import "DetailViewController.h"
|
10
|
+
|
11
|
+
@interface MasterViewController () {
|
12
|
+
NSMutableArray *_objects;
|
13
|
+
}
|
14
|
+
@end
|
15
|
+
|
16
|
+
@implementation MasterViewController
|
17
|
+
|
18
|
+
- (void)awakeFromNib
|
19
|
+
{
|
20
|
+
[super awakeFromNib];
|
21
|
+
}
|
22
|
+
|
23
|
+
- (void)viewDidLoad
|
24
|
+
{
|
25
|
+
[super viewDidLoad];
|
26
|
+
// Do any additional setup after loading the view, typically from a nib.
|
27
|
+
self.navigationItem.leftBarButtonItem = self.editButtonItem;
|
28
|
+
|
29
|
+
UIBarButtonItem *addButton = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self action:@selector(insertNewObject:)];
|
30
|
+
self.navigationItem.rightBarButtonItem = addButton;
|
31
|
+
}
|
32
|
+
|
33
|
+
- (void)didReceiveMemoryWarning
|
34
|
+
{
|
35
|
+
[super didReceiveMemoryWarning];
|
36
|
+
// Dispose of any resources that can be recreated.
|
37
|
+
}
|
38
|
+
|
39
|
+
- (void)insertNewObject:(id)sender
|
40
|
+
{
|
41
|
+
if (!_objects) {
|
42
|
+
_objects = [[NSMutableArray alloc] init];
|
43
|
+
}
|
44
|
+
[_objects insertObject:[NSDate date] atIndex:0];
|
45
|
+
NSIndexPath *indexPath = [NSIndexPath indexPathForRow:0 inSection:0];
|
46
|
+
[self.tableView insertRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationAutomatic];
|
47
|
+
}
|
48
|
+
|
49
|
+
#pragma mark - Table View
|
50
|
+
|
51
|
+
- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
|
52
|
+
{
|
53
|
+
return 1;
|
54
|
+
}
|
55
|
+
|
56
|
+
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
|
57
|
+
{
|
58
|
+
return _objects.count;
|
59
|
+
}
|
60
|
+
|
61
|
+
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
|
62
|
+
{
|
63
|
+
UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"Cell" forIndexPath:indexPath];
|
64
|
+
|
65
|
+
NSDate *object = _objects[indexPath.row];
|
66
|
+
cell.textLabel.text = [object description];
|
67
|
+
return cell;
|
68
|
+
}
|
69
|
+
|
70
|
+
- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
|
71
|
+
{
|
72
|
+
// Return NO if you do not want the specified item to be editable.
|
73
|
+
return YES;
|
74
|
+
}
|
75
|
+
|
76
|
+
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
|
77
|
+
{
|
78
|
+
if (editingStyle == UITableViewCellEditingStyleDelete) {
|
79
|
+
[_objects removeObjectAtIndex:indexPath.row];
|
80
|
+
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
|
81
|
+
} else if (editingStyle == UITableViewCellEditingStyleInsert) {
|
82
|
+
// Create a new instance of the appropriate class, insert it into the array, and add a new row to the table view.
|
83
|
+
}
|
84
|
+
}
|
85
|
+
|
86
|
+
/*
|
87
|
+
// Override to support rearranging the table view.
|
88
|
+
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath toIndexPath:(NSIndexPath *)toIndexPath
|
89
|
+
{
|
90
|
+
}
|
91
|
+
*/
|
92
|
+
|
93
|
+
/*
|
94
|
+
// Override to support conditional rearranging of the table view.
|
95
|
+
- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath
|
96
|
+
{
|
97
|
+
// Return NO if you do not want the item to be re-orderable.
|
98
|
+
return YES;
|
99
|
+
}
|
100
|
+
*/
|
101
|
+
|
102
|
+
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
|
103
|
+
{
|
104
|
+
if ([[segue identifier] isEqualToString:@"showDetail"]) {
|
105
|
+
NSIndexPath *indexPath = [self.tableView indexPathForSelectedRow];
|
106
|
+
NSDate *object = _objects[indexPath.row];
|
107
|
+
[[segue destinationViewController] setDetailItem:object];
|
108
|
+
}
|
109
|
+
}
|
110
|
+
|
111
|
+
@end
|
@@ -0,0 +1,112 @@
|
|
1
|
+
# Sample texts ond expected results for testing
|
2
|
+
|
3
|
+
module SampleText
|
4
|
+
INPUT=<<INPFB
|
5
|
+
#import "ViewController.h"
|
6
|
+
|
7
|
+
@interface ViewController {}
|
8
|
+
|
9
|
+
@end
|
10
|
+
|
11
|
+
|
12
|
+
@interface ViewController (AnotherCategory)
|
13
|
+
{}
|
14
|
+
@end
|
15
|
+
|
16
|
+
@implementation ViewController
|
17
|
+
|
18
|
+
- (void)viewDidLoad
|
19
|
+
{
|
20
|
+
[super viewDidLoad];
|
21
|
+
// A load of spurious conditionals to test formatting.
|
22
|
+
|
23
|
+
if (nil)
|
24
|
+
{
|
25
|
+
NSLog(@"Nothing to see here");
|
26
|
+
} else if (!nil)
|
27
|
+
{
|
28
|
+
NSLog(@"Nothing more to see here");
|
29
|
+
} else
|
30
|
+
{
|
31
|
+
NSLog(@"We really shouldn't get to here");
|
32
|
+
}
|
33
|
+
|
34
|
+
for (NSInteger idx = 0; idx < 2; idx++)
|
35
|
+
{
|
36
|
+
NSLog(@"Print index");
|
37
|
+
}
|
38
|
+
|
39
|
+
NSUInteger anIndex= 0;
|
40
|
+
while (anIndex)
|
41
|
+
{
|
42
|
+
NSLog(@"Increment anIndex");
|
43
|
+
anIndex++;
|
44
|
+
}
|
45
|
+
|
46
|
+
switch (anIndex)
|
47
|
+
{
|
48
|
+
case 1:
|
49
|
+
{
|
50
|
+
NSLog(@"Switch in anIndex");
|
51
|
+
break;
|
52
|
+
}
|
53
|
+
|
54
|
+
default:
|
55
|
+
break;
|
56
|
+
}
|
57
|
+
|
58
|
+
}
|
59
|
+
|
60
|
+
@end
|
61
|
+
INPFB
|
62
|
+
|
63
|
+
EXPECTED =<<EXPFB
|
64
|
+
#import "ViewController.h"
|
65
|
+
|
66
|
+
@interface ViewController {}
|
67
|
+
|
68
|
+
@end
|
69
|
+
|
70
|
+
|
71
|
+
@interface ViewController (AnotherCategory) {}
|
72
|
+
@end
|
73
|
+
|
74
|
+
@implementation ViewController
|
75
|
+
|
76
|
+
- (void)viewDidLoad {
|
77
|
+
[super viewDidLoad];
|
78
|
+
// A load of spurious conditionals to test formatting.
|
79
|
+
|
80
|
+
if (nil) {
|
81
|
+
NSLog(@"Nothing to see here");
|
82
|
+
} else if (!nil) {
|
83
|
+
NSLog(@"Nothing more to see here");
|
84
|
+
} else {
|
85
|
+
NSLog(@"We really shouldn't get to here");
|
86
|
+
}
|
87
|
+
|
88
|
+
for (NSInteger idx = 0; idx < 2; idx++) {
|
89
|
+
NSLog(@"Print index");
|
90
|
+
}
|
91
|
+
|
92
|
+
NSUInteger anIndex= 0;
|
93
|
+
while (anIndex) {
|
94
|
+
NSLog(@"Increment anIndex");
|
95
|
+
anIndex++;
|
96
|
+
}
|
97
|
+
|
98
|
+
switch (anIndex) {
|
99
|
+
case 1: {
|
100
|
+
NSLog(@"Switch in anIndex");
|
101
|
+
break;
|
102
|
+
}
|
103
|
+
|
104
|
+
default:
|
105
|
+
break;
|
106
|
+
}
|
107
|
+
|
108
|
+
}
|
109
|
+
|
110
|
+
@end
|
111
|
+
EXPFB
|
112
|
+
end
|