Rewrite Rule for replacing #should: with #assert:

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Rewrite Rule for replacing #should: with #assert:

Runar Jordahl
I am trying to rewrite senders of should: with assert: . I am doing
this, as XProgramming.SUnit.TestCase>>should: has been deprecated.
This method accepts a block, while assert: accepts a Boolean.

As an example, I want
self should: [1 = 1].
replaced with this code:
self assert: 1 = 1.

I tried the following rule in the rewtite editor.
| `@vars |
`@.before.
`@r should: [| `@newvars |
`@.a].
`@.after

| `@vars `@newvars |
`@.before.
`@r assert: `@.a.
`@.after

But when I run the rule, I get a MessageNotUnderstood for #parent. I
am using VisualWorks 7.8.
How could I change my rule to get this working?

Kind regards
Runar
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc
Reply | Threaded
Open this post in threaded view
|

Re: Rewrite Rule for replacing #should: with #assert:

John Brant-2
On 11/1/2011 3:23 AM, Runar Jordahl wrote:

> I am trying to rewrite senders of should: with assert: . I am doing
> this, as XProgramming.SUnit.TestCase>>should: has been deprecated.
> This method accepts a block, while assert: accepts a Boolean.
>
> As an example, I want
> self should: [1 = 1].
> replaced with this code:
> self assert: 1 = 1.
>
> I tried the following rule in the rewtite editor.
> | `@vars |
> `@.before.
> `@r should: [| `@newvars |
> `@.a].
> `@.after
>
> | `@vars `@newvars |
> `@.before.
> `@r assert: `@.a.
> `@.after
>
> But when I run the rule, I get a MessageNotUnderstood for #parent. I
> am using VisualWorks 7.8.
> How could I change my rule to get this working?

The problem is that `@.a is a list of statements not a single
statement/expression, so it doesn't work as an argument to #assert:. I
would probably write two expressions. The first I would handle the
common case where the block has no arguments and only a single expression:

``@r should: [``@a]
        ->
``@r assert: ``@a

And another one that handles complex blocks:

| `@vars |
``@.before.
``@r should: [| `@newvars | ``@.insert. ``@a].
``@.after
        ->
| `@vars `@newvars |
``@.before.
``@.insert.
``@r assert: ``@a.
``@.after

The second expression will handle the first. However, since it is
performing the rewrite at the sequence node level, you will need to run
it once for each occurrence of a #should: in a sequence node. For
example, if you have:
        testEquals
                self should: [1=1].
                self should: [2=2]
you will need to run the second rule twice. However, the first rule
would fix both of them in a single run.

The second rule will have problems if you reuse the same temporary
variable name in a #should: blocks. If you want to get around that
issue, you could change the second rewrite to eliminate the `@newvars,
and then perform a third rewrite:

``@r should: [| `@newvars | ``@.insert. ``@a]
        ->
[| `@newvars | ``@.insert. self assert: ``@a] value



John Brant
_______________________________________________
vwnc mailing list
[hidden email]
http://lists.cs.uiuc.edu/mailman/listinfo/vwnc