| // Copyright 2025 The Fuchsia Authors. All rights reserved. | |
| // Use of this source code is governed by a BSD-style license that can be | |
| // found in the LICENSE file. | |
| export class FuchsiaTestData { | |
| constructor( | |
| readonly label: string, | |
| readonly name: string, | |
| readonly os: string, | |
| ) { } | |
| get prettyName(): string { | |
| let prettyName = this.name; | |
| const result = /^([^_:]+)_[^/:]+\/(.+)/.exec(prettyName); | |
| if (result) { | |
| const targetName = result[1]; | |
| const testName = result[2]; | |
| return `<${targetName}> · ${testName}`; | |
| } | |
| const FUCHSIA_PKG_PREFIX = 'fuchsia-pkg://fuchsia.com/'; | |
| if (prettyName.startsWith(FUCHSIA_PKG_PREFIX)) { | |
| prettyName = prettyName.slice(FUCHSIA_PKG_PREFIX.length); | |
| } | |
| prettyName = prettyName.replace('#meta/', ' · '); | |
| const CM_SUFFIX = '.cm'; | |
| if (prettyName.endsWith(CM_SUFFIX)) { | |
| prettyName = prettyName.slice(0, -CM_SUFFIX.length); | |
| } | |
| return prettyName; | |
| } | |
| get relativePath(): string | null { | |
| const relativePath = this.label; | |
| const result = /^\/\/([^(:]+)(?::[^(]+)?(?:\([^)]+\))?$/.exec(relativePath); | |
| if (result) { | |
| return `${result[1]}/BUILD.gn`; | |
| } | |
| return null; | |
| } | |
| static fromJSON(object: unknown): FuchsiaTestData | null { | |
| if (typeof object !== 'object' || object === null || Array.isArray(object)) { | |
| return null; | |
| } | |
| const obj = object as Record<string, unknown>; | |
| const label = obj.label; | |
| if (typeof label !== 'string') { | |
| return null; | |
| } | |
| const name = obj.name; | |
| if (typeof name !== 'string') { | |
| return null; | |
| } | |
| const os = obj.os; | |
| if (typeof os !== 'string') { | |
| return null; | |
| } | |
| return new FuchsiaTestData(label, name, os); | |
| } | |
| } |