A coordinate has a latitude, longitude, and an altitude.
",
"Property: latitude": "
The latitude in degrees.
",
diff --git a/tests/data/generated/dokka/kotlin/default/contents.toml b/tests/data/generated/dokka/kotlin/default/contents.toml
new file mode 100644
index 00000000..12c8e61b
--- /dev/null
+++ b/tests/data/generated/dokka/kotlin/default/contents.toml
@@ -0,0 +1,21 @@
+# Copyright (C) 2019, TomTom (http://tomtom.com).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+[package]
+name = "kotlin-default"
+
+[reference]
+type = "dokka"
+dir = ""
+
diff --git a/tests/unit/api_reference_loader.py b/tests/unit/api_reference_loader.py
index 10c5de92..409ea502 100644
--- a/tests/unit/api_reference_loader.py
+++ b/tests/unit/api_reference_loader.py
@@ -29,9 +29,13 @@ def doxygen_versions():
def generated_test_data_factory(reference_type: str, name: str, version: str = None):
- assert reference_type == "doxygen"
- assert version is not None
- return generated_test_data_dir / reference_type / version / name
+ if reference_type == "doxygen":
+ assert version is not None
+ return generated_test_data_dir / reference_type / version / name
+ elif reference_type == "dokka":
+ return generated_test_data_dir / reference_type / name
+ else:
+ assert False
class ApiReferenceLoader:
diff --git a/tests/unit/builders.py b/tests/unit/builders.py
index fb934c39..7ff01900 100644
--- a/tests/unit/builders.py
+++ b/tests/unit/builders.py
@@ -120,10 +120,10 @@ def member_property(self, prot: str, name: str = None):
name=name,
returns=make_return_value(type=make_type_ref(language=self.lang, name="Type")))
- def member_function(self, has_return_value: bool = True, **kwargs):
+ def member_function(self, has_return_value: bool = True, kind: str = "function", **kwargs):
if has_return_value:
returns = make_return_value()
else:
returns = None
self.compound.members.append(
- make_compound(language=self.lang, kind="function", returns=returns, **kwargs))
+ make_compound(language=self.lang, kind=kind, returns=returns, **kwargs))
diff --git a/tests/unit/generator/templates/helpers/test_kotlin.py b/tests/unit/generator/templates/helpers/test_kotlin.py
index 84f70c67..88bb81bd 100644
--- a/tests/unit/generator/templates/helpers/test_kotlin.py
+++ b/tests/unit/generator/templates/helpers/test_kotlin.py
@@ -34,6 +34,10 @@ def kotlin_class():
# add property
builder.member_property(prot=visibility)
+ # add constructor
+ builder.member_function(prot=visibility,
+ name=visibility.capitalize() + "Constructor",
+ kind="constructor")
# add some method
builder.member_function(prot=visibility, name=visibility.capitalize() + "Method")
# add some method without return type
@@ -86,6 +90,28 @@ def test_private_constants__no_filter(helper):
assert result == ["PrivateConstant"]
+def test_public_constructors__no_filter(helper):
+ result = [m.name for m in helper.constructors(prot="public")]
+ assert result == ["PublicConstructor"]
+
+
+def test_public_constructors__filter_match(helper):
+ helper.insert_filter = InsertionFilter(members="Public")
+ result = [m.name for m in helper.constructors(prot="public")]
+ assert result == ["PublicConstructor"]
+
+
+def test_public_constructors__filter_no_match(helper):
+ helper.insert_filter = InsertionFilter(members="NONE")
+ result = [m.name for m in helper.constructors(prot="public")]
+ assert len(result) == 0
+
+
+def test_private_constructors__no_filter(helper):
+ result = [m.name for m in helper.constructors(prot="private")]
+ assert result == ["PrivateConstructor"]
+
+
def test_parameter(helper):
ref = TypeRef(language="kotlin")
ref.name = "MyType"
diff --git a/tests/unit/parser/dokka/__init__.py b/tests/unit/parser/dokka/__init__.py
new file mode 100644
index 00000000..e69de29b
diff --git a/tests/unit/parser/dokka/test_parser.py b/tests/unit/parser/dokka/test_parser.py
new file mode 100644
index 00000000..17795293
--- /dev/null
+++ b/tests/unit/parser/dokka/test_parser.py
@@ -0,0 +1,162 @@
+# Copyright (C) 2019, TomTom (http://tomtom.com).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+import pytest
+from pytest import param
+
+from asciidoxy.api_reference import ApiReference
+from asciidoxy.parser import parser_factory
+from tests.unit.api_reference_loader import ApiReferenceLoader
+from tests.unit.matchers import (
+ IsEmpty,
+ IsNone,
+ Unordered,
+ m_compound,
+ m_parameter,
+ m_returnvalue,
+ m_typeref,
+)
+
+
+@pytest.fixture(scope="module")
+def api_reference():
+ return ApiReferenceLoader().add("dokka", "kotlin/default").load()
+
+
+def test_create_dokka_parser(generated_test_data):
+ api_reference = ApiReference()
+ parser = parser_factory("dokka", api_reference)
+ assert parser is not None
+
+ parser.parse(generated_test_data("dokka", "kotlin/default/asciidoxy.json"))
+
+ element = api_reference.find(name="asciidoxy.Coordinate", kind="class")
+ assert element is not None
+
+
+@pytest.mark.parametrize(
+ "search_params,matcher",
+ [
+ param(dict(name="asciidoxy.Coordinate", kind="class", lang="kotlin"),
+ m_compound(
+ language="kotlin",
+ id="kotlin-asciidoxy1_1_Coordinate",
+ name="Coordinate",
+ full_name="asciidoxy.Coordinate",
+ namespace="asciidoxy",
+ kind="class",
+ prot="public",
+ brief="Class to hold information about a coordinate.",
+ description="A coordinate has a latitude, longitude, and an altitude.",
+ members=Unordered(
+ m_compound(name="isValid"),
+ m_compound(name="latitude"),
+ m_compound(name="longitude"),
+ m_compound(name="altitude"),
+ m_compound(name="Coordinate"),
+ ),
+ ),
+ id="Basic class"),
+ param(
+ dict(name="asciidoxy.Coordinate.isValid", kind="function", lang="kotlin"),
+ m_compound(
+ language="kotlin",
+ id="kotlin-asciidoxy1_1_Coordinate1_1_isValid1_1_2_",
+ name="isValid",
+ full_name="asciidoxy.Coordinate.isValid",
+ namespace="asciidoxy.Coordinate",
+ kind="function",
+ prot="public",
+ brief="Check if the coordinate is valid.",
+ description="A coordinate is valid if its values are within WGS84 bounds.",
+ params=[],
+ returns=m_returnvalue(
+ description="True if valid, false if not.",
+ type=m_typeref(
+ name="Boolean",
+ id=IsNone(), # TODO: id="kotlin-kotlin1_1_Boolean",
+ ),
+ ),
+ ),
+ id="Basic method"),
+ param(
+ dict(name="asciidoxy.Coordinate.latitude", kind="property", lang="kotlin"),
+ m_compound(
+ language="kotlin",
+ id="kotlin-asciidoxy1_1_Coordinate1_1_latitude1_1_2_",
+ name="latitude",
+ full_name="asciidoxy.Coordinate.latitude",
+ namespace="asciidoxy.Coordinate",
+ kind="property",
+ prot="public",
+ brief="The latitude in degrees.",
+ description=IsEmpty(),
+ returns=m_returnvalue(
+ description=IsEmpty(),
+ type=m_typeref(
+ name="Double",
+ id=IsNone(), # TODO: id="kotlin-kotlin1_1_Double",
+ ),
+ ),
+ ),
+ id="Basic property"),
+ param(
+ dict(name="asciidoxy.Coordinate.Coordinate", kind="constructor", lang="kotlin"),
+ m_compound(
+ language="kotlin",
+ id=("kotlin-asciidoxy1_1_Coordinate1_1_Coordinate1_1_2_kotlin1_1_Double2_kotlin"
+ "1_1_Double2_kotlin1_1_Double"),
+ name="Coordinate",
+ full_name="asciidoxy.Coordinate.Coordinate",
+ namespace="asciidoxy.Coordinate",
+ kind="constructor",
+ prot="public",
+ brief=IsEmpty(),
+ params=[
+ m_parameter(
+ name="latitude",
+ description="The latitude in degrees.",
+ type=m_typeref(
+ name="Double",
+ id=IsNone(), # TODO: id="kotlin-kotlin1_1_Double",
+ ),
+ ),
+ m_parameter(
+ name="longitude",
+ description="The longitude in degrees.",
+ type=m_typeref(
+ name="Double",
+ id=IsNone(), # TODO: id="kotlin-kotlin1_1_Double",
+ ),
+ ),
+ m_parameter(
+ name="altitude",
+ description="The altitude in meters.",
+ type=m_typeref(
+ name="Double",
+ id=IsNone(), # TODO: id="kotlin-kotlin1_1_Double",
+ ),
+ ),
+ ],
+ returns=m_returnvalue(
+ description=IsEmpty(),
+ type=m_typeref(
+ name="Coordinate",
+ id="kotlin-asciidoxy1_1_Coordinate",
+ ),
+ ),
+ ),
+ id="Basic constructor"),
+ ])
+def test_parse_kotlin(api_reference, search_params, matcher):
+ matcher.assert_matches(api_reference.find(**search_params))
diff --git a/tests/visual/kotlin.adoc b/tests/visual/kotlin.adoc
new file mode 100644
index 00000000..9305aec4
--- /dev/null
+++ b/tests/visual/kotlin.adoc
@@ -0,0 +1,19 @@
+// Copyright (C) 2019, TomTom (http://tomtom.com).
+//
+// Licensed under the Apache License, Version 2.0 (the "License");
+// you may not use this file except in compliance with the License.
+// You may obtain a copy of the License at
+//
+// http://www.apache.org/licenses/LICENSE-2.0
+//
+// Unless required by applicable law or agreed to in writing, software
+// distributed under the License is distributed on an "AS IS" BASIS,
+// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+// See the License for the specific language governing permissions and
+// limitations under the License.
+= Kotlin test
+:toc: left
+
+== Default
+
+${insert("asciidoxy.Coordinate", leveloffset="+2")}
diff --git a/tests/visual/kotlin.toml b/tests/visual/kotlin.toml
new file mode 100644
index 00000000..1d33e622
--- /dev/null
+++ b/tests/visual/kotlin.toml
@@ -0,0 +1,19 @@
+# Copyright (C) 2019, TomTom (http://tomtom.com).
+#
+# Licensed under the Apache License, Version 2.0 (the "License");
+# you may not use this file except in compliance with the License.
+# You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing, software
+# distributed under the License is distributed on an "AS IS" BASIS,
+# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+# See the License for the specific language governing permissions and
+# limitations under the License.
+
+[packages]
+
+[packages.kotlin-default]
+type = "local"
+package_dir = "tests/data/generated/dokka/kotlin/default"