mirror of
https://github.com/linux-odyssey/linux-odyssey.git
synced 2026-11-08 11:30:12 +08:00
feat: create pattern and command matcher
This commit is contained in:
1 parent
a8a19ca902
commit
3b4a808131
5 files changed
+92
No files matched your search
@@ -0,0 +1,43 @@
|
||||
import { test, expect } from '@jest/globals'
|
||||
import { PatternMatcher, CommandMatcher, ErrorMatcher } from '../src/condition'
|
||||
import { Command } from '../src/command'
|
||||
|
||||
test('pattern match', () => {
|
||||
const matcher = new PatternMatcher('^echo start$')
|
||||
|
||||
expect(matcher.test('echo start')).toBe(true)
|
||||
expect(matcher.test('echo start ')).toBe(false)
|
||||
})
|
||||
|
||||
test('pattern match with flag', () => {
|
||||
const matcher = new PatternMatcher('^echo start$', 'i')
|
||||
|
||||
expect(matcher.test('echo start')).toBe(true)
|
||||
expect(matcher.test('echo Start')).toBe(true)
|
||||
expect(matcher.test('echo Start ')).toBe(false)
|
||||
})
|
||||
|
||||
test('empty pattern return true', () => {
|
||||
const matcher = new PatternMatcher('')
|
||||
expect(matcher.test('echo start')).toBe(true)
|
||||
})
|
||||
|
||||
test('empty error return false', () => {
|
||||
const matcher = new ErrorMatcher()
|
||||
expect(matcher.match({ error: '' })).toBe(true)
|
||||
expect(matcher.match({ error: 'permission denied' })).toBe(false)
|
||||
})
|
||||
|
||||
test('command match', () => {
|
||||
const command: Command = {
|
||||
command: 'echo start',
|
||||
output: 'start',
|
||||
error: '',
|
||||
pwd: '/home/user',
|
||||
}
|
||||
|
||||
const matcher = new CommandMatcher('^echo start$', 'i')
|
||||
expect(matcher.match(command)).toBe(true)
|
||||
})
|
||||
|
||||
test('condition match', () => {})
|
||||
Reference in new issue
Block a user