-
Notifications
You must be signed in to change notification settings - Fork 6
/
converter_spec.coffee
138 lines (107 loc) · 5.89 KB
/
converter_spec.coffee
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
chai.should()
describe "Converter", ->
it "converts multilines to one line", ->
source = """
first_line;
second_line
third_line
"""
expected = """
first_line;
second_line third_line
"""
converter = new Converter source
converter.multilines_to_one_line().s.should.equal expected
it "converts multilines to one line with args", ->
source = """
UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:@"Warning"
message:@"too many alerts"
delegate:nil
"""
expected = 'UIAlertView* alert = [[[UIAlertView alloc] initWithTitle:@"Warning" message:@"too many alerts" delegate:nil'
converter = new Converter source
converter.multilines_to_one_line().s.should.equal expected
it "converts multilines to one line for blank line", ->
source = """
first_line;
second_line
"""
expected = """
first_line;
second_line
"""
converter = new Converter source
converter.multilines_to_one_line().s.should.equal expected
it "replaces NSString", ->
source = 'NSDictionary *updatedLatte = [responseObject objectForKey:@"latte"];'
expected = 'NSDictionary *updatedLatte = [responseObject objectForKey:"latte"];'
converter = new Converter source
converter.replace_nsstring().s.should.equal expected
it "converts square brackets", ->
source = '[self notifyCreated];'
expected = 'self.notifyCreated;'
converter = new Converter source
converter.convert_square_brackets_expression().s.should.equal expected
it 'converts square brackets with args', ->
source = '[self updateFromJSON:updatedLatte];'
expected = 'self.updateFromJSON(updatedLatte);'
converter = new Converter source
converter.convert_square_brackets_expression().s.should.equal expected
it 'converts square brackets with multiple args', ->
source = '[[[UITabBarItem alloc] initWithTabBarSystemItem:UITabBarSystemItemBookmarks tag:0] autorelease];'
expected = 'UITabBarItem.alloc.initWithTabBarSystemItem(UITabBarSystemItemBookmarks,tag:0).autorelease;'
converter = new Converter source
converter.convert_square_brackets_expression().s.should.equal expected
it "removes semicolons at end of lines", ->
source = '[[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];'
expected = '[[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]'
converter = new Converter source
converter.remove_semicolon_at_the_end().s.should.equal expected
it "removes autorelease", ->
source = '[[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]'
expected = 'UIWindow.alloc.initWithFrame(UIScreen.mainScreen.bounds)'
converter = new Converter source
converter.convert_square_brackets_expression()
converter.remove_autorelease().s.should.equal expected
it "removes type declarations", ->
source = 'UIWindow* aWindow = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]'
expected = 'aWindow = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]'
converter = new Converter source
converter.remove_type_declaration().s.should.equal expected
it "removes type declarations with spaces", ->
source = ' UIWindow* aWindow = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]'
expected = ' aWindow = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]'
converter = new Converter source
converter.remove_type_declaration().s.should.equal expected
it "removes multiple type declarations", ->
source = """
UIWindow* aWindow = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
UIWindow* bWindow = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]
"""
expected = """
aWindow = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease];
bWindow = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]
"""
converter = new Converter source
converter.remove_type_declaration().s.should.equal expected
it 'converts multiline expression', ->
source = """
UIAlertView* alertA = [[[UIAlertView alloc] initWithTitle:@"Warning"
message:@"too many alerts"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease];
UIAlertView* alertB = [[[UIAlertView alloc] initWithTitle:@"Warning"
message:@"too many alerts"
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil] autorelease];
[alert show];
"""
expected = """
alertA = UIAlertView.alloc.initWithTitle("Warning",message:"too many alerts",delegate:nil,cancelButtonTitle:"OK",otherButtonTitles:nil)
alertB = UIAlertView.alloc.initWithTitle("Warning",message:"too many alerts",delegate:nil,cancelButtonTitle:"OK",otherButtonTitles:nil)
alert.show
"""
converter = new Converter source
converter.result().should.equal expected