eclipse / Xpect

This repository has been rewritten to move to the Eclipse Foundation. Find the old history here: https://github.com/TypeFox/Xpect
http://www.xpect-tests.org/
Eclipse Public License 2.0
30 stars 28 forks source link

Content assist proposals sometimes invoked at test comment instead of test DSL #345

Closed trancexpress closed 3 months ago

trancexpress commented 3 months ago

Opening an issue since I don't see a discussions section for Xpect.

We have more or less the following test DSL:

    keyword1 name1 {
        // Verify that keyword2.property10, keyword2.property20, keyword2.property30 and
        // keyword2.property40 are not shown.
        // XPECT proposals at 'keyword2.|' --> property1, property2, property3
        // XPECT proposals at '=|' --> value1, value2
        // Verify that safety lines are shown for keyword2.property1
        keyword2.property1 = value1;
    }

When I remove the 2nd XPECT statement, or run this test with my JUnit 5 changes (see https://github.com/eclipse/Xpect/pull/343), the test fails. It fails due due to the wrong offset provided by org.eclipse.xpect.parameter.OffsetProvider.getMatchedOffset().

The region in the fail case is within the comment "// Verify that safety lines are shown for keyword2.property1". The region in the pass case is the actually relevant test DSL "keyword2.property1 = value1;".

What is the defined behavior here? Is there some way to mark Xpect comments as Xpect comments and not as potential DSL comments? To "fix" the test fail, I've moved the "confusing" comment to be above the XPECTstatement:

    keyword1 name1 {
        // Verify that keyword2.property10, keyword2.property20, keyword2.property30 and
        // keyword2.property40 are not shown.
        // Verify that safety lines are shown for keyword2.property1
        // XPECT proposals at 'keyword2.|' --> property1, property2, property3
        // XPECT proposals at '=|' --> value1, value2
        keyword2.property1 = value1;
    }

I also don't know why this behavior shows up only without the 2nd XPECT statement with JUnit 4 XpectRunner, but always with my JUnit 5 alternative.

cdietrich commented 3 months ago

I have not looked at this code for years so I fear you need to debug what the offsetprovider internally does

cdietrich commented 3 months ago

Ps content assist tests are an advantest internal feature afaik. But I assume others show the same behavior

do you also see the problem with a multiline comment

trancexpress commented 3 months ago

do you also see the problem with a multiline comment

You mean like this?

/*
 *
 */

Yes, I still see it.

Alright, I think I was missing this, at the replacement for XpectRunner:

@XpectImport(TestTitleProvider.class)

Probably this is what defines the title of the XPECT test, which is then probably used for some error message or something like that...