Skip to content

Commit

Permalink
Tmain: add cases for testing parser specific fields with data types d…
Browse files Browse the repository at this point in the history
…efined in optlib

Signed-off-by: Masatake YAMATO <yamato@redhat.com>
  • Loading branch information
masatake committed Jan 2, 2025
1 parent d372195 commit f7a7c87
Showing 12 changed files with 157 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
public func foo(n, m);
protected func bar(n);
private func baz(n,...);
X:tagme@iamowner
Y:iamowner2=tagme2
Z:tagme-z@iamowner-z
eset:a
enoset:b
12 changes: 12 additions & 0 deletions Tmain/parser-own-fields-for-foreign-lang-in-json.d/knownz.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--langdef=knownz
--kinddef-knownz=m,mark,makers

--_fielddef-knownz=owner,the owner of the markers{datatype=str}

--_fielddef-knownz=len,the length of owner string{datatype=int}
--fields-knownz=+{len}
--_fielddef-knownz=lenplus,the length of owner string + 1{datatype=int}
--fields-knownz=+{lenplus}

--_fielddef-knownz=exported,whether the marker is exported or not{datatype=bool}
--fields-knownz=+{exported}
19 changes: 19 additions & 0 deletions Tmain/parser-own-fields-for-foreign-lang-in-json.d/run.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Copyright: 2025 Masatake YAMATO
# License: GPL-2

. ../utils.sh

CTAGS=$1

V=
# V=valgrind

is_feature_available "${CTAGS}" json

echo "# output: json"
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
--fields=+l \
--fields-unknownx=+'{protection}{signature}' \
--fields-knownz=+'{owner}' \
--output-format=json \
-o - input.unknownx
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
ctags: Notice: No options will be read from files or environment
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# output: json
{"_type": "tag", "name": "foo", "path": "input.unknownx", "pattern": "/^public func foo(n, m);$/", "language": "unknownx", "kind": "func", "protection": "public ", "signature": "(n, m)"}
{"_type": "tag", "name": "bar", "path": "input.unknownx", "pattern": "/^protected func bar(n);$/", "language": "unknownx", "kind": "func", "protection": "protected ", "signature": "(n)"}
{"_type": "tag", "name": "baz", "path": "input.unknownx", "pattern": "/^private func baz(n,...);$/", "language": "unknownx", "kind": "func", "protection": "private ", "signature": "(n,...)"}
{"_type": "tag", "name": "tagme", "path": "input.unknownx", "pattern": "/^X:tagme@iamowner$/", "language": "knownz", "kind": "mark", "owner": "iamowner"}
{"_type": "tag", "name": "tagme2", "path": "input.unknownx", "pattern": "/^Y:iamowner2=tagme2$/", "language": "knownz", "kind": "mark", "owner": "iamowner2"}
{"_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}
{"_type": "tag", "name": "a", "path": "input.unknownx", "pattern": "/^eset:a$/", "language": "knownz", "kind": "mark", "exported": true}
{"_type": "tag", "name": "b", "path": "input.unknownx", "pattern": "/^enoset:b$/", "language": "knownz", "kind": "mark"}
{"_type": "tag", "name": "7_exported", "path": "input.unknownx", "pattern": "/^enoset:b$/", "language": "knownz", "kind": "mark"}
39 changes: 39 additions & 0 deletions Tmain/parser-own-fields-for-foreign-lang-in-json.d/unknownx.ctags
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
--langdef=unknownx{_foreignLanguage=knownz}
--kinddef-unknownx=f,func,functions
--map-unknownx=+.unknownx

--_fielddef-unknownx=protection,protections
--_fielddef-unknownx=signature,signatures

--_prelude-unknownx={{
/exported false def
}}

--regex-unknownx=/^((public|protected|private) +)?func ([^\(]+)\((.*)\)/\3/f/{_field=protection:\1}{_field=signature:(\4)}
--regex-unknownx=/^X:([a-z]+)@([a-z]+)/\1/m/{_language=knownz}{_field=owner:\2}
--regex-unknownx=/^Y:([a-z0-9]+)=([a-z0-9]+)/\2/m/{_field=owner:\1}{_language=knownz}
--regex-unknownx=/^Z:([-a-z]+)@([-a-z]+)/\1/m/{_language=knownz}{{
. \2 knownz.owner:
. :knownz.owner {
. exch length knownz.len:
} if
. :knownz.len {
1 add
. exch knownz.lenplus:
} if
}}

--regex-unknownx=/^eset:([-a-z]+)/\1/m/{_language=knownz}{{
/exported . def
. true knownz.exported:
}}

--regex-unknownx=/^enoset:([-a-z]+)/\1/m/{_language=knownz}{{
. false knownz.exported:
exported :knownz.exported and {
mark exported 0 string cvs (_exported) _buildstring
/knownz
/mark
1@ _foreigntag _commit pop
} if
}}
3 changes: 3 additions & 0 deletions Tmain/parser-own-fields-for-foreign-lang.d/input.unknownx
Original file line number Diff line number Diff line change
@@ -3,3 +3,6 @@ protected func bar(n);
private func baz(n,...);
X:tagme@iamowner
Y:iamowner2=tagme2
Z:tagme-z@iamowner-z
eset:a
enoset:b
10 changes: 9 additions & 1 deletion Tmain/parser-own-fields-for-foreign-lang.d/knownz.ctags
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
--langdef=knownz
--kinddef-knownz=m,mark,makers

--_fielddef-knownz=owner,the owner of the markers
--_fielddef-knownz=owner,the owner of the markers{datatype=str}

--_fielddef-knownz=len,the length of owner string{datatype=int}
--fields-knownz=+{len}
--_fielddef-knownz=lenplus,the length of owner string + 1{datatype=int}
--fields-knownz=+{lenplus}

--_fielddef-knownz=exported,whether the marker is exported or not{datatype=bool}
--fields-knownz=+{exported}
11 changes: 10 additions & 1 deletion Tmain/parser-own-fields-for-foreign-lang.d/run.sh
Original file line number Diff line number Diff line change
@@ -8,8 +8,17 @@ CTAGS=$1
V=
# V=valgrind

${V} ${CTAGS} --options=NONE --options=./knownz.ctags --options=./unknownx.ctags \
echo "# output: tags"
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
--fields=+l \
--fields-unknownx=+'{protection}{signature}' \
--fields-knownz=+'{owner}' \
-o - input.unknownx

echo "# output: xref"
${V} ${CTAGS} --options=NONE --options=./knownz.ctags --sort=no --options=./unknownx.ctags \
--fields=+l \
--fields-unknownx=+'{protection}{signature}' \
--fields-knownz=+'{owner}' \
-x --_xformat="%N %l / owner:%{knownz.owner},len:%{knownz.len},lenplus:%{knownz.lenplus},exported:%{knownz.exported} / %{unknownx.protection}%{unknownx.signature}" \
-o - input.unknownx
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
ctags: Notice: No options will be read from files or environment
ctags: Notice: No options will be read from files or environment
17 changes: 16 additions & 1 deletion Tmain/parser-own-fields-for-foreign-lang.d/stdout-expected.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,20 @@
# output: tags
foo input.unknownx /^public func foo(n, m);$/;" f language:unknownx protection:public signature:(n, m)
bar input.unknownx /^protected func bar(n);$/;" f language:unknownx protection:protected signature:(n)
baz input.unknownx /^private func baz(n,...);$/;" f language:unknownx protection:private signature:(n,...)
foo input.unknownx /^public func foo(n, m);$/;" f language:unknownx protection:public signature:(n, m)
tagme input.unknownx /^X:tagme@iamowner$/;" m language:knownz owner:iamowner
tagme2 input.unknownx /^Y:iamowner2=tagme2$/;" m language:knownz owner:iamowner2
tagme-z input.unknownx /^Z:tagme-z@iamowner-z$/;" m language:knownz owner:iamowner-z len:10 lenplus:11
a input.unknownx /^eset:a$/;" m language:knownz exported:
b input.unknownx /^enoset:b$/;" m language:knownz
7_exported input.unknownx /^enoset:b$/;" m language:knownz
# output: xref
foo unknownx / owner:,len:,lenplus:,exported:- / public (n, m)
bar unknownx / owner:,len:,lenplus:,exported:- / protected (n)
baz unknownx / owner:,len:,lenplus:,exported:- / private (n,...)
tagme knownz / owner:iamowner,len:,lenplus:,exported:- /
tagme2 knownz / owner:iamowner2,len:,lenplus:,exported:- /
tagme-z knownz / owner:iamowner-z,len:10,lenplus:11,exported:- /
a knownz / owner:,len:,lenplus:,exported:exported /
b knownz / owner:,len:,lenplus:,exported:- /
7_exported knownz / owner:,len:,lenplus:,exported:- /
29 changes: 29 additions & 0 deletions Tmain/parser-own-fields-for-foreign-lang.d/unknownx.ctags
Original file line number Diff line number Diff line change
@@ -5,6 +5,35 @@
--_fielddef-unknownx=protection,protections
--_fielddef-unknownx=signature,signatures

--_prelude-unknownx={{
/exported false def
}}

--regex-unknownx=/^((public|protected|private) +)?func ([^\(]+)\((.*)\)/\3/f/{_field=protection:\1}{_field=signature:(\4)}
--regex-unknownx=/^X:([a-z]+)@([a-z]+)/\1/m/{_language=knownz}{_field=owner:\2}
--regex-unknownx=/^Y:([a-z0-9]+)=([a-z0-9]+)/\2/m/{_field=owner:\1}{_language=knownz}
--regex-unknownx=/^Z:([-a-z]+)@([-a-z]+)/\1/m/{_language=knownz}{{
. \2 knownz.owner:
. :knownz.owner {
. exch length knownz.len:
} if
. :knownz.len {
1 add
. exch knownz.lenplus:
} if
}}

--regex-unknownx=/^eset:([-a-z]+)/\1/m/{_language=knownz}{{
/exported . def
. true knownz.exported:
}}

--regex-unknownx=/^enoset:([-a-z]+)/\1/m/{_language=knownz}{{
. false knownz.exported:
exported :knownz.exported and {
mark exported 0 string cvs (_exported) _buildstring
/knownz
/mark
1@ _foreigntag _commit pop
} if
}}

0 comments on commit f7a7c87

Please sign in to comment.