-
Notifications
You must be signed in to change notification settings - Fork 2
/
pjb-objc-parser-test.el
161 lines (147 loc) · 6.23 KB
/
pjb-objc-parser-test.el
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
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
;;;; -*- mode:emacs-lisp;coding:utf-8 -*-
;;;;**************************************************************************
;;;;FILE: pjb-obj-parser-test.el
;;;;LANGUAGE: emacs lisp
;;;;SYSTEM: POSIX
;;;;USER-INTERFACE: NONE
;;;;DESCRIPTION
;;;;
;;;; XXX
;;;;
;;;;AUTHORS
;;;; <PJB> Pascal Bourguignon <[email protected]>
;;;;MODIFICATIONS
;;;; 2013-01-28 <PJB> Created.
;;;;BUGS
;;;;LEGAL
;;;; AGPL3
;;;;
;;;; Copyright Pascal Bourguignon 2013 - 2013
;;;;
;;;; This program is free software: you can redistribute it and/or modify
;;;; it under the terms of the GNU Affero General Public License as published by
;;;; the Free Software Foundation, either version 3 of the License, or
;;;; (at your option) any later version.
;;;;
;;;; This program is distributed in the hope that it will be useful,
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;;;; GNU Affero General Public License for more details.
;;;;
;;;; You should have received a copy of the GNU Affero General Public License
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
;;;;**************************************************************************
(require 'pjb-objc-parser)
(defun test/pjb-objc-parser--eat-sexp ()
(with-temp-buffer
(lisp-mode)
(insert "
sexp-1 sexp-2
")
(goto-char (point-min))
(let ((sexp (pjb-objc-parser--eat-sexp)))
(assert (equal sexp 'sexp-1) t)
(assert (= (point) 8) t)))
(with-temp-buffer
(lisp-mode)
(insert "; test 2
\(sexp-1 sexp-2)
")
(goto-char (point-min))
(let ((sexp (pjb-objc-parser--eat-sexp)))
(assert (equal sexp '(sexp-1 sexp-2)) t)
(assert (= (point) 26) t)))
:success)
(defun test/pjb-objc-parser--eat-looked ()
(with-temp-buffer
(lisp-mode)
(insert "aaaabbbaaaabbbbaaacccddaaaddaaadd")
(goto-char (point-min))
(looking-at "\\(a+b+\\)*a*c+")
(pjb-objc-parser--eat-looked)
(assert (= (point) 22) t))
:success)
(defun test/pjb-objc-parser--parse-parameter ()
(with-temp-buffer
(objc-mode)
(insert "(int)anInt
\(NSString *)aString
\(^(void)(int a,NSString* b))aBlock;
")
(goto-char (point-min))
(let ((p (pjb-objc-parser--parse-parameter)))
(assert (equal '(int) (pjb-objc-parameter-type p)) t)
(assert (equal 'anInt (pjb-objc-parameter-name p)) t))
(let ((p (pjb-objc-parser--parse-parameter)))
(assert (equal '(NSString *) (pjb-objc-parameter-type p)) t)
(assert (equal 'aString (pjb-objc-parameter-name p)) t))
(let ((p (pjb-objc-parser--parse-parameter)))
;; TODO: this type is parsed anyhow, until we have a true type parser rule.
(assert (equal '(^(void)(int a,NSString* b)) (pjb-objc-parameter-type p)) t)
(assert (equal 'aBlock (pjb-objc-parameter-name p)) t)))
:success)
(defun test/pjb-objc-parser--next ()
(cond
((pjb-objc-parser--looking-at-semicolon)
(pjb-objc-parser--eat-looked))
((pjb-objc-parser--looking-at-block)
(forward-sexp))
((pjb-objc-parser--looking-at-comment)
(c-forward-comments))))
(defun test/pjb-objc-parser--parse-method-signature ()
(with-temp-buffer
(objc-mode)
(insert "+(void)aClassMethodSignature;
-(id)simpleMethod:(int)anInt;
- (NSString *)aMethod:(NSString *)aString with:(^(void)(int a,NSString* b))aBlock
{
return nil;
}
-(NSString*)aMethod:(NSString *)aString with:(^(void)(int a,NSString* b))aBlock andSome:(int)code :(int)count,...;
")
(goto-char (point-min))
(let ((s (pjb-objc-parser--parse-method-signature)))
(assert (equal :class (pjb-objc-method-signature-object s)) t)
(assert (equal '(void) (pjb-objc-method-signature-result-type s)) t)
(assert (equalp (pjb-objc-selector '(aClassMethodSignature))
(pjb-objc-method-signature-selector s)) t)
(assert (equalp '()
(pjb-objc-method-signature-parameters s)) t))
(test/pjb-objc-parser--next)
(let ((s (pjb-objc-parser--parse-method-signature)))
(assert (equal :instance (pjb-objc-method-signature-object s)) t)
(assert (equal '(id) (pjb-objc-method-signature-result-type s)) t)
(assert (equalp (pjb-objc-selector '(simpleMethod:))
(pjb-objc-method-signature-selector s)) t)
(assert (equalp (list (pjb-objc-parameter :name 'anInt :type '(int)))
(pjb-objc-method-signature-parameters s)) t))
(test/pjb-objc-parser--next)
(let ((s (pjb-objc-parser--parse-method-signature)))
(assert (equal :instance (pjb-objc-method-signature-object s)) t)
(assert (equal '(NSString *) (pjb-objc-method-signature-result-type s)) t)
(assert (equalp (pjb-objc-selector '(aMethod: with:))
(pjb-objc-method-signature-selector s)) t)
(assert (equalp (list (pjb-objc-parameter :name 'aString :type '(NSString *))
(pjb-objc-parameter :name 'aBlock :type '(^(void)(int a,NSString* b))))
(pjb-objc-method-signature-parameters s)) t))
(test/pjb-objc-parser--next)
(let ((s (pjb-objc-parser--parse-method-signature)))
(assert (equal :instance (pjb-objc-method-signature-object s)) t)
;; TODO: this type is parsed anyhow, until we have a true type parser rule.
(assert (equal '(NSString*) (pjb-objc-method-signature-result-type s)) t)
(assert (equalp (pjb-objc-selector '(aMethod: with: andSome: :))
(pjb-objc-method-signature-selector s)) t)
(assert (equalp (list (pjb-objc-parameter :name 'aString :type '(NSString *))
(pjb-objc-parameter :name 'aBlock :type '(^(void)(int a,NSString* b)))
(pjb-objc-parameter :name 'code :type '(int))
(pjb-objc-parameter :name 'count :type '(int))
(pjb-objc-parameter :name '\... :type nil))
(pjb-objc-method-signature-parameters s)) t))
(test/pjb-objc-parser--next))
:success)
(defun test/pjb-objc-parser ()
(test/pjb-objc-parser--eat-sexp)
(test/pjb-objc-parser--eat-looked)
(test/pjb-objc-parser--parse-parameter)
(test/pjb-objc-parser--parse-method-signature))
(test/pjb-objc-parser)