diff --git a/src/staxfile/expressions.ts b/src/staxfile/expressions.ts index ace4b64..0bb5fc4 100644 --- a/src/staxfile/expressions.ts +++ b/src/staxfile/expressions.ts @@ -23,7 +23,7 @@ export default class Expressions { if (name === 'user_id') return process.getuid().toString() if (name === 'dasherize') return dasherize(args[0]) if (name === 'exists') return existsSync(args[0]).toString() - if (name === 'grep') return this.grep(args[0], args[1]).toString() + if (name === 'test') return this.test(args[0], args[1]).toString() this.staxfile.warnings.add(`Invalid template expression: ${name}`) } @@ -74,7 +74,7 @@ export default class Expressions { '${{ stax.host_services }}:/run/host-services' } - private grep(filename: string, pattern: string): boolean { + private test(filename: string, pattern: string): boolean { const content = this.read(filename, '') const regex = new RegExp(pattern) return regex.test(content) diff --git a/tests/unit/staxfile/expressions.test.js b/tests/unit/staxfile/expressions.test.js index f8cd233..12763d2 100644 --- a/tests/unit/staxfile/expressions.test.js +++ b/tests/unit/staxfile/expressions.test.js @@ -76,7 +76,7 @@ describe('Expressions', () => { expect(staxfile.warnings).toContain("Undefined reference to 'stax.undefined_key'") }) - describe('grep', () => { + describe('test', () => { let expressions let mockStaxfile @@ -96,19 +96,19 @@ describe('Expressions', () => { it('returns true when pattern is found in file', () => { mockStaxfile.location.readSync.mockImplementation(() => 'Hello, world!') - const result = expressions.evaluate('grep', ['test.txt', 'world']) + const result = expressions.evaluate('test', ['test.txt', 'world']) expect(result).toBe('true') }) it('returns false when pattern is not found in file', () => { mockStaxfile.location.readSync.mockImplementation(() => 'Hello, world!') - const result = expressions.evaluate('grep', ['test.txt', 'foo']) + const result = expressions.evaluate('test', ['test.txt', 'foo']) expect(result).toBe('false') }) it('uses default value when file cannot be read', () => { mockStaxfile.location.readSync.mockImplementation(() => { throw new Error('File not found') }) - const result = expressions.evaluate('grep', ['nonexistent.txt', 'pattern']) + const result = expressions.evaluate('test', ['nonexistent.txt', 'pattern']) expect(result).toBe('false') }) })