From f7a7c87f3c19b96096347b58333522af3326d2e4 Mon Sep 17 00:00:00 2001 From: Masatake YAMATO Date: Fri, 3 Jan 2025 00:31:11 +0900 Subject: [PATCH] Tmain: add cases for testing parser specific fields with data types defined in optlib Signed-off-by: Masatake YAMATO --- .../input.unknownx | 8 ++++ .../knownz.ctags | 12 ++++++ .../run.sh | 19 +++++++++ .../stderr-expected.txt | 1 + .../stdout-expected.txt | 10 +++++ .../unknownx.ctags | 39 +++++++++++++++++++ .../input.unknownx | 3 ++ .../knownz.ctags | 10 ++++- .../run.sh | 11 +++++- .../stderr-expected.txt | 1 + .../stdout-expected.txt | 17 +++++++- .../unknownx.ctags | 29 ++++++++++++++ 12 files changed, 157 insertions(+), 3 deletions(-) create mode 100644 Tmain/parser-own-fields-for-foreign-lang-in-json.d/input.unknownx create mode 100644 Tmain/parser-own-fields-for-foreign-lang-in-json.d/knownz.ctags create mode 100644 Tmain/parser-own-fields-for-foreign-lang-in-json.d/run.sh create mode 100644 Tmain/parser-own-fields-for-foreign-lang-in-json.d/stderr-expected.txt create mode 100644 Tmain/parser-own-fields-for-foreign-lang-in-json.d/stdout-expected.txt create mode 100644 Tmain/parser-own-fields-for-foreign-lang-in-json.d/unknownx.ctags diff --git a/Tmain/parser-own-fields-for-foreign-lang-in-json.d/input.unknownx b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/input.unknownx new file mode 100644 index 0000000000..457e8e343d --- /dev/null +++ b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/input.unknownx @@ -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 diff --git a/Tmain/parser-own-fields-for-foreign-lang-in-json.d/knownz.ctags b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/knownz.ctags new file mode 100644 index 0000000000..92799bce41 --- /dev/null +++ b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/knownz.ctags @@ -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} diff --git a/Tmain/parser-own-fields-for-foreign-lang-in-json.d/run.sh b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/run.sh new file mode 100644 index 0000000000..72756253fb --- /dev/null +++ b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/run.sh @@ -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 diff --git a/Tmain/parser-own-fields-for-foreign-lang-in-json.d/stderr-expected.txt b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/stderr-expected.txt new file mode 100644 index 0000000000..fd87c9c6da --- /dev/null +++ b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/stderr-expected.txt @@ -0,0 +1 @@ +ctags: Notice: No options will be read from files or environment diff --git a/Tmain/parser-own-fields-for-foreign-lang-in-json.d/stdout-expected.txt b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/stdout-expected.txt new file mode 100644 index 0000000000..b647efd9d3 --- /dev/null +++ b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/stdout-expected.txt @@ -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"} diff --git a/Tmain/parser-own-fields-for-foreign-lang-in-json.d/unknownx.ctags b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/unknownx.ctags new file mode 100644 index 0000000000..fed79e76fa --- /dev/null +++ b/Tmain/parser-own-fields-for-foreign-lang-in-json.d/unknownx.ctags @@ -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 +}} diff --git a/Tmain/parser-own-fields-for-foreign-lang.d/input.unknownx b/Tmain/parser-own-fields-for-foreign-lang.d/input.unknownx index 8ce5984bbc..457e8e343d 100644 --- a/Tmain/parser-own-fields-for-foreign-lang.d/input.unknownx +++ b/Tmain/parser-own-fields-for-foreign-lang.d/input.unknownx @@ -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 diff --git a/Tmain/parser-own-fields-for-foreign-lang.d/knownz.ctags b/Tmain/parser-own-fields-for-foreign-lang.d/knownz.ctags index bf91c87100..92799bce41 100644 --- a/Tmain/parser-own-fields-for-foreign-lang.d/knownz.ctags +++ b/Tmain/parser-own-fields-for-foreign-lang.d/knownz.ctags @@ -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} diff --git a/Tmain/parser-own-fields-for-foreign-lang.d/run.sh b/Tmain/parser-own-fields-for-foreign-lang.d/run.sh index 9abae09deb..85e101f1f3 100644 --- a/Tmain/parser-own-fields-for-foreign-lang.d/run.sh +++ b/Tmain/parser-own-fields-for-foreign-lang.d/run.sh @@ -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 diff --git a/Tmain/parser-own-fields-for-foreign-lang.d/stderr-expected.txt b/Tmain/parser-own-fields-for-foreign-lang.d/stderr-expected.txt index fd87c9c6da..dcab199f0d 100644 --- a/Tmain/parser-own-fields-for-foreign-lang.d/stderr-expected.txt +++ b/Tmain/parser-own-fields-for-foreign-lang.d/stderr-expected.txt @@ -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 diff --git a/Tmain/parser-own-fields-for-foreign-lang.d/stdout-expected.txt b/Tmain/parser-own-fields-for-foreign-lang.d/stdout-expected.txt index 690da2ad7a..48e3774890 100644 --- a/Tmain/parser-own-fields-for-foreign-lang.d/stdout-expected.txt +++ b/Tmain/parser-own-fields-for-foreign-lang.d/stdout-expected.txt @@ -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:- / diff --git a/Tmain/parser-own-fields-for-foreign-lang.d/unknownx.ctags b/Tmain/parser-own-fields-for-foreign-lang.d/unknownx.ctags index 523a670b34..fed79e76fa 100644 --- a/Tmain/parser-own-fields-for-foreign-lang.d/unknownx.ctags +++ b/Tmain/parser-own-fields-for-foreign-lang.d/unknownx.ctags @@ -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 +}}