Skip to content

Commit f7a7c87

Browse files
committed
Tmain: add cases for testing parser specific fields with data types defined in optlib
Signed-off-by: Masatake YAMATO <yamato@redhat.com>
1 parent d372195 commit f7a7c87

File tree

12 files changed

+157
-3
lines changed

12 files changed

+157
-3
lines changed
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
public func foo(n, m);
2+
protected func bar(n);
3+
private func baz(n,...);
4+
X:tagme@iamowner
5+
Y:iamowner2=tagme2
6+
Z:tagme-z@iamowner-z
7+
eset:a
8+
enoset:b
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
--langdef=knownz
2+
--kinddef-knownz=m,mark,makers
3+
4+
--_fielddef-knownz=owner,the owner of the markers{datatype=str}
5+
6+
--_fielddef-knownz=len,the length of owner string{datatype=int}
7+
--fields-knownz=+{len}
8+
--_fielddef-knownz=lenplus,the length of owner string + 1{datatype=int}
9+
--fields-knownz=+{lenplus}
10+
11+
--_fielddef-knownz=exported,whether the marker is exported or not{datatype=bool}
12+
--fields-knownz=+{exported}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
# Copyright: 2025 Masatake YAMATO
2+
# License: GPL-2
3+
4+
. ../utils.sh
5+
6+
CTAGS=$1
7+
8+
V=
9+
# V=valgrind
10+
11+
is_feature_available "${CTAGS}" json
12+
13+
echo "# output: json"
14+
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
15+
--fields=+l \
16+
--fields-unknownx=+'{protection}{signature}' \
17+
--fields-knownz=+'{owner}' \
18+
--output-format=json \
19+
-o - input.unknownx
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
ctags: Notice: No options will be read from files or environment
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
# output: json
2+
{"_type": "tag", "name": "foo", "path": "input.unknownx", "pattern": "/^public func foo(n, m);$/", "language": "unknownx", "kind": "func", "protection": "public ", "signature": "(n, m)"}
3+
{"_type": "tag", "name": "bar", "path": "input.unknownx", "pattern": "/^protected func bar(n);$/", "language": "unknownx", "kind": "func", "protection": "protected ", "signature": "(n)"}
4+
{"_type": "tag", "name": "baz", "path": "input.unknownx", "pattern": "/^private func baz(n,...);$/", "language": "unknownx", "kind": "func", "protection": "private ", "signature": "(n,...)"}
5+
{"_type": "tag", "name": "tagme", "path": "input.unknownx", "pattern": "/^X:tagme@iamowner$/", "language": "knownz", "kind": "mark", "owner": "iamowner"}
6+
{"_type": "tag", "name": "tagme2", "path": "input.unknownx", "pattern": "/^Y:iamowner2=tagme2$/", "language": "knownz", "kind": "mark", "owner": "iamowner2"}
7+
{"_type": "tag", "name": "tagme-z", "path": "input.unknownx", "pattern": "/^Z:tagme-z@iamowner-z$/", "language": "knownz", "kind": "mark", "owner": "iamowner-z", "len": 10, "lenplus": 11}
8+
{"_type": "tag", "name": "a", "path": "input.unknownx", "pattern": "/^eset:a$/", "language": "knownz", "kind": "mark", "exported": true}
9+
{"_type": "tag", "name": "b", "path": "input.unknownx", "pattern": "/^enoset:b$/", "language": "knownz", "kind": "mark"}
10+
{"_type": "tag", "name": "7_exported", "path": "input.unknownx", "pattern": "/^enoset:b$/", "language": "knownz", "kind": "mark"}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
--langdef=unknownx{_foreignLanguage=knownz}
2+
--kinddef-unknownx=f,func,functions
3+
--map-unknownx=+.unknownx
4+
5+
--_fielddef-unknownx=protection,protections
6+
--_fielddef-unknownx=signature,signatures
7+
8+
--_prelude-unknownx={{
9+
/exported false def
10+
}}
11+
12+
--regex-unknownx=/^((public|protected|private) +)?func ([^\(]+)\((.*)\)/\3/f/{_field=protection:\1}{_field=signature:(\4)}
13+
--regex-unknownx=/^X:([a-z]+)@([a-z]+)/\1/m/{_language=knownz}{_field=owner:\2}
14+
--regex-unknownx=/^Y:([a-z0-9]+)=([a-z0-9]+)/\2/m/{_field=owner:\1}{_language=knownz}
15+
--regex-unknownx=/^Z:([-a-z]+)@([-a-z]+)/\1/m/{_language=knownz}{{
16+
. \2 knownz.owner:
17+
. :knownz.owner {
18+
. exch length knownz.len:
19+
} if
20+
. :knownz.len {
21+
1 add
22+
. exch knownz.lenplus:
23+
} if
24+
}}
25+
26+
--regex-unknownx=/^eset:([-a-z]+)/\1/m/{_language=knownz}{{
27+
/exported . def
28+
. true knownz.exported:
29+
}}
30+
31+
--regex-unknownx=/^enoset:([-a-z]+)/\1/m/{_language=knownz}{{
32+
. false knownz.exported:
33+
exported :knownz.exported and {
34+
mark exported 0 string cvs (_exported) _buildstring
35+
/knownz
36+
/mark
37+
1@ _foreigntag _commit pop
38+
} if
39+
}}

Tmain/parser-own-fields-for-foreign-lang.d/input.unknownx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,3 +3,6 @@ protected func bar(n);
33
private func baz(n,...);
44
X:tagme@iamowner
55
Y:iamowner2=tagme2
6+
Z:tagme-z@iamowner-z
7+
eset:a
8+
enoset:b
Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
--langdef=knownz
22
--kinddef-knownz=m,mark,makers
33

4-
--_fielddef-knownz=owner,the owner of the markers
4+
--_fielddef-knownz=owner,the owner of the markers{datatype=str}
5+
6+
--_fielddef-knownz=len,the length of owner string{datatype=int}
7+
--fields-knownz=+{len}
8+
--_fielddef-knownz=lenplus,the length of owner string + 1{datatype=int}
9+
--fields-knownz=+{lenplus}
10+
11+
--_fielddef-knownz=exported,whether the marker is exported or not{datatype=bool}
12+
--fields-knownz=+{exported}

Tmain/parser-own-fields-for-foreign-lang.d/run.sh

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,17 @@ CTAGS=$1
88
V=
99
# V=valgrind
1010

11-
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --options=./unknownx.ctags \
11+
echo "# output: tags"
12+
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
1213
--fields=+l \
1314
--fields-unknownx=+'{protection}{signature}' \
1415
--fields-knownz=+'{owner}' \
1516
-o - input.unknownx
17+
18+
echo "# output: xref"
19+
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
20+
--fields=+l \
21+
--fields-unknownx=+'{protection}{signature}' \
22+
--fields-knownz=+'{owner}' \
23+
-x --_xformat="%N %l / owner:%{knownz.owner},len:%{knownz.len},lenplus:%{knownz.lenplus},exported:%{knownz.exported} / %{unknownx.protection}%{unknownx.signature}" \
24+
-o - input.unknownx
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,2 @@
11
ctags: Notice: No options will be read from files or environment
2+
ctags: Notice: No options will be read from files or environment
Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,20 @@
1+
# output: tags
2+
foo input.unknownx /^public func foo(n, m);$/;" f language:unknownx protection:public signature:(n, m)
13
bar input.unknownx /^protected func bar(n);$/;" f language:unknownx protection:protected signature:(n)
24
baz input.unknownx /^private func baz(n,...);$/;" f language:unknownx protection:private signature:(n,...)
3-
foo input.unknownx /^public func foo(n, m);$/;" f language:unknownx protection:public signature:(n, m)
45
tagme input.unknownx /^X:tagme@iamowner$/;" m language:knownz owner:iamowner
56
tagme2 input.unknownx /^Y:iamowner2=tagme2$/;" m language:knownz owner:iamowner2
7+
tagme-z input.unknownx /^Z:tagme-z@iamowner-z$/;" m language:knownz owner:iamowner-z len:10 lenplus:11
8+
a input.unknownx /^eset:a$/;" m language:knownz exported:
9+
b input.unknownx /^enoset:b$/;" m language:knownz
10+
7_exported input.unknownx /^enoset:b$/;" m language:knownz
11+
# output: xref
12+
foo unknownx / owner:,len:,lenplus:,exported:- / public (n, m)
13+
bar unknownx / owner:,len:,lenplus:,exported:- / protected (n)
14+
baz unknownx / owner:,len:,lenplus:,exported:- / private (n,...)
15+
tagme knownz / owner:iamowner,len:,lenplus:,exported:- /
16+
tagme2 knownz / owner:iamowner2,len:,lenplus:,exported:- /
17+
tagme-z knownz / owner:iamowner-z,len:10,lenplus:11,exported:- /
18+
a knownz / owner:,len:,lenplus:,exported:exported /
19+
b knownz / owner:,len:,lenplus:,exported:- /
20+
7_exported knownz / owner:,len:,lenplus:,exported:- /

Tmain/parser-own-fields-for-foreign-lang.d/unknownx.ctags

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,35 @@
55
--_fielddef-unknownx=protection,protections
66
--_fielddef-unknownx=signature,signatures
77

8+
--_prelude-unknownx={{
9+
/exported false def
10+
}}
11+
812
--regex-unknownx=/^((public|protected|private) +)?func ([^\(]+)\((.*)\)/\3/f/{_field=protection:\1}{_field=signature:(\4)}
913
--regex-unknownx=/^X:([a-z]+)@([a-z]+)/\1/m/{_language=knownz}{_field=owner:\2}
1014
--regex-unknownx=/^Y:([a-z0-9]+)=([a-z0-9]+)/\2/m/{_field=owner:\1}{_language=knownz}
15+
--regex-unknownx=/^Z:([-a-z]+)@([-a-z]+)/\1/m/{_language=knownz}{{
16+
. \2 knownz.owner:
17+
. :knownz.owner {
18+
. exch length knownz.len:
19+
} if
20+
. :knownz.len {
21+
1 add
22+
. exch knownz.lenplus:
23+
} if
24+
}}
25+
26+
--regex-unknownx=/^eset:([-a-z]+)/\1/m/{_language=knownz}{{
27+
/exported . def
28+
. true knownz.exported:
29+
}}
30+
31+
--regex-unknownx=/^enoset:([-a-z]+)/\1/m/{_language=knownz}{{
32+
. false knownz.exported:
33+
exported :knownz.exported and {
34+
mark exported 0 string cvs (_exported) _buildstring
35+
/knownz
36+
/mark
37+
1@ _foreigntag _commit pop
38+
} if
39+
}}

0 commit comments

Comments
 (0)