Skip to content

Commit

Permalink
Add support for "append" and "prepend"
Browse files Browse the repository at this point in the history
  • Loading branch information
aranega committed Sep 18, 2024
1 parent 139b774 commit 0a8fc9a
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 1 deletion.
14 changes: 14 additions & 0 deletions pyecoreocl/compiler.py
Original file line number Diff line number Diff line change
Expand Up @@ -545,6 +545,20 @@ def rule_including(emitter, ctx):
emitter.inline(",))")


@call_rule
def rule_append(emitter, ctx):
rule_including(emitter, ctx)


@call_rule
def rule_prepend(emitter, ctx):
emitter.inline("itertools.chain((")
emitter.visit(ctx.argExp())
emitter.inline(",), ")
emitter.visit(ctx.expression)
emitter.inline(")")


@call_rule
def rule_excluding(emitter, ctx):
emitter.inline("_e for _e in ")
Expand Down
18 changes: 17 additions & 1 deletion tests/test_collection_lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -157,4 +157,20 @@ class B(X):
l = [A(), A(), B(), B()]
assert !l->selectByType(A)->asSequence()! == l[:2]
assert !l->selectByType(B)->asSequence()! == l[2:]
assert !l->selectByType(X)->asSequence()! == []
assert !l->selectByType(X)->asSequence()! == []


def test__append():
assert !Set{1, 2}->append(1)->asSet()! == {1, 2}
assert !Set{1, 2}->append(3)->asSet()! == {1, 2, 3}

assert !Set{1, 2}->append(1)->asSequence()! == [1, 2, 1]
assert !Set{1, 2}->append(3)->asSequence()! == [1, 2, 3]


def test__prepend():
assert !Set{1, 2}->prepend(1)->asSet()! == {1, 2}
assert !Set{1, 2}->prepend(3)->asSet()! == {1, 2, 3}

assert !Set{1, 2}->prepend(1)->asSequence()! == [1, 1, 2]
assert !Set{1, 2}->prepend(3)->asSequence()! == [3, 1, 2]

0 comments on commit 0a8fc9a

Please sign in to comment.