blob: b11d21358e5ae4d47b63ffc9a7310b990877b992 [file] [edit]
// Copyright 2026 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
import rule from '../lib/enforce-version-controller-methods.ts';
import {RuleTester} from './utils/RuleTester.ts';
new RuleTester().run('enforce-version-controller-methods', rule, {
valid: [
{
name: 'allows contiguous update methods matching CURRENT_VERSION',
code: `
export class VersionController {
static readonly CURRENT_VERSION = 2;
updateVersionFrom0To1() {}
updateVersionFrom1To2() {}
}
`,
filename: 'front_end/core/common/VersionController.ts',
},
{
// It should ignore classes without CURRENT_VERSION
name: 'allows class without CURRENT_VERSION',
code: `
export class VersionController {
updateVersionFrom0To1() {}
}
`,
filename: 'front_end/core/common/VersionController.ts',
},
{
// It should ignore other classes entirely
name: 'allows non-VersionController class',
code: `
export class OtherClass {
static readonly CURRENT_VERSION = 2;
updateVersionFrom0To1() {}
}
`,
filename: 'front_end/core/common/OtherClass.ts',
},
],
invalid: [
{
name: 'disallows fewer update methods than CURRENT_VERSION',
code: `
export class VersionController {
static readonly CURRENT_VERSION = 2;
updateVersionFrom0To1() {}
}
`,
filename: 'front_end/core/common/VersionController.ts',
errors: [
{
messageId: 'incorrectMethodCount',
data: {
currentVersion: 2,
methodCount: 1,
},
},
],
},
{
name: 'disallows non-contiguous update method numbers',
code: `
export class VersionController {
static readonly CURRENT_VERSION = 3;
updateVersionFrom0To1() {}
updateVersionFrom2To3() {}
updateVersionFrom3To4() {}
}
`,
filename: 'front_end/core/common/VersionController.ts',
errors: [
{
messageId: 'nonContiguousMethods',
data: {
expectedFrom: 1,
expectedTo: 2,
},
},
],
},
{
name: 'disallows more update methods than CURRENT_VERSION',
code: `
export class VersionController {
static readonly CURRENT_VERSION = 2;
updateVersionFrom0To1() {}
updateVersionFrom1To2() {}
updateVersionFrom2To3() {}
}
`,
filename: 'front_end/core/common/VersionController.ts',
errors: [
{
messageId: 'incorrectMethodCount',
data: {
currentVersion: 2,
methodCount: 3,
},
},
],
},
],
});