mirror of
https://github.com/github/codeql.git
synced 2026-05-04 21:25:44 +02:00
Swift: add ?* modifier to schema specification
This indicates a list of optional entries. This is different than simply repeatind entries because of the indexing.
This commit is contained in:
@@ -42,6 +42,7 @@ def test_field_is_single(is_optional, is_repeated, expected):
|
||||
(False, False, "bar"),
|
||||
(True, False, "std::optional<bar>"),
|
||||
(False, True, "std::vector<bar>"),
|
||||
(True, True, "std::vector<std::optional<bar>>"),
|
||||
])
|
||||
def test_field_modal_types(is_optional, is_repeated, expected):
|
||||
f = cpp.Field("name", "bar", is_optional=is_optional, is_repeated=is_repeated)
|
||||
|
||||
@@ -72,6 +72,7 @@ def test_complex_hierarchy_topologically_ordered(generate):
|
||||
(schema.SingleProperty, False, False, None),
|
||||
(schema.OptionalProperty, True, False, "MyClassPropsTrap"),
|
||||
(schema.RepeatedProperty, False, True, "MyClassPropsTrap"),
|
||||
(schema.RepeatedOptionalProperty, True, True, "MyClassPropsTrap"),
|
||||
])
|
||||
def test_class_with_field(generate, type, expected, property_cls, optional, repeated, trap_name):
|
||||
assert generate([
|
||||
|
||||
@@ -126,10 +126,11 @@ def test_final_class_with_optional_field(opts, input, renderer):
|
||||
)
|
||||
|
||||
|
||||
def test_final_class_with_repeated_field(opts, input, renderer):
|
||||
@pytest.mark.parametrize("property_cls", [schema.RepeatedProperty, schema.RepeatedOptionalProperty])
|
||||
def test_final_class_with_repeated_field(opts, input, renderer, property_cls):
|
||||
input.classes = [
|
||||
schema.Class("Object", properties=[
|
||||
schema.RepeatedProperty("foo", "bar"),
|
||||
property_cls("foo", "bar"),
|
||||
]),
|
||||
]
|
||||
assert generate(opts, renderer) == dbscheme.Scheme(
|
||||
@@ -161,7 +162,8 @@ def test_final_class_with_more_fields(opts, input, renderer):
|
||||
schema.SingleProperty("one", "x"),
|
||||
schema.SingleProperty("two", "y"),
|
||||
schema.OptionalProperty("three", "z"),
|
||||
schema.RepeatedProperty("four", "w"),
|
||||
schema.RepeatedProperty("four", "u"),
|
||||
schema.RepeatedOptionalProperty("five", "v"),
|
||||
]),
|
||||
]
|
||||
assert generate(opts, renderer) == dbscheme.Scheme(
|
||||
@@ -190,7 +192,16 @@ def test_final_class_with_more_fields(opts, input, renderer):
|
||||
columns=[
|
||||
dbscheme.Column('id', '@object'),
|
||||
dbscheme.Column('index', 'int'),
|
||||
dbscheme.Column('four', 'w'),
|
||||
dbscheme.Column('four', 'u'),
|
||||
]
|
||||
),
|
||||
dbscheme.Table(
|
||||
name="object_fives",
|
||||
keyset=dbscheme.KeySet(["id", "index"]),
|
||||
columns=[
|
||||
dbscheme.Column('id', '@object'),
|
||||
dbscheme.Column('index', 'int'),
|
||||
dbscheme.Column('five', 'v'),
|
||||
]
|
||||
),
|
||||
],
|
||||
|
||||
@@ -59,6 +59,16 @@ def test_property_indefinite_article(name, expected_article):
|
||||
assert prop.indefinite_article == expected_article
|
||||
|
||||
|
||||
@pytest.mark.parametrize("plural,expected", [
|
||||
(None, False),
|
||||
("", False),
|
||||
("X", True),
|
||||
])
|
||||
def test_property_is_plural(plural, expected):
|
||||
prop = ql.Property("foo", "Foo", "props", ["x"], plural=plural)
|
||||
assert prop.is_repeated is expected
|
||||
|
||||
|
||||
def test_property_no_plural_no_indefinite_article():
|
||||
prop = ql.Property("Prop", "Foo", "props", ["x"])
|
||||
assert prop.indefinite_article is None
|
||||
|
||||
@@ -107,7 +107,8 @@ def test_optional_property(opts, input, renderer):
|
||||
import_file(): ql.ImportList([stub_import_prefix + "MyObject"]),
|
||||
stub_path() / "MyObject.qll": ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"),
|
||||
ql_output_path() / "MyObject.qll": ql.Class(name="MyObject", final=True, properties=[
|
||||
ql.Property(singular="Foo", type="bar", tablename="my_object_foos", tableparams=["this", "result"]),
|
||||
ql.Property(singular="Foo", type="bar", tablename="my_object_foos", tableparams=["this", "result"],
|
||||
is_optional=True),
|
||||
])
|
||||
}
|
||||
|
||||
@@ -126,6 +127,20 @@ def test_repeated_property(opts, input, renderer):
|
||||
}
|
||||
|
||||
|
||||
def test_repeated_optional_property(opts, input, renderer):
|
||||
input.classes = [
|
||||
schema.Class("MyObject", properties=[schema.RepeatedOptionalProperty("foo", "bar")]),
|
||||
]
|
||||
assert generate(opts, renderer) == {
|
||||
import_file(): ql.ImportList([stub_import_prefix + "MyObject"]),
|
||||
stub_path() / "MyObject.qll": ql.Stub(name="MyObject", base_import=gen_import_prefix + "MyObject"),
|
||||
ql_output_path() / "MyObject.qll": ql.Class(name="MyObject", final=True, properties=[
|
||||
ql.Property(singular="Foo", plural="Foos", type="bar", tablename="my_object_foos", params=[index_param],
|
||||
tableparams=["this", "index", "result"], is_optional=True),
|
||||
])
|
||||
}
|
||||
|
||||
|
||||
def test_single_class_property(opts, input, renderer):
|
||||
input.classes = [
|
||||
schema.Class("MyObject", properties=[schema.SingleProperty("foo", "Bar")]),
|
||||
|
||||
@@ -140,6 +140,7 @@ A:
|
||||
one: string
|
||||
two: int?
|
||||
three: bool*
|
||||
four: x?*
|
||||
""")
|
||||
assert ret.classes == [
|
||||
schema.Class(root_name, derived={'A'}),
|
||||
@@ -147,6 +148,7 @@ A:
|
||||
schema.SingleProperty('one', 'string'),
|
||||
schema.OptionalProperty('two', 'int'),
|
||||
schema.RepeatedProperty('three', 'bool'),
|
||||
schema.RepeatedOptionalProperty('four', 'x'),
|
||||
]),
|
||||
]
|
||||
|
||||
|
||||
Reference in New Issue
Block a user