refactor: rename paths

This commit is contained in:
wancat committed 2024-03-07 00:50:42 +08:00
1 parent e5f5590a67
commit b5e20766a3
12 files changed
+52 -52

No files matched your search

-6
View File
@@ -1,6 +0,0 @@
export interface Command {
command: string
output: string
error: string
pwd: string
}
@@ -1,5 +1,5 @@
import { Command } from '../command.js' import { Command } from '../types.js'
import { Matcher } from './matcher.js' import { Matcher } from './Matcher.js'
export class CommandMatcher implements Matcher { export class CommandMatcher implements Matcher {
private matcher: RegExp private matcher: RegExp
@@ -7,7 +7,7 @@ export class CommandMatcher implements Matcher {
this.matcher = new RegExp(command, flags) this.matcher = new RegExp(command, flags)
} }
match(command: Partial<Command>): boolean { match(command: Command): boolean {
return !!command.command && this.matcher.test(command.command) return !!command.command && this.matcher.test(command.command)
} }
} }
@@ -1,21 +1,12 @@
/* eslint-disable max-classes-per-file */ /* eslint-disable max-classes-per-file */
import { Command } from '../command.js' import { Command, ICondition } from '../types.js'
import { PwdMatcher } from './pwdMatcher.js' import { PwdMatcher } from './PwdMatcher.js'
import { CommandMatcher } from './commandMatcher.js' import { CommandMatcher } from './CommandMatcher.js'
import { ErrorMatcher } from './errorMatcher.js' import { ErrorMatcher } from './ErrorMatcher.js'
import { Matcher } from './matcher.js' import { Matcher } from './Matcher.js'
import { OutputMatcher } from './outputMatcher.js' import { OutputMatcher } from './OutputMatcher.js'
import { OrMatcher } from './orMatcher.js' import { OrMatcher } from './OrMatcher.js'
import { NotMatcher } from './notMatcher.js' import { NotMatcher } from './NotMatcher.js'
export interface ICondition {
command?: string
output?: string
error?: string
pwd?: string
or?: ICondition[]
not?: ICondition
}
export class Condition { export class Condition {
private matchers: Matcher[] = [] private matchers: Matcher[] = []
@@ -32,7 +23,7 @@ export class Condition {
this.matchers.push(new ErrorMatcher(error)) // always check unexpected error this.matchers.push(new ErrorMatcher(error)) // always check unexpected error
} }
match(command: Partial<Command>): boolean { match(command: Command): boolean {
return this.matchers.every((matcher) => { return this.matchers.every((matcher) => {
return matcher.match(command) return matcher.match(command)
}) })
@@ -1,5 +1,5 @@
import { Matcher } from './matcher.js' import { Matcher } from './Matcher.js'
import { Command } from '../command.js' import { Command } from '../types.js'
export class ErrorMatcher implements Matcher { export class ErrorMatcher implements Matcher {
private matcher?: RegExp private matcher?: RegExp
@@ -9,7 +9,7 @@ export class ErrorMatcher implements Matcher {
} }
} }
match(command: Partial<Command>): boolean { match(command: Command): boolean {
if (!this.matcher) { if (!this.matcher) {
return !command.error return !command.error
} }
+5
View File
@@ -0,0 +1,5 @@
import { Command } from '../types.js'
export interface Matcher {
match(command: Command): boolean
}
@@ -1,10 +1,10 @@
import { Command } from '../command.js' import { Command } from '../types.js'
import { Matcher } from './matcher.js' import { Matcher } from './Matcher.js'
export class NotMatcher implements Matcher { export class NotMatcher implements Matcher {
constructor(private condition: Matcher) {} constructor(private condition: Matcher) {}
match(command: Partial<Command>): boolean { match(command: Command): boolean {
return !this.condition.match(command) return !this.condition.match(command)
} }
} }
@@ -1,10 +1,10 @@
import { Command } from '../command.js' import { Command } from '../types.js'
import { Matcher } from './matcher.js' import { Matcher } from './Matcher.js'
export class OrMatcher implements Matcher { export class OrMatcher implements Matcher {
constructor(private conditions: Matcher[]) {} constructor(private conditions: Matcher[]) {}
match(command: Partial<Command>): boolean { match(command: Command): boolean {
return this.conditions.some((condition) => condition.match(command)) return this.conditions.some((condition) => condition.match(command))
} }
} }
@@ -1,5 +1,5 @@
import { Command } from '../command.js' import { Command } from '../types.js'
import { Matcher } from './matcher.js' import { Matcher } from './Matcher.js'
export class OutputMatcher implements Matcher { export class OutputMatcher implements Matcher {
private matcher: RegExp private matcher: RegExp
@@ -7,7 +7,7 @@ export class OutputMatcher implements Matcher {
this.matcher = new RegExp(pattern, args) this.matcher = new RegExp(pattern, args)
} }
match(command: Partial<Command>): boolean { match(command: Command): boolean {
return !!command.output && this.matcher.test(command.output.trim()) return !!command.output && this.matcher.test(command.output.trim())
} }
} }
@@ -1,10 +1,10 @@
import { Command } from '../command.js' import { Command } from '../types.js'
import { Matcher } from './matcher.js' import { Matcher } from './Matcher.js'
export class PwdMatcher implements Matcher { export class PwdMatcher implements Matcher {
constructor(private pwd: string) {} constructor(private pwd: string) {}
match(command: Partial<Command>): boolean { match(command: Command): boolean {
return command.pwd === this.pwd return command.pwd === this.pwd
} }
} }
-5
View File
@@ -1,5 +0,0 @@
import { Command } from '../command.js'
export interface Matcher {
match(command: Partial<Command>): boolean
}
+15
View File
@@ -0,0 +1,15 @@
export interface Command {
command?: string
output?: string
error?: string
pwd?: string
}
export interface ICondition {
command?: string
output?: string
error?: string
pwd?: string
or?: ICondition[]
not?: ICondition
}
+5 -5
View File
@@ -1,9 +1,9 @@
import { test, expect } from '@jest/globals' import { test, expect } from '@jest/globals'
import { Condition } from '../src/condition/condition' import { Condition } from '../src/condition/Condition'
import { OutputMatcher } from '../src/condition/outputMatcher' import { OutputMatcher } from '../src/condition/OutputMatcher'
import { PwdMatcher } from '../src/condition/pwdMatcher' import { PwdMatcher } from '../src/condition/PwdMatcher'
import { CommandMatcher } from '../src/condition/commandMatcher' import { CommandMatcher } from '../src/condition/CommandMatcher'
import { ErrorMatcher } from '../src/condition/errorMatcher.js' import { ErrorMatcher } from '../src/condition/ErrorMatcher.js'
test('command match', () => { test('command match', () => {
const matcher = new CommandMatcher('^echo start$') const matcher = new CommandMatcher('^echo start$')