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

analyzePartial broken? #45

Open
dgmltn opened this issue May 26, 2024 · 1 comment
Open

analyzePartial broken? #45

dgmltn opened this issue May 26, 2024 · 1 comment
Labels
bug Something isn't working

Comments

@dgmltn
Copy link

dgmltn commented May 26, 2024

It appears that perhaps something is wrong with snapshots or analyzePartial. The first test here fails, and the second one passes by avoiding using snapshots altogether. (The second appears to be the way that KodeView is working currently).

    @Test
    fun basic_getHighlights_location() {
        val highlighter = Highlights.Builder()
            .language(SyntaxLanguage.JAVASCRIPT)
            .build()

        highlighter.setCode("const foo = 'bar';")
        val highlights1 = highlighter.getHighlights().filterIsInstance<ColorHighlight>().sortedBy { it.location.start }
        highlights1.size shouldEqual 4
        highlights1[0].location shouldEqual PhraseLocation(start=0, end=5)
        highlights1[1].location shouldEqual PhraseLocation(start=10, end=11)
        highlights1[2].location shouldEqual PhraseLocation(start=12, end=17)
        highlights1[3].location shouldEqual PhraseLocation(start=17, end=18)

        highlighter.setCode("const foo = 'barrr';")
        val highlights2 = highlighter.getHighlights().filterIsInstance<ColorHighlight>().sortedBy { it.location.start }
        highlights2.size shouldEqual 4
        highlights2[0].location shouldEqual PhraseLocation(start=0, end=5)
        highlights2[1].location shouldEqual PhraseLocation(start=10, end=11)
        // FAILS HERE:
        highlights2[2].location shouldEqual PhraseLocation(start=12, end=19)
        highlights2[3].location shouldEqual PhraseLocation(start=19, end=20)
    }

    @Test
    fun basic_getHighlights_location_alt() {
        var highlighter = Highlights.Builder()
            .language(SyntaxLanguage.JAVASCRIPT)
            .build()

        highlighter = highlighter
            .getBuilder()
            .code("const foo = 'bar';")
            .build()
        val highlights1 = highlighter.getHighlights().filterIsInstance<ColorHighlight>().sortedBy { it.location.start }
        highlights1.size shouldEqual 4
        highlights1[0].location shouldEqual PhraseLocation(start=0, end=5)
        highlights1[1].location shouldEqual PhraseLocation(start=10, end=11)
        highlights1[2].location shouldEqual PhraseLocation(start=12, end=17)
        highlights1[3].location shouldEqual PhraseLocation(start=17, end=18)

        highlighter = highlighter
            .getBuilder()
            .code("const foo = 'barrr';")
            .build()
        val highlights2 = highlighter.getHighlights().filterIsInstance<ColorHighlight>().sortedBy { it.location.start }
        highlights2.size shouldEqual 4
        highlights2[0].location shouldEqual PhraseLocation(start=0, end=5)
        highlights2[1].location shouldEqual PhraseLocation(start=10, end=11)
        highlights2[2].location shouldEqual PhraseLocation(start=12, end=19)
        highlights2[3].location shouldEqual PhraseLocation(start=19, end=20)
    }

    private infix fun Any?.shouldEqual(expected: Any?) {
        assertEquals(expected, this)
    }
@tmaxxdd tmaxxdd added the bug Something isn't working label Aug 11, 2024
@tmaxxdd
Copy link
Member

tmaxxdd commented Aug 11, 2024

Hi, thanks for that.

After your test I am not able to tell what's wrong. I will need a closer look

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants