Update all enums to be const enums

We will land a rule soon that enforces const enums in the codebase. This
updates any non-const enums to be const enums and updates the tests
accordingly.

R=andoli@chromium.org

Bug: 1130536
Change-Id: I2221a948a88ec7328e7abc2b33f044d14aef73fb
Reviewed-on: https://chromium-review.googlesource.com/c/devtools/devtools-frontend/+/2562853
Commit-Queue: Jack Franklin <jacktfranklin@chromium.org>
Auto-Submit: Jack Franklin <jacktfranklin@chromium.org>
Reviewed-by: Andres Olivares <andoli@chromium.org>
Reviewed-by: Alex Rudenko <alexrudenko@chromium.org>
This commit is contained in:
Jack Franklin
2020-11-30 15:23:42 +00:00
committed by Commit Bot
parent 5bae823824
commit 8d634c2cdf
10 changed files with 41 additions and 30 deletions
+1 -1
View File
@@ -18,7 +18,7 @@ export interface IssueSurveyLinkData {
showSurvey: (trigger: string, callback: ShowSurveyCallback) => void;
}
enum State {
const enum State {
Checking = 'Checking', // (begin state) -> ShowLink | DontShowLink
ShowLink = 'ShowLink', // -> Sending
Sending = 'Sending', // -> SurveyShown | Failed
+1 -4
View File
@@ -25,10 +25,7 @@ devtools_module("linear_memory_inspector") {
"../third_party/lit-html:bundle",
]
visibility = [
"../../test/unittests/front_end/linear_memory_inspector",
"../component_docs/*",
]
visibility = [ "../component_docs/*" ]
}
devtools_entrypoint("bundle") {
@@ -4,7 +4,7 @@
export const VALUE_INTEPRETER_MAX_NUM_BYTES = 8;
export enum ValueType {
export const enum ValueType {
Int8 = 'Integer 8-bit',
Int16 = 'Integer 16-bit',
Int32 = 'Integer 32-bit',
@@ -14,12 +14,12 @@ export enum ValueType {
String = 'String'
}
export enum Endianness {
export const enum Endianness {
Little = 'Little Endian',
Big = 'Big Endian'
}
export enum ValueTypeMode {
export const enum ValueTypeMode {
Decimal = 'dec',
Hexadecimal = 'hex',
Octal = 'oct',
@@ -14,7 +14,7 @@ export interface ValueInterpreterSettingsData {
valueTypes: Set<ValueType>;
}
enum ValueTypeGroup {
const enum ValueTypeGroup {
Integer = 'Integer',
Float = 'Floating point',
Other = 'Other'
+1 -1
View File
@@ -47,7 +47,7 @@ export interface BoxStyle {
hatchColor?: string;
}
enum LinePattern {
const enum LinePattern {
Solid = 'solid',
Dotted = 'dotted',
Dashed = 'dashed'
+1 -1
View File
@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
export enum TextColor {
export const enum TextColor {
DIM = 'DIM',
GREEN = 'GREEN',
RED = 'RED',
@@ -4,7 +4,7 @@
const {assert} = chai;
export enum MutationType {
export const enum MutationType {
ADD = 'ADD',
REMOVE = 'REMOVE',
TEXT_UPDATE = 'TEXT_UPDATE',
@@ -42,7 +42,7 @@ describe('LinearMemoryValueInterpreter', () => {
return component;
}
it('renders settings toolbar', async () => {
it('renders the settings toolbar', async () => {
const component = setUpComponent();
const settingsToolbar = getElementWithinComponent(component, TOOLBAR_SELECTOR, HTMLDivElement);
assert.isNotNull(settingsToolbar);
@@ -64,7 +64,7 @@ describe('ValueInterpreterDisplay', () => {
}
}
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats signed/unsigned and endianness for Integer 8-bit (decimal)',
it('correctly formats signed/unsigned and endianness for Integer 8-bit (decimal)',
async () => {
const formatData = {
buffer: new ArrayBuffer(1),
@@ -74,7 +74,7 @@ describe('ValueInterpreterDisplay', () => {
testNumberFormatCombinations(formatData, combinationsForNumbers);
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats signed/unsigned and endianness for Integer 16-bit (decimal)',
it('correctly formats signed/unsigned and endianness for Integer 16-bit (decimal)',
async () => {
const formatData = {
buffer: new ArrayBuffer(2),
@@ -85,7 +85,7 @@ describe('ValueInterpreterDisplay', () => {
testNumberFormatCombinations(formatData, combinationsForNumbers);
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats signed/unsigned and endianness for Integer 32-bit (decimal)',
it('correctly formats signed/unsigned and endianness for Integer 32-bit (decimal)',
async () => {
const formatData = {
buffer: new ArrayBuffer(4),
@@ -96,7 +96,7 @@ describe('ValueInterpreterDisplay', () => {
testNumberFormatCombinations(formatData, combinationsForNumbers);
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats signed/unsigned and endianness for Integer 64-bit (decimal)',
it('correctly formats signed/unsigned and endianness for Integer 64-bit (decimal)',
async () => {
const formatData = {
buffer: new ArrayBuffer(8),
@@ -107,7 +107,7 @@ describe('ValueInterpreterDisplay', () => {
testNumberFormatCombinations(formatData, combinationsForNumbers);
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats endianness for Float 32-bit (decimal)',
it('correctly formats endianness for Float 32-bit (decimal)',
async () => {
const formatData = {
buffer: new ArrayBuffer(4),
@@ -118,7 +118,7 @@ describe('ValueInterpreterDisplay', () => {
testNumberFormatCombinations(formatData, combinationsForNumbers);
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats endianness for Float 64-bit (decimal)',
it('correctly formats endianness for Float 64-bit (decimal)',
async () => {
const formatData = {
buffer: new ArrayBuffer(8),
@@ -129,42 +129,42 @@ describe('ValueInterpreterDisplay', () => {
testNumberFormatCombinations(formatData, combinationsForNumbers);
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats floats in decimal mode', async () => {
it('correctly formats floats in decimal mode', async () => {
const expectedFloat = 341.34;
const actualValue = LinearMemoryInspector.ValueInterpreterDisplayUtils.formatFloat(
expectedFloat, LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueTypeMode.Decimal);
assert.strictEqual(actualValue, '341.34');
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats floats in scientific mode', async () => {
it('correctly formats floats in scientific mode', async () => {
const expectedFloat = 341.34;
const actualValue = LinearMemoryInspector.ValueInterpreterDisplayUtils.formatFloat(
expectedFloat, LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueTypeMode.Scientific);
assert.strictEqual(actualValue, '3.41e+2');
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats integers in decimal mode', async () => {
it('correctly formats integers in decimal mode', async () => {
const expectedInteger = 120;
const actualValue = LinearMemoryInspector.ValueInterpreterDisplayUtils.formatInteger(
expectedInteger, LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueTypeMode.Decimal);
assert.strictEqual(actualValue, '120');
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats integers in hexadecimal mode', async () => {
it('correctly formats integers in hexadecimal mode', async () => {
const expectedInteger = 16;
const actualValue = LinearMemoryInspector.ValueInterpreterDisplayUtils.formatInteger(
expectedInteger, LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueTypeMode.Hexadecimal);
assert.strictEqual(actualValue, '10');
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats integers in octal mode', async () => {
it('correctly formats integers in octal mode', async () => {
const expectedInteger = 16;
const actualValue = LinearMemoryInspector.ValueInterpreterDisplayUtils.formatInteger(
expectedInteger, LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueTypeMode.Octal);
assert.strictEqual(actualValue, '20');
});
it('correctly LinearMemoryInspector.ValueInterpreterDisplayUtils.formats integers in octal mode', async () => {
it('correctly formats integers in octal mode', async () => {
const expectedInteger = 16;
const actualValue = LinearMemoryInspector.ValueInterpreterDisplayUtils.formatInteger(
expectedInteger, LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueTypeMode.Octal);
@@ -28,14 +28,21 @@ describe('ValueInterpreterSettings', () => {
it('renders all checkboxes', async () => {
const {component} = setUpComponent();
const checkboxes = getElementsWithinComponent(component, SETTINGS_LABEL_SELECTOR, HTMLLabelElement);
assert.lengthOf(checkboxes, Object.values(LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType).length);
const checkboxLabels = Array.from(checkboxes, checkbox => checkbox.getAttribute('title'));
assert.deepEqual(checkboxLabels, [
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Int8,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Int16,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Int32,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Int64,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Float32,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Float64,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.String,
]);
});
it('triggers an event on checkbox click', async () => {
const {component} = setUpComponent();
const labels = getElementsWithinComponent(component, SETTINGS_LABEL_SELECTOR, HTMLLabelElement);
assert.lengthOf(labels, Object.values(LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType).length);
for (const label of labels) {
const checkbox = label.querySelector(SETTINGS_INPUT_SELECTOR);
@@ -71,8 +78,15 @@ describe('ValueInterpreterSettings', () => {
assert.deepEqual(checkedTitles, expectedTitles);
const uncheckedTitles = new Set(elements.filter(n => !n.checked).map(n => n.title.innerText));
const allTypesTitle =
Object.values(LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType).map(type => `${type}`);
const allTypesTitle = [
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Int8,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Int16,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Int32,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Int64,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Float32,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.Float64,
LinearMemoryInspector.ValueInterpreterDisplayUtils.ValueType.String,
];
const expectedUncheckedTitles = new Set(allTypesTitle.filter(title => !expectedTitles.has(title)));
assert.deepEqual(uncheckedTitles, expectedUncheckedTitles);
});