From cf1a0082b0cc5e235a088d1a6d78b5acaa7a903d Mon Sep 17 00:00:00 2001 From: aranega Date: Wed, 18 Sep 2024 18:07:46 -0600 Subject: [PATCH] Add new set of rules and support for various string functions --- pyecoreocl/compiler.py | 381 +------------------- pyecoreocl/dummy_rules/__init__.py | 19 + pyecoreocl/dummy_rules/collections_rules.py | 341 ++++++++++++++++++ pyecoreocl/dummy_rules/primitives_rules.py | 71 ++++ tests/test_collection_lib.py | 4 - tests/test_object_ptypes_lib.py | 30 +- 6 files changed, 464 insertions(+), 382 deletions(-) create mode 100644 pyecoreocl/dummy_rules/__init__.py create mode 100644 pyecoreocl/dummy_rules/collections_rules.py create mode 100644 pyecoreocl/dummy_rules/primitives_rules.py diff --git a/pyecoreocl/compiler.py b/pyecoreocl/compiler.py index c02ccd5..682061d 100644 --- a/pyecoreocl/compiler.py +++ b/pyecoreocl/compiler.py @@ -1,4 +1,6 @@ from antlr4 import CommonTokenStream, InputStream + +from .dummy_rules import RuleSet, default_collection_call, default_primitive_call from .parser import OclExpressionVisitor, OclExpressionParser, OclExpressionLexer @@ -85,20 +87,9 @@ def visitCallExpression(self, ctx): self.inline(")") def visitMethodCall(self, ctx): - if ctx.attname.text == "oclAsType": - self.visit(ctx.expression) - return - if ctx.attname.text == "oclIsKindOf": - self.inline("isinstance(") - self.visit(ctx.expression) - self.inline(", ") - self.visit(ctx.argExp()) - self.inline(")") - return - self.visit(ctx.expression) - self.inline(f".{ctx.attname.text}(") - self.visit(ctx.argExp()) - self.inline(")") + operation = ctx.attname.text + rule = RuleSet.rules_primitives.get(operation, default_primitive_call) + rule(self, ctx) def visitArgumentsExp(self, ctx): for exp in ctx.oclExp(): @@ -280,368 +271,6 @@ def visitUnreservedName(self, ctx): return self.visitChildren(ctx) -class RuleSet: - rules_collections = {} - rules_primitives = {} - - -def register_rule_set(decorator): - register_name = decorator.__name__.split("_")[0] - - def inner(fun): - names = fun.__name__[5:].split("_") - function_name = "".join([names[0], *(f.capitalize() for f in names[1:])]) - getattr(RuleSet, f"rules_{register_name}s")[function_name] = fun - return fun - - return inner - - -@register_rule_set -def collection_rule(fun): - return fun - - -@register_rule_set -def primitive_rule(fun): - return fun - - -@collection_rule -def rule_collect_nested(emitter, ctx): - emitter.inline("(") - emitter.visit(ctx.argExp().body) - variables = [arg.text for arg in ctx.argExp().varnames] - emitter.inline(f" for {', '.join(variables)} in ") - if len(variables) > 1: - emitter.inline("itertools.combinations_with_replacement(") - emitter.visit(ctx.expression) - emitter.inline(f", {len(variables)})") - else: - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_collect(emitter, ctx): - emitter.inline("ocl.flatten(") - emitter.visit(ctx.argExp().body) - variables = [arg.text for arg in ctx.argExp().varnames] - emitter.inline(f" for {', '.join(variables)} in ") - if len(variables) > 1: - emitter.inline("itertools.combinations_with_replacement(") - emitter.visit(ctx.expression) - emitter.inline(f", {len(variables)})") - else: - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_for_all(emitter, ctx): - emitter.inline(f"all(") - emitter.visit(ctx.argExp().body) - variables = [arg.text for arg in ctx.argExp().varnames] - emitter.inline(f" for {', '.join(variables)} in ") - if len(variables) > 1: - emitter.inline("itertools.combinations_with_replacement(") - emitter.visit(ctx.expression) - emitter.inline(f", {len(variables)})") - else: - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_exists(emitter, ctx): - emitter.inline(f"any(") - emitter.visit(ctx.argExp().body) - variables = [arg.text for arg in ctx.argExp().varnames] - emitter.inline(f" for {', '.join(variables)} in ") - if len(variables) > 1: - emitter.inline("itertools.combinations_with_replacement(") - emitter.visit(ctx.expression) - emitter.inline(f", {len(variables)})") - else: - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_one(emitter, ctx): - emitter.inline("(len(list(") - rule_select(emitter, ctx) - emitter.inline(")) == 1)") - - -@collection_rule -def rule_select(emitter, ctx): - variables = [arg.text for arg in ctx.argExp().varnames] - varnames = ", ".join(variables) - emitter.inline(f"({varnames}") - emitter.inline(f" for {varnames} in ") - if len(variables) > 1: - emitter.inline("itertools.combinations_with_replacement(") - emitter.visit(ctx.expression) - emitter.inline(f", {len(variables)})") - else: - emitter.visit(ctx.expression) - emitter.inline(f" if ") - emitter.visit(ctx.argExp().body) - emitter.inline(")") - - -@collection_rule -def rule_reject(emitter, ctx): - variables = [arg.text for arg in ctx.argExp().varnames] - varnames = ", ".join(variables) - emitter.inline(f"({varnames}") - emitter.inline(f" for {varnames} in ") - if len(variables) > 1: - emitter.inline("itertools.combinations_with_replacement(") - emitter.visit(ctx.expression) - emitter.inline(f", {len(variables)})") - else: - emitter.visit(ctx.expression) - emitter.inline(f" if not (") - emitter.visit(ctx.argExp().body) - emitter.inline("))") - - -@collection_rule -def rule_includes(emitter, ctx): - emitter.visit(ctx.argExp()) - emitter.inline(" in ") - emitter.visit(ctx.expression) - - -@collection_rule -def rule_excludes(emitter, ctx): - emitter.visit(ctx.argExp()) - emitter.inline(" not in ") - emitter.visit(ctx.expression) - - -@collection_rule -def rule_not_empty(emitter, ctx): - emitter.inline("len(") - emitter.visit(ctx.expression) - emitter.inline(") > 0") - - -@collection_rule -def rule_is_empty(emitter, ctx): - emitter.inline("len(") - emitter.visit(ctx.expression) - emitter.inline(") == 0") - - -@collection_rule -def rule_at(emitter, ctx): - emitter.visit(ctx.expression) - emitter.inline("[") - emitter.visit(ctx.argExp().body[0]) - emitter.inline("]") - - -@collection_rule -def rule_size(emitter, ctx): - emitter.inline("len(") - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_is_unique(emitter, ctx): - emitter.inline("ocl.is_unique(") - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_sum(emitter, ctx): - emitter.inline("sum(") - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_min(emitter, ctx): - emitter.inline("min(") - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_max(emitter, ctx): - emitter.inline("max(") - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_count(emitter, ctx): - emitter.inline("list(") - emitter.visit(ctx.expression) - emitter.inline(").count(") - emitter.visit(ctx.argExp()) - emitter.inline(")") - - -@collection_rule -def rule_includes_all(emitter, ctx): - emitter.inline("all(e in ") - emitter.visit(ctx.expression) - emitter.inline(" for e in ") - emitter.visit(ctx.argExp()) - emitter.inline(")") - - -@collection_rule -def rule_excludes_all(emitter, ctx): - emitter.inline("all(e not in ") - emitter.visit(ctx.expression) - emitter.inline(" for e in ") - emitter.visit(ctx.argExp()) - emitter.inline(")") - - -@collection_rule -def rule_as_sequence(emitter, ctx): - emitter.inline("list(") - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_as_set(emitter, ctx): - emitter.inline("set(") - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_as_bag(emitter, ctx): - emitter.inline("list(") - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_any(emitter, ctx): - emitter.inline("next(iter(") - emitter.visit(ctx.expression) - emitter.inline("), None)") - - -@collection_rule -def rule_sorted_by(emitter, ctx): - emitter.inline("sorted(") - emitter.visit(ctx.expression) - emitter.inline(", key=") - emitter.visit(ctx.argExp()) - emitter.inline(")") - - -@collection_rule -def rule_iterate(emitter, ctx): - emitter.inline("ocl.flatten(") - emitter.visit(ctx.argExp()) - emitter.inline("(_e, ") - emitter.visit(ctx.argExp().initializer) - emitter.inline(") for _e in ") - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_including(emitter, ctx): - emitter.inline("itertools.chain(") - emitter.visit(ctx.expression) - emitter.inline(", (") - emitter.visit(ctx.argExp()) - emitter.inline(",))") - - -@collection_rule -def rule_append(emitter, ctx): - rule_including(emitter, ctx) - - -@collection_rule -def rule_prepend(emitter, ctx): - emitter.inline("itertools.chain((") - emitter.visit(ctx.argExp()) - emitter.inline(",), ") - emitter.visit(ctx.expression) - emitter.inline(")") - - -@collection_rule -def rule_excluding(emitter, ctx): - emitter.inline("_e for _e in ") - emitter.visit(ctx.expression) - emitter.inline(" if _e != ") - emitter.visit(ctx.argExp()) - - -@collection_rule -def rule_select_by_kind(emitter, ctx): - emitter.inline("_e for _e in ") - emitter.visit(ctx.expression) - emitter.inline(" if isinstance(_e, ") - emitter.visit(ctx.argExp()) - emitter.inline(")") - - -@collection_rule -def rule_select_by_type(emitter, ctx): - emitter.inline("_e for _e in ") - emitter.visit(ctx.expression) - emitter.inline(" if type(_e) == ") - emitter.visit(ctx.argExp()) - - -@collection_rule -def rule_first(emitter, ctx): - emitter.inline("next(iter(") - emitter.visit(ctx.expression) - emitter.inline("))") - - -@collection_rule -def rule_last(emitter, ctx): - emitter.inline("list(") - emitter.visit(ctx.expression) - emitter.inline(")[-1]") - - -@collection_rule -def rule_index_of(emitter, ctx): - emitter.inline("next(_i for _i, _e in enumerate(") - emitter.visit(ctx.expression) - emitter.inline(") if _e == ") - emitter.visit(ctx.argExp().body[0]) - emitter.inline(")") - - -@collection_rule -def rule_closure(emitter, ctx): - emitter.inline("ocl.closure(") - emitter.visit(ctx.expression) - emitter.inline(", ") - emitter.visit(ctx.argExp()) - emitter.inline(")") - - -def default_collection_call(emitter, ctx): - operation = ctx.attname.text - emitter.visit(ctx.expression) - emitter.inline(f".{operation}(") - emitter.visit(ctx.argExp()) - emitter.inline(")") - - def dummy_compiler(s, mode="normal"): input_stream = InputStream(s) lexer = OclExpressionLexer(input_stream) diff --git a/pyecoreocl/dummy_rules/__init__.py b/pyecoreocl/dummy_rules/__init__.py new file mode 100644 index 0000000..36644e1 --- /dev/null +++ b/pyecoreocl/dummy_rules/__init__.py @@ -0,0 +1,19 @@ +class RuleSet: + rules_collections = {} + rules_primitives = {} + + +def register_rule_set(decorator): + register_name = decorator.__name__.split("_")[0] + + def inner(fun): + names = fun.__name__[5:].split("_") + function_name = "".join([names[0], *(f.capitalize() for f in names[1:])]) + getattr(RuleSet, f"rules_{register_name}s")[function_name] = fun + return fun + + return inner + + +from .collections_rules import default_collection_call +from .primitives_rules import default_primitive_call \ No newline at end of file diff --git a/pyecoreocl/dummy_rules/collections_rules.py b/pyecoreocl/dummy_rules/collections_rules.py new file mode 100644 index 0000000..fba3fae --- /dev/null +++ b/pyecoreocl/dummy_rules/collections_rules.py @@ -0,0 +1,341 @@ +from . import register_rule_set + + +@register_rule_set +def collection_rule(fun): + return fun + + +@collection_rule +def rule_collect_nested(emitter, ctx): + emitter.inline("(") + emitter.visit(ctx.argExp().body) + variables = [arg.text for arg in ctx.argExp().varnames] + emitter.inline(f" for {', '.join(variables)} in ") + if len(variables) > 1: + emitter.inline("itertools.combinations_with_replacement(") + emitter.visit(ctx.expression) + emitter.inline(f", {len(variables)})") + else: + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_collect(emitter, ctx): + emitter.inline("ocl.flatten(") + emitter.visit(ctx.argExp().body) + variables = [arg.text for arg in ctx.argExp().varnames] + emitter.inline(f" for {', '.join(variables)} in ") + if len(variables) > 1: + emitter.inline("itertools.combinations_with_replacement(") + emitter.visit(ctx.expression) + emitter.inline(f", {len(variables)})") + else: + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_for_all(emitter, ctx): + emitter.inline(f"all(") + emitter.visit(ctx.argExp().body) + variables = [arg.text for arg in ctx.argExp().varnames] + emitter.inline(f" for {', '.join(variables)} in ") + if len(variables) > 1: + emitter.inline("itertools.combinations_with_replacement(") + emitter.visit(ctx.expression) + emitter.inline(f", {len(variables)})") + else: + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_exists(emitter, ctx): + emitter.inline(f"any(") + emitter.visit(ctx.argExp().body) + variables = [arg.text for arg in ctx.argExp().varnames] + emitter.inline(f" for {', '.join(variables)} in ") + if len(variables) > 1: + emitter.inline("itertools.combinations_with_replacement(") + emitter.visit(ctx.expression) + emitter.inline(f", {len(variables)})") + else: + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_one(emitter, ctx): + emitter.inline("(len(list(") + rule_select(emitter, ctx) + emitter.inline(")) == 1)") + + +@collection_rule +def rule_select(emitter, ctx): + variables = [arg.text for arg in ctx.argExp().varnames] + varnames = ", ".join(variables) + emitter.inline(f"({varnames}") + emitter.inline(f" for {varnames} in ") + if len(variables) > 1: + emitter.inline("itertools.combinations_with_replacement(") + emitter.visit(ctx.expression) + emitter.inline(f", {len(variables)})") + else: + emitter.visit(ctx.expression) + emitter.inline(f" if ") + emitter.visit(ctx.argExp().body) + emitter.inline(")") + + +@collection_rule +def rule_reject(emitter, ctx): + variables = [arg.text for arg in ctx.argExp().varnames] + varnames = ", ".join(variables) + emitter.inline(f"({varnames}") + emitter.inline(f" for {varnames} in ") + if len(variables) > 1: + emitter.inline("itertools.combinations_with_replacement(") + emitter.visit(ctx.expression) + emitter.inline(f", {len(variables)})") + else: + emitter.visit(ctx.expression) + emitter.inline(f" if not (") + emitter.visit(ctx.argExp().body) + emitter.inline("))") + + +@collection_rule +def rule_includes(emitter, ctx): + emitter.visit(ctx.argExp()) + emitter.inline(" in ") + emitter.visit(ctx.expression) + + +@collection_rule +def rule_excludes(emitter, ctx): + emitter.visit(ctx.argExp()) + emitter.inline(" not in ") + emitter.visit(ctx.expression) + + +@collection_rule +def rule_not_empty(emitter, ctx): + emitter.inline("len(") + emitter.visit(ctx.expression) + emitter.inline(") > 0") + + +@collection_rule +def rule_is_empty(emitter, ctx): + emitter.inline("len(") + emitter.visit(ctx.expression) + emitter.inline(") == 0") + + +@collection_rule +def rule_at(emitter, ctx): + emitter.visit(ctx.expression) + emitter.inline("[") + emitter.visit(ctx.argExp().body[0]) + emitter.inline("]") + + +@collection_rule +def rule_size(emitter, ctx): + emitter.inline("len(") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_is_unique(emitter, ctx): + emitter.inline("ocl.is_unique(") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_sum(emitter, ctx): + emitter.inline("sum(") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_min(emitter, ctx): + emitter.inline("min(") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_max(emitter, ctx): + emitter.inline("max(") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_count(emitter, ctx): + emitter.inline("list(") + emitter.visit(ctx.expression) + emitter.inline(").count(") + emitter.visit(ctx.argExp()) + emitter.inline(")") + + +@collection_rule +def rule_includes_all(emitter, ctx): + emitter.inline("all(e in ") + emitter.visit(ctx.expression) + emitter.inline(" for e in ") + emitter.visit(ctx.argExp()) + emitter.inline(")") + + +@collection_rule +def rule_excludes_all(emitter, ctx): + emitter.inline("all(e not in ") + emitter.visit(ctx.expression) + emitter.inline(" for e in ") + emitter.visit(ctx.argExp()) + emitter.inline(")") + + +@collection_rule +def rule_as_sequence(emitter, ctx): + emitter.inline("list(") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_as_set(emitter, ctx): + emitter.inline("set(") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_as_bag(emitter, ctx): + emitter.inline("list(") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_any(emitter, ctx): + emitter.inline("next(iter(") + emitter.visit(ctx.expression) + emitter.inline("), None)") + + +@collection_rule +def rule_sorted_by(emitter, ctx): + emitter.inline("sorted(") + emitter.visit(ctx.expression) + emitter.inline(", key=") + emitter.visit(ctx.argExp()) + emitter.inline(")") + + +@collection_rule +def rule_iterate(emitter, ctx): + emitter.inline("ocl.flatten(") + emitter.visit(ctx.argExp()) + emitter.inline("(_e, ") + emitter.visit(ctx.argExp().initializer) + emitter.inline(") for _e in ") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_including(emitter, ctx): + emitter.inline("itertools.chain(") + emitter.visit(ctx.expression) + emitter.inline(", (") + emitter.visit(ctx.argExp()) + emitter.inline(",))") + + +@collection_rule +def rule_append(emitter, ctx): + rule_including(emitter, ctx) + + +@collection_rule +def rule_prepend(emitter, ctx): + emitter.inline("itertools.chain((") + emitter.visit(ctx.argExp()) + emitter.inline(",), ") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@collection_rule +def rule_excluding(emitter, ctx): + emitter.inline("_e for _e in ") + emitter.visit(ctx.expression) + emitter.inline(" if _e != ") + emitter.visit(ctx.argExp()) + + +@collection_rule +def rule_select_by_kind(emitter, ctx): + emitter.inline("_e for _e in ") + emitter.visit(ctx.expression) + emitter.inline(" if isinstance(_e, ") + emitter.visit(ctx.argExp()) + emitter.inline(")") + + +@collection_rule +def rule_select_by_type(emitter, ctx): + emitter.inline("_e for _e in ") + emitter.visit(ctx.expression) + emitter.inline(" if type(_e) is ") + emitter.visit(ctx.argExp()) + + +@collection_rule +def rule_first(emitter, ctx): + emitter.inline("next(iter(") + emitter.visit(ctx.expression) + emitter.inline("))") + + +@collection_rule +def rule_last(emitter, ctx): + emitter.inline("list(") + emitter.visit(ctx.expression) + emitter.inline(")[-1]") + + +@collection_rule +def rule_index_of(emitter, ctx): + emitter.inline("next(_i for _i, _e in enumerate(") + emitter.visit(ctx.expression) + emitter.inline(") if _e == ") + emitter.visit(ctx.argExp().body[0]) + emitter.inline(")") + + +@collection_rule +def rule_closure(emitter, ctx): + emitter.inline("ocl.closure(") + emitter.visit(ctx.expression) + emitter.inline(", ") + emitter.visit(ctx.argExp()) + emitter.inline(")") + + +def default_collection_call(emitter, ctx): + operation = ctx.attname.text + emitter.visit(ctx.expression) + emitter.inline(f".{operation}(") + emitter.visit(ctx.argExp()) + emitter.inline(")") diff --git a/pyecoreocl/dummy_rules/primitives_rules.py b/pyecoreocl/dummy_rules/primitives_rules.py new file mode 100644 index 0000000..8ddd176 --- /dev/null +++ b/pyecoreocl/dummy_rules/primitives_rules.py @@ -0,0 +1,71 @@ +from . import register_rule_set + + +@register_rule_set +def primitive_rule(fun): + return fun + + +@primitive_rule +def rule_size(emitter, ctx): + emitter.inline("len(") + emitter.visit(ctx.expression) + emitter.inline(")") + + +@primitive_rule +def rule_ocl_as_type(emitter, ctx): + # type_element = ctx.argExp().body[0].text + # if type_element in ("list", "set", "dict"): + # emitter.inline(f"(lambda _x: ") + # emitter.inline(f"_x if isinstance(_x, Iterable) and not isinstance(_x, (bytes, str)) else _e for _e in _x") + # emitter.inline(")(") + # emitter.inline(f"{type_element}(") + # emitter.visit(ctx.expression) + # emitter.inline("))") + + # return + emitter.visit(ctx.expression) + + +@primitive_rule +def rule_ocl_is_type_of(emitter, ctx): + emitter.inline("(type(") + emitter.visit(ctx.expression) + emitter.inline(") is ") + emitter.visit(ctx.argExp()) + emitter.inline(")") + + +@primitive_rule +def rule_ocl_is_kind_of(emitter, ctx): + emitter.inline("isinstance(") + emitter.visit(ctx.expression) + emitter.inline(", ") + emitter.visit(ctx.argExp()) + emitter.inline(")") + + +@primitive_rule +def rule_concat(emitter, ctx): + emitter.inline('f"{') + emitter.visit(ctx.expression) + emitter.inline("}{") + emitter.visit(ctx.argExp()) + emitter.inline('}"') + + +@primitive_rule +def rule_substring(emitter, ctx): + arg1, arg2 = [arg.text for arg in ctx.argExp().body] + arg2 = f"({arg2} + 1)" + emitter.inline("(") + emitter.visit(ctx.expression) + emitter.inline(f")[{arg1}:{arg2}]") + + +def default_primitive_call(emitter, ctx): + emitter.visit(ctx.expression) + emitter.inline(f".{ctx.attname.text}(") + emitter.visit(ctx.argExp()) + emitter.inline(")") diff --git a/tests/test_collection_lib.py b/tests/test_collection_lib.py index 811dddb..8a7e13b 100644 --- a/tests/test_collection_lib.py +++ b/tests/test_collection_lib.py @@ -4,10 +4,6 @@ """ from dataclasses import dataclass -from gc import collect -import itertools -from operator import indexOf -from typing import Sequence def test__basic_collections(): diff --git a/tests/test_object_ptypes_lib.py b/tests/test_object_ptypes_lib.py index fd2c5da..71dccd1 100644 --- a/tests/test_object_ptypes_lib.py +++ b/tests/test_object_ptypes_lib.py @@ -1,4 +1,30 @@ # coding: magic_ocl.strict +""" +This test module goal is to test all functions over primitive types +""" -def test__trigger(): - assert !true implies false! is False \ No newline at end of file +from dataclasses import dataclass + + +def test__string_size(): + assert !'abc'.size()! == 3 + + +def test__is_kind_ok(): + assert !'abc'.oclIsKindOf(str)! is True + + +def test__is_type_of(): + assert !'abc'.oclIsTypeOf(str)! is True + + +def test___as_type(): + assert !'abc'.oclAsType(str)! == 'abc' + + +def test__concat(): + assert !'abc'.concat('def')! == "abcdef" + + +def test__substring(): + assert !'abcd'.substring(1, 2)! == "bc" \ No newline at end of file