Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Sep 12, 2021
1 parent 9a76fbb commit e815635
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 37 deletions.
15 changes: 1 addition & 14 deletions src/combination/dimensions.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
import { getInputIds } from './inputs.js'

// Combination identifiers create a new combination dimension:
// tasks, systems, variations, runners.
// They:
// - can be used in `select`, `limit`, etc.
// - are checked for duplicates
// As opposed to non-combination identifiers: inputs.
// The order is significant as it defines:
// - The sorting order of combinations in reporters
// - The order of dimensions when printing combinationName in reporters,
Expand All @@ -31,20 +28,10 @@ export const COMBINATION_DIMENSIONS = [
},
]

export const N_COMBINATION_DIMENSIONS = [
{
dimension: 'input',
getIds: getInputIds,
createdByUser: true,
},
]

// Dimensions created by users, not by plugins
const getUserDimensions = function () {
return new Set(
[...COMBINATION_DIMENSIONS, ...N_COMBINATION_DIMENSIONS]
.filter(isUserDimension)
.map(getDimensionName),
COMBINATION_DIMENSIONS.filter(isUserDimension).map(getDimensionName),
)
}

Expand Down
45 changes: 24 additions & 21 deletions src/combination/ids.js
Original file line number Diff line number Diff line change
@@ -1,22 +1,7 @@
import { titleColor, noteColor } from '../report/utils/colors.js'

import {
COMBINATION_DIMENSIONS,
N_COMBINATION_DIMENSIONS,
USER_DIMENSIONS,
} from './dimensions.js'

// Retrieve user-defined identifiers
export const getUserIds = function (combinations, inputs) {
const combinationsIds = getCombinationsIds(combinations)
const nonCombinationIds = getNonCombinationsIds(inputs)
const userIds = [...combinationsIds, ...nonCombinationIds].filter(isUserId)
return userIds
}

const isUserId = function ({ dimension }) {
return USER_DIMENSIONS.has(dimension)
}
import { COMBINATION_DIMENSIONS, USER_DIMENSIONS } from './dimensions.js'
import { getInputIds } from './inputs.js'

export const isSameDimension = function (combinationA, combinationB) {
return COMBINATION_DIMENSIONS.every(
Expand Down Expand Up @@ -70,13 +55,31 @@ const isNotSameDimDuplicate = function ({ dimension, id }, index, idInfos) {
.some((idInfo) => idInfo.dimension === dimension && idInfo.id === id)
}

// Retrieve non-combination identifiers.
// Retrieve user-defined identifiers
export const getUserIds = function (combinations, inputs) {
const combinationsUserIds = getCombinationsIds(combinations).filter(isUserId)
const nonCombinationsIds = getNonCombinationsIds(inputs)
return [...combinationsUserIds, ...nonCombinationsIds]
}

const isUserId = function ({ dimension }) {
return USER_DIMENSIONS.has(dimension)
}

// Identifiers that do not relate to dimensions/combinations
const getNonCombinationsIds = function (inputs) {
return N_COMBINATION_DIMENSIONS.flatMap(
getNonCombinationIds.bind(undefined, inputs),
return NON_COMBINATION_IDS.flatMap(({ dimension, getIds }) =>
listNonCombinationIds(dimension, getIds, inputs),
)
}

const getNonCombinationIds = function (inputs, { dimension, getIds }) {
const NON_COMBINATION_IDS = [
{
dimension: 'input',
getIds: getInputIds,
},
]

const listNonCombinationIds = function (dimension, getIds, inputs) {
return getIds(inputs).map((id) => ({ dimension, id }))
}
4 changes: 2 additions & 2 deletions src/combination/list/validate_ids.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import { getUserIds, getCombinationsIds } from '../ids.js'
// Validate combination identifiers.
export const validateCombinationsIds = function (combinations, inputs) {
const userIds = getUserIds(combinations, inputs)
userIds.forEach(validateDimensionIds)
userIds.forEach(validateUserIds)

const combinationsIds = getCombinationsIds(combinations)
combinationsIds.forEach(validateDuplicateId)
Expand All @@ -13,7 +13,7 @@ export const validateCombinationsIds = function (combinations, inputs) {
// Validate that identifiers don't use characters that we are using for parsing
// or could use in the future.
// Only for user-defined identifiers, not plugin-defined.
const validateDimensionIds = function ({ dimension, id }) {
const validateUserIds = function ({ dimension, id }) {
if (id.trim() === '') {
throw new UserError(
`Invalid ${dimension} "${id}": the identifier must not be empty.`,
Expand Down

0 comments on commit e815635

Please sign in to comment.