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

feat(auto-edit): Add more test cases for image rendering #7138

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Diff not rendered.
Diff not rendered.
Diff not rendered.
55 changes: 26 additions & 29 deletions vscode/src/autoedits/renderer/image-gen/test/index.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { type DiffMode, generateSuggestionAsImage, initImageSuggestionService }
import { document } from '../../../../completions/test-helpers'
import { mockLocalStorage } from '../../../../services/LocalStorageProvider'
import type { DecorationInfo } from '../../decorators/base'
import { MOCK_DIFF } from './mock-diff'
import { MIXED_ADDITIONS_AND_DELETIONS, MOCK_DIFFS } from './mock-diff'

expect.extend({ toMatchImageSnapshot })

Expand Down Expand Up @@ -40,62 +40,59 @@ async function generateImageForTest(
}

describe('generateSuggestionAsImage', () => {
describe('addition diff', () => {
it('generates correct images, with correct highlighting applied, from a set of tokens', async () => {
const { darkBuffer, lightBuffer } = await generateImageForTest(
MOCK_DIFF,
'typescript',
'additions'
)
describe.each(MOCK_DIFFS)('$name diff', ({ name, diff, lang }) => {
it('addition diff visual output', async () => {
const { darkBuffer, lightBuffer } = await generateImageForTest(diff, lang, 'additions')
expect(lightBuffer).toMatchImageSnapshot({
customSnapshotIdentifier: 'highlighted-additions-suggestion-light',
customSnapshotIdentifier: `${name}-highlighted-additions-suggestion-light`,
})
expect(darkBuffer).toMatchImageSnapshot({
customSnapshotIdentifier: 'highlighted-additions-suggestion-dark',
customSnapshotIdentifier: `${name}-highlighted-additions-suggestion-dark`,
})
})

it('generates correct images, with correct highlighting applied, from a set of tokens in a language that does not have supported highlighting', async () => {
const { darkBuffer, lightBuffer } = await generateImageForTest(
MOCK_DIFF,
'non-existent-language',
'additions'
)
it('unified diff visual output', async () => {
const { darkBuffer, lightBuffer } = await generateImageForTest(diff, lang, 'unified')
expect(lightBuffer).toMatchImageSnapshot({
customSnapshotIdentifier: 'unhighlighted-additions-suggestion-light',
customSnapshotIdentifier: `${name}-highlighted-unified-suggestion-light`,
})
expect(darkBuffer).toMatchImageSnapshot({
customSnapshotIdentifier: 'unhighlighted-additions-suggestion-dark',
customSnapshotIdentifier: `${name}-highlighted-unified-suggestion-dark`,
})
})
})

describe('unfied diff', () => {
it('generates correct images, with correct highlighting applied, from a set of tokens', async () => {
describe('no syntax highlighting', () => {
// We want to avoid duplicating the tests (and images) for cases with no highlighting, as it is a small
// change that isn't required to be tested for a bunch of different diffs.
// Use a single diff for this case.
const exampleDiff = MIXED_ADDITIONS_AND_DELETIONS.diff

it('addition diff visual output', async () => {
const { darkBuffer, lightBuffer } = await generateImageForTest(
MOCK_DIFF,
'typescript',
'unified'
exampleDiff,
'non-existent-language',
'additions'
)
expect(lightBuffer).toMatchImageSnapshot({
customSnapshotIdentifier: 'highlighted-unified-suggestion-light',
customSnapshotIdentifier: 'no-highlighting-additions-suggestion-light',
})
expect(darkBuffer).toMatchImageSnapshot({
customSnapshotIdentifier: 'highlighted-unified-suggestion-dark',
customSnapshotIdentifier: 'no-highlighting-additions-suggestion-dark',
})
})

it('generates correct images, with correct highlighting applied, from a set of tokens in a language that does not have supported highlighting', async () => {
it('unified diff visual output', async () => {
const { darkBuffer, lightBuffer } = await generateImageForTest(
MOCK_DIFF,
exampleDiff,
'non-existent-language',
'unified'
)
expect(lightBuffer).toMatchImageSnapshot({
customSnapshotIdentifier: 'unhighlighted-unified-suggestion-light',
customSnapshotIdentifier: 'no-highlighting-unified-suggestion-light',
})
expect(darkBuffer).toMatchImageSnapshot({
customSnapshotIdentifier: 'unhighlighted-unified-suggestion-dark',
customSnapshotIdentifier: 'no-highlighting-unified-suggestion-dark',
})
})
})
Expand Down
Loading
Loading