Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix invalid Java unit test assertion #116

Merged
merged 1 commit into from
May 18, 2024
Merged

Conversation

mallman
Copy link
Contributor

@mallman mallman commented May 12, 2024

Fix invalid Java unit test assertion. C3 should not suggest ignored tokens as completions.

See issue #77 for related discussion.

This invalid assertion was hiding a bug in C3. How to fix that bug is up for discussion, but basically it appears that the implementation of the followSetsByATN global cache is problematic. This cache is based on the class name of the parser object, but it does not account for ignored tokens. Two instances of CodeCompletionCore will use the same followSetsByATN entry for the same parser, even if they have different ignored tokens. How to fix this?

The other language implementations of C3 may have the same problem. For example, it looks to me like the C# tests have the same invalid assertion. I'm not sure I want to touch that, though, because I'm not familiar with C#. So this PR just addresses the Java port.

I'm also wondering if this is related to #66 as well. @mike-lischke is the expert here.


import static org.junit.Assert.*;

/**
* Unit tests for CodeCompletionCore
*/
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This annotation was hiding the broken test. Test correctness shouldn't depend on the order in which the test methods are run.

@@ -153,8 +150,8 @@ public void test2_typicalExpressionTest() throws Exception {
assertTrue(candidates.tokens.containsKey(ExprLexer.VAR));
assertTrue(candidates.tokens.containsKey(ExprLexer.LET));

assertEquals(Arrays.asList(new Integer[]{ExprLexer.ID, ExprLexer.EQUAL}), candidates.tokens.get(ExprLexer.VAR));
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ExprLexer.ID and ExprLexer.EQUAL are members of the ignored token set, so they should not be candidate completions.

@mike-lischke
Copy link
Owner

Thanks @mallman, please sign your patch so I can merge it (see the DCO link)

tokens as completions

Signed-off-by: Michael Allman <msa@allman.ms>
@mallman
Copy link
Contributor Author

mallman commented May 13, 2024

Thanks @mallman, please sign your patch so I can merge it (see the DCO link)

Done.

Any thoughts on how to fix the associated bug? Do you want to take that on yourself?

@mike-lischke
Copy link
Owner

No idea yet. If you would like to take that over that would be great.

@mike-lischke mike-lischke merged commit 00a3402 into mike-lischke:main May 18, 2024
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants